Move roster-related models/collections to core
This commit is contained in:
parent
888cd8c982
commit
7f753040de
@ -10,7 +10,7 @@
|
|||||||
define("converse-controlbox", [
|
define("converse-controlbox", [
|
||||||
"converse-core",
|
"converse-core",
|
||||||
"converse-api",
|
"converse-api",
|
||||||
// TODO: remove the next two dependencies
|
// TODO: The next two dependencies can be made optional
|
||||||
"converse-rosterview",
|
"converse-rosterview",
|
||||||
"converse-chatview"
|
"converse-chatview"
|
||||||
], factory);
|
], factory);
|
||||||
|
@ -250,6 +250,7 @@
|
|||||||
// Translation machinery
|
// Translation machinery
|
||||||
// ---------------------
|
// ---------------------
|
||||||
var __ = utils.__.bind(this);
|
var __ = utils.__.bind(this);
|
||||||
|
var DESC_GROUP_TOGGLE = __('Click to hide these contacts');
|
||||||
|
|
||||||
// Default configuration values
|
// 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({
|
this.Message = Backbone.Model.extend({
|
||||||
defaults: function(){
|
defaults: function(){
|
||||||
return {
|
return {
|
||||||
|
@ -18,6 +18,25 @@
|
|||||||
_ = converse_api.env._,
|
_ = converse_api.env._,
|
||||||
__ = utils.__.bind(converse);
|
__ = 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', {
|
converse_api.plugins.add('rosterview', {
|
||||||
|
|
||||||
@ -32,6 +51,29 @@
|
|||||||
this.rosterview.registerRosterXHandler();
|
this.rosterview.registerRosterXHandler();
|
||||||
this.rosterview.registerPresenceHandler();
|
this.rosterview.registerPresenceHandler();
|
||||||
this._super.afterReconnected.apply(this, arguments);
|
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,
|
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({
|
converse.RosterFilter = Backbone.Model.extend({
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.set({
|
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({
|
converse.RosterGroupView = Backbone.Overview.extend({
|
||||||
tagName: 'dt',
|
tagName: 'dt',
|
||||||
className: 'roster-group',
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user