Some minor improvements
authorAlexander Ebert <ebert@woltlab.com>
Fri, 27 May 2016 10:42:18 +0000 (12:42 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 27 May 2016 10:42:24 +0000 (12:42 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/InlineEditor.js
wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Manager.js
wcfsetup/install/files/js/wcf.globalHelper.js

index 3cce87563dfb6eba8191c5cc1daf9ff9795ef09f..3774e80188d6f9c01e6a0d0f939567c8ed05074f 100644 (file)
@@ -47,15 +47,14 @@ define(
                                messageSelector: '.jsMessage'
                        }, options);
                        
-                       this._initElements();
+                       this.rebuild();
                },
                
                /**
-                * Initializes each applicable message.
-                * 
-                * @protected
+                * Initializes each applicable message, should be called whenever new
+                * messages are being displayed.
                 */
-               _initElements: function() {
+               rebuild: function() {
                        var button, canEdit, element, elements = elBySelAll(this._options.messageSelector);
                        
                        for (var i = 0, length = elements.length; i < length; i++) {
index 9550d53cd66c8234948edbb4002f8306a528763d..e7347e03d05c0d24a9c16eccd8c82836fdae02c7 100644 (file)
@@ -2,11 +2,11 @@
  * Provides access and editing of message properties.
  * 
  * @author     Alexander Ebert
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLab/WCF/Ui/Message/Manager
  */
-define(['Ajax', 'Core', 'Dictionary'], function(Ajax, Core, Dictionary) {
+define(['Ajax', 'Core', 'Dictionary', 'Language', 'Dom/Util'], function(Ajax, Core, Dictionary, Language, DomUtil) {
        "use strict";
        
        /**
@@ -116,7 +116,7 @@ define(['Ajax', 'Core', 'Dictionary'], function(Ajax, Core, Dictionary) {
                                }
                                
                                for (var key in data) {
-                                       if (objOwns(data, key)) {
+                                       if (data.hasOwnProperty(key)) {
                                                this._update(element, key, data[key]);
                                        }
                                }
@@ -134,7 +134,7 @@ define(['Ajax', 'Core', 'Dictionary'], function(Ajax, Core, Dictionary) {
                                objectIds.push(objectId);
                        }).bind(this));
                        
-                       this.update(objectIds, data);
+                       this.updateItems(objectIds, data);
                },
                
                /**
@@ -166,14 +166,68 @@ define(['Ajax', 'Core', 'Dictionary'], function(Ajax, Core, Dictionary) {
                        switch (propertyName) {
                                case 'isDeleted':
                                        element.classList[(propertyValueBoolean ? 'add' : 'remove')]('messageDeleted');
+                                       this._toggleMessageStatus(element, 'jsIconDeleted', 'wcf.message.status.deleted', 'red', propertyValueBoolean);
+                                       
                                        break;
                                
                                case 'isDisabled':
                                        element.classList[(propertyValueBoolean ? 'add' : 'remove')]('messageDisabled');
+                                       this._toggleMessageStatus(element, 'jsIconDisabled', 'wcf.message.status.disabled', 'green', propertyValueBoolean);
+                                       
                                        break;
                        }
                },
                
+               /**
+                * Toggles the message status bade for provided element.
+                * 
+                * @param       {Element}       element         message element
+                * @param       {string}        className       badge class name
+                * @param       {string}        phrase          language phrase
+                * @param       {string}        badgeColor      color css class
+                * @param       {boolean}       addBadge        add or remove badge
+                * @protected
+                */
+               _toggleMessageStatus: function(element, className, phrase, badgeColor, addBadge) {
+                       var messageStatus = elBySel('.messageStatus', element);
+                       if (messageStatus === null) {
+                               var messageHeaderMetaData = elBySel('.messageHeaderMetaData', element);
+                               if (messageHeaderMetaData === null) {
+                                       // can't find appropriate location to insert badge
+                                       return;
+                               }
+                               
+                               messageStatus = elCreate('ul');
+                               messageStatus.className = 'messageStatus';
+                               DomUtil.insertAfter(messageStatus, messageHeaderMetaData);
+                       }
+                       
+                       var badge = elBySel('.' + className, messageStatus);
+                       
+                       if (addBadge) {
+                               if (badge !== null) {
+                                       // badge already exists
+                                       return;
+                               }
+                               
+                               badge = elCreate('span');
+                               badge.className = 'badge label ' + badgeColor + ' ' + className;
+                               badge.textContent = Language.get(phrase);
+                               
+                               var listItem = elCreate('li');
+                               listItem.appendChild(badge);
+                               messageStatus.appendChild(listItem);
+                       }
+                       else {
+                               if (badge === null) {
+                                       // badge does not exist
+                                       return;
+                               }
+                               
+                               elRemove(badge.parentNode);
+                       }
+               },
+               
                /**
                 * Transforms camel-cased property names into their attribute equivalent.
                 * 
@@ -199,7 +253,7 @@ define(['Ajax', 'Core', 'Dictionary'], function(Ajax, Core, Dictionary) {
                        return attributeName;
                },
                
-               _ajaxSuccess: function(data) {
+               _ajaxSuccess: function() {
                        throw new Error("Method _ajaxSuccess() must be implemented by deriving functions.");
                },
                
index d3e16555d2c3ea62764e3cc422b7f98f9c897c91..b809335779708d36e2a8c051eadac43e36b5a9bc 100644 (file)
        /**
         * Shorthand function to remove an element.
         * 
-        * @param       {Element}       element         DOM element
+        * @param       {Node}          element         DOM node
         */
        window.elRemove = function(element) {
                element.parentNode.removeChild(element);