From: Matthias Schmidt Date: Mon, 6 May 2013 18:25:55 +0000 (+0200) Subject: Adds JavaScript class for deleting an element with children X-Git-Tag: 2.0.0_Beta_1~247 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8a52f0a47a9fa19345cda4b1f50f23dc9dde6231;p=GitHub%2FWoltLab%2FWCF.git Adds JavaScript class for deleting an element with children --- diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 174efe6e0b..e1231cd582 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -1770,34 +1770,6 @@ WCF.ACP.Category.Collapsible = WCF.Collapsible.SimpleRemote.extend({ } }); -/** - * @see WCF.Action.Delete - */ -WCF.ACP.Category.Delete = WCF.Action.Delete.extend({ - /** - * @see WCF.Action.Delete.triggerEffect() - */ - triggerEffect: function(objectIDs) { - for (var $index in this._containers) { - var $container = $('#' + this._containers[$index]); - if (WCF.inArray($container.find('.jsDeleteButton').data('objectID'), objectIDs)) { - // move child categories up - if ($container.has('ol').has('li')) { - if ($container.is(':only-child')) { - $container.parent().replaceWith($container.find('> ol')); - } - else { - $container.replaceWith($container.find('> ol > li')); - } - } - else { - $container.wcfBlindOut('up', function() { $container.remove(); }); - } - } - } - } -}); - /** * Provides the search dropdown for ACP * diff --git a/wcfsetup/install/files/acp/templates/categoryList.tpl b/wcfsetup/install/files/acp/templates/categoryList.tpl index f84f3ef490..42ee5ded68 100644 --- a/wcfsetup/install/files/acp/templates/categoryList.tpl +++ b/wcfsetup/install/files/acp/templates/categoryList.tpl @@ -7,9 +7,9 @@ {if $collapsibleObjectTypeID} new WCF.ACP.Category.Collapsible('wcf\\data\\category\\CategoryAction', {@$collapsibleObjectTypeID}); {/if} - + {if $objectType->getProcessor()->canDeleteCategory()} - new WCF.ACP.Category.Delete('wcf\\data\\category\\CategoryAction', $('.jsCategory')); + new WCF.Action.NestedDelete('wcf\\data\\category\\CategoryAction', '.jsCategory'); {/if} {if $objectType->getProcessor()->canEditCategory()} new WCF.Action.Toggle('wcf\\data\\category\\CategoryAction', '.jsCategory', '> .sortableNodeLabel > .buttons > .jsToggleButton'); diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 876e96514b..41a6c89baf 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1961,6 +1961,40 @@ WCF.Action.Delete = Class.extend({ } }); +/** + * Basic implementation for deletion of nested elements. + * + * The implementation requires the nested elements to be grouped as numbered lists + * (ol lists). The child elements of the deleted elements are moved to the parent + * element of the deleted element. + * + * @see WCF.Action.Delete + */ +WCF.Action.NestedDelete = WCF.Action.Delete.extend({ + /** + * @see WCF.Action.Delete.triggerEffect() + */ + triggerEffect: function(objectIDs) { + for (var $index in this._containers) { + var $container = $('#' + this._containers[$index]); + if (WCF.inArray($container.find(this._buttonSelector).data('objectID'), objectIDs)) { + // move child categories up + if ($container.has('ol').has('li')) { + if ($container.is(':only-child')) { + $container.parent().replaceWith($container.find('> ol')); + } + else { + $container.replaceWith($container.find('> ol > li')); + } + } + else { + $container.wcfBlindOut('up', function() { $(this).remove(); }); + } + } + } + } +}); + /** * Basic implementation for AJAXProxy-based toggle actions. *