mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-11-15 05:55:01 -05:00
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
|
var BaseCollection = require('./baseCollection');
|
||
|
var Contact = require('./contact');
|
||
|
|
||
|
|
||
|
module.exports = BaseCollection.extend({
|
||
|
type: 'contacts',
|
||
|
model: Contact,
|
||
|
comparator: function (model1, model2) {
|
||
|
var show1 = model1.show;
|
||
|
var show2 = model2.show;
|
||
|
|
||
|
var name1 = model1.displayName.toLowerCase();
|
||
|
var name2 = model2.displayName.toLowerCase();
|
||
|
|
||
|
if (show1 === show2) {
|
||
|
|
||
|
if (name1 === name2) {
|
||
|
return 0;
|
||
|
}
|
||
|
if (name1 < name2) {
|
||
|
return -1;
|
||
|
}
|
||
|
return 1;
|
||
|
} else {
|
||
|
if (show1 === 'offline') {
|
||
|
return 1;
|
||
|
}
|
||
|
if (show2 === 'offline') {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if (name1 === name2) {
|
||
|
return 0;
|
||
|
}
|
||
|
if (name1 < name2) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
},
|
||
|
initialize: function (model, options) {
|
||
|
this.bind('change', this.orderChange, this);
|
||
|
this.bind('add', this.fetchHistory, this);
|
||
|
},
|
||
|
orderChange: function () {
|
||
|
this.sort();
|
||
|
},
|
||
|
fetchHistory: function (contact) {
|
||
|
contact.fetchHistory();
|
||
|
}
|
||
|
});
|