sync
This commit is contained in:
@ -5,26 +5,23 @@ import { createBox, appendMedia } from "./lib";
|
||||
let r = lang;
|
||||
|
||||
export default class CustomerRecordComment {
|
||||
#container;
|
||||
#option;
|
||||
#enter;
|
||||
#message;
|
||||
_var = {};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,28 +29,28 @@ export default class CustomerRecordComment {
|
||||
* @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._var.enter.disabled = flag;
|
||||
this._var.container.querySelector('.button-send-message').disabled = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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('.message-bar .prompt-count').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('.message-bar .prompt-count').style.display = flag === true ? 'none' : '';
|
||||
}
|
||||
|
||||
create() {
|
||||
const readonly = this.#option.readonly;
|
||||
const readonly = this._var.option.readonly;
|
||||
const container = createBox(
|
||||
createElement('div', null,
|
||||
createElement('div', div => {
|
||||
@ -65,7 +62,7 @@ export default class CustomerRecordComment {
|
||||
createElement('button', button => {
|
||||
button.className = 'roundbtn button-close';
|
||||
button.style.backgroundColor = 'transparent';
|
||||
if (this.#option.hasClose !== true) {
|
||||
if (this._var.option.hasClose !== true) {
|
||||
button.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
@ -73,8 +70,8 @@ export default class CustomerRecordComment {
|
||||
fill: '#000'
|
||||
}));
|
||||
button.addEventListener('click', () => {
|
||||
if (typeof this.#option.onClose === 'function') {
|
||||
this.#option.onClose();
|
||||
if (typeof this._var.option.onClose === 'function') {
|
||||
this._var.option.onClose();
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -83,16 +80,16 @@ export default class CustomerRecordComment {
|
||||
// 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 = this._var.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(this._var.option.maxLength);
|
||||
this._var.container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
});
|
||||
if (readonly === true) {
|
||||
enter.disabled = true;
|
||||
}
|
||||
this.#enter = enter;
|
||||
this._var.enter = enter;
|
||||
container.appendChild(
|
||||
createElement('div', 'message-bar',
|
||||
enter,
|
||||
@ -108,8 +105,8 @@ export default class CustomerRecordComment {
|
||||
// setTooltip(button, r('P_M3_SENDMESSAGE', 'Send Message'));
|
||||
setTooltip(button, r('P_CU_POSTNOTE', 'Post Note'));
|
||||
button.addEventListener('click', () => {
|
||||
if (typeof this.#option.onAddComment === 'function') {
|
||||
this.#option.onAddComment(this.text);
|
||||
if (typeof this._var.option.onAddComment === 'function') {
|
||||
this._var.option.onAddComment(this.text);
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -118,9 +115,9 @@ export default class CustomerRecordComment {
|
||||
);
|
||||
|
||||
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) {
|
||||
@ -129,7 +126,7 @@ export default class CustomerRecordComment {
|
||||
for (let comment of data) {
|
||||
const div = createElement('div', 'item-div');
|
||||
// if (sendto !== '') {
|
||||
// sendto = r('P_CU_SENDTO_COLON', 'Send To :') + `\n${sendto}`;
|
||||
// sendto = r('P_CU_SENDTO_COLON', 'Sent To :') + `\n${sendto}`;
|
||||
// }
|
||||
div.appendChild(createElement('div', div => {
|
||||
div.className = 'item-poster';
|
||||
@ -137,8 +134,8 @@ export default class CustomerRecordComment {
|
||||
}));
|
||||
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.Comment)), mmsParts));
|
||||
if (comment.MMSParts?.length > 0) {
|
||||
mmsParts.style.display = '';
|
||||
for (let kv of comment.MMSParts) {
|
||||
appendMedia(mmsParts, kv.Key, kv.Value);
|
||||
@ -155,8 +152,8 @@ export default class CustomerRecordComment {
|
||||
}
|
||||
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