You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/07/25 19:19:27 UTC

[sling-org-apache-sling-app-cms] 03/03: Adding the ability to have components reload the page rather than reloading in context

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch dklco/form-framework
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git

commit 7b38bf025df95dedd352418483b0b8dae72a7c8f
Author: Dan Klco <dk...@apache.org>
AuthorDate: Thu Jul 25 15:19:17 2019 -0400

    Adding the ability to have components reload the page rather than
    reloading in context
---
 api/src/main/java/org/apache/sling/cms/Component.java       | 11 +++++++++--
 .../sling/cms/core/internal/filters/EditIncludeFilter.java  | 13 ++++++-------
 .../sling/cms/core/internal/models/ComponentImpl.java       | 10 ++++++++++
 .../apps/reference/components/forms/actions/sendemail.json  |  3 ++-
 .../reference/components/forms/actions/updateprofile.json   |  3 ++-
 .../apps/reference/components/forms/fields/selection.json   |  3 ++-
 .../apps/reference/components/forms/fields/textarea.json    |  3 ++-
 .../apps/reference/components/forms/fields/textfield.json   |  3 ++-
 .../jcr_root/apps/reference/components/forms/fieldset.json  |  3 ++-
 .../reference/components/forms/providers/userprofile.json   |  3 ++-
 ui/src/main/frontend/src/js/editor.js                       |  8 ++++++--
 11 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/api/src/main/java/org/apache/sling/cms/Component.java b/api/src/main/java/org/apache/sling/cms/Component.java
index c8cd9c4..bc92b22 100644
--- a/api/src/main/java/org/apache/sling/cms/Component.java
+++ b/api/src/main/java/org/apache/sling/cms/Component.java
@@ -61,15 +61,22 @@ public interface Component {
      * @return the title
      */
     String getTitle();
-    
+
     /**
-     * True if the component is editable, false otherwise. 
+     * True if the component is editable, false otherwise.
      * 
      * @return the editable flag
      */
     boolean isEditable();
 
     /**
+     * Returns true if the the property reloadPage is set to true.
+     * 
+     * @return true if page should be reloaded when the component is saved
+     */
+    boolean isReloadPage();
+
+    /**
      * Returns true if the only component type on the component is the specified
      * type.
      * 
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/filters/EditIncludeFilter.java b/core/src/main/java/org/apache/sling/cms/core/internal/filters/EditIncludeFilter.java
index 2527f10..6611291 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/filters/EditIncludeFilter.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/filters/EditIncludeFilter.java
@@ -118,10 +118,11 @@ public class EditIncludeFilter implements Filter {
         String editPath = component.getEditPath();
         String title = StringUtils.isNotEmpty(component.getTitle()) ? component.getTitle()
                 : StringUtils.substringAfterLast(resource.getResourceType(), "/");
-        writer.write("<div class=\"sling-cms-component\" data-component=\"" + component.getResource().getPath()
-                + "\" data-sling-cms-title=\"" + title + "\" data-sling-cms-resource-path=\"" + resource.getPath()
-                + "\" data-sling-cms-resource-type=\"" + resource.getResourceType() + "\" data-sling-cms-edit=\""
-                + editPath + "\"><div class=\"sling-cms-editor\">");
+        writer.write("<div class=\"sling-cms-component\" data-reload=\"" + component.isReloadPage()
+                + "\" data-component=\"" + component.getResource().getPath() + "\" data-sling-cms-title=\"" + title
+                + "\" data-sling-cms-resource-path=\"" + resource.getPath() + "\" data-sling-cms-resource-type=\""
+                + resource.getResourceType() + "\" data-sling-cms-edit=\"" + editPath
+                + "\"><div class=\"sling-cms-editor\">");
         writer.write(
                 "<div class=\"level has-background-grey\"><div class=\"level-left\"><div class=\"field has-addons\">");
 
@@ -156,7 +157,6 @@ public class EditIncludeFilter implements Filter {
             editPath = component.getEditPath();
         }
 
-
         if (StringUtils.isNotEmpty(editPath)) {
             includeEnd = true;
             writeEditorMarkup(resource, writer);
@@ -168,8 +168,7 @@ public class EditIncludeFilter implements Filter {
             }
             writer.write("<div class=\"sling-cms-component\" data-sling-cms-title=\""
                     + (component != null ? component.getTitle() : "") + "\" data-sling-cms-resource-path=\""
-                    + resource.getPath() + "\" data-sling-cms-resource-type=\"" + resource.getResourceType()
-                    + "\">");
+                    + resource.getPath() + "\" data-sling-cms-resource-type=\"" + resource.getResourceType() + "\">");
         }
         return includeEnd;
     }
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/models/ComponentImpl.java b/core/src/main/java/org/apache/sling/cms/core/internal/models/ComponentImpl.java
index 9a76cab..26154d9 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/models/ComponentImpl.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/models/ComponentImpl.java
@@ -43,6 +43,11 @@ public class ComponentImpl implements Component {
     @Default(booleanValues = true)
     private boolean editable;
 
+    @Inject
+    @Optional
+    @Default(booleanValues = false)
+    private boolean reloadPage;
+
     private Resource resource;
 
     @Inject
@@ -161,6 +166,11 @@ public class ComponentImpl implements Component {
         return editable;
     }
 
+    @Override
+    public boolean isReloadPage() {
+        return reloadPage;
+    }
+
     /**
      * Returns true if the only component type on the component is the specified
      * type.
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/sendemail.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/sendemail.json
index 2f8e0ad..efe3d7b 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/sendemail.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/sendemail.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "Email",
-    "componentType": "Form Action"
+    "componentType": "Form Action",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/updateprofile.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/updateprofile.json
index 8549c19..fc11fd1 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/updateprofile.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/actions/updateprofile.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "Update Profile",
-    "componentType": "Form Action"
+    "componentType": "Form Action",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/selection.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/selection.json
index d3f03c2..341d4a1 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/selection.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/selection.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "Selection",
-    "componentType": "Form Field"
+    "componentType": "Form Field",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textarea.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textarea.json
index d9c86e4..0722adc 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textarea.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textarea.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "Textarea",
-    "componentType": "Form Field"
+    "componentType": "Form Field",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textfield.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textfield.json
index c2976c7..7cb2186 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textfield.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fields/textfield.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "Text Field",
-    "componentType": "Form Field"
+    "componentType": "Form Field",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fieldset.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fieldset.json
index 5d40038..3926e8d 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/fieldset.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/fieldset.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "Fieldset",
-    "componentType": "Form Field"
+    "componentType": "Form Field",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/reference/src/main/resources/jcr_root/apps/reference/components/forms/providers/userprofile.json b/reference/src/main/resources/jcr_root/apps/reference/components/forms/providers/userprofile.json
index 3be98ba..eda95b0 100644
--- a/reference/src/main/resources/jcr_root/apps/reference/components/forms/providers/userprofile.json
+++ b/reference/src/main/resources/jcr_root/apps/reference/components/forms/providers/userprofile.json
@@ -1,5 +1,6 @@
 {
     "jcr:primaryType" : "sling:Component",
     "jcr:title": "User Profile",
-    "componentType": "Form Value Provider"
+    "componentType": "Form Value Provider",
+    "reloadPage": true
 }
\ No newline at end of file
diff --git a/ui/src/main/frontend/src/js/editor.js b/ui/src/main/frontend/src/js/editor.js
index abd30b0..a21570f 100644
--- a/ui/src/main/frontend/src/js/editor.js
+++ b/ui/src/main/frontend/src/js/editor.js
@@ -80,14 +80,18 @@
                         }
                     },
                     reloadComponent: function (path, cb) {
-                        var component = document.querySelector('.sling-cms-component[data-sling-cms-resource-path="' + path + '"]');
+                        var component = document.querySelector('.sling-cms-component[data-sling-cms-resource-path="' + path + '"]'),
+                            reloadPage = component.dataset.reload  === 'true';
                         while (!component && path.length > 1) {
                             var pathArr = path.split('\/');
                             pathArr.pop();
                             path = pathArr.join('/');
                             component = document.querySelector('.sling-cms-component[data-sling-cms-resource-path="' + path + '"]');
+                            if(component.dataset.reload  === 'true') {
+                                reloadPage = true;
+                            }
                         }
-                        if (!component) {
+                        if (!component || reloadPage) {
                             CMSEditor.ui.hideModal();
                             window.top.location.reload();
                         }