From 5966cc7f002f6b2e087757fe232401ae1ff42476 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 12 Jul 2013 16:29:34 +0200 Subject: [PATCH] Fixes clipboard's local storing of marked items --- wcfsetup/install/files/js/WCF.js | 48 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 93020c1e6a..d98f033d8d 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1069,10 +1069,10 @@ WCF.Clipboard = { _hasMarkedItems: false, /** - * list of ids of marked objects - * @var array + * list of ids of marked objects grouped by object type + * @var object */ - _markedObjectIDs: [], + _markedObjectIDs: { }, /** * current page @@ -1176,7 +1176,7 @@ WCF.Clipboard = { for (var $typeName in data.markedItems) { var $objectData = data.markedItems[$typeName]; for (var $i in $objectData) { - this._markedObjectIDs.push($objectData[$i]); + this._markedObjectIDs[$typeName].push($objectData[$i]); } // loop through all containers @@ -1191,7 +1191,7 @@ WCF.Clipboard = { // mark items as marked $container.find('input.jsClipboardItem').each($.proxy(function(innerIndex, item) { var $item = $(item); - if (WCF.inArray($item.data('objectID'), this._markedObjectIDs)) { + if (WCF.inArray($item.data('objectID'), this._markedObjectIDs[$typeName])) { $item.prop('checked', true); // add marked class for element container @@ -1225,12 +1225,13 @@ WCF.Clipboard = { * Resets all checkboxes. */ _resetMarkings: function() { - this._containers.each(function(index, container) { + this._containers.each($.proxy(function(index, container) { var $container = $(container); + this._markedObjectIDs[$container.data('type')] = [ ]; $container.find('input.jsClipboardItem, input.jsClipboardMarkAll').prop('checked', false); $container.find('.jsClipboardObject').removeClass('jsMarked'); - }); + }, this)); }, /** @@ -1245,6 +1246,7 @@ WCF.Clipboard = { if (!this._trackedElements[$containerID]) { $container.find('.jsClipboardMarkAll').data('hasContainer', $containerID).click($.proxy(this._markAll, this)); + this._markedObjectIDs[$container.data('type')] = [ ]; this._containerData[$container.data('type')] = {}; $.each($container.data(), $.proxy(function(index, element) { if (index.match(/^type(.+)/)) { @@ -1279,20 +1281,25 @@ WCF.Clipboard = { var $isMarked = ($item.prop('checked')) ? true : false; var $objectIDs = [ $objectID ]; + if ($item.data('hasContainer')) { + var $container = $('#' + $item.data('hasContainer')); + var $type = $container.data('type'); + } + else { + var $type = $item.data('type'); + } + if ($isMarked) { - this._markedObjectIDs.push($objectID); + this._markedObjectIDs[$type].push($objectID); $item.parents('.jsClipboardObject').addClass('jsMarked'); } else { - this._markedObjectIDs = $.removeArrayValue(this._markedObjectIDs, $objectID); + this._markedObjectIDs[$type] = $.removeArrayValue(this._markedObjectIDs[$type], $objectID); $item.parents('.jsClipboardObject').removeClass('jsMarked'); } // item is part of a container if ($item.data('hasContainer')) { - var $container = $('#' + $item.data('hasContainer')); - var $type = $container.data('type'); - // check if all items are marked var $markedAll = true; $container.find('input.jsClipboardItem').each(function(index, containerItem) { @@ -1312,10 +1319,6 @@ WCF.Clipboard = { } }); } - else { - // standalone item - var $type = $item.data('type'); - } this._saveState($type, $objectIDs, $isMarked); }, @@ -1335,11 +1338,16 @@ WCF.Clipboard = { $isMarked = $item.prop('checked'); } - // handle item containers if ($item.data('hasContainer')) { var $container = $('#' + $item.data('hasContainer')); var $type = $container.data('type'); - + } + else { + var $type = $item.data('type'); + } + + // handle item containers + if ($item.data('hasContainer')) { // toggle state for all associated items $container.find('input.jsClipboardItem').each($.proxy(function(index, containerItem) { var $containerItem = $(containerItem); @@ -1347,14 +1355,14 @@ WCF.Clipboard = { if ($isMarked) { if (!$containerItem.prop('checked')) { $containerItem.prop('checked', true); - this._markedObjectIDs.push($objectID); + this._markedObjectIDs[$type].push($objectID); $objectIDs.push($objectID); } } else { if ($containerItem.prop('checked')) { $containerItem.prop('checked', false); - this._markedObjectIDs = $.removeArrayValue(this._markedObjectIDs, $objectID); + this._markedObjectIDs[$type] = $.removeArrayValue(this._markedObjectIDs[$type], $objectID); $objectIDs.push($objectID); } } -- 2.20.1