Просмотр исходного кода

one ajax request and toggle create/edit

sou 7 лет назад
Родитель
Сommit
1d2aa989ce
2 измененных файлов с 32 добавлено и 29 удалено
  1. 28 25
      lib/views/modal/create_page.html
  2. 4 4
      lib/views/modal/create_template.html

+ 28 - 25
lib/views/modal/create_page.html

@@ -73,32 +73,35 @@
   </div><!-- /.modal-dialog -->
   </div><!-- /.modal-dialog -->
 </div><!-- /.modal -->
 </div><!-- /.modal -->
 <script>
 <script>
-  if($("#create-page")) {
-    let buttonTextChildren = 'Create';
-    let buttonTextDecendants = 'Create';
-    let pagePath = $("#link-to-template").attr("href");
+  let buttonTextChildren;
+  let buttonTextDecendants;
+  let pagePath = $("#link-to-template").attr("href");
 
 
-    if (pagePath.endsWith("/")) {
-      pagePath = pagePath.slice(0, -1);
-    };
+  if (pagePath.endsWith("/")) {
+    pagePath = pagePath.slice(0, -1);
+  };
 
 
-    $.get(`/_api/page.template?path=${pagePath}`)
-    .then(templateInfo => {
-      buttonTextChildren = ((templateInfo.childrenTemplateExists) ? 'Edit' : 'Create');
-      buttonTextDecendants = ((templateInfo.decendantsTemplateExists) ? 'Edit' : 'Create');
-    });
+  $.get(`/_api/page.template?path=${pagePath}`)
+  .then(templateInfo => {
+    buttonTextChildren = templateInfo.childrenTemplateExists ? '{{ t('Edit') }}' : '{{ t('Create') }}';
+    buttonTextDecendants = templateInfo.decendantsTemplateExists ? '{{ t('Edit') }}' : '{{ t('Create') }}';
+  });
 
 
-    $("#template-type").on("change", () => {
-      if ($("#template-type").val() === "children") {
-        href = pagePath + "/_template#edit-form";
-        $("#link-to-template").attr("href", href);
-        $('#template-button').text(buttonTextChildren);
-      }
-      else if ($("#template-type").val() === "decentants") {
-        href = pagePath + "/__template#edit-form";
-        $("#link-to-template").attr("href", href);
-        $('#template-button').text(buttonTextDecendants);
-      };
-    });
-  };
+  $("#create-template").ready(() => {
+    $('#template-button-children').text(buttonTextChildren);
+    $('#template-button-decendants').text(buttonTextDecendants);
+  });
+
+  $("#template-type").on("change", () => {
+    if ($("#template-type").val() === "children") {
+      href = pagePath + "/_template#edit-form";
+      $("#link-to-template").attr("href", href);
+      $('#template-button').text(buttonTextChildren);
+    }
+    else if ($("#template-type").val() === "decentants") {
+      href = pagePath + "/__template#edit-form";
+      $("#link-to-template").attr("href", href);
+      $('#template-button').text(buttonTextDecendants);
+    };
+  });
 </script>
 </script>

+ 4 - 4
lib/views/modal/create_template.html

@@ -19,8 +19,8 @@
                 </div>
                 </div>
                 <div class="panel-footer text-center">
                 <div class="panel-footer text-center">
                   <a href="{% if page.path.endsWith('/') %}{{ page.path }}{% else %}{{ page.path}}/{% endif %}_template#edit-form"
                   <a href="{% if page.path.endsWith('/') %}{{ page.path }}{% else %}{{ page.path}}/{% endif %}_template#edit-form"
-                      class="btn btn-sm btn-primary">
-                    {% if childrenTemplateExists %}{{ t('Edit') }}{% else %}{{ t('Create') }}{% endif %}
+                      class="btn btn-sm btn-primary" id="template-button-children">
+
                   </a>
                   </a>
                 </div>
                 </div>
               </div>
               </div>
@@ -34,8 +34,8 @@
                 </div>
                 </div>
                 <div class="panel-footer text-center">
                 <div class="panel-footer text-center">
                   <a href="{% if page.path.endsWith('/') %}{{ page.path }}{% else %}{{ page.path}}/{% endif %}__template#edit-form"
                   <a href="{% if page.path.endsWith('/') %}{{ page.path }}{% else %}{{ page.path}}/{% endif %}__template#edit-form"
-                      class="btn btn-sm btn-primary">
-                  {% if decendantsTemplateExists %}{{ t('Edit') }}{% else %}{{ t('Create') }}{% endif %}
+                      class="btn btn-sm btn-primary" id="template-button-decendants">
+
                   </a>
                   </a>
                 </div>
                 </div>
               </div>
               </div>