瀏覽代碼

Move roster-related models/collections to core

JC Brand 9 年之前
父節點
當前提交
7f753040de
共有 3 個文件被更改,包括 61 次插入58 次删除
  1. 1 1
      src/converse-controlbox.js
  2. 18 0
      src/converse-core.js
  3. 42 57
      src/converse-rosterview.js

+ 1 - 1
src/converse-controlbox.js

@@ -10,7 +10,7 @@
     define("converse-controlbox", [
             "converse-core",
             "converse-api",
-            // TODO: remove the next two dependencies
+            // TODO: The next two dependencies can be made optional
             "converse-rosterview",
             "converse-chatview"
     ], factory);

+ 18 - 0
src/converse-core.js

@@ -250,6 +250,7 @@
         // Translation machinery
         // ---------------------
         var __ = utils.__.bind(this);
+        var DESC_GROUP_TOGGLE = __('Click to hide these contacts');
 
         // Default configuration values
         // ----------------------------
@@ -1178,6 +1179,23 @@
         });
 
 
+        this.RosterGroup = Backbone.Model.extend({
+            initialize: function (attributes, options) {
+                this.set(_.extend({
+                    description: DESC_GROUP_TOGGLE,
+                    state: converse.OPENED
+                }, attributes));
+                // Collection of contacts belonging to this group.
+                this.contacts = new converse.RosterContacts();
+            }
+        });
+
+
+        this.RosterGroups = Backbone.Collection.extend({
+            model: converse.RosterGroup,
+        });
+
+
         this.Message = Backbone.Model.extend({
             defaults: function(){
                 return {

+ 42 - 57
src/converse-rosterview.js

@@ -18,6 +18,25 @@
         _ = converse_api.env._,
         __ = utils.__.bind(converse);
 
+    var STATUSES = {
+        'dnd': __('This contact is busy'),
+        'online': __('This contact is online'),
+        'offline': __('This contact is offline'),
+        'unavailable': __('This contact is unavailable'),
+        'xa': __('This contact is away for an extended period'),
+        'away': __('This contact is away')
+    };
+    var LABEL_CONTACTS = __('Contacts');
+    var LABEL_GROUPS = __('Groups');
+    var HEADER_CURRENT_CONTACTS =  __('My contacts');
+    var HEADER_PENDING_CONTACTS = __('Pending contacts');
+    var HEADER_REQUESTING_CONTACTS = __('Contact requests');
+    var HEADER_UNGROUPED = __('Ungrouped');
+    var HEADER_WEIGHTS = {};
+    HEADER_WEIGHTS[HEADER_CURRENT_CONTACTS]    = 0;
+    HEADER_WEIGHTS[HEADER_UNGROUPED]           = 1;
+    HEADER_WEIGHTS[HEADER_REQUESTING_CONTACTS] = 2;
+    HEADER_WEIGHTS[HEADER_PENDING_CONTACTS]    = 3;
 
     converse_api.plugins.add('rosterview', {
 
@@ -32,6 +51,29 @@
                 this.rosterview.registerRosterXHandler();
                 this.rosterview.registerPresenceHandler();
                 this._super.afterReconnected.apply(this, arguments);
+            },
+
+            RosterGroups: {
+                comparator: function (a, b) {
+                    /* Groups are sorted alphabetically, ignoring case.
+                     * However, Ungrouped, Requesting Contacts and Pending Contacts
+                     * appear last and in that order.
+                     */
+                    a = a.get('name');
+                    b = b.get('name');
+                    var special_groups = _.keys(HEADER_WEIGHTS);
+                    var a_is_special = _.contains(special_groups, a);
+                    var b_is_special = _.contains(special_groups, b);
+                    if (!a_is_special && !b_is_special ) {
+                        return a.toLowerCase() < b.toLowerCase() ? -1 : (a.toLowerCase() > b.toLowerCase() ? 1 : 0);
+                    } else if (a_is_special && b_is_special) {
+                        return HEADER_WEIGHTS[a] < HEADER_WEIGHTS[b] ? -1 : (HEADER_WEIGHTS[a] > HEADER_WEIGHTS[b] ? 1 : 0);
+                    } else if (!a_is_special && b_is_special) {
+                        return (b === HEADER_CURRENT_CONTACTS) ? 1 : -1;
+                    } else if (a_is_special && !b_is_special) {
+                        return (a === HEADER_CURRENT_CONTACTS) ? -1 : 1;
+                    }
+                }
             }
         },
 
@@ -46,27 +88,6 @@
                 show_toolbar: true,
             });
 
-            var STATUSES = {
-                'dnd': __('This contact is busy'),
-                'online': __('This contact is online'),
-                'offline': __('This contact is offline'),
-                'unavailable': __('This contact is unavailable'),
-                'xa': __('This contact is away for an extended period'),
-                'away': __('This contact is away')
-            };
-            var DESC_GROUP_TOGGLE = __('Click to hide these contacts');
-            var LABEL_CONTACTS = __('Contacts');
-            var LABEL_GROUPS = __('Groups');
-            var HEADER_CURRENT_CONTACTS =  __('My contacts');
-            var HEADER_PENDING_CONTACTS = __('Pending contacts');
-            var HEADER_REQUESTING_CONTACTS = __('Contact requests');
-            var HEADER_UNGROUPED = __('Ungrouped');
-            var HEADER_WEIGHTS = {};
-            HEADER_WEIGHTS[HEADER_CURRENT_CONTACTS]    = 0;
-            HEADER_WEIGHTS[HEADER_UNGROUPED]           = 1;
-            HEADER_WEIGHTS[HEADER_REQUESTING_CONTACTS] = 2;
-            HEADER_WEIGHTS[HEADER_PENDING_CONTACTS]    = 3;
-
             converse.RosterFilter = Backbone.Model.extend({
                 initialize: function () {
                     this.set({
@@ -692,18 +713,6 @@
             });
 
 
-            converse.RosterGroup = Backbone.Model.extend({
-                initialize: function (attributes, options) {
-                    this.set(_.extend({
-                        description: DESC_GROUP_TOGGLE,
-                        state: converse.OPENED
-                    }, attributes));
-                    // Collection of contacts belonging to this group.
-                    this.contacts = new converse.RosterContacts();
-                }
-            });
-
-
             converse.RosterGroupView = Backbone.Overview.extend({
                 tagName: 'dt',
                 className: 'roster-group',
@@ -879,30 +888,6 @@
                     }
                 }
             });
-
-
-            converse.RosterGroups = Backbone.Collection.extend({
-                model: converse.RosterGroup,
-                comparator: function (a, b) {
-                    /* Groups are sorted alphabetically, ignoring case.
-                     * However, Ungrouped, Requesting Contacts and Pending Contacts
-                     * appear last and in that order. */
-                    a = a.get('name');
-                    b = b.get('name');
-                    var special_groups = _.keys(HEADER_WEIGHTS);
-                    var a_is_special = _.contains(special_groups, a);
-                    var b_is_special = _.contains(special_groups, b);
-                    if (!a_is_special && !b_is_special ) {
-                        return a.toLowerCase() < b.toLowerCase() ? -1 : (a.toLowerCase() > b.toLowerCase() ? 1 : 0);
-                    } else if (a_is_special && b_is_special) {
-                        return HEADER_WEIGHTS[a] < HEADER_WEIGHTS[b] ? -1 : (HEADER_WEIGHTS[a] > HEADER_WEIGHTS[b] ? 1 : 0);
-                    } else if (!a_is_special && b_is_special) {
-                        return (b === HEADER_CURRENT_CONTACTS) ? 1 : -1;
-                    } else if (a_is_special && !b_is_special) {
-                        return (a === HEADER_CURRENT_CONTACTS) ? -1 : 1;
-                    }
-                }
-            });
         }
     });
 }));