FIX: save button is deactivated on create group page

This commit is contained in:
Régis Hanol 2015-04-03 16:50:51 +02:00
parent d2934ae8fe
commit 7a31131239

View File

@ -25,31 +25,30 @@ export default Em.ObjectController.extend({
}.property(),
actions: {
next: function() {
next() {
if (this.get("showingLast")) { return; }
var group = this.get("model"),
offset = Math.min(group.get("offset") + group.get("limit"), group.get("user_count"));
const group = this.get("model"),
offset = Math.min(group.get("offset") + group.get("limit"), group.get("user_count"));
group.set("offset", offset);
return group.findMembers();
},
previous: function() {
previous() {
if (this.get("showingFirst")) { return; }
var group = this.get("model"),
offset = Math.max(group.get("offset") - group.get("limit"), 0);
const group = this.get("model"),
offset = Math.max(group.get("offset") - group.get("limit"), 0);
group.set("offset", offset);
return group.findMembers();
},
removeMember: function(member) {
var self = this,
message = I18n.t("admin.groups.delete_member_confirm", { username: member.get("username"), group: this.get("name") });
removeMember(member) {
const message = I18n.t("admin.groups.delete_member_confirm", { username: member.get("username"), group: this.get("name") });
return bootbox.confirm(message, I18n.t("no_value"), I18n.t("yes_value"), function(confirm) {
if (confirm) {
self.get("model").removeMember(member);
@ -57,57 +56,49 @@ export default Em.ObjectController.extend({
});
},
addMembers: function() {
addMembers() {
if (Em.isEmpty(this.get("usernames"))) { return; }
this.get("model").addMembers(this.get("usernames"));
// clear the user selector
this.set("usernames", null);
},
save: function() {
var self = this,
group = this.get('model'),
groupsController = this.get("controllers.adminGroupsType");
save() {
const group = this.get('model'),
groupsController = this.get("controllers.adminGroupsType");
this.set('disableSave', true);
var promise;
if (group.get("id")) {
promise = group.save();
} else {
promise = group.create().then(function() {
groupsController.addObject(group);
});
}
promise.then(function() {
self.transitionToRoute("adminGroup", group);
}, function(e) {
var message = $.parseJSON(e.responseText).errors;
bootbox.alert(message);
}).finally(function() {
self.set('disableSave', false);
});
let promise = group.get("id") ? group.save() : group.create().then(() => groupsController.addObject(group));
promise.then(() => this.transitionToRoute("adminGroup", group))
.catch(e => bootbox.alert($.parseJSON(e.responseText).errors))
.finally(() => this.set('disableSave', false));
},
destroy: function() {
var group = this.get('model'),
groupsController = this.get('controllers.adminGroupsType'),
self = this;
destroy() {
const group = this.get('model'),
groupsController = this.get('controllers.adminGroupsType'),
self = this;
this.set('disableSave', true);
bootbox.confirm(I18n.t("admin.groups.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(confirmed) {
if (confirmed) {
group.destroy().then(function() {
groupsController.get('model').removeObject(group);
self.transitionToRoute('adminGroups.index');
}, function() {
bootbox.alert(I18n.t("admin.groups.delete_failed"));
}).finally(function() {
bootbox.confirm(
I18n.t("admin.groups.delete_confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
group.destroy().then(() => {
groupsController.get('model').removeObject(group);
self.transitionToRoute('adminGroups.index');
}).catch(() => bootbox.alert(I18n.t("admin.groups.delete_failed")))
.finally(() => self.set('disableSave', false));
} else {
self.set('disableSave', false);
});
}
}
});
);
}
}
});