From 904450594d5c747588d2b3e85fd80ddd697c35db Mon Sep 17 00:00:00 2001 From: Keegan George Date: Tue, 4 Jul 2023 12:42:36 -0700 Subject: [PATCH] DEV: Convert form template modals to new component-based API (#22196) --- .../addon/components/form-template/form.hbs | 9 ++++- .../addon/components/form-template/form.js | 7 +--- .../components/form-template/row-item.hbs | 12 +++++- .../components/form-template/row-item.js | 9 ----- .../modal/customize-form-template-view.hbs | 37 +++++++++++++++++++ .../modal}/customize-form-template-view.js | 9 ++--- .../modal/form-template-form-preview.hbs | 9 +++++ .../controllers/form-template-form-preview.js | 6 --- .../modal/customize-form-template-view.hbs | 33 ----------------- .../modal/form-template-form-preview.hbs | 6 --- 10 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.hbs rename app/assets/javascripts/discourse/app/{controllers => components/modal}/customize-form-template-view.js (78%) create mode 100644 app/assets/javascripts/discourse/app/components/modal/form-template-form-preview.hbs delete mode 100644 app/assets/javascripts/discourse/app/controllers/form-template-form-preview.js delete mode 100644 app/assets/javascripts/discourse/app/templates/modal/customize-form-template-view.hbs delete mode 100644 app/assets/javascripts/discourse/app/templates/modal/form-template-form-preview.hbs diff --git a/app/assets/javascripts/admin/addon/components/form-template/form.hbs b/app/assets/javascripts/admin/addon/components/form-template/form.hbs index 907310123d4..01b8caf4d42 100644 --- a/app/assets/javascripts/admin/addon/components/form-template/form.hbs +++ b/app/assets/javascripts/admin/addon/components/form-template/form.hbs @@ -68,4 +68,11 @@ /> {{/if}} - \ No newline at end of file + + +{{#if this.showFormTemplateFormPreview}} + +{{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/admin/addon/components/form-template/form.js b/app/assets/javascripts/admin/addon/components/form-template/form.js index f6655a7de4a..0666eb26e14 100644 --- a/app/assets/javascripts/admin/addon/components/form-template/form.js +++ b/app/assets/javascripts/admin/addon/components/form-template/form.js @@ -14,6 +14,7 @@ export default class FormTemplateForm extends Component { @tracked formSubmitted = false; @tracked templateContent = this.args.model?.template || ""; @tracked templateName = this.args.model?.name || ""; + @tracked showFormTemplateFormPreview; isEditing = this.args.model?.id ? true : false; quickInsertFields = [ { @@ -129,11 +130,7 @@ export default class FormTemplateForm extends Component { FormTemplate.validateTemplate(data) .then(() => { - return showModal("form-template-form-preview", { - model: { - content: this.templateContent, - }, - }); + this.showFormTemplateFormPreview = true; }) .catch(popupAjaxError); } diff --git a/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs b/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs index a4cd830244c..c7c1791b260 100644 --- a/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs +++ b/app/assets/javascripts/admin/addon/components/form-template/row-item.hbs @@ -10,7 +10,7 @@ @title="admin.form_templates.list_table.actions.view" @icon="far-eye" @class="btn-view-template" - @action={{this.viewTemplate}} + @action={{fn (mut this.showViewTemplateModal) true}} /> - \ No newline at end of file + + +{{#if this.showViewTemplateModal}} + +{{/if}} \ No newline at end of file diff --git a/app/assets/javascripts/admin/addon/components/form-template/row-item.js b/app/assets/javascripts/admin/addon/components/form-template/row-item.js index b5e8dd30066..f95df2bb5ce 100644 --- a/app/assets/javascripts/admin/addon/components/form-template/row-item.js +++ b/app/assets/javascripts/admin/addon/components/form-template/row-item.js @@ -1,6 +1,5 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; -import showModal from "discourse/lib/show-modal"; import { inject as service } from "@ember/service"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; @@ -17,14 +16,6 @@ export default class FormTemplateRowItem extends Component { ); } - @action - viewTemplate() { - showModal("customize-form-template-view", { - model: this.args.template, - refreshModel: this.args.refreshModel, - }); - } - @action editTemplate() { this.router.transitionTo( diff --git a/app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.hbs b/app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.hbs new file mode 100644 index 00000000000..4ba90c4e275 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.hbs @@ -0,0 +1,37 @@ + + <:body> +
+ +
+ {{#if this.showPreview}} + + {{else}} + + {{/if}} + + + <:footer> + + + + +
\ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/controllers/customize-form-template-view.js b/app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.js similarity index 78% rename from app/assets/javascripts/discourse/app/controllers/customize-form-template-view.js rename to app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.js index 302d77f782b..d3c300bf3f5 100644 --- a/app/assets/javascripts/discourse/app/controllers/customize-form-template-view.js +++ b/app/assets/javascripts/discourse/app/components/modal/customize-form-template-view.js @@ -1,5 +1,4 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; +import Component from "@glimmer/component"; import { action } from "@ember/object"; import { inject as service } from "@ember/service"; import I18n from "I18n"; @@ -7,9 +6,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; import { ajax } from "discourse/lib/ajax"; import { tracked } from "@glimmer/tracking"; -export default class AdminCustomizeFormTemplateView extends Controller.extend( - ModalFunctionality -) { +export default class CustomizeFormTemplateViewModal extends Component { @service router; @service dialog; @tracked showPreview = false; @@ -35,7 +32,7 @@ export default class AdminCustomizeFormTemplateView extends Controller.extend( type: "DELETE", }) .then(() => { - this.refreshModel(); + this.args.refreshModel(); }) .catch(popupAjaxError); }, diff --git a/app/assets/javascripts/discourse/app/components/modal/form-template-form-preview.hbs b/app/assets/javascripts/discourse/app/components/modal/form-template-form-preview.hbs new file mode 100644 index 00000000000..9f2dd782b3f --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/form-template-form-preview.hbs @@ -0,0 +1,9 @@ + + <:body> + + + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/controllers/form-template-form-preview.js b/app/assets/javascripts/discourse/app/controllers/form-template-form-preview.js deleted file mode 100644 index 15a936ada6b..00000000000 --- a/app/assets/javascripts/discourse/app/controllers/form-template-form-preview.js +++ /dev/null @@ -1,6 +0,0 @@ -import Controller from "@ember/controller"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; - -export default class AdminFormTemplateValidationOptions extends Controller.extend( - ModalFunctionality -) {} diff --git a/app/assets/javascripts/discourse/app/templates/modal/customize-form-template-view.hbs b/app/assets/javascripts/discourse/app/templates/modal/customize-form-template-view.hbs deleted file mode 100644 index dac821bbd70..00000000000 --- a/app/assets/javascripts/discourse/app/templates/modal/customize-form-template-view.hbs +++ /dev/null @@ -1,33 +0,0 @@ - -
- -
- {{#if this.showPreview}} - - {{else}} - - {{/if}} -
- \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/templates/modal/form-template-form-preview.hbs b/app/assets/javascripts/discourse/app/templates/modal/form-template-form-preview.hbs deleted file mode 100644 index 1624b7bc369..00000000000 --- a/app/assets/javascripts/discourse/app/templates/modal/form-template-form-preview.hbs +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file