Allow removing initial excess items in static item list
authorMatthias Schmidt <gravatronics@live.com>
Sun, 18 Aug 2019 08:21:42 +0000 (10:21 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 18 Aug 2019 08:21:42 +0000 (10:21 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/ItemList/Static.js

index 9fb1c326f601a5adc30dd4e7e3f0f35a515e5c15..7c7ddc10a001c32169d8b16c4c605c1e55f7a62e 100644 (file)
@@ -116,13 +116,14 @@ define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'Ui/Simple
                        values = (data.values.length) ? data.values : values;
                        if (Array.isArray(values)) {
                                var value;
+                               var forceRemoveIcon = !data.element.disabled;
                                for (var i = 0, length = values.length; i < length; i++) {
                                        value = values[i];
                                        if (typeof value === 'string') {
                                                value = { objectId: 0, value: value };
                                        }
                                        
-                                       this._addItem(elementId, value);
+                                       this._addItem(elementId, value, forceRemoveIcon);
                                }
                        }
                },
@@ -384,10 +385,11 @@ define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'Ui/Simple
                /**
                 * Adds an item to the list.
                 *
-                * @param       {string}        elementId       input element id
-                * @param       {object}        value           item value
+                * @param       {string}        elementId               input element id
+                * @param       {object}        value                   item value
+                * @param       {?boolean}      forceRemoveIcon         if `true`, the icon to remove the item will be added in every case
                 */
-               _addItem: function(elementId, value) {
+               _addItem: function(elementId, value, forceRemoveIcon) {
                        var data = _data.get(elementId);
                        
                        var listItem = elCreate('li');
@@ -399,7 +401,7 @@ define(['Core', 'Dictionary', 'Language', 'Dom/Traverse', 'EventKey', 'Ui/Simple
                        content.textContent = value.value;
                        listItem.appendChild(content);
                        
-                       if (!data.element.disabled) {
+                       if (forceRemoveIcon || !data.element.disabled) {
                                var button = elCreate('a');
                                button.className = 'icon icon16 fa-times';
                                button.addEventListener(WCF_CLICK_EVENT, _callbackRemoveItem);