浏览代码

部分ajax接口移到server目录

star7th 8 年之前
父节点
当前提交
6f5848ea27

+ 0 - 20
Application/Home/Controller/ItemController.class.php

@@ -5,30 +5,10 @@ class ItemController extends BaseController {
     //项目列表页
     public function index(){
         $login_user = $this->checkLogin();        
-        $items  = D("Item")->where("uid = '$login_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$login_user[uid]' ) ")->select();
-        //读取需要置顶的项目
-        $top_items = D("ItemTop")->where("uid = '$login_user[uid]'")->select();
-        if ($top_items) {
-            $top_item_ids = array() ;
-            foreach ($top_items as $key => $value) {
-                $top_item_ids[] = $value['item_id'];
-            }
-            foreach ($items as $key => $value) {
-                $items[$key]['top'] = 0 ;
-                if (in_array($value['item_id'], $top_item_ids) ) {
-                    $items[$key]['top'] = 1 ;
-                    $tmp = $items[$key] ;
-                    unset($items[$key]);
-                    array_unshift($items,$tmp) ;
-                }
-            }
 
-            $items = array_values($items);
-        }
         
         $share_url = get_domain().__APP__.'/uid/'.$login_user['uid'];
 
-        $this->assign("items" , $items);
         $this->assign("login_user" , $login_user);
     	$this->assign("share_url" , $share_url);
         $this->display();

+ 1 - 1
Application/Home/View/Common/header.html

@@ -18,6 +18,6 @@
 
       DocConfig.hostUrl = DocConfig.host + "/" + DocConfig.app;
       </script>
-      <script src="__PUBLIC__/js/lang.{:LANG_SET}.js?v=21"></script>
+      <script src="__PUBLIC__/js/lang.{:LANG_SET}.js?v=212"></script>
   </head>
   <body>

+ 2 - 24
Application/Home/View/Item/index.html

@@ -27,30 +27,8 @@
       <hr>
 
     <div class="container-thumbnails">
-      <ul class="thumbnails">
+      <ul class="thumbnails" id="item-list">
 
-        <foreach name="items" item="item">
-          <li class="span3 text-center">
-            <a class="thumbnail item-thumbnail" href="{:U('Home/Item/show',array('item_id'=>$item['item_id']))}" title="{$item.item_description}">
-              <span class="item-setting" data-src="{:U('/home/item/setting',array('item_id'=>$item[item_id]))}"  title="项目设置">
-                <i class="icon-wrench" ></i>
-              </span>
-
-              <if condition="$item['top']">
-                  <span class="item-top" data-action="cancel" data-item_id="{$item.item_id}" title="取消置顶"><i class="icon-arrow-down" ></i></span>
-              <else />
-                  <span class="item-top" data-action="top" data-item_id="{$item.item_id}" title="置顶项目"><i class="icon-arrow-up"  ></i></span>
-              </if>
-              <p class="my-item">{$item.item_name}</p>
-            </a>
-          </li>     
-        </foreach>
-
-        <li class="span3 text-center">
-          <a class="thumbnail " href="{:U('Home/Item/add')}" title="{$Think.Lang.add_an_item}添加一个新项目">
-            <p class="my-item ">{$Think.Lang.new_item}&nbsp;<i class="icon-plus"></i></p>
-          </a>
-        </li>
       </ul>
     </div>
 
@@ -71,4 +49,4 @@
 
 
  <include file="Common/footer" />
- <script src="__PUBLIC__/js/item/index.js?v=1"></script>
+ <script src="__PUBLIC__/js/item/index.js?v=12"></script>

+ 95 - 47
Public/js/item/index.js

@@ -1,53 +1,101 @@
 
-//当鼠标放在项目上时将浮现设置和置顶图标
-$(".item-thumbnail").mouseover(function(){
-  $(this).find(".item-setting").show();
-  $(this).find(".item-top").show();
-  $(this).find(".item-down").show();
+layer_index = layer.load(1, {
+  shade: [0.1, '#fff'] //0.1透明度的白色背景
 });
+$.get(
+  DocConfig.server+"/api/item/myList",
+  {},
+  function(data){
+    var html = '';
+    if (data.error_code == 0) {
+        console.log(data.data);
+        var json = data.data;
+        for (var i = 0; i < json.length; i++) {
+             html += '<li class="span3 text-center">' ;
+             html += '<a class="thumbnail item-thumbnail" href="?s=home/item/show&item_id='+json[i]['item_id']+'" title="'+json[i]['item_description']+'">';
+             html +=  '<span class="item-setting" data-src="?s=home/item/setting&item_id='+json[i]['item_id']+'"  title="项目设置">';
+             html +=  '<i class="icon-wrench" ></i>';
+             html +=  '</span>';
+             if (json[i]['top'] > 0 ) {
+                html +=  '<span class="item-top" data-action="cancel" data-item_id="'+json[i]['item_id']+'" title="取消置顶"><i class="icon-arrow-down" ></i></span>';
+             }else{
+                html +=  '<span class="item-top" data-action="top" data-item_id="'+json[i]['item_id']+'" title="置顶项目"><i class="icon-arrow-up"  ></i></span>';
+             }
+             html +=  '<p class="my-item">'+json[i]['item_name']+'</p>';
+             html +=  '</a>';
+             html +=  '</li> ';
+        };
+        html +=  '<li class="span3 text-center" >';
+        html +=  '<a class="thumbnail" href="?s=home/item/add" title="'+lang["add_an_item"]+'">';
+        html +=  '<p class="my-item ">'+lang["new_item"]+'&nbsp;<i class="icon-plus"></i></p>';
+        html +=  '</a></li>';
+        $("#item-list").html(html);
+        $("#add-item").show();
+        layer.closeAll();
+        bind_events();
+    } else {
+      $.alert(lang["save_fail"]);
 
-//当鼠标离开项目上时将隐藏设置和置顶图标
-$(".item-thumbnail").mouseout(function(){
-  $(this).find(".item-setting").hide();
-  $(this).find(".item-top").hide();
-  $(this).find(".item-down").hide();
-});
+    }
+  },
+  "json"
 
-//点击项目设置图标时
-$(".item-setting").click(function(){
-  var url = $(this).data("src");
-  window.location.href = url ;
-  return false;
-});
+  );
 
-//点击项目置顶图标时
-$(".item-top").click(function(){
-
-  var action = $(this).data("action");
-  var item_id = $(this).data("item_id");
-  $.post(
-    DocConfig.server+"/api/item/top",
-    {"action":action,"item_id":item_id},
-    function(data){
-      window.location.reload();
-    },
-    "json"
-    );
-  return false;
-});
 
-//点击取消置顶图标时
-$(".item-down").click(function(){
-
-  var action = 'cancel';
-  var item_id = $(this).data("item_id");
-  $.post(
-    DocConfig.server+"/api/item/top",
-    {"action":action,"item_id":item_id},
-    function(data){
-      window.location.reload();
-    },
-    "json"
-    );
-  return false;
-});
+function bind_events(){
+
+  //当鼠标放在项目上时将浮现设置和置顶图标
+  $(".item-thumbnail").mouseover(function(){
+    $(this).find(".item-setting").show();
+    $(this).find(".item-top").show();
+    $(this).find(".item-down").show();
+  });
+
+  //当鼠标离开项目上时将隐藏设置和置顶图标
+  $(".item-thumbnail").mouseout(function(){
+    $(this).find(".item-setting").hide();
+    $(this).find(".item-top").hide();
+    $(this).find(".item-down").hide();
+  });
+
+  //点击项目设置图标时
+  $(".item-setting").click(function(){
+    var url = $(this).data("src");
+    window.location.href = url ;
+    return false;
+  });
+
+  //点击项目置顶图标时
+  $(".item-top").click(function(){
+
+    var action = $(this).data("action");
+    var item_id = $(this).data("item_id");
+    $.post(
+      DocConfig.server+"/api/item/top",
+      {"action":action,"item_id":item_id},
+      function(data){
+        window.location.reload();
+      },
+      "json"
+      );
+    return false;
+  });
+
+  //点击取消置顶图标时
+  $(".item-down").click(function(){
+
+    var action = 'cancel';
+    var item_id = $(this).data("item_id");
+    $.post(
+      DocConfig.server+"/api/item/top",
+      {"action":action,"item_id":item_id},
+      function(data){
+        window.location.reload();
+      },
+      "json"
+      );
+    return false;
+  });
+
+}

+ 2 - 1
Public/js/lang.en-us.js

@@ -14,7 +14,8 @@ lang["delete_fail"] = "Delete fail";
 
 //item
 lang["back_to_top"] = "Back to top";
-
+lang["new_item"] = "New item";
+lang["add_an_item"] = "add an item";
 
 //page/edite
 lang["params"] = "Params";

+ 2 - 1
Public/js/lang.zh-cn.js

@@ -14,7 +14,8 @@ lang["delete_fail"] = "删除失败!";
 
 //item
 lang["back_to_top"] = "回到顶部";
-
+lang["new_item"] = "新建项目";
+lang["add_an_item"] = "新建一个新的项目";
 
 //page/edite
 lang["params"] = "参数名";

+ 29 - 0
server/Application/Api/Controller/ItemController.class.php

@@ -2,6 +2,35 @@
 namespace Api\Controller;
 use Think\Controller;
 class ItemController extends BaseController {
+    
+    //我的项目列表
+    public function myList(){
+        $login_user = $this->checkLogin();        
+        $items  = D("Item")->field("item_id,item_name,last_update_time,item_description")->where("uid = '$login_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$login_user[uid]' ) ")->order("item_id asc")->select();
+        //读取需要置顶的项目
+        $top_items = D("ItemTop")->where("uid = '$login_user[uid]'")->select();
+        if ($top_items) {
+            $top_item_ids = array() ;
+            foreach ($top_items as $key => $value) {
+                $top_item_ids[] = $value['item_id'];
+            }
+            foreach ($items as $key => $value) {
+                $items[$key]['top'] = 0 ;
+                if (in_array($value['item_id'], $top_item_ids) ) {
+                    $items[$key]['top'] = 1 ;
+                    $tmp = $items[$key] ;
+                    unset($items[$key]);
+                    array_unshift($items,$tmp) ;
+                }
+            }
+
+            $items = array_values($items);
+        }
+
+        $items = $items ? $items : array();
+        $this->sendResult($items);
+
+    }
 
     //项目详情
     public function detail(){