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