2014-07-22 23:20:45 -04:00
|
|
|
export default Em.ObjectController.extend({
|
2015-01-21 14:52:48 -05:00
|
|
|
needs: ['adminGroupsType'],
|
2014-04-23 13:25:02 -04:00
|
|
|
disableSave: false,
|
2015-01-05 12:51:45 -05:00
|
|
|
|
|
|
|
currentPage: function() {
|
2015-02-10 17:20:16 -05:00
|
|
|
if (this.get("user_count") === 0) { return 0; }
|
2015-01-05 12:51:45 -05:00
|
|
|
return Math.floor(this.get("offset") / this.get("limit")) + 1;
|
|
|
|
}.property("limit", "offset", "user_count"),
|
|
|
|
|
|
|
|
totalPages: function() {
|
2015-02-10 17:20:16 -05:00
|
|
|
if (this.get("user_count") === 0) { return 0; }
|
2015-01-05 12:51:45 -05:00
|
|
|
return Math.floor(this.get("user_count") / this.get("limit")) + 1;
|
|
|
|
}.property("limit", "user_count"),
|
|
|
|
|
|
|
|
showingFirst: Em.computed.lte("currentPage", 1),
|
|
|
|
showingLast: Discourse.computed.propertyEqual("currentPage", "totalPages"),
|
2014-04-23 13:25:02 -04:00
|
|
|
|
|
|
|
aliasLevelOptions: function() {
|
|
|
|
return [
|
2015-01-05 12:51:45 -05:00
|
|
|
{ name: I18n.t("groups.alias_levels.nobody"), value: 0 },
|
|
|
|
{ name: I18n.t("groups.alias_levels.mods_and_admins"), value: 2 },
|
|
|
|
{ name: I18n.t("groups.alias_levels.members_mods_and_admins"), value: 3 },
|
|
|
|
{ name: I18n.t("groups.alias_levels.everyone"), value: 99 }
|
2014-04-23 13:25:02 -04:00
|
|
|
];
|
|
|
|
}.property(),
|
|
|
|
|
|
|
|
actions: {
|
2015-01-05 12:51:45 -05:00
|
|
|
next: function() {
|
|
|
|
if (this.get("showingLast")) { return; }
|
|
|
|
|
|
|
|
var 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() {
|
|
|
|
if (this.get("showingFirst")) { return; }
|
|
|
|
|
|
|
|
var 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") });
|
|
|
|
return bootbox.confirm(message, I18n.t("no_value"), I18n.t("yes_value"), function(confirm) {
|
|
|
|
if (confirm) {
|
|
|
|
self.get("model").removeMember(member);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
addMembers: function() {
|
|
|
|
if (Em.isEmpty(this.get("usernames"))) { return; }
|
|
|
|
this.get("model").addMembers(this.get("usernames"));
|
2015-01-21 14:52:48 -05:00
|
|
|
// clear the user selector
|
|
|
|
this.set("usernames", null);
|
2015-01-05 12:51:45 -05:00
|
|
|
},
|
|
|
|
|
2014-04-23 13:25:02 -04:00
|
|
|
save: function() {
|
|
|
|
var self = this,
|
2015-01-21 14:52:48 -05:00
|
|
|
group = this.get('model'),
|
|
|
|
groupsController = this.get("controllers.adminGroupsType");
|
2014-04-23 13:25:02 -04:00
|
|
|
|
2015-01-21 14:52:48 -05:00
|
|
|
this.set('disableSave', true);
|
2014-04-23 13:25:02 -04:00
|
|
|
|
|
|
|
var promise;
|
2015-01-21 14:52:48 -05:00
|
|
|
if (group.get("id")) {
|
2015-01-05 12:51:45 -05:00
|
|
|
promise = group.save();
|
2014-04-23 13:25:02 -04:00
|
|
|
} else {
|
2015-01-05 12:51:45 -05:00
|
|
|
promise = group.create().then(function() {
|
2014-04-23 13:25:02 -04:00
|
|
|
groupsController.addObject(group);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
promise.then(function() {
|
2015-01-21 14:52:48 -05:00
|
|
|
self.transitionToRoute("adminGroup", group);
|
2014-04-23 13:25:02 -04:00
|
|
|
}, function(e) {
|
|
|
|
var message = $.parseJSON(e.responseText).errors;
|
|
|
|
bootbox.alert(message);
|
|
|
|
}).finally(function() {
|
|
|
|
self.set('disableSave', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
var group = this.get('model'),
|
2015-01-21 14:52:48 -05:00
|
|
|
groupsController = this.get('controllers.adminGroupsType'),
|
2014-04-23 13:25:02 -04:00
|
|
|
self = this;
|
|
|
|
|
2015-01-21 14:52:48 -05:00
|
|
|
this.set('disableSave', true);
|
|
|
|
|
|
|
|
bootbox.confirm(I18n.t("admin.groups.delete_confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(confirmed) {
|
|
|
|
if (confirmed) {
|
2014-04-23 13:25:02 -04:00
|
|
|
group.destroy().then(function() {
|
|
|
|
groupsController.get('model').removeObject(group);
|
|
|
|
self.transitionToRoute('adminGroups.index');
|
|
|
|
}, function() {
|
|
|
|
bootbox.alert(I18n.t("admin.groups.delete_failed"));
|
|
|
|
}).finally(function() {
|
|
|
|
self.set('disableSave', false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|