sync
This commit is contained in:
@ -1,33 +1,48 @@
|
||||
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";
|
||||
import { fileSupported, insertFile, getMessageSendTo, getMessageStatus, updateCustomerName } from "./lib";
|
||||
|
||||
let r = lang;
|
||||
|
||||
export default class InternalComment {
|
||||
#container;
|
||||
#option;
|
||||
#enter;
|
||||
#fileControl;
|
||||
#file;
|
||||
#message;
|
||||
_var = {};
|
||||
// _var.container;
|
||||
// _var.option;
|
||||
// _var.enter;
|
||||
// _var.fileControl;
|
||||
// _var.file;
|
||||
// _var.message;
|
||||
|
||||
constructor(opt) {
|
||||
this.#option = opt ?? {};
|
||||
this._var.option = opt ?? {};
|
||||
const getText = opt?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
}
|
||||
}
|
||||
|
||||
get text() { return this.#enter?.value }
|
||||
get text() { return this._var.enter?.value }
|
||||
set text(s) {
|
||||
const element = this.#enter;
|
||||
const element = this._var.enter;
|
||||
if (element != null) {
|
||||
element.value = s
|
||||
s = String(nullOrEmpty(s) ? 0 : val.length) + '/' + String(this.#option.maxLength);
|
||||
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
s = String(nullOrEmpty(s) ? 0 : val.length) + '/' + String(this._var.option.maxLength);
|
||||
this._var.container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} contacts
|
||||
*/
|
||||
set contacts(contacts) {
|
||||
this._var.contacts = contacts;
|
||||
if (this._var.contactsUpdated !== true && contacts?.length > 0) {
|
||||
const comments = this._var.comments;
|
||||
if (comments?.length > 0) {
|
||||
updateCustomerName(this._var.comments, contacts);
|
||||
this._var.contactsUpdated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,21 +50,21 @@ export default class InternalComment {
|
||||
* @param {boolean} flag
|
||||
*/
|
||||
set loading(flag) {
|
||||
if (this.#container == null) {
|
||||
if (this._var.container == null) {
|
||||
return;
|
||||
}
|
||||
this.#enter.disabled = flag;
|
||||
this.#container.querySelector('.button-send-message').disabled = flag;
|
||||
this.#container.querySelector('.button-post-note').disabled = flag;
|
||||
this._var.enter.disabled = flag;
|
||||
this._var.container.querySelector('.button-send-message').disabled = flag;
|
||||
this._var.container.querySelector('.button-post-note').disabled = flag;
|
||||
}
|
||||
|
||||
get file() { return this.#file || this.#fileControl?.files?.[0] }
|
||||
get file() { return this._var.file || this._var.fileControl?.files?.[0] }
|
||||
set file(f) {
|
||||
this.#fileControl?.remove();
|
||||
const label = this.#container.querySelector('.file-selector>.selector-name');
|
||||
this._var.fileControl?.remove();
|
||||
const label = this._var.container.querySelector('.file-selector>.selector-name');
|
||||
if (f == null) {
|
||||
this.#fileControl = null;
|
||||
this.#file = null;
|
||||
this._var.fileControl = null;
|
||||
this._var.file = null;
|
||||
if (label != null) {
|
||||
label.style.display = 'none';
|
||||
label.innerText = '';
|
||||
@ -57,15 +72,15 @@ export default class InternalComment {
|
||||
}
|
||||
} else {
|
||||
if (f instanceof HTMLInputElement) {
|
||||
this.#fileControl = f;
|
||||
this.#file = f.files[0];
|
||||
const link = this.#container.querySelector('.file-selector>.selector-link');
|
||||
this._var.fileControl = f;
|
||||
this._var.file = f.files[0];
|
||||
const link = this._var.container.querySelector('.file-selector>.selector-link');
|
||||
if (link != null) {
|
||||
link.appendChild(f);
|
||||
}
|
||||
} else {
|
||||
this.#fileControl = null;
|
||||
this.#file = f;
|
||||
this._var.fileControl = null;
|
||||
this._var.file = f;
|
||||
}
|
||||
if (label != null) {
|
||||
label.style.display = '';
|
||||
@ -79,16 +94,17 @@ export default class InternalComment {
|
||||
* @param {boolean} flag
|
||||
*/
|
||||
set readonly(flag) {
|
||||
this.#option.readonly = flag;
|
||||
if (this.#container == null) {
|
||||
this._var.option.readonly = flag;
|
||||
if (this._var.container == null) {
|
||||
return;
|
||||
}
|
||||
this.#enter.disabled = flag === true;
|
||||
this.#container.querySelector('.button-send-message').style.display = flag === true ? 'none' : '';
|
||||
this.#container.querySelector('.button-post-note').style.display = flag === true ? 'none' : '';
|
||||
this._var.enter.disabled = flag === true;
|
||||
this._var.container.querySelector('.button-send-message').style.display = flag === true ? 'none' : '';
|
||||
this._var.container.querySelector('.button-post-note').style.display = flag === true ? 'none' : '';
|
||||
}
|
||||
|
||||
create() {
|
||||
const option = this._var.option;
|
||||
const container = createBox(
|
||||
createElement('div', null,
|
||||
createElement('div', div => {
|
||||
@ -97,96 +113,93 @@ export default class InternalComment {
|
||||
})
|
||||
), []
|
||||
);
|
||||
const readonly = this.#option.readonly;
|
||||
const readonly = option.readonly;
|
||||
// enter box
|
||||
const enter = createElement('textarea', 'ui-text');
|
||||
enter.placeholder = r('P_CU_ENTERCOMMENTHERE', 'Enter Comment Here');
|
||||
enter.maxLength = this.#option.maxLength ??= 3000;
|
||||
enter.maxLength = option.maxLength ??= 3000;
|
||||
enter.addEventListener('input', () => {
|
||||
const val = this.text;
|
||||
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/' + String(this.#option.maxLength);
|
||||
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/' + String(option.maxLength);
|
||||
this._var.container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
});
|
||||
if (readonly === true) {
|
||||
enter.disabled = true;
|
||||
}
|
||||
// enter.addEventListener('paste', e => {
|
||||
// const file = e.clipboardData.files[0];
|
||||
// if (file != null) {
|
||||
// e.preventDefault();
|
||||
// this.file = insertFile(container, file, r);
|
||||
// }
|
||||
// });
|
||||
this.#enter = enter;
|
||||
enter.addEventListener('paste', e => {
|
||||
const file = e.clipboardData.files[0];
|
||||
if (file != null) {
|
||||
e.preventDefault();
|
||||
this.file = insertFile(container, file, r);
|
||||
}
|
||||
});
|
||||
this._var.enter = enter;
|
||||
container.appendChild(
|
||||
createElement('div', div => {
|
||||
div.className = 'message-bar';
|
||||
// div.addEventListener('dragover', e => {
|
||||
// if (option.readonly !== true) {
|
||||
// const item = e.dataTransfer.items[0];
|
||||
// if (item?.kind === 'file') {
|
||||
// e.preventDefault();
|
||||
// if (item.type.length > 0 && fileSupported.indexOf(item.type) < 0) {
|
||||
// e.dataTransfer.dropEffect = 'none';
|
||||
// } else {
|
||||
// e.dataTransfer.dropEffect = 'link';
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// div.addEventListener('drop', e => {
|
||||
// if (option.readonly !== true) {
|
||||
// const file = e.dataTransfer.files[0];
|
||||
// if (file != null) {
|
||||
// e.preventDefault();
|
||||
// this.file = insertFile(container, file, r);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
div.addEventListener('dragover', e => {
|
||||
if (option.readonly !== true) {
|
||||
const item = e.dataTransfer.items[0];
|
||||
if (item?.kind === 'file') {
|
||||
e.preventDefault();
|
||||
if (item.type.length > 0 && fileSupported.indexOf(item.type) < 0) {
|
||||
e.dataTransfer.dropEffect = 'none';
|
||||
} else {
|
||||
e.dataTransfer.dropEffect = 'link';
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
div.addEventListener('drop', e => {
|
||||
if (option.readonly !== true) {
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file != null) {
|
||||
e.preventDefault();
|
||||
this.file = insertFile(container, file, r);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
enter,
|
||||
createElement('div', div => div.style.textAlign = 'right',
|
||||
createElement('div', selector => {
|
||||
selector.className = 'file-selector';
|
||||
if (this.#option.noMessage === true) {
|
||||
selector.style.display = 'none';
|
||||
}
|
||||
},
|
||||
createElement('div', div => {
|
||||
div.className = 'selector-link';
|
||||
div.style.display = 'none';
|
||||
// div.addEventListener('click', () => {
|
||||
// this.#fileControl?.remove();
|
||||
// const file = createElement('input', input => {
|
||||
// input.type = 'file';
|
||||
// input.accept = fileSupported.join(',');
|
||||
// input.addEventListener('change', () => {
|
||||
// const file = insertFile(container, input.files?.[0], r);
|
||||
// if (file != null) {
|
||||
// this.file = file;
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// div.appendChild(this.#fileControl = file);
|
||||
// file.dispatchEvent(new MouseEvent('click'));
|
||||
// });
|
||||
},
|
||||
createIcon('fa-regular', 'link')
|
||||
),
|
||||
createElement('span', span => {
|
||||
span.className = 'selector-name';
|
||||
span.style.display = 'none';
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.appendChild(createIcon('fa-regular', 'times'));
|
||||
layer.addEventListener('click', () => this.file = null);
|
||||
})
|
||||
createElement('div', 'customer-left',
|
||||
createElement('div', 'file-selector',
|
||||
createElement('div', div => {
|
||||
div.className = 'selector-link';
|
||||
// div.style.display = 'none';
|
||||
div.addEventListener('click', () => {
|
||||
this._var.fileControl?.remove();
|
||||
const file = createElement('input', input => {
|
||||
input.type = 'file';
|
||||
input.accept = fileSupported.join(',');
|
||||
input.addEventListener('change', () => {
|
||||
const file = insertFile(container, input.files?.[0], r);
|
||||
if (file != null) {
|
||||
this.file = file;
|
||||
}
|
||||
});
|
||||
});
|
||||
div.appendChild(this._var.fileControl = file);
|
||||
file.dispatchEvent(new MouseEvent('click'));
|
||||
});
|
||||
},
|
||||
createIcon('fa-regular', 'link')
|
||||
),
|
||||
createElement('span', span => {
|
||||
span.className = 'selector-name';
|
||||
span.style.display = 'none';
|
||||
}),
|
||||
createElement('layer', layer => {
|
||||
layer.appendChild(createIcon('fa-regular', 'times'));
|
||||
layer.addEventListener('click', () => this.file = null);
|
||||
})
|
||||
)
|
||||
),
|
||||
createElement('div', 'prompt-count'),
|
||||
createElement('button', button => {
|
||||
button.className = 'roundbtn button-send-message';
|
||||
button.style.backgroundColor = 'rgb(19, 150, 204)';
|
||||
if (readonly === true || this.#option.noMessage === true) {
|
||||
if (readonly === true || option.noMessage === true) {
|
||||
button.style.display = 'none';
|
||||
}
|
||||
button.appendChild(createIcon('fa-solid', 'paper-plane'));
|
||||
@ -196,9 +209,9 @@ export default class InternalComment {
|
||||
if (nullOrEmpty(val?.trim())) {
|
||||
return;
|
||||
}
|
||||
if (typeof this.#option.onAddMessage === 'function') {
|
||||
if (typeof option.onAddMessage === 'function') {
|
||||
this.loading = true;
|
||||
this.#option.onAddMessage(this.text);
|
||||
option.onAddMessage(this.text);
|
||||
}
|
||||
})
|
||||
}),
|
||||
@ -216,9 +229,9 @@ export default class InternalComment {
|
||||
if (nullOrEmpty(val?.trim())) {
|
||||
return;
|
||||
}
|
||||
if (typeof this.#option.onAddComment === 'function') {
|
||||
if (typeof option.onAddComment === 'function') {
|
||||
this.loading = true;
|
||||
this.#option.onAddComment(this.text, this.file);
|
||||
option.onAddComment(this.text, this.file);
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -227,54 +240,77 @@ export default class InternalComment {
|
||||
);
|
||||
|
||||
const message = createElement('div', 'list-bar');
|
||||
this.#message = message;
|
||||
this._var.message = message;
|
||||
container.appendChild(message);
|
||||
return this.#container = container;
|
||||
return this._var.container = container;
|
||||
}
|
||||
|
||||
load(data) {
|
||||
const children = [];
|
||||
if (data?.length > 0) {
|
||||
this._var.comments = data;
|
||||
if (this._var.contactsUpdated !== true) {
|
||||
const contacts = this._var.contacts;
|
||||
if (contacts?.length > 0) {
|
||||
updateCustomerName(data, contacts);
|
||||
this._var.contactsUpdated = true;
|
||||
}
|
||||
}
|
||||
for (let comment of data) {
|
||||
const div = createElement('div', 'item-div');
|
||||
// if (sendto !== '') {
|
||||
// sendto = r('P_CU_SENDTO_COLON', 'Send To :') + `\n${sendto}`;
|
||||
// }
|
||||
const sendto = getMessageSendTo(comment, null, null, r)
|
||||
div.appendChild(createElement('div', div => {
|
||||
div.className = 'item-poster';
|
||||
div.innerText = comment.UserName;
|
||||
div.innerText = comment.Sender;
|
||||
if (sendto?.length > 0) {
|
||||
setTooltip(div, sendto);
|
||||
}
|
||||
}));
|
||||
const content = createElement('div', 'item-content');
|
||||
const mmsParts = createElement('div', div => div.style.display = 'none');
|
||||
content.appendChild(createElement('span', span => span.innerHTML = escapeEmoji(escapeHtml(comment.Comment)), mmsParts));
|
||||
if (comment.IsMMS && comment.MMSParts?.length > 0) {
|
||||
content.appendChild(createElement('span', span => span.innerHTML = escapeHtml(escapeEmoji(comment.Message)), mmsParts));
|
||||
if (comment.MMSParts?.length > 0) {
|
||||
mmsParts.style.display = '';
|
||||
for (let kv of comment.MMSParts) {
|
||||
appendMedia(mmsParts, kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
if (comment.FollowUp?.length > 0) {
|
||||
div.classList.add('item-sent');
|
||||
const sendto = r('P_CU_SENDTO_COLON', 'Send To :') + '\r\n' + comment.FollowUp.split(';').join('\r\n');
|
||||
content.appendChild(createElement('div', div => {
|
||||
// if (comment.FollowUp?.length > 0) {
|
||||
// div.classList.add('item-sent');
|
||||
// const sendto = r('P_CU_SENDTO_COLON', 'Sent To :') + '\r\n' + comment.FollowUp.split(';').join('\r\n');
|
||||
// content.appendChild(createElement('div', div => {
|
||||
// div.className = 'item-status';
|
||||
// div.innerText = r('P_WO_SENT', 'Sent');
|
||||
// setTooltip(div, sendto);
|
||||
// }));
|
||||
// }
|
||||
const [status, text, color, tips] = getMessageStatus(comment, r, this._var);
|
||||
if (status !== -100) {
|
||||
if (color != null) {
|
||||
content.style.backgroundColor = color;
|
||||
}
|
||||
const divstatus = createElement('div', div => {
|
||||
div.className = 'item-status';
|
||||
div.innerText = r('P_WO_SENT', 'Sent');
|
||||
setTooltip(div, sendto);
|
||||
}));
|
||||
div.innerText = text;
|
||||
if (tips != null) {
|
||||
setTooltip(div, tips);
|
||||
}
|
||||
});
|
||||
content.appendChild(divstatus);
|
||||
}
|
||||
div.append(
|
||||
content,
|
||||
createElement('div', div => {
|
||||
div.className = 'item-time';
|
||||
div.innerText = comment.SubmitDateStr;
|
||||
div.innerText = comment.TimeStr;
|
||||
})
|
||||
);
|
||||
children.push(div);
|
||||
}
|
||||
children[0].style.marginTop = '0';
|
||||
}
|
||||
this.#message.replaceChildren(...children);
|
||||
this.#message.scrollTop = this.#message.scrollHeight
|
||||
// setTimeout(() => this.#message.scrollTop = this.#message.scrollHeight, 0);
|
||||
this._var.message.replaceChildren(...children);
|
||||
this._var.message.scrollTop = this._var.message.scrollHeight
|
||||
// setTimeout(() => this._var.message.scrollTop = this._var.message.scrollHeight, 0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user