فهرست منبع

dropdown modal and function transfer

sou 7 سال پیش
والد
کامیت
55dc10a63a
5فایلهای تغییر یافته به همراه56 افزوده شده و 21 حذف شده
  1. 13 1
      lib/models/page.js
  2. 1 20
      lib/routes/page.js
  3. 40 0
      lib/views/modal/create_template.html
  4. 1 0
      lib/views/widget/page_modals.html
  5. 1 0
      lib/views/widget/page_tabs.html

+ 13 - 1
lib/models/page.js

@@ -528,8 +528,10 @@ module.exports = function(crowi) {
   };
 
   // find all templates applicable to the new page
-  pageSchema.statics.findTemplate = function(pathList, templatePath) {
+  pageSchema.statics.findTemplate = function(path) {
     const Page = this;
+    const templatePath = cutOffLastSlash(path);
+    const pathList = generatePathsOnTree(templatePath, []);
     const regexpList = pathList.map(path => new RegExp(`${path}/[_@]template`));
 
     return Page
@@ -545,6 +547,16 @@ module.exports = function(crowi) {
     return path.substr(0, lastSlash);
   };
 
+  const generatePathsOnTree = (path, pathList) => {
+    if (path === '') {
+      return pathList;
+    }
+
+    pathList.push(path);
+    const newPath = cutOffLastSlash(path);
+    return generatePathsOnTree(newPath, pathList);
+  };
+
   const assignTemplateByType = (templates, path, type) => {
     for (let i = 0; i < templates.length; i++) {
       if (templates[i].path === `${path}/${type}template`) {

+ 1 - 20
lib/routes/page.js

@@ -311,10 +311,7 @@ module.exports = function(crowi, app) {
     .catch(function(err) {
       pageTeamplate = 'customlayout-selector/not_found';
 
-      const templatePath = cutOffLastSlash(originalPath);
-      const pathList = generatePathsOnTree(originalPath, []);
-
-      return Page.findTemplate(pathList, templatePath)
+      return Page.findTemplate(originalPath)
         .then(template => {
           renderVars.template = template;
         });
@@ -367,22 +364,6 @@ module.exports = function(crowi, app) {
     });
   };
 
-  const cutOffLastSlash = path => {
-    const lastSlash = path.lastIndexOf('/');
-    return path.substr(0, lastSlash);
-  };
-
-  const generatePathsOnTree = (path, pathList) => {
-    const newPath = cutOffLastSlash(path);
-
-    if (newPath === '') {
-      return pathList;
-    }
-
-    pathList.push(newPath);
-    return generatePathsOnTree(newPath, pathList);
-  };
-
   actions.deletedPageListShow = function(req, res) {
     var path = '/trash' + getPathFromRequest(req);
     var limit = 50;

+ 40 - 0
lib/views/modal/create_template.html

@@ -0,0 +1,40 @@
+<div class="modal" id="create-template">
+  <div class="modal-dialog">
+    <div class="modal-content">
+
+      <div class="modal-header bg-primary">
+        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+        <div class="modal-title">Create/Edit Template</div>
+      </div>
+      <div class="modal-body">
+          <div class="form-group">
+            <label for="">Create a new template for <code>{{ page.path }}</code></label><br>
+            <div class="row">
+              <div class="col-sm-6">
+                <p class="help-block">Local Template</p>
+                <p class="help-block">Applies only to immediate decendant pages</p>
+                <div class="d-flex justify-content-center">
+                  {% if template %}
+                  <a href="{{ page.path }}/@template#edit-form"><button type="submit" class="btn btn-xs btn-primary">Edit</button></a>
+                  {% else %}
+                  <a href="{{ page.path }}/@template#edit-form"><button type="submit" class="btn btn-xs btn-primary">Create</button></a>
+                  {% endif %}
+                </div>
+              </div>
+              <div class="col-sm-6">
+                  <p class="help-block">Global Template</p>
+                  <p class="help-block">Applies to all decendant pages</p>
+                  <div class="d-flex justify-content-center">
+                    {% if template %}
+                    <a href="{{ page.path }}/_template#edit-form"><button type="submit" class="btn btn-xs btn-primary">Edit</button></a>
+                    {% else %}
+                    <a href="{{ page.path }}/_template#edit-form"><button type="submit" class="btn btn-xs btn-primary">Create</button></a>
+                    {% endif %}
+                  </div>
+              </div>
+            </div>
+          </div>
+      </div>
+    </div><!-- /.modal-content -->
+  </div><!-- /.modal-dialog -->
+</div><!-- /.modal -->

+ 1 - 0
lib/views/widget/page_modals.html

@@ -1,5 +1,6 @@
 {% include '../modal/rename.html' %}
 {% include '../modal/delete.html' %}
+{% include '../modal/create_template.html' %}
 {% include '../modal/duplicate.html' %}
 {% include '../modal/put_back.html' %}
 {% include '../modal/page_name_warning.html' %}

+ 1 - 0
lib/views/widget/page_tabs.html

@@ -30,6 +30,7 @@
       <ul class="dropdown-menu">
         <li><a href="#" data-target="#renamePage" data-toggle="modal"><i class="icon-fw icon-action-redo"></i> {{ t('Move') }}</a></li>
         <li class="divider"></li>
+        <li class=""><a href="#" data-target="#create-template" data-toggle="modal"><i class="icon-fw icon-docs"></i> Create Template</a></li>
         <li><a href="#" data-target="#duplicatePage" data-toggle="modal"><i class="icon-fw icon-docs"></i> {{ t('Duplicate') }}</a></li>
         {% if isDeletablePage() %}
         <li class="divider"></li>