cartodb-4.42/lib/assets/javascripts/cartodb/models/grantables.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
/**
* A collection of Grantable objects.
*/
cdb.admin.Grantables = Backbone.Collection.extend({
model: cdb.admin.Grantable,
url: function(method) {
var version = cdb.config.urlVersion('organizationGrantables', method);
return '/api/' + version + '/organization/' + this.organization.id + '/grantables';
},
initialize: function(users, opts) {
if (!opts.organization) throw new Error('organization is required');
this.organization = opts.organization;
this.currentUserId = opts.currentUserId;
this.sync = Backbone.syncAbort; // adds abort behaviour
},
parse: function(response) {
this.total_entries = response.total_entries;
return _.reduce(response.grantables, function(memo, m) {
if (m.id === this.currentUserId) {
this.total_entries--;
} else {
memo.push(m);
}
return memo;
}, [], this);
},
// @return {Number, undefined} may be undefined until a first fetch is done
totalCount: function() {
return this.total_entries;
}
});