Update npm dependencies
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / js / WoltLabSuite / Core / Conversation / Ui / Subject / Editor.js
1 define(["require", "exports", "tslib", "WoltLabSuite/Core/Ui/Dialog", "WoltLabSuite/Core/Dom/Util", "WoltLabSuite/Core/Ajax", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Ui/Notification"], function (require, exports, tslib_1, Dialog_1, Util_1, Ajax, Language, UiNotification) {
2 "use strict";
3 Object.defineProperty(exports, "__esModule", { value: true });
4 exports.beginEdit = void 0;
5 Dialog_1 = tslib_1.__importDefault(Dialog_1);
6 Util_1 = tslib_1.__importDefault(Util_1);
7 Ajax = tslib_1.__importStar(Ajax);
8 Language = tslib_1.__importStar(Language);
9 UiNotification = tslib_1.__importStar(UiNotification);
10 class UiSubjectEditor {
11 constructor(objectId) {
12 this.objectId = objectId;
13 }
14 /**
15 * Shows the subject editor dialog.
16 */
17 show() {
18 Dialog_1.default.open(this);
19 }
20 /**
21 * Validates and saves the new subject.
22 */
23 saveEdit(event) {
24 event.preventDefault();
25 const value = this.subject.value.trim();
26 if (value === "") {
27 Util_1.default.innerError(this.subject, Language.get("wcf.global.form.error.empty"));
28 }
29 else {
30 Util_1.default.innerError(this.subject, "");
31 Ajax.api(this, {
32 parameters: {
33 subject: value,
34 },
35 objectIDs: [this.objectId],
36 });
37 }
38 }
39 /**
40 * Returns the current conversation subject.
41 */
42 getCurrentValue() {
43 return Array.from(document.querySelectorAll(`.jsConversationSubject[data-conversation-id="${this.objectId}"], .conversationLink[data-object-id="${this.objectId}"]`))
44 .map((subject) => subject.textContent)
45 .slice(-1)[0];
46 }
47 _ajaxSuccess(data) {
48 Dialog_1.default.close(this);
49 document
50 .querySelectorAll(`.jsConversationSubject[data-conversation-id="${this.objectId}"], .conversationLink[data-object-id="${this.objectId}"]`)
51 .forEach((subject) => {
52 subject.textContent = data.returnValues.subject;
53 });
54 UiNotification.show();
55 }
56 _dialogSetup() {
57 return {
58 id: "dialogConversationSubjectEditor",
59 options: {
60 onSetup: (content) => {
61 this.subject = document.getElementById("jsConversationSubject");
62 this.subject.addEventListener("keyup", (ev) => {
63 if (ev.key === "Enter") {
64 this.saveEdit(ev);
65 }
66 });
67 content.querySelector(".jsButtonSave").addEventListener("click", (ev) => this.saveEdit(ev));
68 },
69 onShow: () => {
70 this.subject.value = this.getCurrentValue();
71 },
72 title: Language.get("wcf.conversation.edit.subject"),
73 },
74 source: `
75 <dl>
76 <dt>
77 <label for="jsConversationSubject">${Language.get("wcf.global.subject")}</label>
78 </dt>
79 <dd>
80 <input type="text" id="jsConversationSubject" class="long" maxlength="255">
81 </dd>
82 </dl>
83 <div class="formSubmit">
84 <button class="buttonPrimary jsButtonSave">${Language.get("wcf.global.button.save")}</button>
85 </div>
86 `,
87 };
88 }
89 _ajaxSetup() {
90 return {
91 data: {
92 actionName: "editSubject",
93 className: "wcf\\data\\conversation\\ConversationAction",
94 },
95 };
96 }
97 }
98 let editor;
99 function beginEdit(objectId) {
100 editor = new UiSubjectEditor(objectId);
101 editor.show();
102 }
103 exports.beginEdit = beginEdit;
104 });