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
commit 15637ebdd35d9e311b600130ed3894cd52ddd5cd Author: Dan Klco <[email protected]> AuthorDate: Tue Aug 28 08:22:04 2018 -0400 Fixing an issue where delete / move on a page caused an error to be displayed --- ui/src/main/frontend/src/js/scripts.js | 82 ++++++++++++++-------- .../components/editor/slingform/slingform.jsp | 2 +- .../libs/sling-cms/content/shared/delete.json | 3 +- .../libs/sling-cms/content/shared/movecopy.json | 1 + 4 files changed, 57 insertions(+), 31 deletions(-) diff --git a/ui/src/main/frontend/src/js/scripts.js b/ui/src/main/frontend/src/js/scripts.js index ca3ecfa..6760a4f 100644 --- a/ui/src/main/frontend/src/js/scripts.js +++ b/ui/src/main/frontend/src/js/scripts.js @@ -83,26 +83,11 @@ Sling.CMS = { } }; - //support links which fetch HTML and display a modal - Sling.CMS.ext['fetch-modal'] = { - decorate : function($ctx){ - $ctx.find('a.Fetch-Modal').click(function(){ - var $link = $(this); - $link.attr('disabled', 'disabled'); - Sling.CMS.ui.fetchModal($link.attr('data-title'), encodeURI($link.attr('href')), $link.attr('data-path'), function(){ - $link.removeAttr('disabled'); - }); - return false; - }); - } - }; - Sling.CMS.ext['ajaxform'] = { decorate: function($ctx){ $ctx.find('.Form-Ajax').submit(function(){ var $form = $(this); - var $inputs = $form.find('input,select,textarea,button'); var jcrcontent = false; $form.find('input,select,textarea').each(function(idx,inp){ if(inp.name.indexOf('jcr:content') != -1){ @@ -122,6 +107,7 @@ Sling.CMS = { $form.append('<input type="hidden" name="jcr:createdBy" />'); } } + var callback = $form.data('callback'); var data = new FormData(this); $form.find('.Form-Ajax__wrapper').attr('disabled', 'disabled'); $.ajax({ @@ -132,14 +118,10 @@ Sling.CMS = { contentType: false, dataType: 'json', success: function(res,msg){ - if(window.self !== window.top){ - window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){ - window.top.location.reload(); - }); + if (callback && Sling.CMS.ext[callback]){ + Sling.CMS.ext[callback](res, msg); } else { - Sling.CMS.ui.confirmMessage(msg, res.title,function(){ - location.reload(); - }); + Sling.CMS.ext.reload(res, msg); } }, error: function(xhr, msg, err){ @@ -190,7 +172,6 @@ Sling.CMS = { if($h.data('sort-status')){ sortStatus = parseInt($h.data('sort-status'),10); } - var name = $h.data('attribute'); var list = $table.find(".sortable__row").get(); list.sort(function(rowa, rowb) { var vala = null; @@ -232,7 +213,6 @@ Sling.CMS = { // mouse button down over the element element.addEventListener('mousedown', function(evt){ - console.log('mousedown'); if(document.querySelector('.Modal-Body').contains(evt.target)){ return; } @@ -241,8 +221,7 @@ Sling.CMS = { mouseDown = true; }); - var moveComplete = function(evt){ - console.log('mouseup'); + var moveComplete = function(){ mouseDown = false; elementX = parseInt(element.style.left) || 0; elementY = parseInt(element.style.top) || 0; @@ -256,7 +235,6 @@ Sling.CMS = { if (!mouseDown) { return; } - console.log('mousemove'); var deltaX = event.clientX - mouseX; var deltaY = event.clientY - mouseY; element.style.left = elementX + deltaX + 'px'; @@ -285,6 +263,20 @@ Sling.CMS = { }); } }; + + //support links which fetch HTML and display a modal + Sling.CMS.ext['fetch-modal'] = { + decorate : function($ctx){ + $ctx.find('a.Fetch-Modal').click(function(){ + var $link = $(this); + $link.attr('disabled', 'disabled'); + Sling.CMS.ui.fetchModal($link.attr('data-title'), encodeURI($link.attr('href')), $link.attr('data-path'), function(){ + $link.removeAttr('disabled'); + }); + return false; + }); + } + }; Sling.CMS.ext['getform'] = { decorate: function($ctx){ @@ -321,6 +313,27 @@ Sling.CMS = { } }; + Sling.CMS.ext['handledelete'] = function(res, msg){ + if(window.location.pathname.indexOf(res.path) !== -1){ + window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){ + window.location = '/cms'; + }); + } else { + Sling.CMS.ext.reload(res, msg); + } + } + + Sling.CMS.ext['handlemove'] = function(res, msg){ + var changes = res.changes[0]; + if(changes.type === 'moved' && window.location.pathname.indexOf(changes.argument[0]) !== -1){ + window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){ + window.location = window.location.href.replace(changes.argument[0], changes.argument[1]); + }); + } else { + Sling.CMS.ext.reload(res, msg); + } + } + Sling.CMS.ext['namehint'] = { decorate: function($ctx){ $ctx.find('.namehint').each(function(){ @@ -365,7 +378,6 @@ Sling.CMS = { try { xhr.abort(); } catch(e){} - var t = term; if(term === '/'){ term = base; } @@ -384,6 +396,18 @@ Sling.CMS = { } }; + Sling.CMS.ext['reload'] = function(res, msg) { + if(window.self !== window.top){ + window.top.Sling.CMS.ui.confirmMessage(msg, res.title,function(){ + window.top.location.reload(); + }); + } else { + Sling.CMS.ui.confirmMessage(msg, res.title,function(){ + location.reload(); + }); + } + } + Sling.CMS.ext['repeating'] = { decorate: function($ctx){ $ctx.find('.repeating').each(function(){ @@ -419,7 +443,7 @@ Sling.CMS = { return url; }, callbacks: { - onDialogShown: function(e){ + onDialogShown: function(){ Sling.CMS.ext.pathfield.suggest($('.note-link-url')[0], 'content', '/content'); Sling.CMS.ext.pathfield.suggest($('.note-image-url')[0], 'content', '/content'); } diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/slingform/slingform.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/slingform/slingform.jsp index dd14a96..f2e2e9b 100644 --- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/slingform/slingform.jsp +++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/editor/slingform/slingform.jsp @@ -17,7 +17,7 @@ * under the License. */ --%> <%@include file="/libs/sling-cms/global.jsp"%> -<form method="post" action="${slingRequest.requestPathInfo.suffix}${properties.actionSuffix}" enctype="multipart/form-data" class="Form-Ajax" data-add-date="${properties.addDate != false}"> +<form method="post" action="${slingRequest.requestPathInfo.suffix}${properties.actionSuffix}" enctype="multipart/form-data" class="Form-Ajax" data-add-date="${properties.addDate != false}" data-callback="${properties.callback}"> <fieldset class="Form-Ajax__wrapper"> <input type="hidden" name="_charset_" value="utf-8" /> <sling:include path="fields" resourceType="sling-cms/components/general/container" /> diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/delete.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/delete.json index 29fd916..27c13a9 100644 --- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/delete.json +++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/delete.json @@ -16,12 +16,13 @@ "jcr:primaryType": "nt:unstructured", "sling:resourceType": "sling-cms/components/editor/slingform", "button": "Delete", + "callback": "handledelete", "fields": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "sling-cms/components/general/container", "path": { "jcr:primaryType": "nt:unstructured", - "sling:resourceType" : "sling-cms/components/editor/fields/suffixlabel", + "sling:resourceType": "sling-cms/components/editor/fields/suffixlabel", "label": "Do you want to delete:" }, "operation": { diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/movecopy.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/movecopy.json index ce2bd3d..8d6c399 100644 --- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/movecopy.json +++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/shared/movecopy.json @@ -16,6 +16,7 @@ "jcr:primaryType": "nt:unstructured", "sling:resourceType": "sling-cms/components/editor/slingform", "button": "Move/Copy", + "callback": "handlemove", "fields": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "sling-cms/components/general/container",
