2015-05-21 14:57:45 -04:00
|
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
2016-12-12 09:46:45 -05:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
2015-05-21 14:57:45 -04:00
|
|
|
|
2015-08-11 12:27:07 -04:00
|
|
|
export default Ember.Controller.extend({
|
2016-10-20 13:26:41 -04:00
|
|
|
adminGroupsType: Ember.inject.controller(),
|
2014-04-23 13:25:02 -04:00
|
|
|
disableSave: false,
|
2015-12-27 22:21:07 -05:00
|
|
|
savingStatus: '',
|
2015-01-05 12:51:45 -05:00
|
|
|
|
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(),
|
|
|
|
|
2015-09-01 16:52:05 -04:00
|
|
|
trustLevelOptions: function() {
|
|
|
|
return [
|
|
|
|
{ name: I18n.t("groups.trust_levels.none"), value: 0 },
|
|
|
|
{ name: 1, value: 1 }, { name: 2, value: 2 }, { name: 3, value: 3 }, { name: 4, value: 4 }
|
|
|
|
];
|
|
|
|
}.property(),
|
|
|
|
|
2017-04-20 15:47:25 -04:00
|
|
|
@computed('model.visible', 'model.public')
|
2016-12-12 09:46:45 -05:00
|
|
|
disableMembershipRequestSetting(visible, publicGroup) {
|
2017-04-20 15:47:25 -04:00
|
|
|
return !visible || publicGroup;
|
2016-12-12 09:46:45 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
@computed('model.visible', 'model.allow_membership_requests')
|
|
|
|
disablePublicSetting(visible, allowMembershipRequests) {
|
|
|
|
return !visible || allowMembershipRequests;
|
|
|
|
},
|
|
|
|
|
2014-04-23 13:25:02 -04:00
|
|
|
actions: {
|
2015-11-09 08:52:04 -05:00
|
|
|
removeOwner(member) {
|
|
|
|
const self = this,
|
|
|
|
message = I18n.t("admin.groups.delete_owner_confirm", { username: member.get("username"), group: this.get("model.name") });
|
|
|
|
return bootbox.confirm(message, I18n.t("no_value"), I18n.t("yes_value"), function(confirm) {
|
|
|
|
if (confirm) {
|
|
|
|
self.get("model").removeOwner(member);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
addOwners() {
|
|
|
|
if (Em.isEmpty(this.get("model.ownerUsernames"))) { return; }
|
|
|
|
this.get("model").addOwners(this.get("model.ownerUsernames")).catch(popupAjaxError);
|
|
|
|
this.set("model.ownerUsernames", null);
|
|
|
|
},
|
|
|
|
|
2015-04-03 10:50:51 -04:00
|
|
|
save() {
|
|
|
|
const group = this.get('model'),
|
2016-10-20 13:26:41 -04:00
|
|
|
groupsController = this.get("adminGroupsType"),
|
2015-09-17 10:20:21 -04:00
|
|
|
groupType = groupsController.get("type");
|
2014-04-23 13:25:02 -04:00
|
|
|
|
2015-01-21 14:52:48 -05:00
|
|
|
this.set('disableSave', true);
|
2015-12-27 22:21:07 -05:00
|
|
|
this.set('savingStatus', I18n.t('saving'));
|
2014-04-23 13:25:02 -04:00
|
|
|
|
2016-10-20 13:26:41 -04:00
|
|
|
let promise = group.get("id") ? group.save() : group.create().then(() => groupsController.get('model').addObject(group));
|
2015-04-03 10:50:51 -04:00
|
|
|
|
2015-12-27 22:21:07 -05:00
|
|
|
promise.then(() => {
|
|
|
|
this.transitionToRoute("adminGroup", groupType, group.get('name'));
|
|
|
|
this.set('savingStatus', I18n.t('saved'));
|
|
|
|
}).catch(popupAjaxError)
|
|
|
|
.finally(() => this.set('disableSave', false));
|
2014-04-23 13:25:02 -04:00
|
|
|
},
|
|
|
|
|
2015-04-03 10:50:51 -04:00
|
|
|
destroy() {
|
|
|
|
const group = this.get('model'),
|
2016-10-20 13:26:41 -04:00
|
|
|
groupsController = this.get('adminGroupsType'),
|
2015-04-03 10:50:51 -04:00
|
|
|
self = this;
|
2014-04-23 13:25:02 -04:00
|
|
|
|
2015-09-17 10:20:21 -04:00
|
|
|
if (!group.get('id')) {
|
|
|
|
self.transitionToRoute('adminGroupsType.index', 'custom');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-21 14:52:48 -05:00
|
|
|
this.set('disableSave', true);
|
|
|
|
|
2015-04-03 10:50:51 -04:00
|
|
|
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 {
|
2014-04-23 13:25:02 -04:00
|
|
|
self.set('disableSave', false);
|
2015-04-03 10:50:51 -04:00
|
|
|
}
|
2014-04-23 13:25:02 -04:00
|
|
|
}
|
2015-04-03 10:50:51 -04:00
|
|
|
);
|
2014-04-23 13:25:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|