Initial commit
This commit is contained in:
40
lib/assets/javascripts/builder/data/organization-model.js
Executable file
40
lib/assets/javascripts/builder/data/organization-model.js
Executable file
@@ -0,0 +1,40 @@
|
||||
var Backbone = require('backbone');
|
||||
var _ = require('underscore');
|
||||
|
||||
/**
|
||||
* Organization info model
|
||||
*
|
||||
*/
|
||||
module.exports = Backbone.Model.extend({
|
||||
|
||||
url: function () {
|
||||
var baseUrl = this._configModel.get('base_url');
|
||||
return baseUrl + '/api/v1/org';
|
||||
},
|
||||
|
||||
initialize: function (attrs, opts) {
|
||||
if (!opts.configModel) throw new Error('configModel is required');
|
||||
|
||||
this._configModel = opts.configModel;
|
||||
|
||||
if (!_.isEmpty(this.get('owner'))) {
|
||||
this._ownerModel = new Backbone.Model(
|
||||
_.omit(this.get('owner'), 'organization')
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
getOwnerId: function () {
|
||||
return this._ownerModel && this._ownerModel.get('id');
|
||||
},
|
||||
|
||||
getOwnerEmail: function () {
|
||||
return this._ownerModel && this._ownerModel.get('email');
|
||||
},
|
||||
|
||||
isOrgAdmin: function (user) {
|
||||
return this.getOwnerId() === user.get('id') || !!_.find(this.get('admins'), function (u) {
|
||||
return u.id === user.get('id');
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user