sync
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Grid, GridColumn, createElement, setTooltip, createIcon, createCheckbox, createRadiobox, showAlert, showConfirm, Popup } from "../../ui";
|
||||
import { r as lang, nullOrEmpty, formatUrl, escapeEmoji, isEmail, isPhone } from "../../utility";
|
||||
import { createBox, appendMedia, fileSupported, insertFile } from "./lib";
|
||||
import { createBox, appendMedia, fileSupported, insertFile, getMessageSendTo, getMessageStatus, updateCustomerName } from "./lib";
|
||||
import { Contact, CustomerRecordContact } from "./contact";
|
||||
import Follower from "./follower";
|
||||
|
||||
@ -31,31 +31,22 @@ class NoteCol extends GridColumn {
|
||||
let r = lang;
|
||||
|
||||
export default class CustomerCommunication {
|
||||
#container;
|
||||
#option;
|
||||
#contacts;
|
||||
#followers;
|
||||
#buttonFollower;
|
||||
#enter;
|
||||
#fileControl;
|
||||
#file;
|
||||
#message;
|
||||
#data = {};
|
||||
#gridContact;
|
||||
#gridWo;
|
||||
_var = {
|
||||
data: {}
|
||||
};
|
||||
|
||||
constructor(opt) {
|
||||
this.#option = opt ?? {};
|
||||
this._var.option = opt ?? {};
|
||||
const getText = opt?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
}
|
||||
}
|
||||
|
||||
get #autoUpdates() { return this.#container.querySelector('.check-auto-update>input') }
|
||||
get autoUpdatesEnabled() { return this.#autoUpdates?.disabled !== true }
|
||||
get _autoUpdates() { return this._var.container.querySelector('.check-auto-update>input') }
|
||||
get autoUpdatesEnabled() { return this._autoUpdates?.disabled !== true }
|
||||
set autoUpdatesEnabled(flag) {
|
||||
const element = this.#autoUpdates;
|
||||
const element = this._autoUpdates;
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
@ -67,9 +58,9 @@ export default class CustomerCommunication {
|
||||
element.parentElement?.classList?.remove('disabled');
|
||||
}
|
||||
}
|
||||
get autoUpdates() { return this.#autoUpdates?.checked }
|
||||
get autoUpdates() { return this._autoUpdates?.checked }
|
||||
set autoUpdates(flag) {
|
||||
const element = this.#autoUpdates;
|
||||
const element = this._autoUpdates;
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
@ -77,10 +68,10 @@ export default class CustomerCommunication {
|
||||
element.dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
get #statusLink() { return this.#container.querySelector('.check-status-link>input') }
|
||||
get statusLinkEnabled() { return this.#statusLink?.disabled !== true }
|
||||
get _statusLink() { return this._var.container.querySelector('.check-status-link>input') }
|
||||
get statusLinkEnabled() { return this._statusLink?.disabled !== true }
|
||||
set statusLinkEnabled(flag) {
|
||||
const element = this.#statusLink;
|
||||
const element = this._statusLink;
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
@ -92,9 +83,9 @@ export default class CustomerCommunication {
|
||||
element.parentElement?.classList?.remove('disabled');
|
||||
}
|
||||
}
|
||||
get statusLink() { return this.#statusLink?.checked }
|
||||
get statusLink() { return this._statusLink?.checked }
|
||||
set statusLink(flag) {
|
||||
const element = this.#statusLink;
|
||||
const element = this._statusLink;
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
@ -106,33 +97,33 @@ export default class CustomerCommunication {
|
||||
* @param {boolean} flag
|
||||
*/
|
||||
set loading(flag) {
|
||||
if (this.#container == null) {
|
||||
if (this._var.container == null) {
|
||||
return;
|
||||
}
|
||||
this.#enter.disabled = flag;
|
||||
this.#container.querySelector('.customer-name>.ui-input').disabled = flag;
|
||||
this.#container.querySelector('.button-send-message').disabled = flag;
|
||||
this.#container.querySelector('.button-edit-contacts').disabled = flag;
|
||||
this.#container.querySelector('.button-edit-followers').disabled = flag;
|
||||
this._var.enter.disabled = flag;
|
||||
this._var.container.querySelector('.customer-name>.ui-input').disabled = flag;
|
||||
this._var.container.querySelector('.button-send-message').disabled = flag;
|
||||
this._var.container.querySelector('.button-edit-contacts').disabled = flag;
|
||||
this._var.container.querySelector('.button-edit-followers').disabled = flag;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 = '';
|
||||
@ -140,15 +131,15 @@ export default class CustomerCommunication {
|
||||
}
|
||||
} 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 = '';
|
||||
@ -158,9 +149,9 @@ export default class CustomerCommunication {
|
||||
}
|
||||
}
|
||||
|
||||
get customerName() { return this.#container.querySelector('.customer-name>.ui-input')?.value }
|
||||
get customerName() { return this._var.container.querySelector('.customer-name>.ui-input')?.value }
|
||||
set customerName(name) {
|
||||
const element = this.#container.querySelector('.customer-name>.ui-input');
|
||||
const element = this._var.container.querySelector('.customer-name>.ui-input');
|
||||
if (element == null) {
|
||||
return;
|
||||
}
|
||||
@ -168,7 +159,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
|
||||
get contacts() {
|
||||
return [...this.#contacts.children].filter(el => {
|
||||
return [...this._var.contacts.children].filter(el => {
|
||||
return el.querySelector('span').dataset.notsend == "false";
|
||||
}).map(el => {
|
||||
const span = el.querySelector('span');
|
||||
@ -176,11 +167,20 @@ export default class CustomerCommunication {
|
||||
});
|
||||
}
|
||||
set contacts(contacts) {
|
||||
this.#contacts.replaceChildren();
|
||||
this.setData('contacts', contacts);
|
||||
this._var.contacts.replaceChildren();
|
||||
if (contacts?.length > 0) {
|
||||
var cs = contacts.sort(function (a, b) {
|
||||
if (a.Name == b.Name) return 0; return a.Name > b.Name ? 1 : -1;
|
||||
if (a.Name == b.Name) {
|
||||
return 0;
|
||||
}
|
||||
return a.Name > b.Name ? 1 : -1;
|
||||
});
|
||||
const messages = this._var.data.messages;
|
||||
if (this._var.contactsUpdated !== true && messages?.length > 0) {
|
||||
updateCustomerName(messages, contacts);
|
||||
this._var.contactsUpdated = true;
|
||||
}
|
||||
for (let c of cs) {
|
||||
//if (c.OptOut || c.OptOut_BC || c.selected === false) {
|
||||
// continue;
|
||||
@ -195,19 +195,28 @@ export default class CustomerCommunication {
|
||||
const to = pref === '1' ? email : mp;
|
||||
let icon;
|
||||
let method;
|
||||
let tipstr;
|
||||
if (c.OptOut || c.OptOut_BC || c.selected === false) {
|
||||
icon = 'times';
|
||||
method = r('P_CU_OPTEDOUT_COLON', 'Opted Out:');
|
||||
tipstr = r('P_CU_OPTEDOUT_PROMPT', 'User has opted out of messages');
|
||||
}
|
||||
else {
|
||||
switch (pref) {
|
||||
case '0':
|
||||
icon = 'comment-lines';
|
||||
if (c.MobilePhoneStatus !== 0) {
|
||||
icon = 'times';
|
||||
if (c.MobilePhoneStatus === 412) {
|
||||
// landline
|
||||
tipstr = r('P_CU_LANDLINE', 'Landline');
|
||||
}
|
||||
} else {
|
||||
icon = 'comment-lines';
|
||||
}
|
||||
method = r('P_CU_TEXTSTO_COLON', 'Texts to:');
|
||||
break;
|
||||
case '2':
|
||||
icon = 'mobile';
|
||||
method = r('P_CU_CALLSTO_COLON', 'Calls to:');
|
||||
icon = 'phone';
|
||||
tipstr = r('P_CU_NOMESSAGE', 'No Messages Sent');
|
||||
break;
|
||||
default:
|
||||
icon = 'envelope';
|
||||
@ -225,14 +234,14 @@ export default class CustomerCommunication {
|
||||
createIcon('fa-light', icon, { 'fill': (c.OptOut || c.OptOut_BC || c.selected === false) ? 'red' : '' }),
|
||||
span
|
||||
);
|
||||
this.#contacts.appendChild(item);
|
||||
let tip = `${method} ${to}`;
|
||||
this._var.contacts.appendChild(item);
|
||||
let tip = tipstr || `${method} ${to}`;
|
||||
if (span.scrollWidth > span.offsetWidth) {
|
||||
tip = r('P_WO_NAME_COLON', 'Name:') + ` ${c.Name}\n${tip}`;
|
||||
}
|
||||
setTooltip(span, tip);
|
||||
}
|
||||
this.#message.scrollTop = this.#message.scrollHeight
|
||||
this._var.message.scrollTop = this._var.message.scrollHeight
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,11 +249,11 @@ export default class CustomerCommunication {
|
||||
* @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;
|
||||
}
|
||||
const link = this.#container.querySelector('.check-status-link');
|
||||
const link = this._var.container.querySelector('.check-status-link');
|
||||
if (flag === true) {
|
||||
link.classList.add('disabled');
|
||||
} else {
|
||||
@ -252,31 +261,31 @@ export default class CustomerCommunication {
|
||||
}
|
||||
link.querySelector('input').disabled = flag;
|
||||
const display = flag === true ? 'none' : '';
|
||||
this.#container.querySelector('.button-edit-contacts').style.display = display;
|
||||
this.#container.querySelector('.button-edit-followers').style.display = display;
|
||||
// this.#enter.disabled = flag === true;
|
||||
this.#container.querySelector('.message-bar').style.display = display;
|
||||
// this.#container.querySelector('.button-send-message').style.display = display;
|
||||
this._var.container.querySelector('.button-edit-contacts').style.display = display;
|
||||
this._var.container.querySelector('.button-edit-followers').style.display = display;
|
||||
// this._var.enter.disabled = flag === true;
|
||||
this._var.container.querySelector('.message-bar').style.display = display;
|
||||
// this._var.container.querySelector('.button-send-message').style.display = display;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} flag
|
||||
*/
|
||||
set recordReadonly(flag) {
|
||||
this.#option.recordReadonly = flag;
|
||||
if (this.#container == null) {
|
||||
this._var.option.recordReadonly = flag;
|
||||
if (this._var.container == null) {
|
||||
return;
|
||||
}
|
||||
this.#container.querySelector('.button-edit-contacts').style.display = flag === true ? 'none' : '';
|
||||
this.#container.querySelector('.button-edit-followers').style.display = flag === true ? 'none' : '';
|
||||
this._var.container.querySelector('.button-edit-contacts').style.display = flag === true ? 'none' : '';
|
||||
this._var.container.querySelector('.button-edit-followers').style.display = flag === true ? 'none' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
*/
|
||||
set companyName(name) {
|
||||
this.#option.companyName = name;
|
||||
const div = this.#container.querySelector('.title-company');
|
||||
this._var.option.companyName = name;
|
||||
const div = this._var.container.querySelector('.title-company');
|
||||
if (nullOrEmpty(name)) {
|
||||
div.style.display = 'none';
|
||||
} else {
|
||||
@ -288,9 +297,9 @@ export default class CustomerCommunication {
|
||||
* @param {String} code
|
||||
*/
|
||||
set companyCode(code) {
|
||||
const option = this.#option;
|
||||
const option = this._var.option;
|
||||
option.companyCode = code;
|
||||
const div = this.#container.querySelector('.title-company');
|
||||
const div = this._var.container.querySelector('.title-company');
|
||||
if (nullOrEmpty(option.companyName)) {
|
||||
div.style.display = 'none';
|
||||
} else {
|
||||
@ -302,18 +311,18 @@ export default class CustomerCommunication {
|
||||
}
|
||||
|
||||
get followers() {
|
||||
return [...this.#followers.children].map(el => {
|
||||
return [...this._var.followers.children].map(el => {
|
||||
const span = el.querySelector('span');
|
||||
return { 'Email': span.dataset.email, 'MobilePhone': span.dataset.mp, 'Value': span.dataset.name };
|
||||
});
|
||||
}
|
||||
set followers(followers) {
|
||||
this.#data.followers = followers;
|
||||
this.#followers.replaceChildren();
|
||||
this._var.data.followers = followers;
|
||||
this._var.followers.replaceChildren();
|
||||
if (followers?.length > 0) {
|
||||
this.#container.querySelector('.follower-bar').style.display = '';
|
||||
setTooltip(this.#buttonFollower, r('P_CU_EDITFOLLOWERS', 'Edit Followers'));
|
||||
this.#container.querySelector('.follower-bar>.bar-list').appendChild(this.#buttonFollower);
|
||||
this._var.container.querySelector('.follower-bar').style.display = '';
|
||||
setTooltip(this._var.buttonFollower, r('P_CU_EDITFOLLOWERS', 'Edit Followers'));
|
||||
this._var.container.querySelector('.follower-bar>.bar-list').appendChild(this._var.buttonFollower);
|
||||
for (let f of followers) {
|
||||
if (f.OptOut) {
|
||||
continue;
|
||||
@ -326,7 +335,7 @@ export default class CustomerCommunication {
|
||||
tips.push(r('P_CU_EMAILSTO_COLON', 'Emails to:') + ` ${email}`);
|
||||
}
|
||||
if (f.SendText) {
|
||||
tips.push(r('P_CU_TEXTSTO_COLON', 'Texts to:' + ` ${mpDisplay}`));
|
||||
tips.push(r('P_CU_TEXTSTO_COLON', 'Texts to:') + ` ${mpDisplay}`);
|
||||
}
|
||||
let icon;
|
||||
if (f.SendText && f.SendEmail) {
|
||||
@ -348,26 +357,26 @@ export default class CustomerCommunication {
|
||||
createIcon('fa-light', icon),
|
||||
span
|
||||
);
|
||||
this.#followers.appendChild(item);
|
||||
this._var.followers.appendChild(item);
|
||||
if (span.scrollWidth > span.offsetWidth) {
|
||||
tips.splice(0, 0, r('P_WO_NAME_COLON', 'Name:') + ` ${c.Name}`);
|
||||
}
|
||||
setTooltip(span, tips.join('\n'));
|
||||
}
|
||||
} else {
|
||||
this.#container.querySelector('.follower-bar').style.display = 'none';
|
||||
setTooltip(this.#buttonFollower, r('P_CR_ADDFOLLOWERS', 'Add Followers'));
|
||||
this.#container.querySelector('.button-edit-contacts').insertAdjacentElement('beforebegin', this.#buttonFollower)
|
||||
this._var.container.querySelector('.follower-bar').style.display = 'none';
|
||||
setTooltip(this._var.buttonFollower, r('P_CR_ADDFOLLOWERS', 'Add Followers'));
|
||||
this._var.container.querySelector('.button-edit-contacts').insertAdjacentElement('beforebegin', this._var.buttonFollower)
|
||||
}
|
||||
this.#message.scrollTop = this.#message.scrollHeight
|
||||
this._var.message.scrollTop = this._var.message.scrollHeight
|
||||
}
|
||||
|
||||
setData(key, data) {
|
||||
this.#data[key] = data;
|
||||
this._var.data[key] = data;
|
||||
}
|
||||
|
||||
create() {
|
||||
const option = this.#option;
|
||||
const option = this._var.option;
|
||||
const readonly = option.readonly;
|
||||
// functions
|
||||
const checkAutoUpdate = createCheckbox({
|
||||
@ -428,9 +437,9 @@ export default class CustomerCommunication {
|
||||
]
|
||||
);
|
||||
// contacts
|
||||
this.#contacts = this.#createContacts(container, option);
|
||||
this._var.contacts = this._createContacts(container, option);
|
||||
// followers
|
||||
this.#followers = this.#createFollowers(container, option);
|
||||
this._var.followers = this._createFollowers(container, option);
|
||||
// enter box
|
||||
const enter = createElement('textarea', 'ui-text');
|
||||
enter.placeholder = r('P_CU_ENTERMESSAGEHERE', 'Enter Message Here');
|
||||
@ -442,7 +451,7 @@ export default class CustomerCommunication {
|
||||
enter.addEventListener('input', () => {
|
||||
const val = this.text;
|
||||
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/' + String(option.maxLength);
|
||||
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
this._var.container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
});
|
||||
enter.addEventListener('paste', e => {
|
||||
if (option.customerNameVisible === true) {
|
||||
@ -466,7 +475,7 @@ export default class CustomerCommunication {
|
||||
// this.file = insertFile(container, file, r);
|
||||
// }
|
||||
});
|
||||
this.#enter = enter;
|
||||
this._var.enter = enter;
|
||||
container.appendChild(
|
||||
createElement('div', div => {
|
||||
div.className = 'message-bar';
|
||||
@ -498,52 +507,49 @@ export default class CustomerCommunication {
|
||||
},
|
||||
enter,
|
||||
createElement('div', div => div.style.textAlign = 'right',
|
||||
createElement('div', div => {
|
||||
div.className = 'customer-name';
|
||||
if (option.customerNameVisible !== true) {
|
||||
div.style.display = 'none';
|
||||
}
|
||||
},
|
||||
createElement('span', span => span.innerText = r('P_WO_NAME_COLON', 'Name:')),
|
||||
createElement('input', input => {
|
||||
input.type = 'text';
|
||||
input.className = 'ui-input';
|
||||
})
|
||||
),
|
||||
createElement('div', selector => {
|
||||
selector.className = 'file-selector';
|
||||
if (option.customerNameVisible === true) {
|
||||
selector.style.display = 'none';
|
||||
}
|
||||
},
|
||||
createElement('div', 'customer-left',
|
||||
createElement('div', div => {
|
||||
div.className = 'selector-link';
|
||||
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'));
|
||||
});
|
||||
div.className = 'customer-name';
|
||||
if (option.customerNameVisible !== true) {
|
||||
div.style.display = 'none';
|
||||
}
|
||||
},
|
||||
createIcon('fa-regular', 'link')
|
||||
createElement('span', span => span.innerText = r('P_WO_NAME_COLON', 'Name:')),
|
||||
createElement('input', input => {
|
||||
input.type = 'text';
|
||||
input.className = 'ui-input';
|
||||
})
|
||||
),
|
||||
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', 'file-selector',
|
||||
createElement('div', div => {
|
||||
div.className = 'selector-link';
|
||||
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 => {
|
||||
@ -575,12 +581,12 @@ export default class CustomerCommunication {
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#createContacts(container, option) {
|
||||
_createContacts(container, option) {
|
||||
const readonly = option.readonly;
|
||||
const recordReadonly = option.recordReadonly;
|
||||
const contacts = createElement('div', 'bar-list-container');
|
||||
@ -616,6 +622,7 @@ export default class CustomerCommunication {
|
||||
createElement('div', div => div.innerText = r('P_CU_EDITCONTACTS', 'Edit Contacts')),
|
||||
createElement('div', div => {
|
||||
div.className = 'title-company';
|
||||
div.style.maxWidth = '540px';
|
||||
if (nullOrEmpty(option.companyName)) {
|
||||
div.style.display = 'none';
|
||||
} else {
|
||||
@ -652,8 +659,8 @@ export default class CustomerCommunication {
|
||||
});
|
||||
const result = option.onSelectCRContacts(list);
|
||||
}
|
||||
const r = this.#data.contacts;
|
||||
this.#gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
const r = this._var.data.contacts;
|
||||
this._var.gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -662,7 +669,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
return c;
|
||||
});
|
||||
this.#gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
this._var.gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -681,7 +688,7 @@ export default class CustomerCommunication {
|
||||
if (typeof result?.then === 'function') {
|
||||
return result.then(r => {
|
||||
r.map(c => {
|
||||
for (let cc of this.#data.contacts) {
|
||||
for (let cc of this._var.data.contacts) {
|
||||
if (c.Id === cc.Id) {
|
||||
c.selected = true;
|
||||
break;
|
||||
@ -692,7 +699,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
return c;
|
||||
});
|
||||
this.#data.contacts.filter(c => c.Id >= 0).map(c => {
|
||||
this._var.data.contacts.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -729,7 +736,7 @@ export default class CustomerCommunication {
|
||||
// onMasking: option.onMasking,
|
||||
company: !nullOrEmpty(option.companyName),
|
||||
onSave: item => {
|
||||
const exists = this.#gridContact.source.some(s => s.Name === item.Name && s.MobilePhone === item.MobilePhone);
|
||||
const exists = this._var.gridContact.source.some(s => s.Name === item.Name && s.MobilePhone === item.MobilePhone);
|
||||
if (exists) {
|
||||
showAlert(r('P_CR_ADDCONTACT', 'Add Contact'), r('P_WO_CONTACTNAMEANDMOBILEUNIQUECOMBINATION', 'Contact name and contact mobile must be a unique combination.'), 'warn');
|
||||
return false;
|
||||
@ -738,7 +745,7 @@ export default class CustomerCommunication {
|
||||
const result = option.onSave(item, true);
|
||||
if (typeof result?.then === 'function') {
|
||||
return result.then(r => {
|
||||
this.#gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
this._var.gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -747,7 +754,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
return c;
|
||||
});
|
||||
this.#gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
this._var.gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -807,7 +814,7 @@ export default class CustomerCommunication {
|
||||
enabled: item => !item.OptOut && !item.OptOut_BC,
|
||||
onchanged: function () {
|
||||
if (typeof option.onChanged === 'function') {
|
||||
option.onChanged([...This.#gridContact.source, ...This.#gridWo.source]);
|
||||
option.onChanged([...This._var.gridContact.source, ...This._var.gridWo.source]);
|
||||
}
|
||||
},
|
||||
tooltip: item => item.selected ? r('P_CU_OPTEDIN', 'Opted In') : r('P_CU_OPTEDOUT', 'Opted Out')
|
||||
@ -850,8 +857,8 @@ export default class CustomerCommunication {
|
||||
company: !nullOrEmpty(option.companyName),
|
||||
onSave: (item, _op) => {
|
||||
const exists =
|
||||
This.#gridContact.source.some(s => s !== this && s.Name === item.Name && s.MobilePhone === item.MobilePhone) ||
|
||||
This.#gridWo.source.some(s => s !== this && s.Name === item.Name && s.MobilePhone === item.MobilePhone);
|
||||
This._var.gridContact.source.some(s => s !== this && s.Name === item.Name && s.MobilePhone === item.MobilePhone) ||
|
||||
This._var.gridWo.source.some(s => s !== this && s.Name === item.Name && s.MobilePhone === item.MobilePhone);
|
||||
if (exists) {
|
||||
showAlert(r('P_CR_EDITCONTACT', 'Edit Contact'), r('P_WO_CONTACTNAMEANDMOBILEUNIQUECOMBINATION', 'Contact name and contact mobile must be a unique combination.'), 'warn');
|
||||
return false;
|
||||
@ -860,7 +867,7 @@ export default class CustomerCommunication {
|
||||
const result = option.onSave(item);
|
||||
if (typeof result?.then === 'function') {
|
||||
return result.then(r => {
|
||||
This.#gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
This._var.gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -869,7 +876,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
return c;
|
||||
});
|
||||
This.#gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
This._var.gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -957,7 +964,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
];
|
||||
grid.init(pop.container.querySelector('.contacts-record'));
|
||||
const customerRecords = this.#data.contacts.filter(c => c.Id >= 0).map(c => {
|
||||
const customerRecords = this._var.data.contacts.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -969,11 +976,11 @@ export default class CustomerCommunication {
|
||||
grid.extraRows = customerRecords.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
grid.source = customerRecords;
|
||||
grid.selectedRowChanged = index => {
|
||||
if (index >= 0 && this.#gridWo.selectedIndexes?.length > 0) {
|
||||
this.#gridWo.selectedIndexes = [];
|
||||
if (index >= 0 && this._var.gridWo.selectedIndexes?.length > 0) {
|
||||
this._var.gridWo.selectedIndexes = [];
|
||||
}
|
||||
};
|
||||
this.#gridContact = grid;
|
||||
this._var.gridContact = grid;
|
||||
|
||||
// contacts from work order only
|
||||
const gridWo = new Grid();
|
||||
@ -1016,7 +1023,7 @@ export default class CustomerCommunication {
|
||||
}
|
||||
];
|
||||
gridWo.init(pop.container.querySelector('.contacts-wo'));
|
||||
const workOrderOnly = this.#data.contacts.filter(c => c.Id < 0).map(c => {
|
||||
const workOrderOnly = this._var.data.contacts.filter(c => c.Id < 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
@ -1028,11 +1035,11 @@ export default class CustomerCommunication {
|
||||
gridWo.extraRows = workOrderOnly.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
gridWo.source = workOrderOnly;
|
||||
gridWo.selectedRowChanged = index => {
|
||||
if (index >= 0 && this.#gridContact.selectedIndexes?.length > 0) {
|
||||
this.#gridContact.selectedIndexes = [];
|
||||
if (index >= 0 && this._var.gridContact.selectedIndexes?.length > 0) {
|
||||
this._var.gridContact.selectedIndexes = [];
|
||||
}
|
||||
};
|
||||
this.#gridWo = gridWo;
|
||||
this._var.gridWo = gridWo;
|
||||
});
|
||||
});
|
||||
})
|
||||
@ -1072,7 +1079,7 @@ export default class CustomerCommunication {
|
||||
return contacts;
|
||||
}
|
||||
|
||||
#createFollowers(container, option) {
|
||||
_createFollowers(container, option) {
|
||||
const readonly = option.readonly;
|
||||
const recordReadonly = option.recordReadonly;
|
||||
const followers = createElement('div', 'bar-list-container');
|
||||
@ -1086,7 +1093,7 @@ export default class CustomerCommunication {
|
||||
setTooltip(button, r('P_CU_EDITFOLLOWERS', 'Edit Followers'));
|
||||
button.addEventListener('click', () => {
|
||||
if (typeof option.onInitFollower === 'function') {
|
||||
option.onInitFollower(this.#data.followers).then(data => {
|
||||
option.onInitFollower(this._var.data.followers).then(data => {
|
||||
if (typeof data === 'string') {
|
||||
showAlert(r('P_CUSTOMERRECORD', 'Customer Record'), data, 'warn');
|
||||
return;
|
||||
@ -1108,13 +1115,13 @@ export default class CustomerCommunication {
|
||||
}
|
||||
}
|
||||
});
|
||||
var title = this.#data.followers?.length > 0 ? r('P_CU_EDITFOLLOWERS', 'Edit Followers') : r('P_CR_ADDFOLLOWERS', 'Add Followers');
|
||||
var title = this._var.data.followers?.length > 0 ? r('P_CU_EDITFOLLOWERS', 'Edit Followers') : r('P_CR_ADDFOLLOWERS', 'Add Followers');
|
||||
add.show(title, container);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
this.#buttonFollower = buttonEditFollower;
|
||||
this._var.buttonFollower = buttonEditFollower;
|
||||
container.append(
|
||||
createElement('div', div => {
|
||||
div.className = 'contact-bar follower-bar';
|
||||
@ -1141,8 +1148,16 @@ export default class CustomerCommunication {
|
||||
load(data, contacts, followers) {
|
||||
const children = [];
|
||||
if (data?.length > 0) {
|
||||
contacts ??= this.#data.contacts;
|
||||
followers ??= this.#data.allfollowers;
|
||||
contacts ??= this._var.data.contacts;
|
||||
followers ??= this._var.data.allfollowers;
|
||||
this.setData('messages', data);
|
||||
if (this._var.contactsUpdated !== true) {
|
||||
const contacts = this._var.data.contacts;
|
||||
if (contacts?.length > 0) {
|
||||
updateCustomerName(data, contacts);
|
||||
this._var.contactsUpdated = true;
|
||||
}
|
||||
}
|
||||
for (let comm of data) {
|
||||
const div = createElement('div', 'item-div');
|
||||
let name;
|
||||
@ -1153,32 +1168,7 @@ export default class CustomerCommunication {
|
||||
name = c?.Name;
|
||||
}
|
||||
name ??= comm.IsReply && String(comm.FormatSender) !== '' ? comm.FormatSender : comm.Sender;
|
||||
let sendto = '';
|
||||
if (!comm.IsReply && comm.OriPhoneNumbers?.length > 0) {
|
||||
for (let oriph of comm.OriPhoneNumbers) {
|
||||
let cname;
|
||||
const email = isEmail(oriph);
|
||||
if (contacts?.length > 0) {
|
||||
let c = email ?
|
||||
contacts.find(c => c.Email === oriph) :
|
||||
contacts.find(c => c.MobilePhone === oriph);
|
||||
if (c != null) {
|
||||
cname = `${email ? c.Email : c.MobilePhoneDisplayText} - ${c.Name}`;
|
||||
} else if (followers?.length > 0) {
|
||||
c = email ?
|
||||
followers.find(f => f.Email === oriph) :
|
||||
followers.find(f => f.MobilePhone === oriph);
|
||||
if (c != null) {
|
||||
cname = `${email ? c.Email : c.MobilePhoneDisplayText} - ${c.Name}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
sendto += (cname ?? oriph) + '\n';
|
||||
}
|
||||
}
|
||||
if (sendto !== '') {
|
||||
sendto = r('P_CU_SENDTO_COLON', 'Send To :') + `\n${sendto}`;
|
||||
}
|
||||
const sendto = getMessageSendTo(comm, contacts, followers, r)
|
||||
div.appendChild(createElement('div', div => {
|
||||
div.className = 'item-poster';
|
||||
div.innerText = name;
|
||||
@ -1190,13 +1180,13 @@ export default class CustomerCommunication {
|
||||
const mmsParts = createElement('div', div => div.style.display = 'none');
|
||||
content.appendChild(createElement('span', span => {
|
||||
if (/https?:\/\//i.test(comm.Message)) {
|
||||
span.innerHTML = escapeEmoji(formatUrl(comm.Message));
|
||||
span.innerHTML = formatUrl(escapeEmoji(comm.Message));
|
||||
} else {
|
||||
span.innerText = escapeEmoji(comm.Message);
|
||||
}
|
||||
span.appendChild(mmsParts);
|
||||
}));
|
||||
if (comm.IsMMS && comm.MMSParts?.length > 0) {
|
||||
if (comm.MMSParts?.length > 0) {
|
||||
mmsParts.style.display = '';
|
||||
for (let kv of comm.MMSParts) {
|
||||
appendMedia(mmsParts, kv.Key, kv.Value);
|
||||
@ -1206,39 +1196,16 @@ export default class CustomerCommunication {
|
||||
div.classList.add('item-other');
|
||||
} else {
|
||||
div.classList.add('item-self');
|
||||
const [status, statusmsg] = this.#getMessageStatus(comm);
|
||||
const [status, text, color, tips] = getMessageStatus(comm, r, this._var);
|
||||
if (status !== -100) {
|
||||
let statustext;
|
||||
switch (status) {
|
||||
case 0:
|
||||
statustext = r('P_CU_PENDING', 'Pending');
|
||||
content.style.backgroundColor = '#ffc107';
|
||||
break;
|
||||
case 1:
|
||||
statustext = r('P_WO_SENT', 'Sent');
|
||||
break;
|
||||
case 9:
|
||||
statustext = r('P_MA_FAILED', 'Failed');
|
||||
content.style.backgroundColor = '#ffc107';
|
||||
break;
|
||||
case 10:
|
||||
statustext = r('P_CU_OPTOUT', 'Opt-Out');
|
||||
content.style.backgroundColor = '#ffc107';
|
||||
break;
|
||||
case 412:
|
||||
statustext = r('P_CU_LANDLINE', 'Landline');
|
||||
content.style.backgroundColor = '#ffc107';
|
||||
break;
|
||||
default:
|
||||
statustext = r('P_CU_UNDELIVERED', 'Undelivered');
|
||||
content.style.backgroundColor = '#ffc107';
|
||||
break;
|
||||
if (color != null) {
|
||||
content.style.backgroundColor = color;
|
||||
}
|
||||
const divstatus = createElement('div', div => {
|
||||
div.className = 'item-status';
|
||||
div.innerText = statustext;
|
||||
if (status == -10) {
|
||||
setTooltip(div, statusmsg);
|
||||
div.innerText = text;
|
||||
if (tips != null) {
|
||||
setTooltip(div, tips);
|
||||
}
|
||||
});
|
||||
content.appendChild(divstatus);
|
||||
@ -1255,43 +1222,8 @@ export default class CustomerCommunication {
|
||||
}
|
||||
children[0].style.marginTop = '0';
|
||||
}
|
||||
this.#message.replaceChildren(...children);
|
||||
this.#message.scrollTop = this.#message.scrollHeight
|
||||
// setTimeout(() => this.#message.scrollTop = this.#message.scrollHeight, 0);
|
||||
}
|
||||
|
||||
#getMessageStatus(comm) {
|
||||
let status = -100; // 没有状态,页面上不显示
|
||||
const ls = [];
|
||||
let statusmsg = '';
|
||||
if (!comm.StatusIncorrect && comm.Participator?.length > 0) {
|
||||
for (let p of comm.Participator) {
|
||||
if (!isEmail(p.CustomerNumber)) {
|
||||
if (ls.indexOf(p.Status) < 0) {
|
||||
ls.push(p.Status);
|
||||
}
|
||||
if (statusmsg.length > 0) {
|
||||
statusmsg += '\n';
|
||||
}
|
||||
statusmsg += `${p.CustomerNumber}: `;
|
||||
const st = ({
|
||||
0: r('P_CU_UNDELIVERED', 'Undelivered'),
|
||||
1: r('P_WO_SENT', 'Sent'),
|
||||
9: r('P_MA_FAILED', 'Failed')
|
||||
})[p.Status];
|
||||
if (st != null) {
|
||||
statusmsg += st;
|
||||
}
|
||||
else
|
||||
statusmsg += r('P_MA_XXXXXX', 'Unknown');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ls.length === 1) {
|
||||
status = ls[0];
|
||||
} else if (ls.length > 1) {
|
||||
status = -10; // 多种状态
|
||||
}
|
||||
return [status, statusmsg];
|
||||
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