2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2017-04-12 10:52:52 -04:00
|
|
|
import I18n from "I18n";
|
2020-01-16 12:56:53 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import { url } from "discourse/lib/computed";
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2017-04-12 10:52:52 -04:00
|
|
|
section: null,
|
2018-09-06 14:56:00 -04:00
|
|
|
currentTarget: 0,
|
|
|
|
maximized: false,
|
|
|
|
previewUrl: url("model.id", "/admin/themes/%@/preview"),
|
2019-02-19 07:56:01 -05:00
|
|
|
showAdvanced: false,
|
2018-03-28 16:35:24 -04:00
|
|
|
editRouteName: "adminCustomizeThemes.edit",
|
2019-02-19 07:56:01 -05:00
|
|
|
showRouteName: "adminCustomizeThemes.show",
|
2017-04-19 15:24:00 -04:00
|
|
|
|
2021-11-13 08:01:55 -05:00
|
|
|
setTargetName(name) {
|
2019-02-19 07:56:01 -05:00
|
|
|
const target = this.get("model.targets").find((t) => t.name === name);
|
2018-03-04 19:04:23 -05:00
|
|
|
this.set("currentTarget", target && target.id);
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("currentTarget")
|
2018-03-04 19:04:23 -05:00
|
|
|
currentTargetName(id) {
|
2019-02-19 07:56:01 -05:00
|
|
|
const target = this.get("model.targets").find(
|
|
|
|
(t) => t.id === parseInt(id, 10)
|
|
|
|
);
|
2018-03-04 19:04:23 -05:00
|
|
|
return target && target.name;
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.isSaving")
|
2018-09-06 14:56:00 -04:00
|
|
|
saveButtonText(isSaving) {
|
|
|
|
return isSaving ? I18n.t("saving") : I18n.t("admin.customize.save");
|
|
|
|
},
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("model.changed", "model.isSaving")
|
2018-09-06 14:56:00 -04:00
|
|
|
saveDisabled(changed, isSaving) {
|
|
|
|
return !changed || isSaving;
|
|
|
|
},
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
2017-04-19 16:46:28 -04:00
|
|
|
this.set("saving", true);
|
2019-05-27 04:42:53 -04:00
|
|
|
this.model.saveChanges("theme_fields").finally(() => {
|
|
|
|
this.set("saving", false);
|
|
|
|
});
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
2019-02-19 07:56:01 -05:00
|
|
|
fieldAdded(target, name) {
|
2019-05-27 04:42:53 -04:00
|
|
|
this.replaceRoute(this.editRouteName, this.get("model.id"), target, name);
|
2019-02-19 07:56:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
onlyOverriddenChanged(onlyShowOverridden) {
|
|
|
|
if (onlyShowOverridden) {
|
2019-05-27 04:42:53 -04:00
|
|
|
if (!this.model.hasEdited(this.currentTargetName, this.fieldName)) {
|
2019-02-19 07:56:01 -05:00
|
|
|
let firstTarget = this.get("model.targets").find((t) => t.edited);
|
|
|
|
let firstField = this.get(`model.fields.${firstTarget.name}`).find(
|
|
|
|
(f) => f.edited
|
|
|
|
);
|
|
|
|
|
|
|
|
this.replaceRoute(
|
2019-05-27 04:15:39 -04:00
|
|
|
this.editRouteName,
|
2019-02-19 07:56:01 -05:00
|
|
|
this.get("model.id"),
|
|
|
|
firstTarget.name,
|
|
|
|
firstField.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
2020-12-07 18:54:44 -05:00
|
|
|
|
|
|
|
goBack() {
|
|
|
|
this.replaceRoute(this.showRouteName, this.model.id);
|
|
|
|
},
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
});
|