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