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 2018/12/07 03:50:51 UTC

[sling-org-apache-sling-app-cms] branch master updated: Fixed incorrect loading of components when deleted, moved or created.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new f8d6df8  Fixed incorrect loading of components when deleted, moved or created.
f8d6df8 is described below

commit f8d6df8474ec221b0fc652fc627da715fc818bc1
Author: Dan Klco <dk...@apache.org>
AuthorDate: Thu Dec 6 21:45:41 2018 -0500

    Fixed incorrect loading of components when deleted, moved or created.
---
 ui/src/main/frontend/src/js/cms.form.js | 14 +++++++++++++-
 ui/src/main/frontend/src/js/editor.js   |  9 +++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/ui/src/main/frontend/src/js/cms.form.js b/ui/src/main/frontend/src/js/cms.form.js
index bf4673b..9d41e3d 100644
--- a/ui/src/main/frontend/src/js/cms.form.js
+++ b/ui/src/main/frontend/src/js/cms.form.js
@@ -68,7 +68,19 @@ rava.decorate(".Form-Ajax", {
                     if (callback && Sling.CMS.handlers[callback]){
                         Sling.CMS.handlers[callback](res, msg);
                     } else if (window.parent.window.CMSEditor) {
-                        Sling.CMS.ui.confirmReloadComponent(res, msg, $form.attr('action'));
+                        var reloadParent = false;
+                        res.changes.forEach(change => {
+                           if (change.type !== 'modified') {
+                               reloadParent = true;
+                           } 
+                        });
+                        var path = $form.attr('action');
+                        if (reloadParent) {
+                            var pathArr = path.split('\/');
+                            pathArr.pop();
+                            path = pathArr.join('/');
+                        }
+                        Sling.CMS.ui.confirmReloadComponent(res, msg, path);
                     } else {
                         Sling.CMS.ui.confirmReload(res, msg);
                     }
diff --git a/ui/src/main/frontend/src/js/editor.js b/ui/src/main/frontend/src/js/editor.js
index 8467b40..33023f7 100644
--- a/ui/src/main/frontend/src/js/editor.js
+++ b/ui/src/main/frontend/src/js/editor.js
@@ -78,6 +78,15 @@
                 },
                 reloadComponent: function (path, cb) {
                     var component = document.querySelector('.sling-cms-component[data-sling-cms-resource-path="' + path + '"]');
+                    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){
+                        window.top.location.reload();
+                    }
                     var request = new XMLHttpRequest();
                     request.open('GET', '/cms/page/pagewrapper.html' + path + '?forceResourceType=' + component.dataset.slingCmsResourceType, true);
                     request.onload = function () {