From 70a75857774d37d5f6da6043a74849c71e140935 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Tue, 2 Apr 2024 18:22:30 +0400 Subject: [PATCH] A new modal for editing topic assignments --- .../modal/edit-topic-assignments.hbs | 24 +++++++++++++++++ .../modal/edit-topic-assignments.js | 27 +++++++++++++++++++ .../components/topic-level-assign-menu.js | 9 ++++--- .../initializers/extend-for-assigns.js | 7 ++++- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 assets/javascripts/discourse/components/modal/edit-topic-assignments.hbs create mode 100644 assets/javascripts/discourse/components/modal/edit-topic-assignments.js diff --git a/assets/javascripts/discourse/components/modal/edit-topic-assignments.hbs b/assets/javascripts/discourse/components/modal/edit-topic-assignments.hbs new file mode 100644 index 0000000..c3143cd --- /dev/null +++ b/assets/javascripts/discourse/components/modal/edit-topic-assignments.hbs @@ -0,0 +1,24 @@ + + <:body> +

Edit topic assignments form

+ + + + + + + + <:footer> + + + + +
\ No newline at end of file diff --git a/assets/javascripts/discourse/components/modal/edit-topic-assignments.js b/assets/javascripts/discourse/components/modal/edit-topic-assignments.js new file mode 100644 index 0000000..caa80a9 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/edit-topic-assignments.js @@ -0,0 +1,27 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; +import { TrackedObject } from "@ember-compat/tracked-built-ins"; +import I18n from "I18n"; + +export default class EditTopicAssignments extends Component { + @service taskActions; + + model = new TrackedObject(this.args.model); + + // `submit` property will be mutated by the `AssignUserForm` component + formApi = { + submit() {}, + }; + + get title() { + const title = this.model.topic.isAssigned() ? "reassign_title" : "title"; + return I18n.t(`discourse_assign.assign_modal.${title}`); + } + + @action + async onSubmit() { + this.args.closeModal(); + await this.taskActions.assign(this.model); + } +} diff --git a/assets/javascripts/discourse/components/topic-level-assign-menu.js b/assets/javascripts/discourse/components/topic-level-assign-menu.js index adc1d56..c08c277 100644 --- a/assets/javascripts/discourse/components/topic-level-assign-menu.js +++ b/assets/javascripts/discourse/components/topic-level-assign-menu.js @@ -3,6 +3,7 @@ import { htmlSafe } from "@ember/template"; import { renderAvatar } from "discourse/helpers/user-avatar"; import { iconHTML } from "discourse-common/lib/icon-library"; import I18n from "I18n"; +import EditTopicAssignments from "../components/modal/edit-topic-assignments"; const DEPENDENT_KEYS = [ "topic.assigned_to_user", @@ -22,6 +23,7 @@ export default { } const taskActions = getOwner(this).lookup("service:task-actions"); + const modal = getOwner(this).lookup("service:modal"); const firstPostId = this.topic.postStream.firstPostId; switch (id) { @@ -42,9 +44,10 @@ export default { break; } case "reassign": { - await taskActions.showAssignModal(this.topic, { - targetType: "Topic", - isAssigned: this.topic.isAssigned(), + await modal.show(EditTopicAssignments, { + model: { + topic: this.topic, + }, onSuccess: () => this.appEvents.trigger("post-stream:refresh", { id: firstPostId }), }); diff --git a/assets/javascripts/discourse/initializers/extend-for-assigns.js b/assets/javascripts/discourse/initializers/extend-for-assigns.js index dcde7df..e8c77d1 100644 --- a/assets/javascripts/discourse/initializers/extend-for-assigns.js +++ b/assets/javascripts/discourse/initializers/extend-for-assigns.js @@ -17,6 +17,7 @@ import I18n from "I18n"; import BulkAssign from "../components/bulk-actions/assign-user"; import BulkActionsAssignUser from "../components/bulk-actions/bulk-assign-user"; import TopicLevelAssignMenu from "../components/topic-level-assign-menu"; +import EditTopicAssignments from "../components/modal/edit-topic-assignments"; const PLUGIN_ID = "discourse-assign"; @@ -110,6 +111,7 @@ function registerTopicFooterButtons(api) { } const taskActions = getOwner(this).lookup("service:task-actions"); + const modal = getOwner(this).lookup("service:modal"); if (this.topic.isAssigned()) { this.set("topic.assigned_to_user", null); @@ -121,7 +123,10 @@ function registerTopicFooterButtons(api) { id: this.topic.postStream.firstPostId, }); } else { - await taskActions.showAssignModal(this.topic, { + await modal.show(EditTopicAssignments, { + model: { + topic: this.topic, + }, onSuccess: () => this.appEvents.trigger("post-stream:refresh", { id: this.topic.postStream.firstPostId,