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/12/18 07:22:32 UTC

[sling-org-apache-sling-app-cms] branch SLING-8919-fix-error-dialog updated (4369988 -> b105249)

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

dklco pushed a change to branch SLING-8919-fix-error-dialog
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git.


    from 4369988  SLING-8919 - Cleaning up a couple eslint warnings
     new ea7aa31  Fixing sonar lint issues
     new b105249  SLING-8919 - Fixing failure or handle editor dialogs on the page

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ui/src/main/frontend/js/cms.pathfield.js |  37 +++++---
 ui/src/main/frontend/js/editor.js        | 146 ++++++++++++++++++++-----------
 2 files changed, 121 insertions(+), 62 deletions(-)


[sling-org-apache-sling-app-cms] 01/02: Fixing sonar lint issues

Posted by dk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch SLING-8919-fix-error-dialog
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git

commit ea7aa310a38282941dbef3df0572513a0c140756
Author: Dan Klco <dk...@apache.org>
AuthorDate: Tue Dec 17 23:21:52 2019 -0800

    Fixing sonar lint issues
---
 ui/src/main/frontend/js/cms.pathfield.js | 37 +++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/ui/src/main/frontend/js/cms.pathfield.js b/ui/src/main/frontend/js/cms.pathfield.js
index bc5a41a..e66b14d 100644
--- a/ui/src/main/frontend/js/cms.pathfield.js
+++ b/ui/src/main/frontend/js/cms.pathfield.js
@@ -33,9 +33,15 @@ rava.bind('input.pathfield', {
           if (term === '/') {
             term = base;
           }
-          fetch(`/bin/cms/paths?path=${encodeURIComponent(term)}&type=${encodeURIComponent(type)}`).then((resp) => resp.json()).then((data) => {
-            response(data);
-          });
+          fetch(
+            `/bin/cms/paths?path=${encodeURIComponent(
+              term,
+            )}&type=${encodeURIComponent(type)}`,
+          )
+            .then((resp) => resp.json())
+            .then((data) => {
+              response(data);
+            });
         },
       });
     },
@@ -57,18 +63,25 @@ rava.bind('.search-select-button', {
       if (Sling.CMS.pathfield instanceof HTMLInputElement) {
         Sling.CMS.pathfield.value = this.dataset.path;
       } else {
-        Sling.CMS.pathfield.postMessage({
-          action: 'slingcms.setpath',
-          path,
-        }, window.location.origin);
+        Sling.CMS.pathfield.postMessage(
+          {
+            action: 'slingcms.setpath',
+            path,
+          },
+          window.location.origin,
+        );
       }
       this.closest('.modal').remove();
     },
   },
 });
 
-window.addEventListener('message', (event) => {
-  if (event.data.action === 'slingcms.setpath') {
-    Sling.CMS.pathfield.value = event.data.path;
-  }
-}, false);
+window.addEventListener(
+  'message',
+  (event) => {
+    if (event.data.action === 'slingcms.setpath') {
+      Sling.CMS.pathfield.value = event.data.path;
+    }
+  },
+  false,
+);


[sling-org-apache-sling-app-cms] 02/02: SLING-8919 - Fixing failure or handle editor dialogs on the page

Posted by dk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch SLING-8919-fix-error-dialog
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git

commit b105249dc079042ee276e76cfef2faf2a6e59ad4
Author: Dan Klco <dk...@apache.org>
AuthorDate: Tue Dec 17 23:22:19 2019 -0800

    SLING-8919 - Fixing failure or handle editor dialogs on the page
---
 ui/src/main/frontend/js/editor.js | 146 +++++++++++++++++++++++++-------------
 1 file changed, 96 insertions(+), 50 deletions(-)

diff --git a/ui/src/main/frontend/js/editor.js b/ui/src/main/frontend/js/editor.js
index e6c204a..ee22dc0 100644
--- a/ui/src/main/frontend/js/editor.js
+++ b/ui/src/main/frontend/js/editor.js
@@ -26,9 +26,13 @@ if (!window.CMSEditor) {
     init() {
       CMSEditor.util.attachEvents(document);
       // closing the modal
-      CMSEditor.util.attachClick(document, '.sling-cms-editor .modal-close, .sling-cms-editor .modal-background', () => {
-        CMSEditor.ui.hideModal();
-      });
+      CMSEditor.util.attachClick(
+        document,
+        '.sling-cms-editor .modal-close, .sling-cms-editor .modal-background',
+        () => {
+          CMSEditor.ui.hideModal();
+        },
+      );
       window.addEventListener('keypress', (e) => {
         if (e.keyCode === 27 && CMSEditor.ui.modalDisplayed === true) {
           CMSEditor.ui.hideModal();
@@ -80,13 +84,17 @@ if (!window.CMSEditor) {
       },
       reloadComponent(ip, cb) {
         let path = ip;
-        let component = document.querySelector(`.sling-cms-component[data-sling-cms-resource-path="${path}"]`);
+        let component = document.querySelector(
+          `.sling-cms-component[data-sling-cms-resource-path="${path}"]`,
+        );
         let reloadPage = component.dataset.reload === 'true';
         while (!component && path.length > 1) {
           const pathArr = path.split('/');
           pathArr.pop();
           path = pathArr.join('/');
-          component = document.querySelector(`.sling-cms-component[data-sling-cms-resource-path="${path}"]`);
+          component = document.querySelector(
+            `.sling-cms-component[data-sling-cms-resource-path="${path}"]`,
+          );
           if (component.dataset.reload === 'true') {
             reloadPage = true;
           }
@@ -95,23 +103,28 @@ if (!window.CMSEditor) {
           CMSEditor.ui.hideModal();
           window.top.location.reload();
         }
-        fetch(`/cms/page/pagewrapper.html${path}?forceResourceType=${component.dataset.slingCmsResourceType}`, {
-          redirect: 'manual',
-        }).then((response) => {
-          if (!response.ok) {
+        fetch(
+          `/cms/page/pagewrapper.html${path}?forceResourceType=${component.dataset.slingCmsResourceType}`,
+          {
+            redirect: 'manual',
+          },
+        )
+          .then((response) => {
+            if (!response.ok) {
+              CMSEditor.ui.hideModal();
+              window.top.location.reload();
+            }
+            return response.text();
+          })
+          .then((html) => {
+            const tmp = document.createElement('div');
+            tmp.innerHTML = html;
+            CMSEditor.util.attachEvents(tmp);
+            component.replaceWith(tmp.querySelector('.sling-cms-component'));
+            tmp.remove();
             CMSEditor.ui.hideModal();
-            window.top.location.reload();
-          }
-          return response.text();
-        }).then((html) => {
-          const tmp = document.createElement('div');
-          tmp.innerHTML = html;
-          CMSEditor.util.attachEvents(tmp);
-          component.replaceWith(tmp.querySelector('.sling-cms-component'));
-          tmp.remove();
-          CMSEditor.ui.hideModal();
-          cb();
-        });
+            cb();
+          });
       },
       showModal(url, t) {
         const title = t || '';
@@ -119,13 +132,25 @@ if (!window.CMSEditor) {
           CMSEditor.ui.hideModal();
         }
         document.querySelector('.sling-cms-editor-final').innerHTML = '<div class="modal"><div class="modal-background"></div><div class="modal-content"><div class="box"><h3 class="modal-title"></h3><section class="modal-body"></section></div></div><button class="modal-close is-large" aria-label="close"></button>';
-        document.querySelector('.sling-cms-editor .modal-title').innerText = title;
-        document.querySelector('.sling-cms-editor .modal-body').innerHTML = `<iframe class="modal-frame" src="${url}"></iframe>`;
-        document.querySelector('.sling-cms-editor .modal').classList.add('is-active');
-        CMSEditor.util.attachClick(document, '.sling-cms-editor .modal-background, .sling-cms-editor .modal-close', () => {
-          CMSEditor.ui.hideModal();
-        });
-        CMSEditor.ui.draggable(document.querySelector('.sling-cms-editor .modal-content'));
+        document.querySelector(
+          '.sling-cms-editor .modal-title',
+        ).innerText = title;
+        document.querySelector(
+          '.sling-cms-editor .modal-body',
+        ).innerHTML = `<iframe class="modal-frame" src="${url}"></iframe>`;
+        document
+          .querySelector('.sling-cms-editor .modal')
+          .classList.add('is-active');
+        CMSEditor.util.attachClick(
+          document,
+          '.sling-cms-editor .modal-background, .sling-cms-editor .modal-close',
+          () => {
+            CMSEditor.ui.hideModal();
+          },
+        );
+        CMSEditor.ui.draggable(
+          document.querySelector('.sling-cms-editor .modal-content'),
+        );
         CMSEditor.ui.modalDisplayed = true;
       },
     },
@@ -180,7 +205,11 @@ if (!window.CMSEditor) {
             });
             const res = await response.json();
             if (!response.ok) {
-              ui.confirmMessage('Failed to move', res['status.message'] || response.statusText, () => {});
+              ui.confirmMessage(
+                'Failed to move',
+                res['status.message'] || response.statusText,
+                () => {},
+              );
             } else {
               ui.confirmReload(res, 'success');
             }
@@ -203,16 +232,19 @@ if (!window.CMSEditor) {
               headers: {
                 Accept: 'application/json',
               },
-            }).then((response) => {
-              if (!response.ok) {
-                throw new Error(response.statusText);
-              }
-              return response.json();
-            }).catch((error) => {
-              ui.confirmMessage(error.message, error.message, () => {});
-            }).then(() => {
-              move();
-            });
+            })
+              .then((response) => {
+                if (!response.ok) {
+                  throw new Error(response.statusText);
+                }
+                return response.json();
+              })
+              .catch((error) => {
+                ui.confirmMessage(error.message, error.message, () => {});
+              })
+              .then(() => {
+                move();
+              });
           } else {
             move();
           }
@@ -245,35 +277,48 @@ if (!window.CMSEditor) {
           dragActive = true;
           event.dataTransfer.effectAllowed = 'move';
           dragImage = document.createElement('div');
-          dragImage.setAttribute('style', `position: absolute; left: 0px; top: 0px; width: ${ed.offsetWidth
-          }px; height: ${ed.offsetHeight}px; padding: 0.5em; background: grey; z-index: -1`);
+          dragImage.setAttribute(
+            'style',
+            `position: absolute; left: 0px; top: 0px; width: ${ed.offsetWidth}px; height: ${ed.offsetHeight}px; padding: 0.5em; background: grey; z-index: -1`,
+          );
           dragImage.innerText = ed.querySelector('.level-right').innerText;
           document.body.appendChild(dragImage);
           event.dataTransfer.setDragImage(dragImage, 20, 20);
-          event.dataTransfer.setData('path', ed.closest('.sling-cms-component').dataset.slingCmsResourcePath);
-          event.dataTransfer.setData('name', ed.closest('.sling-cms-component').dataset.slingCmsResourceName);
+          event.dataTransfer.setData(
+            'path',
+            ed.closest('.sling-cms-component').dataset.slingCmsResourcePath,
+          );
+          event.dataTransfer.setData(
+            'name',
+            ed.closest('.sling-cms-component').dataset.slingCmsResourceName,
+          );
           setTimeout(activateTargets, 10);
         });
         ed.addEventListener('dragend', deactivateTargets);
       },
       attachEvents(ctx) {
-        CMSEditor.util.attachClick(ctx, '.sling-cms-editor .action-button', (event) => {
+        function handleClick(event) {
           event.preventDefault();
           CMSEditor.ui.showModal(this.href, this.title);
-        });
+        }
+        CMSEditor.util.attachClick(ctx, '.sling-cms-editor .action-button', handleClick);
         if (ctx.matches && ctx.matches('.sling-cms-component')) {
           CMSEditor.util.attachHover(ctx);
         }
         ctx.querySelectorAll('.sling-cms-component').forEach((c) => {
           CMSEditor.util.attachHover(c);
         });
-        ctx.querySelectorAll('.sling-cms-editor').forEach(CMSEditor.util.attachDrag);
+        ctx
+          .querySelectorAll('.sling-cms-editor')
+          .forEach(CMSEditor.util.attachDrag);
       },
       attachHover(ctx) {
         function resetActive() {
-          document.querySelectorAll('.sling-cms-component__is-active').forEach((a) => {
-            a.classList.remove('sling-cms-component__is-active');
-          });
+          document
+            .querySelectorAll('.sling-cms-component__is-active')
+            .forEach((a) => {
+              a.classList.remove('sling-cms-component__is-active');
+            });
         }
         ctx.addEventListener('mouseover', (evt) => {
           resetActive();
@@ -285,7 +330,8 @@ if (!window.CMSEditor) {
       findParent(el, exp) {
         if (el === null || el.parentElement === null) {
           return null;
-        } if (el.parentElement.matches(exp)) {
+        }
+        if (el.parentElement.matches(exp)) {
           return el.parentElement;
         }
         return CMSEditor.util.findParent(el.parentElement, exp);