2013-04-17 03:08:21 -04:00
|
|
|
Discourse.Group = Discourse.Model.extend({
|
2013-05-09 03:37:34 -04:00
|
|
|
loaded: false,
|
|
|
|
|
2013-05-08 01:20:38 -04:00
|
|
|
userCountDisplay: function(){
|
|
|
|
var c = this.get('user_count');
|
|
|
|
// don't display zero its ugly
|
|
|
|
if(c > 0) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}.property('user_count'),
|
|
|
|
|
2013-05-09 03:37:34 -04:00
|
|
|
load: function() {
|
|
|
|
var id = this.get('id');
|
|
|
|
if(id && !this.get('loaded')) {
|
|
|
|
var group = this;
|
|
|
|
Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){
|
|
|
|
var users = Em.A()
|
|
|
|
payload.each(function(user){
|
|
|
|
users.addObject(Discourse.User.create(user));
|
|
|
|
});
|
|
|
|
group.set('users', users)
|
|
|
|
group.set('loaded', true)
|
2013-05-08 01:20:38 -04:00
|
|
|
});
|
2013-05-09 03:37:34 -04:00
|
|
|
}
|
2013-05-08 01:20:38 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
usernames: function() {
|
|
|
|
var users = this.get('users');
|
|
|
|
var usernames = "";
|
|
|
|
if(users) {
|
|
|
|
usernames = $.map(users, function(user){
|
|
|
|
return user.get('username');
|
|
|
|
}).join(',')
|
|
|
|
}
|
|
|
|
return usernames;
|
2013-05-09 03:37:34 -04:00
|
|
|
}.property('users'),
|
|
|
|
|
|
|
|
destroy: function(){
|
|
|
|
var group = this;
|
|
|
|
group.set('disableSave', true);
|
|
|
|
|
|
|
|
return Discourse.ajax("/admin/groups/" + this.get("id"), {type: "DELETE"})
|
|
|
|
.then(function(){
|
|
|
|
group.set('disableSave', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
create: function(){
|
|
|
|
var group = this;
|
|
|
|
group.set('disableSave', true);
|
|
|
|
|
|
|
|
return Discourse.ajax("/admin/groups", {type: "POST", data: {
|
|
|
|
group: {
|
|
|
|
name: this.get('name'),
|
|
|
|
usernames: this.get('usernames')
|
|
|
|
}
|
|
|
|
}}).then(function(r){
|
|
|
|
group.set('disableSave', false);
|
|
|
|
group.set('id', r.id);
|
|
|
|
});
|
2013-05-24 07:04:26 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
save: function(){
|
|
|
|
var group = this;
|
|
|
|
group.set('disableSave', true);
|
|
|
|
|
|
|
|
return Discourse.ajax("/admin/groups/" + this.get('id'), {type: "PUT", data: {
|
|
|
|
group: {
|
|
|
|
name: this.get('name'),
|
|
|
|
usernames: this.get('usernames')
|
|
|
|
}
|
|
|
|
}}).then(function(r){
|
|
|
|
group.set('disableSave', false);
|
|
|
|
});
|
2013-05-09 03:37:34 -04:00
|
|
|
}
|
2013-04-17 03:08:21 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.Group.reopenClass({
|
|
|
|
findAll: function(){
|
|
|
|
var list = Discourse.SelectableArray.create();
|
|
|
|
|
2013-05-08 01:20:38 -04:00
|
|
|
Discourse.ajax("/admin/groups").then(function(groups){
|
|
|
|
groups.each(function(group){
|
|
|
|
list.addObject(Discourse.Group.create(group));
|
|
|
|
});
|
|
|
|
});
|
2013-04-17 03:08:21 -04:00
|
|
|
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
|
|
|
find: function(id) {
|
|
|
|
var promise = new Em.Deferred();
|
2013-05-08 01:20:38 -04:00
|
|
|
|
2013-04-17 03:08:21 -04:00
|
|
|
setTimeout(function(){
|
|
|
|
promise.resolve(Discourse.Group.create({id: 1, name: "all mods", members: ["A","b","c"]}));
|
|
|
|
}, 1000);
|
2013-05-08 01:20:38 -04:00
|
|
|
|
2013-04-17 03:08:21 -04:00
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
});
|