sou 7 лет назад
Родитель
Сommit
52b1a55d3d
2 измененных файлов с 13 добавлено и 26 удалено
  1. 1 18
      lib/routes/page.js
  2. 12 8
      lib/views/modal/create_page.html

+ 1 - 18
lib/routes/page.js

@@ -252,8 +252,6 @@ module.exports = function(crowi, app) {
       tree: [],
       tree: [],
       pageRelatedGroup: null,
       pageRelatedGroup: null,
       template: null,
       template: null,
-      childrenTemplateExists: false,
-      decendantsTemplateExists: false,
     };
     };
 
 
     var pageTeamplate = 'customlayout-selector/page';
     var pageTeamplate = 'customlayout-selector/page';
@@ -285,10 +283,6 @@ module.exports = function(crowi, app) {
         .then(function() {
         .then(function() {
           return Page.checkIfTemplatesExist(originalPath);
           return Page.checkIfTemplatesExist(originalPath);
         })
         })
-        .then(function(templateInfo) {
-          renderVars.childrenTemplateExists = templateInfo.childrenTemplateExists;
-          renderVars.decendantsTemplateExists = templateInfo.decendantsTemplateExists;
-        })
         .then(() => {
         .then(() => {
           return PageGroupRelation.findByPage(renderVars.page);
           return PageGroupRelation.findByPage(renderVars.page);
         })
         })
@@ -463,8 +457,6 @@ module.exports = function(crowi, app) {
       page: pageData,
       page: pageData,
       revision: pageData.revision || {},
       revision: pageData.revision || {},
       author: pageData.revision.author || false,
       author: pageData.revision.author || false,
-      childrenTemplateExists: false,
-      decendantsTemplateExists: false,
     };
     };
     var userPage = isUserPage(pageData.path);
     var userPage = isUserPage(pageData.path);
     var userData = null;
     var userData = null;
@@ -509,12 +501,6 @@ module.exports = function(crowi, app) {
       }
       }
     }).then(function() {
     }).then(function() {
       return interceptorManager.process('beforeRenderPage', req, res, renderVars);
       return interceptorManager.process('beforeRenderPage', req, res, renderVars);
-    }).then(function() {
-      return Page.checkIfTemplatesExist(pageData.path)
-        .then(function(templateInfo) {
-          renderVars.childrenTemplateExists = templateInfo.childrenTemplateExists;
-          renderVars.decendantsTemplateExists = templateInfo.decendantsTemplateExists;
-        });
     }).then(function() {
     }).then(function() {
       var defaultPageTeamplate = 'customlayout-selector/page';
       var defaultPageTeamplate = 'customlayout-selector/page';
       if (userData) {
       if (userData) {
@@ -1205,10 +1191,7 @@ module.exports = function(crowi, app) {
     const templateFinder = Page.checkIfTemplatesExist(pagePath);
     const templateFinder = Page.checkIfTemplatesExist(pagePath);
 
 
     templateFinder.then(function(templateInfo) {
     templateFinder.then(function(templateInfo) {
-      var result = {};
-      result.templateInfo = templateInfo;
-
-      return res.json(ApiResponse.success(result));
+      return res.json(ApiResponse.success(templateInfo));
     }).catch(function(err) {
     }).catch(function(err) {
       return res.json(ApiResponse.error(err));
       return res.json(ApiResponse.error(err));
     });
     });

+ 12 - 8
lib/views/modal/create_page.html

@@ -56,7 +56,12 @@
                 </select>
                 </select>
               </div>
               </div>
               <div class="create-page-button-container">
               <div class="create-page-button-container">
-                  <a id="link-to-template" href="{{ page.path || path }}"><button class="fcbtn btn btn-outline btn-rounded btn-primary btn-1b"><i class="icon-fw icon-doc"></i>{{ t('Create') }}</button></a>
+                  <a id="link-to-template" href="{{ page.path || path }}">
+                    <button class="fcbtn btn btn-outline btn-rounded btn-primary btn-1b">
+                      <i class="icon-fw icon-doc"></i>
+                      <span id="template-button">{{ t('Create') }}</span>
+                    </button>
+                  </a>
               </div>
               </div>
             </div>
             </div>
           </fieldset>
           </fieldset>
@@ -69,6 +74,8 @@
 </div><!-- /.modal -->
 </div><!-- /.modal -->
 <script>
 <script>
   if($("#create-page")) {
   if($("#create-page")) {
+    let buttonTextChildren = 'Create';
+    let buttonTextDecendants = 'Create';
     let pagePath = $("#link-to-template").attr("href");
     let pagePath = $("#link-to-template").attr("href");
 
 
     if (pagePath.endsWith("/")) {
     if (pagePath.endsWith("/")) {
@@ -77,23 +84,20 @@
 
 
     $.get(`/_api/page.template?path=${pagePath}`)
     $.get(`/_api/page.template?path=${pagePath}`)
     .then(templateInfo => {
     .then(templateInfo => {
-      console.log('data', templateInfo);
-      // merge master and change variable name to childrenTemplateExists and decendantsTemplateExists
-      let buttonTextChildren = templateInfo.localTemplateExists ? 'Edit' : 'Create';
-      let buttonTextDecendants = templateInfo.globalTemplateExists ? 'Edit' : 'Create';
-      console.log(buttonTextChildren)
-      console.log(buttonTextDecendants)
-
+      buttonTextChildren = ((templateInfo.childrenTemplateExists) ? 'Edit' : 'Create');
+      buttonTextDecendants = ((templateInfo.decendantsTemplateExists) ? 'Edit' : 'Create');
     });
     });
 
 
     $("#template-type").on("change", () => {
     $("#template-type").on("change", () => {
       if ($("#template-type").val() === "children") {
       if ($("#template-type").val() === "children") {
         href = pagePath + "/_template#edit-form";
         href = pagePath + "/_template#edit-form";
         $("#link-to-template").attr("href", href);
         $("#link-to-template").attr("href", href);
+        $('#template-button').text(buttonTextChildren);
       }
       }
       else if ($("#template-type").val() === "decentants") {
       else if ($("#template-type").val() === "decentants") {
         href = pagePath + "/__template#edit-form";
         href = pagePath + "/__template#edit-form";
         $("#link-to-template").attr("href", href);
         $("#link-to-template").attr("href", href);
+        $('#template-button').text(buttonTextDecendants);
       };
       };
     });
     });
   };
   };