1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-12-02 22:22:15 -05:00
kaiwa/clientapp/models/resources.js

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-08-29 23:38:28 -04:00
"use strict";
2013-08-20 13:45:06 -04:00
var BaseCollection = require('./baseCollection');
var Resource = require('./resource');
module.exports = BaseCollection.extend({
type: 'resources',
model: Resource,
comparator: function (res1, res2) {
if (res1.priority > res2.priority) {
return -1;
}
if (res1.priority < res2.priority) {
return 1;
}
if (res1.show === res2.show) {
2013-09-27 00:29:45 -04:00
if (!!res1.idleSince && !!res2.idleSince) {
return 0;
}
2013-12-31 18:24:40 -05:00
if (res1.idleSince && !!res2.idleSince) {
2013-09-27 00:29:45 -04:00
return 1;
}
return -1;
2013-08-20 13:45:06 -04:00
}
var ranking = {
xa: 0,
away: 1,
'': 2,
chat: 3,
dnd: 3
};
var r1 = ranking[res1.show];
var r2 = ranking[res2.show];
if (r1 === r2) {
return 0;
}
if (r1 > r2) {
return -1;
}
return 1;
},
search : function (letters, removeMe, addAll) {
if(letters == "" && !removeMe) return this;
var collection = new module.exports(this.models);
if (addAll)
collection.add({id: this.parent.jid.bare + '/all'});
var pattern = new RegExp('^' + letters + '.*$', "i");
var filtered = collection.filter(function(data) {
var nick = data.get("mucDisplayName");
if (nick === me.nick) return false;
return pattern.test(nick);
});
return new module.exports(filtered);
2013-08-20 13:45:06 -04:00
}
});