Unify reputation counter
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 3 Nov 2018 13:08:13 +0000 (14:08 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 3 Nov 2018 13:09:08 +0000 (14:09 +0100)
See #2508

com.woltlab.wcf/templates/article.tpl
com.woltlab.wcf/templates/articleListItems.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/ReputationButtons.js [deleted file]
wcfsetup/install/files/style/ui/reactions.scss

index b336d01d0fafd543c101d015d2eb3754ed61c9c3..5e0d03631544fa50bb0b4bdf4543de3bd967556b 100644 (file)
                                
                                {if $article->isDeleted}<li><span class="badge label red">{lang}wcf.message.status.deleted{/lang}</span></li>{/if}
                                
-                               {if $articleLikeData|isset && $articleLikeData[$article->articleID]|isset && !$articleLikeData[$article->articleID]->getReactions()|empty}
-                                       <li class="reputationCounter {if $articleLikeData[$article->articleID]->getReputation() > 0}positive{elseif $articleLikeData[$article->articleID]->getReputation() < 0}negative{else}neutral{/if}" data-object-id="{@$article->articleID}" data-object-type="com.woltlab.wcf.likeableArticle">{if $articleLikeData[$article->articleID]->getReputation() > 0}+{elseif $articleLikeData[$article->articleID]->getReputation() < 0}−{else}±{/if}{#$articleLikeData[$article->articleID]->getReputation()}</li>
-                               {else}
-                                       <li class="reputationCounter" data-object-id="{@$article->articleID}" data-object-type="com.woltlab.wcf.likeableArticle"></li>
-                               {/if}
-                               
                                {event name='contentHeaderMetaData'}
                        </ul>
                        
index e98ef3371750d636a6f38f54d5cb0301a13bfcaa..5067b8e89d9a27465254a663fdb94b2630042ae3 100644 (file)
@@ -36,7 +36,7 @@
                                                                
                                                                {if MODULE_LIKE && $__wcf->getSession()->getPermission('user.like.canViewLike')}
                                                                        {if $article->likes || $article->dislikes || $article->neutralReactions}
-                                                                               <li class="reputationCounter {if $article->cumulativeLikes > 0}positive{elseif $article->cumulativeLikes < 0}negative{else}neutral{/if}" data-object-id="{@$article->articleID}" data-object-type="com.woltlab.wcf.likeableArticle">{if $article->cumulativeLikes > 0}+{elseif $article->cumulativeLikes == 0}±{/if}{#$article->cumulativeLikes}</li>
+                                                                               <li class="reputationCounter {if $article->cumulativeLikes > 0}positive{elseif $article->cumulativeLikes < 0}negative{else}neutral{/if}">{if $article->cumulativeLikes > 0}+{elseif $article->cumulativeLikes == 0}±{/if}{#$article->cumulativeLikes}</li>
                                                                        {/if}
                                                                {/if}
                                                                
index 721e746a65635bf7c82d4dd007f17f7f92c592aa..158245f63b1efbd8069896118b94e639932072d6 100644 (file)
@@ -12,13 +12,13 @@ define(
                'Ajax',      'Core',                            'Dictionary',           'Language',
                'ObjectMap', 'StringUtil',                      'Dom/ChangeListener',   'Dom/Util',
                'Ui/Dialog', 'WoltLabSuite/Core/Ui/User/List',  'User',                 'WoltLabSuite/Core/Ui/Reaction/CountButtons', 
-               'Ui/Alignment', 'Ui/CloseOverlay',              'Ui/Screen',            'WoltLabSuite/Core/Ui/Reaction/ReputationButtons',
+               'Ui/Alignment', 'Ui/CloseOverlay',              'Ui/Screen'
        ],
        function(
                Ajax,        Core,              Dictionary,             Language,
                ObjectMap,   StringUtil,        DomChangeListener,      DomUtil,
                UiDialog,    UiUserList,        User,                   CountButtons, 
-               UiAlignment, UiCloseOverlay,    UiScreen,               ReputationButtons
+               UiAlignment, UiCloseOverlay,    UiScreen
        )
        {
                "use strict";
@@ -63,8 +63,7 @@ define(
                                
                                this.initReactButtons(options, objectType);
                                
-                               this.countButtons = new CountButtons(this._objectType, this._options); 
-                               this.reputationButtons = new ReputationButtons(this._objectType);
+                               this.countButtons = new CountButtons(this._objectType, this._options);
                                
                                DomChangeListener.add('WoltLabSuite/Core/Ui/Reaction/Handler-' + objectType, this.initReactButtons.bind(this));
                                UiCloseOverlay.add('WoltLabSuite/Core/Ui/Reaction/Handler', this._closePopover.bind(this));
@@ -364,7 +363,6 @@ define(
                        
                        _ajaxSuccess: function(data) {
                                this.countButtons.updateCountButtons(data.returnValues.objectID, data.returnValues.reactions);
-                               this.reputationButtons.setReputationCount(data.returnValues.objectID, data.returnValues.reputationCount);
                                
                                // update react button status
                                this._updateReactButton(data.returnValues.objectID, data.returnValues.reactionTypeID);
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/ReputationButtons.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/ReputationButtons.js
deleted file mode 100644 (file)
index 6608cac..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Handles the reputation count buttons.
- *
- * @author     Joshua Ruesweg
- * @copyright  2001-2018 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Ui/Reaction/Handler
- * @since       3.2
- */
-define(
-       ['Ajax', 'Dictionary', 'Dom/ChangeListener', 'Ui/Dialog'],
-       function(Ajax, Dictionary, DomChangeListener, UiDialog)
-       {
-               "use strict";
-               
-               /**
-                * @constructor
-                */
-               function ReputationButtons(objectType, options) { this.init(objectType, options); }
-               ReputationButtons.prototype = {
-                       /**
-                        * Initializes the reputation buttons.
-                        *
-                        * @param       {string}        objectType      object type
-                        */
-                       init: function(objectType) {
-                               if (objectType === '') {
-                                       throw new Error("[WoltLabSuite/Core/Ui/Reaction/ReputationButtons] Expected a non-empty string for objectType 'containerSelector'.");
-                               }
-                               
-                               this._containers = new Dictionary();
-                               this._objectType = objectType;
-                               
-                               this.initContainers();
-                               
-                               DomChangeListener.add('WoltLabSuite/Core/Ui/Reaction/ReputationButtons-' + objectType, this.initContainers.bind(this));
-                       },
-                       
-                       /**
-                        * Initialises the containers.
-                        */
-                       initContainers: function() {
-                               var element, elements = elBySelAll(".reputationCounter[data-object-type='" + this._objectType + "']"), elementData, triggerChange = false, objectId;
-                               for (var i = 0, length = elements.length; i < length; i++) {
-                                       element = elements[i];
-                                       objectId = ~~elData(element, 'object-id');
-                                       if (this._containers.has(objectId)) {
-                                               continue;
-                                       }
-                                       
-                                       elementData = {
-                                               objectId: ~~elData(element, 'object-id'),
-                                               element: element
-                                       };
-                                       
-                                       this._containers.set(objectId, elementData);
-                                       
-                                       this._initReputationCountButton(elementData.element, elementData.objectId);
-                                       
-                                       triggerChange = true;
-                               }
-                               
-                               if (triggerChange) {
-                                       DomChangeListener.trigger();
-                               }
-                       },
-                       
-                       /**
-                        * Sets the count of a specific reputation button. 
-                        * 
-                        * @param       {int}           objectId
-                        * @param       {int}           count
-                        */
-                       setReputationCount: function(objectId, count) {
-                               if (this._containers.has(objectId)) {
-                                       this._containers.get(objectId).element.classList.remove("neutral", "negative", "positive");
-                                       
-                                       if (count > 0) {
-                                               this._containers.get(objectId).element.innerHTML = "+" + count;
-                                               this._containers.get(objectId).element.classList.add("positive");
-                                       }
-                                       else if (count < 0) {
-                                               this._containers.get(objectId).element.innerHTML = count;
-                                               this._containers.get(objectId).element.classList.add("negative");
-                                       }
-                                       else if (count === 0) {
-                                               this._containers.get(objectId).element.innerHTML = "±" + count;
-                                               this._containers.get(objectId).element.classList.add("neutral");
-                                       }
-                                       else {
-                                               this._containers.get(objectId).element.innerHTML = "";
-                                       }
-                               } 
-                       },
-                       
-                       /**
-                        * Initialized a specific reaction count button for an object.
-                        *
-                        * @param       {element}        element
-                        * @param       {int}            objectId
-                        */
-                       _initReputationCountButton: function(element, objectId) {
-                               element.addEventListener(WCF_CLICK_EVENT, this._showReactionOverlay.bind(this, objectId));
-                       },
-                       
-                       /**
-                        * Shows the reaction overly for a specific object.
-                        *
-                        * @param       {int}        objectId
-                        */
-                       _showReactionOverlay: function(objectId) {
-                               this._currentObjectId = objectId;
-                               this._showOverlay();
-                       },
-                       
-                       /**
-                        * Shows the overlay for the reactions.
-                        */
-                       _showOverlay: function() {
-                               Ajax.api(this, {
-                                       parameters: {
-                                               data: {
-                                                       containerID: this._objectType + '-' + this._currentObjectId,
-                                                       objectID: this._currentObjectId,
-                                                       objectType: this._objectType
-                                               }
-                                       }
-                               });
-                       },
-                       
-                       _ajaxSuccess: function(data) {
-                               UiDialog.open(this, data.returnValues.template);
-                               UiDialog.setTitle('userReactionOverlay-' + this._objectType, data.returnValues.title);
-                       },
-                       
-                       _ajaxSetup: function() {
-                               return {
-                                       data: {
-                                               actionName: 'getReactionDetails',
-                                               className: '\\wcf\\data\\reaction\\ReactionAction'
-                                       }
-                               };
-                       },
-                       
-                       _dialogSetup: function() {
-                               return {
-                                       id: 'userReactionOverlay-' + this._objectType,
-                                       options: {
-                                               title: ""
-                                       },
-                                       source: null
-                               };
-                       }
-               };
-               
-               return ReputationButtons;
-       });
index b998ba917b75ce16fa61e7341c5796aa6ad4238b..91f007ac2de99223d36898061d1b5878f4b0851d 100644 (file)
@@ -124,7 +124,6 @@ li.reactCountButton:hover {
 
 .reputationCounter {
        color: $wcfContentDimmedText;
-       cursor: pointer;
        
        &.positive {
                color: #060 !important;