فهرست منبع

部分ajax接口移到server目录

star7th 8 سال پیش
والد
کامیت
27ccad98d3

+ 1 - 90
Application/Home/Controller/ItemController.class.php

@@ -40,89 +40,7 @@ class ItemController extends BaseController {
     //新建项目
     public function add(){
         $login_user = $this->checkLogin();
-        $item_id = I("item_id/d");
-        if (!IS_POST) {
-          $item = D("Item")->where("item_id = '$item_id' ")->find();
-          $this->assign("item" , $item);
-          $this->display ();
-
-        }else{
-            $item_name = I("item_name");
-            $item_domain = I("item_domain") ? I("item_domain") : '';
-            $copy_item_id = I("copy_item_id");
-            $password = I("password");
-            $item_description = I("item_description");
-            $item_type = I("item_type");
-
-            if ($item_domain) {
-                $item = D("Item")->where("item_domain = '%s' and item_id !='%s' ",array($item_domain,$item_id))->find();
-                if ($item) {
-                    //个性域名已经存在
-                    $this->message(L('domain_already_exists'));
-                    return false;
-                }
-                if(!ctype_alnum($item_domain) ||  is_numeric($item_domain) ){
-                    //echo '个性域名只能是字母或数字的组合';exit;
-                    $this->message(L('item_domain_illegal'));
-                    return false;
-                }
-            }
-            
-            //如果是复制项目
-            if ($copy_item_id > 0) {
-                if (!$this->checkItemPermn($login_user['uid'] , $copy_item_id)) {
-                    $this->message(L('no_permissions'));
-                    return;
-                }
-                $ret = D("Item")->copy($copy_item_id,$login_user['uid'],$item_name,$item_description,$password,$item_domain);
-                if ($ret) {
-                    $this->message(L('operation_succeeded'),U('Home/Item/index'));              
-                }else{
-                    $this->message(L('operation_failed'),U('Home/Item/index'));
-                }
-                return ;
-            }
-            if ($item_id > 0 ) {
-                $data = array(
-                    "item_name" => $item_name ,
-                    "item_domain" => $item_domain ,
-                    "password" => $password ,
-                    "item_description" => $item_description ,
-                    );
-                $ret = D("Item")->where("item_id = '$item_id' ")->save($data);
-            }else{
-                $insert = array(
-                    "uid" => $login_user['uid'] ,
-                    "username" => $login_user['username'] ,
-                    "item_name" => $item_name ,
-                    "password" => $password ,
-                    "item_description" => $item_description ,
-                    "item_domain" => $item_domain ,
-                    "item_type" => $item_type ,
-                    "addtime" =>time()
-                    );
-                $item_id = D("Item")->add($insert);
-            }
-
-            if ($item_id) {
-                //如果是单页应用,则新建一个默认页
-                if ($item_type == 2 ) {
-                    $insert = array(
-                        'author_uid' => $login_user['uid'] ,
-                        'author_username' => $login_user['username'],
-                        "page_title" => $item_name ,
-                        "item_id" => $item_id ,
-                        "cat_id" => 0 ,
-                        "page_content" => '欢迎使用showdoc。点击右上方的编辑按钮进行编辑吧!' ,
-                        "addtime" =>time()
-                        );
-                    D("Page")->add($insert);
-                }
-                $this->message(L('operation_succeeded'),U('Home/Item/index'));              
-            }else{
-                $this->message(L('operation_failed'),U('Home/Item/index'));
-            }
-        }
+        $this->display ();
     }
 
     //根据项目类型展示项目
@@ -353,13 +271,6 @@ class ItemController extends BaseController {
         }
     }
 
-    public function itemList(){
-        $login_user = $this->checkLogin();        
-        $items  = D("Item")->where("uid = '$login_user[uid]' ")->select();
-        $items = $items ? $items : array();
-        $this->sendResult($items);
-    }
-
     public function setting(){
         $login_user = $this->checkLogin();
         $item_id = I("item_id/d");  

+ 26 - 5
Application/Home/View/Item/add.html

@@ -11,16 +11,15 @@
 </style>
     <div class="container">
 
-      <form class="form-signin" method="post">
-        <input type="hidden" id="item_id" name="item_id" value="{$item.item_id}">
+      <form class="form-signin myform" method="post"  action="server/index.php?s=/api/item/add">
         <!-- <h3 class="form-signin-heading">新建项目</h3> -->
         <div class="choose_type">
             <label class="radio inline">
-              <input type="radio" name="item_type" id="item_type1" value="1" <?php if(!$item['item_type'] || $item['item_type'] == 1 )echo 'checked'?> >
+              <input type="radio" name="item_type" id="item_type1" value="1" checked >
               常规项目
             </label>
             <label class="radio inline">
-              <input type="radio" name="item_type" id="item_type2" value="2" <?php if($item['item_type'] == 2 )echo 'checked'?>>
+              <input type="radio" name="item_type" id="item_type2" value="2" >
               单页项目
               &nbsp;
               <a href="https://www.showdoc.cc/page/65391" target="_blank"><i class="icon-question-sign"></i></a>
@@ -52,6 +51,7 @@
 
 
  <include file="Common/footer" />
+ <script src="__PUBLIC__/js/jquery.form.min.js"></script>
  <script type="text/javascript">
  var password = $("#password").val();
  if (password) {
@@ -90,7 +90,7 @@ $("#show_copy").change(function(){
 function get_item_list(){
     //获取已有项目列表
     $.get(
-            "?s=/home/item/itemList",
+            DocConfig.server+"/api/item/itemList",
             {},
             function(data){
              if (data.error_code === 0) {
@@ -119,4 +119,25 @@ $("#choose_item").change(function(){
     $("#password").val(password);
 
 });
+
+
+//上传表单参数
+var ajax_option = {
+  dataType:"json",
+  beforeSubmit:function(){
+
+  },
+  success:function(res){
+    if (res.error_code === 0) {
+      window.location.href = "?s=/home/item/index";
+    }else{
+      $.alert(res.error_message);
+    }
+
+    return false;
+  }
+};
+
+$('.myform').ajaxForm(ajax_option); 
+
  </script>

+ 3 - 3
server/Application/Api/Controller/CatalogController.class.php

@@ -8,7 +8,7 @@ class CatalogController extends BaseController {
         $login_user = $this->checkLogin();
         $item_id = I("item_id/d");
         if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
-            $this->sendError(10303);
+            $this->sendError(10103);
             return ;
         }
         if ($item_id > 0 ) {
@@ -28,7 +28,7 @@ class CatalogController extends BaseController {
         $login_user = $this->checkLogin();
         $item_id = I("item_id/d");
         if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
-            $this->sendError(10303);
+            $this->sendError(10103);
             return ;
         }
         if ($item_id > 0 ) {
@@ -68,7 +68,7 @@ class CatalogController extends BaseController {
 
         $login_user = $this->checkLogin();
         if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
-            $this->sendError(10303);
+            $this->sendError(10103);
             return;
         }
         //禁止空目录的生成

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

@@ -382,4 +382,86 @@ class ItemController extends BaseController {
 
     }
 
+    public function itemList(){
+        $login_user = $this->checkLogin();        
+        $items  = D("Item")->where("uid = '$login_user[uid]' ")->select();
+        $items = $items ? $items : array();
+        $this->sendResult($items);
+    }
+
+    //新建项目
+    public function add(){
+        $login_user = $this->checkLogin();
+        $item_name = I("item_name");
+        $item_domain = I("item_domain") ? I("item_domain") : '';
+        $copy_item_id = I("copy_item_id");
+        $password = I("password");
+        $item_description = I("item_description");
+        $item_type = I("item_type");
+
+        if ($item_domain) {
+            
+            if(!ctype_alnum($item_domain) ||  is_numeric($item_domain) ){
+                //echo '个性域名只能是字母或数字的组合';exit;
+                $this->sendError(10305);
+                return false;
+            }
+
+            $item = D("Item")->where("item_domain = '%s'  ",array($item_domain))->find();
+            if ($item) {
+                //个性域名已经存在
+                $this->sendError(10304);
+                return false;
+            }
+        }
+        
+        //如果是复制项目
+        if ($copy_item_id > 0) {
+            if (!$this->checkItemPermn($login_user['uid'] , $copy_item_id)) {
+                $this->sendError(10103);
+                return;
+            }
+            $ret = D("Item")->copy($copy_item_id,$login_user['uid'],$item_name,$item_description,$password,$item_domain);
+            if ($ret) {
+                $this->sendResult(array());             
+            }else{
+                $this->sendError(10101);
+            }
+            return ;
+        }
+        
+        $insert = array(
+            "uid" => $login_user['uid'] ,
+            "username" => $login_user['username'] ,
+            "item_name" => $item_name ,
+            "password" => $password ,
+            "item_description" => $item_description ,
+            "item_domain" => $item_domain ,
+            "item_type" => $item_type ,
+            "addtime" =>time()
+            );
+        $item_id = D("Item")->add($insert);
+
+        if ($item_id) {
+            //如果是单页应用,则新建一个默认页
+            if ($item_type == 2 ) {
+                $insert = array(
+                    'author_uid' => $login_user['uid'] ,
+                    'author_username' => $login_user['username'],
+                    "page_title" => $item_name ,
+                    "item_id" => $item_id ,
+                    "cat_id" => 0 ,
+                    "page_content" => '欢迎使用showdoc。点击右上方的编辑按钮进行编辑吧!' ,
+                    "addtime" =>time()
+                    );
+                $page_id = D("Page")->add($insert);
+            }
+            $this->sendResult(array());               
+        }else{
+            $this->sendError(10101);
+        }
+        
+    }
+
+
 }

+ 2 - 2
server/Application/Api/Controller/PageController.class.php

@@ -9,7 +9,7 @@ class PageController extends BaseController {
         $page = D("Page")->where(" page_id = '$page_id' ")->find();
         $login_user = $this->checkLogin(false);
         if (!$this->checkItemVisit($login_user['uid'] , $page['item_id'])) {
-            $this->sendError(10303);
+            $this->sendError(10103);
             return;
         }
         $page = $page ? $page : array();
@@ -57,7 +57,7 @@ class PageController extends BaseController {
 
         $login_user = $this->checkLogin();
         if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
-            $this->sendError(10303);
+            $this->sendError(10103);
             return;
         }