From 758f56978b7a77ef6ba7b991d743038a57e2c1d8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 27 May 2016 12:42:18 +0200 Subject: [PATCH] Some minor improvements --- .../js/WoltLab/WCF/Ui/Message/InlineEditor.js | 9 ++- .../js/WoltLab/WCF/Ui/Message/Manager.js | 64 +++++++++++++++++-- wcfsetup/install/files/js/wcf.globalHelper.js | 2 +- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/InlineEditor.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/InlineEditor.js index 3cce87563d..3774e80188 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/InlineEditor.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/InlineEditor.js @@ -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++) { diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Manager.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Manager.js index 9550d53cd6..e7347e03d0 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Manager.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/Message/Manager.js @@ -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 * @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."); }, diff --git a/wcfsetup/install/files/js/wcf.globalHelper.js b/wcfsetup/install/files/js/wcf.globalHelper.js index d3e16555d2..b809335779 100644 --- a/wcfsetup/install/files/js/wcf.globalHelper.js +++ b/wcfsetup/install/files/js/wcf.globalHelper.js @@ -148,7 +148,7 @@ /** * Shorthand function to remove an element. * - * @param {Element} element DOM element + * @param {Node} element DOM node */ window.elRemove = function(element) { element.parentNode.removeChild(element); -- 2.20.1