Adds JavaScript class for deleting an element with children
authorMatthias Schmidt <gravatronics@live.com>
Mon, 6 May 2013 18:25:55 +0000 (20:25 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 6 May 2013 18:25:55 +0000 (20:25 +0200)
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/categoryList.tpl
wcfsetup/install/files/js/WCF.js

index 174efe6e0bfe2a54bb746598c0e6c6205ff08c31..e1231cd582f308094d362a70f032ec2707c13268 100644 (file)
@@ -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
  * 
index f84f3ef49059d07ddc92113a164db8f00cf1366f..42ee5ded683afebe588190078bb4bb53c0e8873a 100644 (file)
@@ -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');
index 876e96514b8a2f0830c31b778a83e8cf41b02d0d..41a6c89bafcb81909e122cb68bd7b61602dfb277 100755 (executable)
@@ -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.
  *