diff --git a/packages/form-builder/addon/components/cfb-form-editor/copy-modal.hbs b/packages/form-builder/addon/components/cfb-form-editor/copy-modal.hbs new file mode 100644 index 000000000..9e4da8abb --- /dev/null +++ b/packages/form-builder/addon/components/cfb-form-editor/copy-modal.hbs @@ -0,0 +1,50 @@ + + {{#if this.visible}} + + +

+ {{t "caluma.form-builder.copy-modal.title" form=@item.name}} +

+
+ + + + + + + {{t "caluma.form-builder.copy-modal.submit"}} + + +
+ {{/if}} +
+ +{{yield (hash toggle=this.toggle)}} \ No newline at end of file diff --git a/packages/form-builder/addon/components/cfb-form-editor/copy-modal.js b/packages/form-builder/addon/components/cfb-form-editor/copy-modal.js new file mode 100644 index 000000000..cc17a7a28 --- /dev/null +++ b/packages/form-builder/addon/components/cfb-form-editor/copy-modal.js @@ -0,0 +1,63 @@ +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { queryManager } from "ember-apollo-client"; +import { Changeset } from "ember-changeset"; +import lookupValidator from "ember-changeset-validations"; +import { dropTask } from "ember-concurrency"; + +import copyFormMutation from "@projectcaluma/ember-form-builder/gql/mutations/copy-form.graphql"; +import validations from "@projectcaluma/ember-form-builder/validations/form"; + +export default class CfbFormEditorCopyModal extends Component { + @queryManager apollo; + @service notification; + @service router; + @service intl; + @tracked visible = false; + + constructor(owner, args) { + super(owner, args); + + this.changeset = Changeset( + { ...this.args.item, id: undefined }, + lookupValidator(validations), + validations, + ); + } + + @action + toggle() { + this.visible = !this.visible; + } + + @dropTask + *submit(changeset) { + try { + yield this.apollo.mutate( + { + mutation: copyFormMutation, + variables: { + input: { + source: this.args.item.slug, + name: changeset.name, + slug: changeset.slug, + }, + }, + }, + "copyForm.form", + ); + + this.notification.success( + this.intl.t("caluma.form-builder.notification.form.create.success"), + ); + + this.router.transitionTo("edit", changeset.slug); + } catch (e) { + this.notification.danger( + this.intl.t("caluma.form-builder.notification.form.create.error"), + ); + } + } +} diff --git a/packages/form-builder/addon/components/cfb-form-editor/general.hbs b/packages/form-builder/addon/components/cfb-form-editor/general.hbs index c684760b5..69cf2da25 100644 --- a/packages/form-builder/addon/components/cfb-form-editor/general.hbs +++ b/packages/form-builder/addon/components/cfb-form-editor/general.hbs @@ -50,6 +50,15 @@ />
+ + + + diff --git a/packages/form-builder/addon/components/cfb-slug-input.hbs b/packages/form-builder/addon/components/cfb-slug-input.hbs index f65fccd8a..36bd9854a 100644 --- a/packages/form-builder/addon/components/cfb-slug-input.hbs +++ b/packages/form-builder/addon/components/cfb-slug-input.hbs @@ -14,6 +14,7 @@ {{/if}}