Sort reactions by showOrder in frontend
authorJoshua Rüsweg <josh@bastelstu.be>
Sat, 28 Jul 2018 09:38:49 +0000 (11:38 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Sat, 28 Jul 2018 09:39:48 +0000 (11:39 +0200)
See #2508

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Reaction/Handler.js
wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php

index a042922c09e93391ff1346c790ea80f184112e9d..e3bc33cccd7aed25f31e8d9d3403bd7c625ec328 100644 (file)
@@ -180,14 +180,16 @@ define(
                                        
                                        var popoverContentHTML = elCreate('ul');
                                        
-                                       for (var key in REACTION_TYPES) {
-                                               if (!REACTION_TYPES.hasOwnProperty(key)) continue;
+                                       var sortedReactionTypes = this._getSortedReactionTypes();
+                                       
+                                       for (var key in sortedReactionTypes) {
+                                               if (!sortedReactionTypes.hasOwnProperty(key)) continue;
                                                
-                                               var reactionType = REACTION_TYPES[key];
+                                               var reactionType = sortedReactionTypes[key];
                                                
                                                var reactionTypeItem = elCreate('li');
                                                reactionTypeItem.className = 'reactionTypeButton jsTooltip';
-                                               elData(reactionTypeItem, 'reaction-type-id', key);
+                                               elData(reactionTypeItem, 'reaction-type-id', reactionType.reactionTypeID);
                                                elData(reactionTypeItem, 'title', reactionType.title);
                                                reactionTypeItem.title = reactionType.title;
                                                
@@ -220,10 +222,28 @@ define(
                                return this._popover; 
                        },
                        
+                       /**
+                        * Sort the reaction types by the showOrder field. 
+                        * 
+                        * @returns     {Array}         the reaction types sorted by showOrder
+                        */
+                       _getSortedReactionTypes: function() {
+                               var sortedReactionTypes = [];
+                               
+                               for (var key in REACTION_TYPES) {
+                                       if (!REACTION_TYPES.hasOwnProperty(key)) continue;
+                                       var reactionType = REACTION_TYPES[key];
+                                       
+                                       sortedReactionTypes[reactionType.showOrder] = reactionType;
+                               }
+                               
+                               return sortedReactionTypes;
+                       },
+                       
                        /**
                         * Closes the react popover. 
                         */
-                       _closePopover: function(objectId, element) {
+                       _closePopover: function() {
                                if (this._popoverCurrentObjectId !== 0) {
                                        this._getPopover().classList.remove('active');
                                        
index 0b220ee0a45a8e5427cc5de3dda082a7b65eed60..b62f1c666a6ec131c659ef4daa2294d069590bf3 100644 (file)
@@ -70,7 +70,9 @@ class ReactionHandler extends SingletonFactory {
                        $returnValues[$reaction->reactionTypeID] = [
                                'title' => $reaction->getTitle(), 
                                'renderedIcon' => $reaction->renderIcon(), 
-                               'iconPath' => $reaction->getIconPath()
+                               'iconPath' => $reaction->getIconPath(), 
+                               'showOrder' => $reaction->showOrder, 
+                               'reactionTypeID' => $reaction->reactionTypeID
                        ];
                }