tray/src/messenger/webim/js/source/users/collections/agents.js
2013-03-13 15:32:48 +00:00

70 lines
2.0 KiB
JavaScript

/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, _){
/**
* @class Represents collection of agents
*/
Mibew.Collections.Agents = Backbone.Collection.extend(
/** @lends Mibew.Collections.Agents.prototype */
{
/**
* Model type of the collection items
*/
model: Mibew.Models.Agent,
/**
* Use for sort controls in collection
* @param {Backbone.Model} model Agent model
*/
comparator: function(model) {
return model.get('name');
},
/**
* Collection initializer
*/
initialize: function() {
// Register some shortcuts
var agent = Mibew.Objects.Models.agent;
// Call updateOperators periodically at the server
Mibew.Objects.server.callFunctionsPeriodically(
function(){
return [
{
'function': 'updateOperators',
'arguments': {
'agentId': agent.id,
'return': {
'operators': 'operators'
},
'references': {}
}
}
];
},
_.bind(this.updateOperators, this)
);
},
/**
* Update available agents.
* @param {Object} args Arguments from the server
*/
updateOperators: function(args) {
this.update(args.operators);
}
}
);
})(Mibew, Backbone, _);