mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UX: simplifies editing email templates by always having a default (#10179)
This commit is contained in:
@@ -3,8 +3,12 @@ import discourseComputed from "discourse-common/utils/decorators";
|
|||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
import { inject as controller } from "@ember/controller";
|
||||||
|
|
||||||
export default Controller.extend(bufferedProperty("emailTemplate"), {
|
export default Controller.extend(bufferedProperty("emailTemplate"), {
|
||||||
|
adminCustomizeEmailTemplates: controller(),
|
||||||
|
emailTemplate: null,
|
||||||
saved: false,
|
saved: false,
|
||||||
|
|
||||||
@discourseComputed("buffered.body", "buffered.subject")
|
@discourseComputed("buffered.body", "buffered.subject")
|
||||||
@@ -23,35 +27,35 @@ export default Controller.extend(bufferedProperty("emailTemplate"), {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
saveChanges() {
|
saveChanges() {
|
||||||
this.set("saved", false);
|
this.set("saved", false);
|
||||||
const buffered = this.buffered;
|
const buffered = this.buffered;
|
||||||
this.emailTemplate
|
this.emailTemplate
|
||||||
.save(buffered.getProperties("subject", "body"))
|
.save(buffered.getProperties("subject", "body"))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.set("saved", true);
|
this.set("saved", true);
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
||||||
revertChanges() {
|
@action
|
||||||
this.set("saved", false);
|
revertChanges() {
|
||||||
bootbox.confirm(
|
this.set("saved", false);
|
||||||
I18n.t("admin.customize.email_templates.revert_confirm"),
|
bootbox.confirm(
|
||||||
result => {
|
I18n.t("admin.customize.email_templates.revert_confirm"),
|
||||||
if (result) {
|
result => {
|
||||||
this.emailTemplate
|
if (result) {
|
||||||
.revert()
|
this.emailTemplate
|
||||||
.then(props => {
|
.revert()
|
||||||
const buffered = this.buffered;
|
.then(props => {
|
||||||
buffered.setProperties(props);
|
const buffered = this.buffered;
|
||||||
this.commitBuffer();
|
buffered.setProperties(props);
|
||||||
})
|
this.commitBuffer();
|
||||||
.catch(popupAjaxError);
|
})
|
||||||
}
|
.catch(popupAjaxError);
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { sort } from "@ember/object/computed";
|
import { sort } from "@ember/object/computed";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
emailTemplates: null,
|
|
||||||
sortedTemplates: sort("emailTemplates", "titleSorting"),
|
sortedTemplates: sort("emailTemplates", "titleSorting"),
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
this.titleSorting = ["title"];
|
this.set("titleSorting", ["title"]);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
selectTemplate(template) {
|
onSelectTemplate(template) {
|
||||||
this.transitionToRoute("adminCustomizeEmailTemplates.edit", template);
|
this.transitionToRoute("adminCustomizeEmailTemplates.edit", template);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,5 +10,9 @@ export default Route.extend({
|
|||||||
setupController(controller, emailTemplate) {
|
setupController(controller, emailTemplate) {
|
||||||
controller.setProperties({ emailTemplate, saved: false });
|
controller.setProperties({ emailTemplate, saved: false });
|
||||||
scrollTop();
|
scrollTop();
|
||||||
|
},
|
||||||
|
|
||||||
|
deactivate() {
|
||||||
|
this.controller.set("emailTemplate", null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import Route from "@ember/routing/route";
|
import Route from "@ember/routing/route";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
|
||||||
export default Route.extend({
|
export default Route.extend({
|
||||||
model() {
|
model() {
|
||||||
return this.store.findAll("email-template");
|
return this.store.findAll("email-template");
|
||||||
@@ -6,5 +8,19 @@ export default Route.extend({
|
|||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
controller.set("emailTemplates", model);
|
controller.set("emailTemplates", model);
|
||||||
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
|
didTransition() {
|
||||||
|
const editController = this.controllerFor(
|
||||||
|
"adminCustomizeEmailTemplates.edit"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!editController.emailTemplate) {
|
||||||
|
this.transitionTo(
|
||||||
|
"adminCustomizeEmailTemplates.edit",
|
||||||
|
this.controller.get("sortedTemplates.firstObject")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
{{combo-box
|
||||||
|
value=emailTemplate.id
|
||||||
|
content=adminCustomizeEmailTemplates.sortedTemplates
|
||||||
|
onChange=adminCustomizeEmailTemplates.onSelectTemplate
|
||||||
|
nameProperty="title"
|
||||||
|
}}
|
||||||
|
|
||||||
<div class="email-template">
|
<div class="email-template">
|
||||||
<label>{{i18n "admin.customize.email_templates.subject"}}</label>
|
<label>{{i18n "admin.customize.email_templates.subject"}}</label>
|
||||||
{{#if hasMultipleSubjects}}
|
{{#if hasMultipleSubjects}}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<p>{{i18n "admin.customize.email_templates.none_selected"}}</p>
|
|
||||||
@@ -1,8 +1 @@
|
|||||||
{{combo-box
|
|
||||||
content=sortedTemplates
|
|
||||||
valueProperty="id"
|
|
||||||
nameProperty="title"
|
|
||||||
onChange=(action "selectTemplate")
|
|
||||||
}}
|
|
||||||
|
|
||||||
{{outlet}}
|
{{outlet}}
|
||||||
|
|||||||
@@ -3791,7 +3791,6 @@ en:
|
|||||||
subject: "Subject"
|
subject: "Subject"
|
||||||
multiple_subjects: "This email template has multiple subjects."
|
multiple_subjects: "This email template has multiple subjects."
|
||||||
body: "Body"
|
body: "Body"
|
||||||
none_selected: "Select an email template to begin editing."
|
|
||||||
revert: "Revert Changes"
|
revert: "Revert Changes"
|
||||||
revert_confirm: "Are you sure you want to revert your changes?"
|
revert_confirm: "Are you sure you want to revert your changes?"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user