This commit is contained in:
2023-08-28 15:04:23 +08:00
parent 29209a3a00
commit 84190ed9f1
14 changed files with 1004 additions and 527 deletions

View File

@ -1,8 +1,11 @@
import { createElement, setTooltip, createIcon, showAlert } from "../../ui";
import { r, nullOrEmpty, escapeHtml } from "../../utility";
import { createBox, appendMedia, fileSupported, insertFile } from "./lib";
import { createElement, setTooltip, createIcon } from "../../ui";
import { r as lang, nullOrEmpty, escapeHtml, escapeEmoji } from "../../utility";
import { createBox, appendMedia } from "./lib";
// import { fileSupported, insertFile } from "./lib";
class InternalComment {
let r = lang;
export default class InternalComment {
#container;
#option;
#enter;
@ -12,6 +15,10 @@ class InternalComment {
constructor(opt) {
this.#option = opt ?? {};
const getText = opt?.getText;
if (typeof getText === 'function') {
r = getText;
}
}
get text() { return this.#enter?.value }
@ -86,14 +93,14 @@ class InternalComment {
createElement('div', null,
createElement('div', div => {
div.className = 'title-module';
div.innerText = r('internalComments', 'Internal Comments');
div.innerText = r('P_WO_INTERNALCOMMENTS', 'Internal Comments');
})
), []
);
const readonly = this.#option.readonly;
// enter box
const enter = createElement('textarea', 'ui-text');
enter.placeholder = r('typeComment', 'Enter Comment Here');
enter.placeholder = r('P_CU_ENTERCOMMENTHERE', 'Enter Comment Here');
enter.maxLength = this.#option.maxLength ??= 3000;
enter.addEventListener('input', () => {
const val = this.text;
@ -107,7 +114,7 @@ class InternalComment {
// const file = e.clipboardData.files[0];
// if (file != null) {
// e.preventDefault();
// this.file = insertFile(container, file);
// this.file = insertFile(container, file, r);
// }
// });
this.#enter = enter;
@ -132,7 +139,7 @@ class InternalComment {
// const file = e.dataTransfer.files[0];
// if (file != null) {
// e.preventDefault();
// this.file = insertFile(container, file);
// this.file = insertFile(container, file, r);
// }
// }
// });
@ -154,7 +161,7 @@ class InternalComment {
// input.type = 'file';
// input.accept = fileSupported.join(',');
// input.addEventListener('change', () => {
// const file = insertFile(container, input.files?.[0]);
// const file = insertFile(container, input.files?.[0], r);
// if (file != null) {
// this.file = file;
// }
@ -183,9 +190,14 @@ class InternalComment {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'paper-plane'));
setTooltip(button, r('sendMessage', 'Send Message'));
setTooltip(button, r('P_M3_SENDMESSAGE', 'Send Message'));
button.addEventListener('click', () => {
const val = this.text;
if (nullOrEmpty(val?.trim())) {
return;
}
if (typeof this.#option.onAddMessage === 'function') {
this.loading = true;
this.#option.onAddMessage(this.text);
}
})
@ -198,9 +210,14 @@ class InternalComment {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'comment-alt-lines'));
setTooltip(button, r('postNote', 'Post Note'));
setTooltip(button, r('P_CU_POSTNOTE', 'Post Note'));
button.addEventListener('click', () => {
const val = this.text;
if (nullOrEmpty(val?.trim())) {
return;
}
if (typeof this.#option.onAddComment === 'function') {
this.loading = true;
this.#option.onAddComment(this.text, this.file);
}
})
@ -221,16 +238,15 @@ class InternalComment {
for (let comment of data) {
const div = createElement('div', 'item-div');
// if (sendto !== '') {
// sendto = r('sendToColon', 'Send To :') + `\n${sendto}`;
// sendto = r('P_CU_SENDTO_COLON', 'Send To :') + `\n${sendto}`;
// }
div.appendChild(createElement('div', div => {
div.className = 'item-poster';
div.innerText = comment.UserName;
}));
const content = createElement('div', 'item-content');
const emoji = s => s.replace(/(=[A-Fa-f0-9]{2}){4}/, s => decodeURIComponent(s.replaceAll('=', '%')));
const mmsParts = createElement('div', div => div.style.display = 'none');
content.appendChild(createElement('span', span => span.innerHTML = emoji(escapeHtml(comment.Comment)), mmsParts));
content.appendChild(createElement('span', span => span.innerHTML = escapeEmoji(escapeHtml(comment.Comment)), mmsParts));
if (comment.IsMMS && comment.MMSParts?.length > 0) {
mmsParts.style.display = '';
for (let kv of comment.MMSParts) {
@ -239,10 +255,10 @@ class InternalComment {
}
if (comment.FollowUp?.length > 0) {
div.classList.add('item-sent');
const sendto = r('sendToColon', 'Send To :') + '\r\n' + comment.FollowUp.split(';').join('\r\n');
const sendto = r('P_CU_SENDTO_COLON', 'Send To :') + '\r\n' + comment.FollowUp.split(';').join('\r\n');
content.appendChild(createElement('div', div => {
div.className = 'item-status';
div.innerText = r('sent', 'Sent');
div.innerText = r('P_WO_SENT', 'Sent');
setTooltip(div, sendto);
}));
}
@ -261,6 +277,4 @@ class InternalComment {
this.#message.scrollTop = this.#message.scrollHeight
// setTimeout(() => this.#message.scrollTop = this.#message.scrollHeight, 0);
}
}
export default InternalComment;
}