2018-06-15 23:03:24 +08:00
|
|
|
import { url } from "discourse/lib/computed";
|
2019-02-19 20:56:01 +08:00
|
|
|
import { default as computed } from "ember-addons/ember-computed-decorators";
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
|
|
|
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-06-15 23:03: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
|
|
|
},
|
|
|
|
|
|
|
|
@computed("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
|
|
|
},
|
|
|
|
|
2018-09-07 02:56:00 +08:00
|
|
|
@computed("model.isSaving")
|
|
|
|
saveButtonText(isSaving) {
|
|
|
|
return isSaving ? I18n.t("saving") : I18n.t("admin.customize.save");
|
|
|
|
},
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2018-09-07 02:56:00 +08:00
|
|
|
@computed("model.changed", "model.isSaving")
|
|
|
|
saveDisabled(changed, isSaving) {
|
|
|
|
return !changed || isSaving;
|
|
|
|
},
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("saving", true);
|
|
|
|
this.get("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) {
|
|
|
|
this.replaceRoute(
|
|
|
|
this.get("editRouteName"),
|
|
|
|
this.get("model.id"),
|
|
|
|
target,
|
|
|
|
name
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
onlyOverriddenChanged(onlyShowOverridden) {
|
|
|
|
if (onlyShowOverridden) {
|
|
|
|
if (
|
|
|
|
!this.get("model").hasEdited(
|
|
|
|
this.get("currentTargetName"),
|
|
|
|
this.get("fieldName")
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
let firstTarget = this.get("model.targets").find(t => t.edited);
|
|
|
|
let firstField = this.get(`model.fields.${firstTarget.name}`).find(
|
|
|
|
f => f.edited
|
|
|
|
);
|
|
|
|
|
|
|
|
this.replaceRoute(
|
|
|
|
this.get("editRouteName"),
|
|
|
|
this.get("model.id"),
|
|
|
|
firstTarget.name,
|
|
|
|
firstField.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|