Removes double code
authorMatthias Schmidt <gravatronics@live.com>
Tue, 1 Jan 2013 15:17:21 +0000 (16:17 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 1 Jan 2013 15:17:21 +0000 (16:17 +0100)
wcfsetup/install/files/js/WCF.ACL.js

index 36ac507ec3d6a50c71fc35e7bf6d6db370a98855..0aec613326de44f4784dfa53baaf61679f1987f9 100644 (file)
@@ -171,9 +171,7 @@ WCF.ACL.List = Class.extend({
         * @param       object          data
         */
        addObject: function(data) {
-               var $listItem = $('<li><img src="' + WCF.Icon.get('wcf.icon.user' + ((data.type == 'group') ? 's' : '')) + '" alt="" class="icon16" /> <span>' + data.label + '</span></li>').appendTo(this._containerElements.aclList);
-               $listItem.data('objectID', data.objectID).data('type', data.type).click($.proxy(this._click, this));
-               $('<img src="' + WCF.Icon.get('wcf.icon.delete') + '" alt="" title="' + WCF.Language.get('wcf.global.button.delete') + '" class="icon16 jsTooltip" />').click($.proxy(this._removeItem, this)).appendTo($listItem);
+               var $listItem = this._createListItem(data.objectID, data.label, data.type);
                
                // toggle element
                this._savePermissions();
@@ -192,6 +190,22 @@ WCF.ACL.List = Class.extend({
                this._containerElements.permissionList.show();
        },
        
+       /**
+        * Creates a list item with the given data and returns it.
+        * 
+        * @param       integer         objectID
+        * @param       string          label
+        * @param       string          type
+        * @return      jQuery
+        */
+       _createListItem: function(objectID, label, type) {
+               var $listItem = $('<li><img src="' + WCF.Icon.get('wcf.icon.user' + ((type == 'group') ? 's' : '')) + '" alt="" class="icon16" /> <span>' + label + '</span></li>').appendTo(this._containerElements.aclList);
+               $listItem.data('objectID', objectID).data('type', type).click($.proxy(this._click, this));
+               $('<img src="' + WCF.Icon.get('wcf.icon.delete') + '" alt="" title="' + WCF.Language.get('wcf.global.button.delete') + '" class="icon16 jsTooltip" />').click($.proxy(this._removeItem, this)).appendTo($listItem);
+               
+               return $listItem;
+       },
+       
        /**
         * Removes an item from list.
         * 
@@ -315,9 +329,7 @@ WCF.ACL.List = Class.extend({
                
                // add list items
                for (var $typeID in data.returnValues[type].label) {
-                       var $listItem = $('<li><img src="' + WCF.Icon.get('wcf.icon.user' + ((data.type == 'group') ? 's' : '')) + '" alt="" class="icon16" /> <span>' + data.returnValues[type].label[$typeID] + '</span></li>').appendTo(this._containerElements.aclList);
-                       $listItem.data('objectID', $typeID).data('type', type).click($.proxy(this._click, this));
-                       $('<img src="' + WCF.Icon.get('wcf.icon.delete') + '" alt="" title="' + WCF.Language.get('wcf.global.button.delete') + '" class="icon16 jsTooltip" />').click($.proxy(this._removeItem, this)).appendTo($listItem);
+                       this._createListItem($typeID, data.returnValues[type].label[$typeID], type);
                        
                        this._search.addExcludedSearchValue(data.returnValues[type].label[$typeID]);
                }