diff --git a/ghost/admin/.lint-todo b/ghost/admin/.lint-todo index d5754c7c05..1cf8d019c2 100644 --- a/ghost/admin/.lint-todo +++ b/ghost/admin/.lint-todo @@ -1001,3 +1001,6 @@ add|ember-template-lint|no-passed-in-event-handlers|383|24|383|24|d8b5d7c4140d1d add|ember-template-lint|no-passed-in-event-handlers|396|24|396|24|3e1dad0fb19c62adea14c5534d52cd95cfad280a|1662508800000|1672880400000|1678064400000|app/components/tags/tag-form.hbs add|ember-template-lint|require-input-label|30|28|30|28|af62541280c3dc86d2ca7a4be8c980ee164fba5a|1662508800000|1672880400000|1678064400000|app/components/tags/tag-form.hbs add|ember-template-lint|require-input-label|47|32|47|32|8e299cf5bf0e93e054410239451997a196933d25|1662508800000|1672880400000|1678064400000|app/components/tags/tag-form.hbs +remove|ember-template-lint|no-action|22|85|22|85|8024e7e42cf37a5954ea4db401cbf123931da388|1658102400000|1668474000000|1673658000000|app/templates/tag.hbs +remove|ember-template-lint|no-action|41|17|41|17|712a767fa44489687284ef2aa32c1acc5221afce|1658102400000|1668474000000|1673658000000|app/templates/tag.hbs +remove|ember-template-lint|no-action|42|15|42|15|d3fea3e454ca345739d46caf51afd85a3eea1041|1658102400000|1668474000000|1673658000000|app/templates/tag.hbs diff --git a/ghost/admin/app/components/modal-delete-tag.hbs b/ghost/admin/app/components/modal-delete-tag.hbs deleted file mode 100644 index 808d8972f6..0000000000 --- a/ghost/admin/app/components/modal-delete-tag.hbs +++ /dev/null @@ -1,16 +0,0 @@ - -{{svg-jar "close"}} - - - - diff --git a/ghost/admin/app/components/modal-delete-tag.js b/ghost/admin/app/components/modal-delete-tag.js deleted file mode 100644 index 9118fc616d..0000000000 --- a/ghost/admin/app/components/modal-delete-tag.js +++ /dev/null @@ -1,32 +0,0 @@ -import ModalComponent from 'ghost-admin/components/modal-base'; -import {alias} from '@ember/object/computed'; -import {computed} from '@ember/object'; -import {task} from 'ember-concurrency'; - -export default ModalComponent.extend({ - attributeBindings: ['dataTestModal:data-test-modal'], - dataTestModal: 'confirm-delete-tag', - - // Allowed actions - confirm: () => {}, - - tag: alias('model'), - - postInflection: computed('tag.count.posts', function () { - return this.get('tag.count.posts') > 1 ? 'posts' : 'post'; - }), - - actions: { - confirm() { - this.deleteTag.perform(); - } - }, - - deleteTag: task(function* () { - try { - yield this.confirm(); - } finally { - this.send('closeModal'); - } - }).drop() -}); diff --git a/ghost/admin/app/components/tags/delete-tag-modal.hbs b/ghost/admin/app/components/tags/delete-tag-modal.hbs new file mode 100644 index 0000000000..02b9908611 --- /dev/null +++ b/ghost/admin/app/components/tags/delete-tag-modal.hbs @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/ghost/admin/app/components/tags/delete-tag-modal.js b/ghost/admin/app/components/tags/delete-tag-modal.js new file mode 100644 index 0000000000..99c60a5583 --- /dev/null +++ b/ghost/admin/app/components/tags/delete-tag-modal.js @@ -0,0 +1,29 @@ +import Component from '@glimmer/component'; +import {inject as service} from '@ember/service'; +import {task} from 'ember-concurrency'; + +export default class DeleteTagModal extends Component { + @service notifications; + @service router; + + @task({drop: true}) + *deleteTagTask() { + try { + const {tag} = this.args.data; + + if (tag.isDeleted) { + return true; + } + + yield tag.destroyRecord(); + + this.notifications.closeAlerts('tag.delete'); + this.router.transitionTo('tags'); + return true; + } catch (error) { + this.notifications.showAPIError(error, {key: 'tag.delete.failed'}); + } finally { + this.args.close(); + } + } +} diff --git a/ghost/admin/app/controllers/tag.js b/ghost/admin/app/controllers/tag.js index c75825c12b..5eb371189a 100644 --- a/ghost/admin/app/controllers/tag.js +++ b/ghost/admin/app/controllers/tag.js @@ -1,4 +1,5 @@ import Controller from '@ember/controller'; +import DeleteTagModal from '../components/tags/delete-tag-modal'; import EmberObject, {action, computed, defineProperty} from '@ember/object'; import boundOneWay from 'ghost-admin/utils/bound-one-way'; import classic from 'ember-classic-decorator'; @@ -11,11 +12,10 @@ const SCRATCH_PROPS = ['name', 'slug', 'description', 'metaTitle', 'metaDescript @classic export default class TagController extends Controller { + @service modals; @service notifications; @service router; - showDeleteTagModal = false; - @alias('model') tag; @@ -32,23 +32,9 @@ export default class TagController extends Controller { } @action - openDeleteTagModal() { - this.set('showDeleteTagModal', true); - } - - @action - closeDeleteTagModal() { - this.set('showDeleteTagModal', false); - } - - @action - deleteTag() { - return this.tag.destroyRecord().then(() => { - this.set('showDeleteTagModal', false); - this.router.transitionTo('tags'); - return true; - }, (error) => { - return this.notifications.showAPIError(error, {key: 'tag.delete'}); + confirmDeleteTag() { + return this.modals.open(DeleteTagModal, { + tag: this.model }); } diff --git a/ghost/admin/app/templates/tag.hbs b/ghost/admin/app/templates/tag.hbs index f0a49e1f9c..c9a2fec48c 100644 --- a/ghost/admin/app/templates/tag.hbs +++ b/ghost/admin/app/templates/tag.hbs @@ -19,7 +19,7 @@ {{#unless this.tag.isNew}}
-
@@ -32,13 +32,4 @@ @confirm={{action "leaveScreen"}} @close={{action "toggleUnsavedChangesModal"}} @modifier="action wide" /> -{{/if}} - -{{#if this.showDeleteTagModal}} - {{/if}} \ No newline at end of file