Cleanup to take comments into account
authorCory Chaplin <cory.chaplin@laposte.net>
Mon, 3 Mar 2014 10:19:44 +0000 (11:19 +0100)
committerCory Chaplin <cory.chaplin@laposte.net>
Mon, 3 Mar 2014 10:19:44 +0000 (11:19 +0100)
client/src/applets/chanlist.js
client/src/index.html.tmpl

index 8fb67bf94583dc77564eef2504eabbfc404d4007..2cc676ae1c64bb8a2b1bfd08826c2ee59c47497e 100644 (file)
@@ -11,8 +11,8 @@
         \r
         initialize: function (options) {\r
             var text = {\r
-                channel_name: '<a class="channel_name_title">' + _kiwi.global.i18n.translate('client_applets_chanlist_channelname').fetch() + '</a>',\r
-                users: '<a class="users_title">' + _kiwi.global.i18n.translate('client_applets_chanlist_users').fetch() + '</a>',\r
+                channel_name: _kiwi.global.i18n.translate('client_applets_chanlist_channelname').fetch(),\r
+                users: _kiwi.global.i18n.translate('client_applets_chanlist_users').fetch(),\r
                 topic: _kiwi.global.i18n.translate('client_applets_chanlist_topic').fetch()\r
             };\r
             this.$el = $(_.template($('#tmpl_channel_list').html().trim(), text));\r
                 tbody = table.children('tbody:first').detach(),\r
                 that = this,\r
                 channels_length = this.channels.length,\r
-                icon_asc = '<span class="icon-sort-up">&nbsp;&nbsp;</span>',\r
-                icon_desc = '<span class="icon-sort-down">&nbsp;&nbsp;</span>',\r
                 i;\r
             \r
-            if (override_channels != undefined) {\r
+            if (override_channels !== undefined) {\r
                 that.channels = override_channels;\r
                 tbody.remove();\r
                 this.sorting_channels = true;\r
                 that.channels = this.sortChannels(this.channels, this.order);\r
             }\r
 \r
-            // Clean the sorting icon and add the new one\r
-            $('.applet_chanlist .users_title').find('span').remove();\r
-            $('.applet_chanlist .channel_name_title').find('span').remove();\r
+            // Create the sort icon container and clean previous any previous ones\r
+            if($('.applet_chanlist .users_title').find('span.chanlist_sort_users').length == 0) {\r
+                this.$('.users_title').append('<span class="chanlist_sort_users">&nbsp;&nbsp;</span>');\r
+            } else {\r
+                this.$('.users_title span.chanlist_sort_users').removeClass('icon-sort-up');\r
+                this.$('.users_title span.chanlist_sort_users').removeClass('icon-sort-down');\r
+            }\r
+            if ($('.applet_chanlist .channel_name_title').find('span.chanlist_sort_names').length == 0) {\r
+                this.$('.channel_name_title').append('<span class="chanlist_sort_names">&nbsp;&nbsp;</span>');\r
+            } else {\r
+                this.$('.channel_name_title span.chanlist_sort_names').removeClass('icon-sort-up');\r
+                this.$('.channel_name_title span.chanlist_sort_names').removeClass('icon-sort-down');\r
+            }\r
+\r
+            // Push the new sort icon\r
             switch (this.order) {\r
                 case 'user_desc':\r
                 default:\r
-                    this.$('.users_title').append(icon_desc);\r
+                    this.$('.users_title span.chanlist_sort_users').addClass('icon-sort-down');\r
                     break;\r
                 case 'user_asc':\r
-                    this.$('.users_title').append(icon_asc);\r
+                    this.$('.users_title span.chanlist_sort_users').addClass('icon-sort-up');\r
                     break;\r
                 case 'name_asc':\r
-                    this.$('.channel_name_title').append(icon_asc);\r
+                    this.$('.channel_name_title span.chanlist_sort_names').addClass('icon-sort-up');\r
                     break;\r
                 case 'name_desc':\r
-                    this.$('.channel_name_title').append(icon_desc);\r
+                    this.$('.channel_name_title span.chanlist_sort_names').addClass('icon-sort-down');\r
                     break;\r
             }\r
             \r
         \r
         sortChannelsByNameClick: function (event) {\r
             // Revert the sorting to switch between orders\r
-            if (this.order == 'name_asc') {\r
-                this.order = 'name_desc';\r
-            } else {\r
-                this.order = 'name_asc';\r
-            }\r
+            this.order = (this.order == 'name_asc') ? 'name_desc' : 'name_asc';\r
             \r
             this.sortChannelsClick(this.order);\r
         },\r
         \r
         sortChannelsByUsersClick: function (event) {\r
             // Revert the sorting to switch between orders\r
-            if (this.order == 'user_desc' || this.order == '') {\r
-                this.order = 'user_asc';\r
-            } else {\r
-                this.order = 'user_desc';\r
-            }\r
+            this.order = (this.order == 'user_desc' || this.order == '') ? 'user_asc' : 'user_desc';\r
             \r
             this.sortChannelsClick(this.order);\r
         },\r
                 switch (order) {\r
                     case 'user_asc':\r
                         return a.num_users - b.num_users;\r
-                        break;\r
                     case 'user_desc':\r
                         return b.num_users - a.num_users;\r
-                        break;                \r
                     case 'name_asc':\r
                         if (a.channel.toLowerCase() > b.channel.toLowerCase()) return 1;\r
                         if (a.channel.toLowerCase() < b.channel.toLowerCase()) return -1;\r
-                        break;\r
                     case 'name_desc':\r
                         if (a.channel.toLowerCase() < b.channel.toLowerCase()) return 1;\r
                         if (a.channel.toLowerCase() > b.channel.toLowerCase()) return -1;\r
-                        break;\r
                     default:\r
                         return b.num_users - a.num_users;\r
-                        break;\r
                 }\r
                 return 0;\r
             });\r
index bd9af3c1ab38c3e9c7832a5f0caa971cc0b5592e..c5fd5c56a06875da29485be7a218942434c21f24 100644 (file)
             <table>\r
                 <thead style="font-weight: bold;">\r
                     <tr>\r
-                        <td><%= channel_name %></td>\r
-                        <td><%= users %></td>\r
+                        <td><a class="channel_name_title"><%= channel_name %></a></td>\r
+                        <td><a class="users_title"><%= users %></a></td>\r
                         <td style="padding-left: 2em;"><%= topic %></td>\r
                     </tr>\r
                 </thead>\r