mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
DEV: Convert delete-posts-confirmation
modal to component-based API (#22700)
This commit is contained in:
@ -0,0 +1,36 @@
|
|||||||
|
<DModal
|
||||||
|
@title={{html-safe
|
||||||
|
(i18n
|
||||||
|
"admin.user.delete_posts.confirmation.title" username=@model.user.username
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
@closeModal={{@closeModal}}
|
||||||
|
>
|
||||||
|
<:body>
|
||||||
|
<p>{{html-safe
|
||||||
|
(i18n
|
||||||
|
"admin.user.delete_posts.confirmation.description"
|
||||||
|
username=@model.user.username
|
||||||
|
post_count=@model.user.post_count
|
||||||
|
text=this.text
|
||||||
|
)
|
||||||
|
}}</p>
|
||||||
|
<Input @type="text" @value={{this.value}} />
|
||||||
|
</:body>
|
||||||
|
<:footer>
|
||||||
|
<DButton
|
||||||
|
class="btn-danger"
|
||||||
|
@action={{@model.deleteAllPosts}}
|
||||||
|
@icon="trash-alt"
|
||||||
|
@disabled={{this.deleteDisabled}}
|
||||||
|
@translatedLabel={{i18n
|
||||||
|
"admin.user.delete_posts.confirmation.delete"
|
||||||
|
username=@model.user.username
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<DButton
|
||||||
|
@action={{@closeModal}}
|
||||||
|
@label="admin.user.delete_posts.confirmation.cancel"
|
||||||
|
/>
|
||||||
|
</:footer>
|
||||||
|
</DModal>
|
@ -0,0 +1,18 @@
|
|||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { tracked } from "@glimmer/tracking";
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
|
export default class DeletePostsConfirmation extends Component {
|
||||||
|
@tracked value;
|
||||||
|
|
||||||
|
get text() {
|
||||||
|
return I18n.t("admin.user.delete_posts.confirmation.text", {
|
||||||
|
username: this.args.model.user.username,
|
||||||
|
post_count: this.args.model.user.post_count,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get deleteDisabled() {
|
||||||
|
return !this.value || this.text !== this.value;
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ import getURL from "discourse-common/lib/get-url";
|
|||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { extractError, popupAjaxError } from "discourse/lib/ajax-error";
|
import { extractError, popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
import DeletePostsConfirmationModal from "../components/modal/delete-posts-confirmation";
|
||||||
|
|
||||||
export default class AdminUserIndexController extends Controller.extend(
|
export default class AdminUserIndexController extends Controller.extend(
|
||||||
CanCheckEmails
|
CanCheckEmails
|
||||||
@ -20,6 +21,7 @@ export default class AdminUserIndexController extends Controller.extend(
|
|||||||
@service router;
|
@service router;
|
||||||
@service dialog;
|
@service dialog;
|
||||||
@service adminTools;
|
@service adminTools;
|
||||||
|
@service modal;
|
||||||
|
|
||||||
originalPrimaryGroupId = null;
|
originalPrimaryGroupId = null;
|
||||||
customGroupIdsBuffer = null;
|
customGroupIdsBuffer = null;
|
||||||
@ -619,9 +621,8 @@ export default class AdminUserIndexController extends Controller.extend(
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
showDeletePostsConfirmation() {
|
showDeletePostsConfirmation() {
|
||||||
showModal("admin-delete-posts-confirmation", {
|
this.modal.show(DeletePostsConfirmationModal, {
|
||||||
admin: true,
|
model: { user: this.model, deleteAllPosts: this.deleteAllPosts },
|
||||||
model: this.model,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
import { alias } from "@ember/object/computed";
|
|
||||||
import Controller, { inject as controller } from "@ember/controller";
|
|
||||||
import I18n from "I18n";
|
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
||||||
import { action } from "@ember/object";
|
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
|
||||||
|
|
||||||
export default class AdminDeletePostsConfirmationController extends Controller.extend(
|
|
||||||
ModalFunctionality
|
|
||||||
) {
|
|
||||||
@controller adminUserIndex;
|
|
||||||
|
|
||||||
@alias("model.username") username;
|
|
||||||
@alias("model.post_count") postCount;
|
|
||||||
|
|
||||||
onShow() {
|
|
||||||
this.set("value", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@discourseComputed("username", "postCount")
|
|
||||||
text(username, postCount) {
|
|
||||||
return I18n.t(`admin.user.delete_posts.confirmation.text`, {
|
|
||||||
username,
|
|
||||||
postCount,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@discourseComputed("username")
|
|
||||||
deleteButtonText(username) {
|
|
||||||
return I18n.t(`admin.user.delete_posts.confirmation.delete`, {
|
|
||||||
username,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@discourseComputed("value", "text")
|
|
||||||
deleteDisabled(value, text) {
|
|
||||||
return !value || text !== value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
confirm() {
|
|
||||||
this.adminUserIndex.send("deleteAllPosts");
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
close() {
|
|
||||||
this.send("closeModal");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
<div>
|
|
||||||
<DModalBody
|
|
||||||
@rawTitle={{i18n
|
|
||||||
"admin.user.delete_posts.confirmation.title"
|
|
||||||
username=this.username
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<p>{{html-safe
|
|
||||||
(i18n
|
|
||||||
"admin.user.delete_posts.confirmation.description"
|
|
||||||
username=this.username
|
|
||||||
post_count=this.postCount
|
|
||||||
text=this.text
|
|
||||||
)
|
|
||||||
}}</p>
|
|
||||||
<Input @type="text" @value={{this.value}} />
|
|
||||||
</DModalBody>
|
|
||||||
|
|
||||||
<div class="modal-footer">
|
|
||||||
<DButton
|
|
||||||
@class="btn-danger"
|
|
||||||
@action={{action "confirm"}}
|
|
||||||
@icon="trash-alt"
|
|
||||||
@disabled={{this.deleteDisabled}}
|
|
||||||
@translatedLabel={{this.deleteButtonText}}
|
|
||||||
/>
|
|
||||||
<DButton
|
|
||||||
@action={{action "close"}}
|
|
||||||
@label="admin.user.delete_posts.confirmation.cancel"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -55,7 +55,6 @@ const KNOWN_LEGACY_MODALS = [
|
|||||||
"topic-summary",
|
"topic-summary",
|
||||||
"user-status",
|
"user-status",
|
||||||
"admin-add-upload",
|
"admin-add-upload",
|
||||||
"admin-delete-posts-confirmation",
|
|
||||||
"admin-merge-users-prompt",
|
"admin-merge-users-prompt",
|
||||||
"admin-start-backup",
|
"admin-start-backup",
|
||||||
"admin-watched-word-test",
|
"admin-watched-word-test",
|
||||||
|
Reference in New Issue
Block a user