move ajax into models

This commit is contained in:
Benjamin Kampmann 2014-07-15 16:11:39 +02:00
parent 5025e97712
commit 518207aa90
2 changed files with 22 additions and 13 deletions

View file

@ -50,23 +50,13 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({
},
groupAdded: function(added){
var self = this;
Discourse.ajax("/admin/users/" + this.get('id') + "/groups", {
type: 'POST',
data: {group_id: added.id}
}).then(function () {
self.get('model.groups').pushObject(added);
}).catch(function() {
this.get('model').groupAdded(added).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},
groupRemoved: function(removed){
var self = this;
Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + removed.id, {
type: 'DELETE'
}).then(function () {
self.set('model.groups.[]', self.get('model.groups').rejectBy("id", removed.id));
}).catch(function() {
this.get('model').groupRemoved(removed).catch(function() {
bootbox.alert(I18n.t('generic_error'));
});
},

View file

@ -23,6 +23,25 @@ Discourse.AdminUser = Discourse.User.extend({
});
},
groupAdded: function(added){
var self = this;
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups", {
type: 'POST',
data: {group_id: added.id}
}).then(function () {
self.get('groups').pushObject(added);
});
},
groupRemoved: function(removed){
var self = this;
return Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + removed.id, {
type: 'DELETE'
}).then(function () {
self.set('groups.[]', self.get('groups').rejectBy("id", removed.id));
})
},
/**
Revokes a user's current API key