2020-03-06 17:49:28 -05:00
|
|
|
import { isBlank } from "@ember/utils";
|
2020-02-05 11:14:42 -05:00
|
|
|
import Controller from "@ember/controller";
|
2020-03-06 17:49:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-11-05 09:10:23 -05:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
|
2020-02-05 11:14:42 -05:00
|
|
|
export default Controller.extend({
|
2019-11-05 09:10:23 -05:00
|
|
|
userModes: [
|
|
|
|
{ id: "all", name: I18n.t("admin.api.all_users") },
|
|
|
|
{ id: "single", name: I18n.t("admin.api.single_user") }
|
|
|
|
],
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("userMode")
|
2019-11-05 09:10:23 -05:00
|
|
|
showUserSelector(mode) {
|
|
|
|
return mode === "single";
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.description", "model.username", "userMode")
|
2019-11-05 09:10:23 -05:00
|
|
|
saveDisabled(description, username, userMode) {
|
2020-03-06 17:49:28 -05:00
|
|
|
if (isBlank(description)) return true;
|
|
|
|
if (userMode === "single" && isBlank(username)) return true;
|
2019-11-05 09:10:23 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
changeUserMode(value) {
|
|
|
|
if (value === "all") {
|
|
|
|
this.model.set("username", null);
|
|
|
|
}
|
|
|
|
this.set("userMode", value);
|
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2019-12-12 06:45:00 -05:00
|
|
|
this.model.save().catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
|
|
|
|
continue() {
|
|
|
|
this.transitionToRoute("adminApiKeys.show", this.model.id);
|
2019-11-05 09:10:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|