Sotaro KARASAWA 10 лет назад
Родитель
Сommit
bb8c71cd88
8 измененных файлов с 128 добавлено и 125 удалено
  1. 14 5
      lib/models/page.js
  2. 1 0
      lib/routes/index.js
  3. 5 2
      lib/routes/page.js
  4. 6 2
      lib/views/_form.html
  5. 0 5
      lib/views/page.html
  6. 89 103
      lib/views/page_list.html
  7. 8 8
      resource/css/_form.scss
  8. 5 0
      resource/js/crowi.js

+ 14 - 5
lib/models/page.js

@@ -10,6 +10,14 @@ module.exports = function(crowi) {
     , USER_PUBLIC_FIELDS = '_id fbId image googleId name username email status createdAt' // TODO: どこか別の場所へ...
     , USER_PUBLIC_FIELDS = '_id fbId image googleId name username email status createdAt' // TODO: どこか別の場所へ...
     , pageSchema;
     , pageSchema;
 
 
+  function isPortalPath(path) {
+    if (path.match(/.+\/$/)) {
+      return true;
+    }
+
+    return false;
+  }
+
   function populatePageData(pageData, revisionId) {
   function populatePageData(pageData, revisionId) {
     var Page = crowi.model('Page');
     var Page = crowi.model('Page');
 
 
@@ -61,11 +69,7 @@ module.exports = function(crowi) {
   };
   };
 
 
   pageSchema.methods.isPortal = function() {
   pageSchema.methods.isPortal = function() {
-    if (this.path.match(/.+\/$/)) {
-      return true;
-    }
-
-    return false;
+    return isPortalPath(this.path);
   };
   };
 
 
   pageSchema.methods.isCreator = function(userData) {
   pageSchema.methods.isCreator = function(userData) {
@@ -473,6 +477,11 @@ module.exports = function(crowi) {
       , grant = options.grant || GRANT_PUBLIC
       , grant = options.grant || GRANT_PUBLIC
       , redirectTo = options.redirectTo || null;
       , redirectTo = options.redirectTo || null;
 
 
+    // force public
+    if (isPortalPath(path)) {
+      grant = GRANT_PUBLIC;
+    }
+
     return new Promise(function(resolve, reject) {
     return new Promise(function(resolve, reject) {
       Page.findOne({path: path}, function(err, pageData) {
       Page.findOne({path: path}, function(err, pageData) {
         if (pageData) {
         if (pageData) {

+ 1 - 0
lib/routes/index.js

@@ -80,6 +80,7 @@ module.exports = function(crowi, app) {
   app.post('/_api/comments.add'       , form.comment, accessTokenParser(crowi, app) , loginRequired(crowi, app) , comment.api.add);
   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);
   app.get( '/_api/bookmarks.get'      , accessTokenParser(crowi, app) , loginRequired(crowi, app) , bookmark.api.get);
   app.post('/_api/bookmarks.add'      , accessTokenParser(crowi, app) , loginRequired(crowi, app) , bookmark.api.add);
   app.post('/_api/bookmarks.add'      , accessTokenParser(crowi, app) , loginRequired(crowi, app) , bookmark.api.add);
+  app.post('/_api/bookmarks.remove'   , accessTokenParser(crowi, app) , loginRequired(crowi, app) , bookmark.api.remove);
   app.post('/_api/likes.add'          , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.like);
   app.post('/_api/likes.add'          , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.like);
   app.post('/_api/likes.remove'       , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.unlike);
   app.post('/_api/likes.remove'       , accessTokenParser(crowi, app) , loginRequired(crowi, app) , page.api.unlike);
 
 

+ 5 - 2
lib/routes/page.js

@@ -150,6 +150,9 @@ module.exports = function(crowi, app) {
 
 
     var redirectPath = encodeURI(path);
     var redirectPath = encodeURI(path);
 
 
+    // set to render
+    res.locals.pageForm = pageForm;
+
     if (!Page.isCreatableName(path)) {
     if (!Page.isCreatableName(path)) {
       res.redirect(redirectPath);
       res.redirect(redirectPath);
       return ;
       return ;
@@ -160,13 +163,13 @@ module.exports = function(crowi, app) {
     .then(function(pageData) {
     .then(function(pageData) {
       if (!req.form.isValid) {
       if (!req.form.isValid) {
         renderPage(pageData, req, res);
         renderPage(pageData, req, res);
-        return;
+        return Promise.reject(new Error('form error'));
       }
       }
 
 
       if (pageData && !pageData.isUpdatable(currentRevision)) {
       if (pageData && !pageData.isUpdatable(currentRevision)) {
         req.form.errors.push('すでに他の人がこのページを編集していたため保存できませんでした。ページを再読み込み後、自分の編集箇所のみ再度編集してください。');
         req.form.errors.push('すでに他の人がこのページを編集していたため保存できませんでした。ページを再読み込み後、自分の編集箇所のみ再度編集してください。');
         renderPage(pageData, req, res);
         renderPage(pageData, req, res);
-        return;
+        return Promise.reject(new Error('form error'));
       }
       }
 
 
       if (pageData) {
       if (pageData) {

+ 6 - 2
lib/views/_form.html

@@ -10,10 +10,10 @@
 {% endif %}
 {% endif %}
 <div id="form-box" class="row">
 <div id="form-box" class="row">
   <form action="/_/edit" id="page-form" method="post" class="col-md-6 {% if isUploadable() %}uploadable{% endif %}">
   <form action="/_/edit" id="page-form" method="post" class="col-md-6 {% if isUploadable() %}uploadable{% endif %}">
-    <textarea name="pageForm[body]" class="form-control" id="form-body">{% if pageForm.body %}{{ pageForm.body }}{% elseif not revision.body %}# {{ path|path2name }}{% else %}{{ revision.body }}{% endif %}</textarea>
+    <textarea name="pageForm[body]" class="form-control" id="form-body">{% if pageForm.body %}{{ pageForm.body }}{% elseif not page.revision.body %}# {{ path|path2name }}{% else %}{{ page.revision.body }}{% endif %}</textarea>
 
 
     <input type="hidden" name="pageForm[path]" value="{{ path }}">
     <input type="hidden" name="pageForm[path]" value="{{ path }}">
-    <input type="hidden" name="pageForm[currentRevision]" value="{{ pageForm.currentRevision|default(revision._id.toString()) }}">
+    <input type="hidden" name="pageForm[currentRevision]" value="{{ pageForm.currentRevision|default(page.revision._id.toString()) }}">
     <div class="form-submit-group form-group form-inline">
     <div class="form-submit-group form-group form-inline">
       {#<button class="btn btn-default">
       {#<button class="btn btn-default">
         <i class="fa fa-file-text"></i>
         <i class="fa fa-file-text"></i>
@@ -21,11 +21,15 @@
       </button>#}
       </button>#}
 
 
       <div class="pull-right form-inline">
       <div class="pull-right form-inline">
+        {% if forceGrant %}
+        <input type="hidden" name="pageForm[grant]" value="forceGrant">
+        {% else %}
         <select name="pageForm[grant]" class="form-control">
         <select name="pageForm[grant]" class="form-control">
           {% for grantId, grantLabel in consts.pageGrants %}
           {% for grantId, grantLabel in consts.pageGrants %}
           <option value="{{ grantId }}" {% if pageForm.grant|default(page.grant) == grantId %}selected{% endif %}>{{ grantLabel }}</option>
           <option value="{{ grantId }}" {% if pageForm.grant|default(page.grant) == grantId %}selected{% endif %}>{{ grantLabel }}</option>
           {% endfor %}
           {% endfor %}
         </select>
         </select>
+        {% endif %}
         <input type="submit" class="btn btn-primary" id="edit-form-submit" value="ページを更新" />
         <input type="submit" class="btn btn-primary" id="edit-form-submit" value="ページを更新" />
       </div>
       </div>
     </div>
     </div>

+ 0 - 5
lib/views/page.html

@@ -114,11 +114,6 @@
       <div class="wiki {{ revision.format }}" id="revision-body-content"></div>
       <div class="wiki {{ revision.format }}" id="revision-body-content"></div>
     </div>
     </div>
 
 
-    {# raw text #}
-    <div class="tab-pane" id="raw-text">
-      <pre id="">{{ revision.body }}</pre>
-    </div>
-
     {# edit form #}
     {# edit form #}
     <div class="edit-form tab-pane {% if req.body.pageForm %}active{% endif %}" id="edit-form">
     <div class="edit-form tab-pane {% if req.body.pageForm %}active{% endif %}" id="edit-form">
       {% include '_form.html' %}
       {% include '_form.html' %}

+ 89 - 103
lib/views/page_list.html

@@ -11,8 +11,8 @@
   <header class="portal-header {% if page %}has-page{% endif %}">
   <header class="portal-header {% if page %}has-page{% endif %}">
     {% if page %}
     {% if page %}
       <a href="#" title="Bookmark" class="bookmark-link" id="bookmark-button" data-bookmarked="0"><i class="fa fa-star-o"></i></a>
       <a href="#" title="Bookmark" class="bookmark-link" id="bookmark-button" data-bookmarked="0"><i class="fa fa-star-o"></i></a>
-    {% endif %}
 
 
+    {% endif %}
     <h1 class="title" id="revision-path">
     <h1 class="title" id="revision-path">
       {{ path }}
       {{ path }}
     </h1>
     </h1>
@@ -39,38 +39,33 @@
   data-page-is-seen="{% if page and page.isSeenUser(user) %}1{% else %}0{% endif %}"
   data-page-is-seen="{% if page and page.isSeenUser(user) %}1{% else %}0{% endif %}"
   >
   >
 
 
-<div class="portal">
+<div class="portal {% if not page %}hide{% endif %}">
 
 
-  {% if page %} {# portal tab #}
   <ul class="nav nav-tabs hidden-print">
   <ul class="nav nav-tabs hidden-print">
+   {# portal tab #}
     <li class=" {% if not req.body.pageForm %}active{% endif %}">
     <li class=" {% if not req.body.pageForm %}active{% endif %}">
-      {% if page.isPortal() %}
-      <a href="#revision-body" data-toggle="tab">
+      {% if page %}
+      <a href="#revision-body-content" data-toggle="tab">
         <i class="fa fa-magic"></i>
         <i class="fa fa-magic"></i>
-        <span class="portal-label">PORTAL</span>
+        PORTAL
       </a>
       </a>
+      {% else %}
+      <a>Create Portal: {{ path }}</a>
       {% endif %}
       {% endif %}
     </li>
     </li>
     <li {% if req.body.pageForm %}class="active"{% endif %}><a href="#edit-form" data-toggle="tab"><i class="fa fa-pencil-square-o"></i> 編集</a></li>
     <li {% if req.body.pageForm %}class="active"{% endif %}><a href="#edit-form" data-toggle="tab"><i class="fa fa-pencil-square-o"></i> 編集</a></li>
 
 
-
-    {#
-    <li class="dropdown pull-right">
-      <a class="dropdown-toggle" data-toggle="dropdown" href="#">
-        <i class="fa fa-wrench"></i> <span class="caret"></span>
+    {% if not page %}
+    <li class="pull-right close-button">
+      <a href="#" id="portal-form-close">
+        <i class="fa fa-times"></i>
       </a>
       </a>
-      <ul class="dropdown-menu">
-       <li><a href="#" data-target="#" data-toggle="modal"><i class="fa fa-share"></i> 移動</a></li>
-      </ul>
     </li>
     </li>
-    #}
+    {% endif %}
   </ul>
   </ul>
 
 
-  {% endif %} {# portal tab #}
-
-  {% if page %} {# portal tab #}
-  <div class="tab-content wiki-content">
-    <div class="wiki tab-pane" id="revision-body-content">
+  <div class="tab-content">
+    <div class="wiki tab-pane {% if not req.body.pageForm %}active{% endif %}" id="revision-body-content">
     </div>
     </div>
 
 
     <script type="text/template" id="raw-text-original">{{ page.revision.body }}</script>
     <script type="text/template" id="raw-text-original">{{ page.revision.body }}</script>
@@ -81,98 +76,89 @@
           Crowi.correctHeaders('#revision-body-content');
           Crowi.correctHeaders('#revision-body-content');
       });
       });
     </script>
     </script>
-    <div class="tab-pane portal-edit" id="edit-form">
-      <div class="portal-form-header">
-        Create Portal: <strong>{{ path }}</strong>
-        <p class="pull-right ">
-          <a href="#" id="portal-form-close"><i class="fa fa-times"></i></a>
-        </p>
-      </div>
-      <div class="portal-form">
-        <div class="edit-form">
-          {% include '_form.html' %}
-        </div>
-      </div>
+    <div class="tab-pane edit-form portal-form {% if req.body.pageForm %}active{% endif %}" id="edit-form">
+      {% include '_form.html' with {forceGrant: 1} %}
     </div>
     </div>
   </div>
   </div>
-  {% endif %} {# portal tab #}
-</div>
-
-<ul class="nav nav-tabs">
-    <li class="active"><a href="#view-list" data-toggle="tab">リスト表示</a></li>
-    <li><a href="#view-timeline" data-toggle="tab">タイムライン表示</a></li>
-</ul>
-
-<div class="tab-content">
-  {% if pages.length == 0 %}
-  There are no pages under <strong>{{ path }}</strong>.
+</div> {# /.portal #}
 
 
-  <h3>Next Actions</h3>
-
-  <ul>
-    <li>Create portal page?
-      <ul>
-        <li>Great! To create the portal of <strong>{{ path }}</strong>, click "Create Portal" button.</li>
-      </ul>
-    </li>
-    <li>Create the under page directly?
-      <ul>
-        <li>Nice. To create the page under <strong>{{ path }}</strong> directly, type the page name on your browser.</li>
-      </ul>
-    </li>
+<div class="page-list-container">
+  <ul class="nav nav-tabs">
+      <li class="active"><a href="#view-list" data-toggle="tab">リスト表示</a></li>
+      <li><a href="#view-timeline" data-toggle="tab">タイムライン表示</a></li>
   </ul>
   </ul>
-  {% endif  %}
-
-  {# list view #}
-  <div class="active tab-pane fade page-list-container in" id="view-list">
-    <ul class="page-list-ul">
-    {% for page in pages %}
-    <li class="page-list-li">
-      <img src="{{ page.revision.author|picture }}" class="picture picture-rounded">
-
-      <a class="page-list-link" href="{{ page.path }}"
-        data-path="{{ page.path }}"
-        data-short-path="{{ page.path|path2name }}">{{ page.path }}</a>
-
-      <span class="page-list-meta">
-        {% if page.isPortal() %}
-          <span class="label label-info">PORTAL</span>
-        {% endif  %}
-
-
-        {% if page.commentCount > 0 %}
-          <i class="fa fa-comment"></i>{{ page.commentCount }}
-        {% endif  %}
 
 
-        {% if !page.isPublic() %}
-          <i class="fa fa-lock"></i>
-        {% endif %}
-      </span>
-    </li>
-    {% endfor %}
+  <div class="tab-content">
+    {% if pages.length == 0 %}
+    There are no pages under <strong>{{ path }}</strong>.
+
+    <h3>Next Actions</h3>
+
+    <ul>
+      <li>Create portal page?
+        <ul>
+          <li>Great! To create the portal of <strong>{{ path }}</strong>, click "Create Portal" button.</li>
+        </ul>
+      </li>
+      <li>Create the under page directly?
+        <ul>
+          <li>Nice. To create the page under <strong>{{ path }}</strong> directly, type the page name on your browser.</li>
+        </ul>
+      </li>
     </ul>
     </ul>
-
-      <ul class="pagination">
-        {% if pager.prev != null %}
-          <li class="prev"><a href="{{ path }}?offset={{ pager.prev }}&limit={{ pager.limit }}"><i class="fa fa-arrow-left"></i> Prev</a></li>
-        {% endif %}
-        {# この条件は無いな.. #}
-        {% if pages.length > 0 %}
-          <li class="next"><a href="{{ path }}?offset={{ pager.next }}&limit={{ pager.limit }}">Next <i class="fa fa-arrow-right"></i></a></li>
-        {% endif %}
+    {% endif  %}
+
+    {# list view #}
+    <div class="active tab-pane fade page-list-container in" id="view-list">
+      <ul class="page-list-ul">
+      {% for page in pages %}
+      <li class="page-list-li">
+        <img src="{{ page.revision.author|picture }}" class="picture picture-rounded">
+
+        <a class="page-list-link" href="{{ page.path }}"
+          data-path="{{ page.path }}"
+          data-short-path="{{ page.path|path2name }}">{{ page.path }}</a>
+
+        <span class="page-list-meta">
+          {% if page.isPortal() %}
+            <span class="label label-info">PORTAL</span>
+          {% endif  %}
+
+
+          {% if page.commentCount > 0 %}
+            <i class="fa fa-comment"></i>{{ page.commentCount }}
+          {% endif  %}
+
+          {% if !page.isPublic() %}
+            <i class="fa fa-lock"></i>
+          {% endif %}
+        </span>
+      </li>
+      {% endfor %}
       </ul>
       </ul>
-  </div>
 
 
-  {# timeline view #}
-  <div class="tab-pane" id="view-timeline">
-    {% for page in pages %}
-    <div class="timeline-body" id="id-{{ page.id }}">
-      <h3 class="revision-path"><a href="{{ page.path }}">{{ page.path }}</a></h3>
-      <div class="revision-body wiki"></div>
-      <script type="text/template">{{ page.revision.body }}</script>
+        <ul class="pagination">
+          {% if pager.prev != null %}
+            <li class="prev"><a href="{{ path }}?offset={{ pager.prev }}&limit={{ pager.limit }}"><i class="fa fa-arrow-left"></i> Prev</a></li>
+          {% endif %}
+          {# この条件は無いな.. #}
+          {% if pages.length > 0 %}
+            <li class="next"><a href="{{ path }}?offset={{ pager.next }}&limit={{ pager.limit }}">Next <i class="fa fa-arrow-right"></i></a></li>
+          {% endif %}
+        </ul>
+    </div>
+
+    {# timeline view #}
+    <div class="tab-pane" id="view-timeline">
+      {% for page in pages %}
+      <div class="timeline-body" id="id-{{ page.id }}">
+        <h3 class="revision-path"><a href="{{ page.path }}">{{ page.path }}</a></h3>
+        <div class="revision-body wiki"></div>
+        <script type="text/template">{{ page.revision.body }}</script>
+      </div>
+      <hr>
+      {% endfor %}
     </div>
     </div>
-    <hr>
-    {% endfor %}
   </div>
   </div>
 </div>
 </div>
 
 

+ 8 - 8
resource/css/_form.scss

@@ -12,7 +12,6 @@
     height: 40px;
     height: 40px;
   }
   }
 
 
-  .portal-form,
   .tab-content {
   .tab-content {
     top: 48px;
     top: 48px;
     bottom: 58px;
     bottom: 58px;
@@ -98,15 +97,16 @@
 } // }}}
 } // }}}
 
 
 .crowi.main-container .main .page-list.content-main { // {{{ Edit Form of Page List
 .crowi.main-container .main .page-list.content-main { // {{{ Edit Form of Page List
-  .portal-form-header,
-  .portal-form {
+  .close-button {
     display: none;
     display: none;
   }
   }
 }
 }
 .crowi.main-container .main .page-list.content-main.on-edit { // {{{ Edit Form of Page List
 .crowi.main-container .main .page-list.content-main.on-edit { // {{{ Edit Form of Page List
-  .wiki,
-  .nav,
-  .tab-content {
+  .close-button {
+    display: block;
+  }
+
+  .page-list-container {
     display: none;
     display: none;
   }
   }
   .portal-form-header,
   .portal-form-header,
@@ -115,8 +115,8 @@
   }
   }
 
 
   .portal-form-header {
   .portal-form-header {
-    height: 48px;
-    padding: 14px;
+    height: 16px;
+    padding: 8px;
     border-bottom: solid 1px #ccc;
     border-bottom: solid 1px #ccc;
   }
   }
 } // }}}
 } // }}}

+ 5 - 0
resource/js/crowi.js

@@ -283,10 +283,15 @@ $(function() {
   });
   });
 
 
   $('#create-portal-button').on('click', function(e) {
   $('#create-portal-button').on('click', function(e) {
+    $('.portal').removeClass('hide');
     $('.content-main').addClass('on-edit');
     $('.content-main').addClass('on-edit');
+    $('.portal a[data-toggle="tab"][href="#edit-form"]').tab('show');
   });
   });
   $('#portal-form-close').on('click', function(e) {
   $('#portal-form-close').on('click', function(e) {
+    $('.portal').addClass('hide');
     $('.content-main').removeClass('on-edit');
     $('.content-main').removeClass('on-edit');
+
+    return false;
   });
   });