WCF.Action.Delete overhaul
authorAlexander Ebert <ebert@woltlab.com>
Sun, 16 Dec 2012 21:32:26 +0000 (22:32 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 16 Dec 2012 21:32:26 +0000 (22:32 +0100)
Furthermore added WCF.DOMNodeInsertedHandler.forceExecution()

wcfsetup/install/files/acp/templates/cronjobList.tpl
wcfsetup/install/files/acp/templates/pageMenuItemList.tpl
wcfsetup/install/files/acp/templates/updateServerList.tpl
wcfsetup/install/files/acp/templates/userGroupList.tpl
wcfsetup/install/files/acp/templates/userList.tpl
wcfsetup/install/files/js/WCF.js

index fc2114fcb5cb1171b201811bdfb988ba48e6ca83..35ad80c2180596fee6381e78e82349b1f3030e01 100644 (file)
@@ -10,7 +10,7 @@
 <script type="text/javascript">
        //<![CDATA[
        $(function() {
-               new WCF.Action.Delete('wcf\\data\\cronjob\\CronjobAction', $('.jsCronjobRow'));
+               new WCF.Action.Delete('wcf\\data\\cronjob\\CronjobAction', '.jsCronjobRow');
                new WCF.Action.Toggle('wcf\\data\\cronjob\\CronjobAction', $('.jsCronjobRow'));
                new WCF.Action.SimpleProxy({
                        action: 'execute',
index 1acfa1f94a63a08d33b5f8a8cb471ae6f9d9e30f..23dca21a79ac94317757324af3911b84a01ce4f8 100644 (file)
@@ -9,7 +9,7 @@
 <script type="text/javascript">
        //<![CDATA[
        $(function() {
-               new WCF.Action.Delete('wcf\\data\\page\\menu\\item\\PageMenuItemAction', $('.sortableNode'));
+               new WCF.Action.Delete('wcf\\data\\page\\menu\\item\\PageMenuItemAction', '.sortableNode');
                new WCF.Action.Toggle('wcf\\data\\page\\menu\\item\\PageMenuItemAction', $('.sortableNode'));
                
                {if $headerItems|count}new WCF.Sortable.List('pageMenuItemHeaderList', 'wcf\\data\\page\\menu\\item\\PageMenuItemAction', undefined, { protectRoot: true }, false, { menuPosition: 'header' });{/if}
index ed0c9c08cd745e1c9d81defd3dcd1475694915f3..24ed0f35e5b20d9d883ef3be2c105396f5e64c5c 100644 (file)
@@ -3,7 +3,7 @@
 <script type="text/javascript">
        //<![CDATA[
        $(function() {
-               new WCF.Action.Delete('wcf\\data\\package\\update\\server\\PackageUpdateServerAction', $('.jsUpdateServerRow'));
+               new WCF.Action.Delete('wcf\\data\\package\\update\\server\\PackageUpdateServerAction', '.jsUpdateServerRow');
                new WCF.Action.Toggle('wcf\\data\\package\\update\\server\\PackageUpdateServerAction', $('.jsUpdateServerRow'));
        });
        //]]>
index a562eea8532b678902ec01eca04a93c7f2238751..20c0bcafa0b1bd73d3955abdcacf9fd2ca49b28d 100644 (file)
@@ -3,7 +3,7 @@
 <script type="text/javascript">
        //<![CDATA[
        $(function() {
-               new WCF.Action.Delete('wcf\\data\\user\\group\\UserGroupAction', $('.jsUserGroupRow'));
+               new WCF.Action.Delete('wcf\\data\\user\\group\\UserGroupAction', '.jsUserGroupRow');
        });
        //]]>
 </script>
index 470d39b3c6f3bc7e8bba515bf83d63ee877820ef..6f872fdd61e77af8b6dd3d4ef738566ce74dc0b6 100644 (file)
@@ -11,7 +11,7 @@
        $(function() {
                var actionObjects = { };
                actionObjects['com.woltlab.wcf.user'] = { };
-               actionObjects['com.woltlab.wcf.user']['delete'] = new WCF.Action.Delete('wcf\\data\\user\\UserAction', $('.jsUserRow'), $('#userTableContainer .wcf-menu li:first-child .wcf-badge'));
+               actionObjects['com.woltlab.wcf.user']['delete'] = new WCF.Action.Delete('wcf\\data\\user\\UserAction', '.jsUserRow');
                
                WCF.Clipboard.init('wcf\\acp\\page\\UserListPage', {@$hasMarkedItems}, actionObjects);
                
index 88dc39c30d9d07e9b333af7de48acc513c4a34a7..f6db066a52cc76935591c114f99b51ed494b87c0 100755 (executable)
@@ -1693,33 +1693,59 @@ WCF.Action.SimpleProxy = Class.extend({
  * Basic implementation for AJAXProxy-based deletion.
  * 
  * @param      string          className
- * @param      jQuery          containerList
- * @param      jQuery          badgeList
+ * @param      string          containerSelector
  */
 WCF.Action.Delete = Class.extend({
+       /**
+        * action class name
+        * @var string
+        */
+       _className: '',
+       
+       /**
+        * container selector
+        * @var string
+        */
+       _containerSelector: '',
+       
+       /**
+        * list of known container ids
+        * @var array<string>
+        */
+       _containers: [ ],
+       
        /**
         * Initializes 'delete'-Proxy.
         * 
         * @param       string          className
-        * @param       jQuery          containerList
-        * @param       jQuery          badgeList
+        * @param       string          containerSelector
         */
-       init: function(className, containerList, badgeList) {
-               if (!containerList.length) return;
-               this.containerList = containerList;
-               this.className = className;
-               this.badgeList = badgeList;
-               
-               // initialize proxy
-               var options = {
+       init: function(className, containerSelector) {
+               this._containerSelector = containerSelector;
+               this._className = className;
+               this.proxy = new WCF.Action.Proxy({
                        success: $.proxy(this._success, this)
-               };
-               this.proxy = new WCF.Action.Proxy(options);
+               });
                
-               // bind event listener
-               this.containerList.each($.proxy(function(index, container) {
-                       $(container).find('.jsDeleteButton').bind('click', $.proxy(this._click, this));
-               }, this));
+               this._initElements();
+               
+               WCF.DOMNodeInsertedHandler.addCallback('WCF.Action.Delete' + this._className.hashCode(), $.proxy(this._initElements, this));
+       },
+       
+       /**
+        * Initializes available element containers.
+        */
+       _initElements: function() {
+               var self = this;
+               $(this._containerSelector).each(function(index, container) {
+                       var $container = $(container);
+                       var $containerID = $container.wcfIdentify();
+                       
+                       if (!WCF.inArray($containerID, self._containers)) {
+                               self._containers.push($containerID);
+                               $container.find('.jsDeleteButton').click($.proxy(self._click, self));
+                       }
+               });
        },
        
        /**
@@ -1757,7 +1783,7 @@ WCF.Action.Delete = Class.extend({
        _sendRequest: function(object) {
                this.proxy.setOption('data', {
                        actionName: 'delete',
-                       className: this.className,
+                       className: this._className,
                        objectIDs: [ $(object).data('objectID') ]
                });
                
@@ -1781,21 +1807,12 @@ WCF.Action.Delete = Class.extend({
         * @param       array           objectIDs
         */
        triggerEffect: function(objectIDs) {
-               this.containerList.each($.proxy(function(index, container) {
-                       var $objectID = $(container).find('.jsDeleteButton').data('objectID');
-                       if (WCF.inArray($objectID, objectIDs)) {
-                               $(container).wcfBlindOut('up', function() {
-                                       $(container).empty().remove();
-                               }, container);
-                               
-                               // update badges
-                               if (this.badgeList) {
-                                       this.badgeList.each(function(innerIndex, badge) {
-                                               $(badge).html($(badge).html() - 1);
-                                       });
-                               }
+               for (var $index in this._containers) {
+                       var $container = $('#' + this._containers[$index]);
+                       if (WCF.inArray($container.find('.jsDeleteButton').data('objectID'), objectIDs)) {
+                               $container.wcfBlindOut('up', function() { $container.remove(); });
                        }
-               }, this));
+               }
        }
 });
 
@@ -4141,6 +4158,12 @@ WCF.DOMNodeInsertedHandler = {
         */
        _discardEvent: true,
        
+       /**
+        * counts requests to enable WCF.DOMNodeInsertedHandler
+        * @var integer
+        */
+       _discardEventCount: 0,
+       
        /**
         * prevent infinite loop if a callback manipulates DOM
         * @var boolean
@@ -4160,6 +4183,7 @@ WCF.DOMNodeInsertedHandler = {
         * @param       object          callback
         */
        addCallback: function(identifier, callback) {
+               this._discardEventCount = 0;
                this._bindListener();
                
                if (this._callbacks.isset(identifier)) {
@@ -4195,7 +4219,7 @@ WCF.DOMNodeInsertedHandler = {
        /**
         * Executes callbacks on click.
         */
-       _executeCallbacks: function(event) {
+       _executeCallbacks: function() {
                if (this._discardEvent || this._isExecuting) return;
                
                // do not track events while executing callbacks
@@ -4203,7 +4227,7 @@ WCF.DOMNodeInsertedHandler = {
                
                this._callbacks.each(function(pair) {
                        // execute callback
-                       pair.value(event);
+                       pair.value();
                });
                
                // enable listener again
@@ -4214,7 +4238,12 @@ WCF.DOMNodeInsertedHandler = {
         * Disables DOMNodeInsertedHandler, should be used after you've enabled it.
         */
        disable: function() {
-               this._discardEvent = true;
+               this._discardEventCount--;
+               
+               if (this._discardEventCount < 1) {
+                       this._discardEvent = true;
+                       this._discardEventCount = 0;
+               }
        },
        
        /**
@@ -4223,7 +4252,18 @@ WCF.DOMNodeInsertedHandler = {
         * once you've enabled it, if you fail it will cause an infinite loop!
         */
        enable: function() {
+               this._discardEventCount++;
+               
                this._discardEvent = false;
+       },
+       
+       /**
+        * Forces execution of DOMNodeInsertedHandler.
+        */
+       forceExecution: function() {
+               this.enable();
+               this._executeCallbacks();
+               this.disable();
        }
 };