Sotaro KARASAWA 9 лет назад
Родитель
Сommit
932215a7c8
5 измененных файлов с 59 добавлено и 1 удалено
  1. 4 0
      lib/models/page.js
  2. 1 0
      lib/routes/index.js
  3. 20 1
      lib/routes/page.js
  4. 31 0
      lib/views/modal/widget_delete.html
  5. 3 0
      lib/views/page.html

+ 4 - 0
lib/models/page.js

@@ -772,6 +772,10 @@ module.exports = function(crowi) {
     });
   };
 
+  pageSchema.statics.deletePage = function(pageData, options) {
+    var Page = this,
+  };
+
   pageSchema.statics.getHistories = function() {
     // TODO
     return;

+ 1 - 0
lib/routes/index.js

@@ -98,6 +98,7 @@ module.exports = function(crowi, app) {
   app.get('/_api/pages.updatePost'    , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.getUpdatePost);
   app.post('/_api/pages.seen'         , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.seen);
   app.post('/_api/pages.rename'       , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.rename);
+  app.post('/_api/pages.remove'       , loginRequired(crowi, app) , page.api.remove); // (Avoid from API Token)
   app.get('/_api/comments.get'        , accessTokenParser(crowi, app) , loginRequired(crowi, app) , comment.api.get);
   app.post('/_api/comments.add'       , form.comment, accessTokenParser(crowi, app) , loginRequired(crowi, app) , comment.api.add);
   app.get( '/_api/bookmarks.get'      , accessTokenParser(crowi, app) , loginRequired(crowi, app) , bookmark.api.get);

+ 20 - 1
lib/routes/page.js

@@ -581,9 +581,28 @@ module.exports = function(crowi, app) {
     });
   };
 
+  /**
+   * @api {post} /pages.remove Remove page
+   * @apiName RemovePage
+   * @apiGroup Page
+   *
+   * @apiParam {String} page_id Page Id.
+   * @apiParam {String} revision_id
+   */
+  api.remove = function(req, res){
+    var pageId = req.body.page_id;
+    var previousRevision = req.body.revision_id || null;
+
+    Page.findPageByIdAndGrantedUser(id, req.user)
+    .then(function(pageData) {
+      return Page.removePage(pageData);
+    }).then(function(data) {
+    });
+  };
+
   /**
    * @api {post} /pages.rename Rename page
-   * @apiName SeenPage
+   * @apiName RenamePage
    * @apiGroup Page
    *
    * @apiParam {String} page_id Page Id.

+ 31 - 0
lib/views/modal/widget_delete.html

@@ -0,0 +1,31 @@
+  <div class="modal fade" id="deletePage">
+    <div class="modal-dialog">
+      <div class="modal-content">
+
+      <form role="form" id="deletePageForm" onsubmit="return false;">
+
+        <div class="modal-header">
+          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+          <h4 class="modal-title">Delete Page</h4>
+        </div>
+        <div class="modal-body">
+          <ul>
+           <li>You can’t undo this action.</li>
+          </ul>
+            <div class="form-group">
+              <label for="">This page:</label><br>
+              <code>{{ page.path }}</code>
+            </div>
+        </div>
+        <div class="modal-footer">
+          <p><small class="pull-left" id="newPageNameCheck"></small></p>
+          <input type="hidden" name="path" value="{{ page.path }}">
+          <input type="hidden" name="page_id" value="{{ page._id.toString() }}">
+          <input type="hidden" name="revision_id" value="{{ page.revision._id.toString() }}">
+          <input type="submit" class="btn btn-danger" value="Delete!">
+        </div>
+
+      </form>
+      </div><!-- /.modal-content -->
+    </div><!-- /.modal-dialog -->
+  </div><!-- /.modal -->

+ 3 - 0
lib/views/page.html

@@ -76,6 +76,8 @@
       <ul class="dropdown-menu">
        <li><a href="#" data-target="#renamePage" data-toggle="modal"><i class="fa fa-share"></i> 移動</a></li>
        <li><a href="?presentation=1" class="toggle-presentation"><i class="fa fa-arrows-alt"></i> プレゼンモード (beta)</a></li>
+       <li class="divider"></li>
+       <li class=""><a href="#" data-target="#deletePage" data-toggle="modal"><i class="fa fa-remove text-danger"></i> 削除</a></li>
       </ul>
     </li>
     {% if page %}
@@ -84,6 +86,7 @@
   </ul>
 
   {% include 'modal/widget_rename.html' %}
+  {% include 'modal/widget_delete.html' %}
 
   <div class="tab-content wiki-content">
   {% if req.query.renamed %}