[BUGFIX] Read page ID correctly when drag-dropping content 40/57640/4
authorClaus Due <claus@namelesscoder.net>
Fri, 20 Jul 2018 12:04:55 +0000 (14:04 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 3 Aug 2018 15:15:04 +0000 (17:15 +0200)
Fixes an issue where drag and dropping a content element
would send the page title, not the page ID, as part of the
command map DataHandler receives.

The reason was an indiscriminate lookup in DOM for any
element which had any `data-page` attribute and assuming
that the first found object contained the integer value.

Using the drop target’s parent element instead will resolve
the value from the nearest relative place it can be found.

Effect is that DataHandler command hooks can once again
safely assume that the value of the “move” command is the
target page ID, not an arbitrary title on v9 and ID on v8.

Change-Id: I3b34bd099d50f6ef88fc6df1bbb647acbaa253d2
Releases: master
Resolves: #85603
Reviewed-on: https://review.typo3.org/57640
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Paweł Rogowicz <rogowicz.pawel@gmail.com>
Reviewed-by: Łukasz Uznański <l.uznanski@macopedia.pl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Resources/Private/TypeScript/LayoutModule/DragDrop.ts
typo3/sysext/backend/Resources/Public/JavaScript/LayoutModule/DragDrop.js

index d814e79..1418faa 100644 (file)
@@ -185,8 +185,8 @@ class DragDrop {
       let targetPid = 0;
 
       if (typeof targetFound === 'undefined') {
-        // the actual page is needed
-        targetPid = $('[data-page]').first().data('page');
+        // the actual page is needed. Read it from the container into which the element was dropped.
+        targetPid = parseInt((<HTMLElement>evt.target).offsetParent.getAttribute('data-page'), 10);
       } else {
         // the negative value of the content element after where it should be moved
         targetPid = 0 - parseInt(targetFound, 10);
index fcb59a9..ca04c14 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","../AjaxDataHandler","jquery-ui/droppable"],function(e,t,n,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(){}return e.initialize=function(){n(e.contentIdentifier).draggable({handle:e.dragHeaderIdentifier,scope:"tt_content",cursor:"move",distance:20,revert:"invalid",zIndex:100,start:function(t,o){e.onDragStart(n(t.target))},stop:function(t,o){e.onDragStop(n(t.target))}}),n(e.dropZoneIdentifier).droppable({accept:this.contentIdentifier,scope:"tt_content",tolerance:"pointer",over:function(t,o){e.onDropHoverOver(n(o.draggable),n(t.target))},out:function(t,o){e.onDropHoverOut(n(o.draggable),n(t.target))},drop:function(t,o){e.onDrop(n(o.draggable),n(t.target),t)}})},e.onDragStart=function(t){e.originalStyles=t.get(0).style.cssText,t.children(e.dragIdentifier).addClass("dragitem-shadow"),t.append('<div class="ui-draggable-copy-message">'+TYPO3.lang["dragdrop.copy.message"]+"</div>"),t.children(e.dropZoneIdentifier).addClass("drag-start"),t.closest(e.columnIdentifier).removeClass("active"),t.find(e.dropZoneIdentifier).hide(),n(e.dropZoneIdentifier).each(function(t,o){var a=n(o);a.parent().find(".t3js-toggle-new-content-element-wizard").length?a.addClass(e.validDropZoneClass):a.closest(e.contentIdentifier).find("> "+e.addContentIdentifier+", > > "+e.addContentIdentifier).show()})},e.onDragStop=function(t){t.children(e.dragIdentifier).removeClass("dragitem-shadow"),t.children(e.dropZoneIdentifier).removeClass("drag-start"),t.closest(e.columnIdentifier).addClass("active"),t.find(e.dropZoneIdentifier).show(),t.find(".ui-draggable-copy-message").remove(),t.get(0).style.cssText=e.originalStyles,n(e.dropZoneIdentifier+"."+e.validDropZoneClass).removeClass(e.validDropZoneClass)},e.onDropHoverOver=function(t,n){n.hasClass(e.validDropZoneClass)&&n.addClass(e.dropPossibleHoverClass)},e.onDropHoverOut=function(t,n){n.removeClass(e.dropPossibleHoverClass)},e.onDrop=function(t,o,a){var r=e.getColumnPositionForElement(o);o.removeClass(e.dropPossibleHoverClass);var i="number"==typeof t,s=!0===i?t:parseInt(t.data("uid"),10);if("number"==typeof s&&s>0){var d={},l=o.closest(e.contentIdentifier).data("uid"),c=0;c=void 0===l?n("[data-page]").first().data("page"):0-parseInt(l,10);var p=parseInt(o.closest("[data-language-uid]").data("language-uid"),10),g=0;0!==c&&(g=r),d.cmd={tt_content:{}},d.data={tt_content:{}};var f=a&&a.originalEvent.ctrlKey||o.hasClass("t3js-paste-copy");f?(d.cmd.tt_content[s]={copy:{action:"paste",target:c,update:{colPos:g,sys_language_uid:p}}},e.ajaxAction(o,t,d,f,i)):(d.data.tt_content[s]={colPos:g,sys_language_uid:p},i?d={CB:{paste:"tt_content|"+c,update:{colPos:g,sys_language_uid:p}}}:d.cmd.tt_content[s]={move:c},e.ajaxAction(o,t,d,f,i))}},e.ajaxAction=function(t,n,a,r,i){o.process(a).done(function(o){o.hasErrors||(i||(t.parent().hasClass(e.contentIdentifier.substring(1))?n.detach().css({top:0,left:0}).insertAfter(t.closest(e.contentIdentifier)):n.detach().css({top:0,left:0}).insertAfter(t.closest(e.dropZoneIdentifier))),self.location.reload(!0))})},e.getColumnPositionForElement=function(e){var t=e.closest("[data-colpos]");return!(!t.length||"undefined"===t.data("colpos"))&&t.data("colpos")},e.contentIdentifier=".t3js-page-ce",e.dragIdentifier=".t3-page-ce-dragitem",e.dragHeaderIdentifier=".t3js-page-ce-draghandle",e.dropZoneIdentifier=".t3js-page-ce-dropzone-available",e.columnIdentifier=".t3js-page-column",e.validDropZoneClass="active",e.dropPossibleHoverClass="t3-page-ce-dropzone-possible",e.addContentIdentifier=".t3js-page-new-ce",e.originalStyles="",e}();t.default=a,n(a.initialize)});
\ No newline at end of file
+define(["require","exports","jquery","../AjaxDataHandler","jquery-ui/droppable"],function(e,t,n,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(){}return e.initialize=function(){n(e.contentIdentifier).draggable({handle:e.dragHeaderIdentifier,scope:"tt_content",cursor:"move",distance:20,revert:"invalid",zIndex:100,start:function(t,o){e.onDragStart(n(t.target))},stop:function(t,o){e.onDragStop(n(t.target))}}),n(e.dropZoneIdentifier).droppable({accept:this.contentIdentifier,scope:"tt_content",tolerance:"pointer",over:function(t,o){e.onDropHoverOver(n(o.draggable),n(t.target))},out:function(t,o){e.onDropHoverOut(n(o.draggable),n(t.target))},drop:function(t,o){e.onDrop(n(o.draggable),n(t.target),t)}})},e.onDragStart=function(t){e.originalStyles=t.get(0).style.cssText,t.children(e.dragIdentifier).addClass("dragitem-shadow"),t.append('<div class="ui-draggable-copy-message">'+TYPO3.lang["dragdrop.copy.message"]+"</div>"),t.children(e.dropZoneIdentifier).addClass("drag-start"),t.closest(e.columnIdentifier).removeClass("active"),t.find(e.dropZoneIdentifier).hide(),n(e.dropZoneIdentifier).each(function(t,o){var a=n(o);a.parent().find(".t3js-toggle-new-content-element-wizard").length?a.addClass(e.validDropZoneClass):a.closest(e.contentIdentifier).find("> "+e.addContentIdentifier+", > > "+e.addContentIdentifier).show()})},e.onDragStop=function(t){t.children(e.dragIdentifier).removeClass("dragitem-shadow"),t.children(e.dropZoneIdentifier).removeClass("drag-start"),t.closest(e.columnIdentifier).addClass("active"),t.find(e.dropZoneIdentifier).show(),t.find(".ui-draggable-copy-message").remove(),t.get(0).style.cssText=e.originalStyles,n(e.dropZoneIdentifier+"."+e.validDropZoneClass).removeClass(e.validDropZoneClass)},e.onDropHoverOver=function(t,n){n.hasClass(e.validDropZoneClass)&&n.addClass(e.dropPossibleHoverClass)},e.onDropHoverOut=function(t,n){n.removeClass(e.dropPossibleHoverClass)},e.onDrop=function(t,n,o){var a=e.getColumnPositionForElement(n);n.removeClass(e.dropPossibleHoverClass);var r="number"==typeof t,i=!0===r?t:parseInt(t.data("uid"),10);if("number"==typeof i&&i>0){var s={},d=n.closest(e.contentIdentifier).data("uid"),l=0;l=void 0===d?parseInt(o.target.offsetParent.getAttribute("data-page"),10):0-parseInt(d,10);var c=parseInt(n.closest("[data-language-uid]").data("language-uid"),10),p=0;0!==l&&(p=a),s.cmd={tt_content:{}},s.data={tt_content:{}};var g=o&&o.originalEvent.ctrlKey||n.hasClass("t3js-paste-copy");g?(s.cmd.tt_content[i]={copy:{action:"paste",target:l,update:{colPos:p,sys_language_uid:c}}},e.ajaxAction(n,t,s,g,r)):(s.data.tt_content[i]={colPos:p,sys_language_uid:c},r?s={CB:{paste:"tt_content|"+l,update:{colPos:p,sys_language_uid:c}}}:s.cmd.tt_content[i]={move:l},e.ajaxAction(n,t,s,g,r))}},e.ajaxAction=function(t,n,a,r,i){o.process(a).done(function(o){o.hasErrors||(i||(t.parent().hasClass(e.contentIdentifier.substring(1))?n.detach().css({top:0,left:0}).insertAfter(t.closest(e.contentIdentifier)):n.detach().css({top:0,left:0}).insertAfter(t.closest(e.dropZoneIdentifier))),self.location.reload(!0))})},e.getColumnPositionForElement=function(e){var t=e.closest("[data-colpos]");return!(!t.length||"undefined"===t.data("colpos"))&&t.data("colpos")},e.contentIdentifier=".t3js-page-ce",e.dragIdentifier=".t3-page-ce-dragitem",e.dragHeaderIdentifier=".t3js-page-ce-draghandle",e.dropZoneIdentifier=".t3js-page-ce-dropzone-available",e.columnIdentifier=".t3js-page-column",e.validDropZoneClass="active",e.dropPossibleHoverClass="t3-page-ce-dropzone-possible",e.addContentIdentifier=".t3js-page-new-ce",e.originalStyles="",e}();t.default=a,n(a.initialize)});
\ No newline at end of file