2013-08-29 23:38:28 -04:00
|
|
|
/*global app*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var async = require('async');
|
2013-08-20 13:45:06 -04:00
|
|
|
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) {
|
2013-08-29 23:38:28 -04:00
|
|
|
var self = this;
|
2013-08-20 13:45:06 -04:00
|
|
|
this.bind('change', this.orderChange, this);
|
2013-08-29 23:38:28 -04:00
|
|
|
|
|
|
|
app.storage.roster.getAll(function (err, contacts) {
|
|
|
|
if (err) return;
|
|
|
|
|
|
|
|
contacts.forEach(function (contact) {
|
|
|
|
contact = new Contact(contact);
|
2013-09-09 19:00:13 -04:00
|
|
|
contact.inRoster = true;
|
2013-08-29 23:38:28 -04:00
|
|
|
contact.save();
|
|
|
|
self.add(contact);
|
|
|
|
});
|
|
|
|
});
|
2013-08-20 13:45:06 -04:00
|
|
|
},
|
|
|
|
orderChange: function () {
|
|
|
|
this.sort();
|
|
|
|
}
|
|
|
|
});
|