sync from work
This commit is contained in:
@ -56,7 +56,7 @@ class Contact {
|
||||
}
|
||||
item.SaveToCustomer = 1;
|
||||
if (typeof this.#option.onSave === 'function') {
|
||||
return this.#option.onSave.call(this, item, c == null);
|
||||
return this.#option.onSave.call(this, item, 'customerrecord');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -69,9 +69,10 @@ class Contact {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
item.Id = -1;
|
||||
item.SaveToCustomer = 0;
|
||||
if (typeof this.#option.onSave === 'function') {
|
||||
return this.#option.onSave.call(this, item, c == null);
|
||||
return this.#option.onSave.call(this, item, 'workorder');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -162,6 +163,10 @@ class Contact {
|
||||
let contact = this.#option.contact;
|
||||
if (contact == null) {
|
||||
contact = {};
|
||||
} else if (contact.OptOut !== opt) {
|
||||
if (opt !== false || contact.OptOut_BC === false) {
|
||||
contact.selected = !opt;
|
||||
}
|
||||
}
|
||||
contact.Name = name;
|
||||
contact.ContactPreference = pref;
|
||||
|
@ -165,10 +165,19 @@ class CustomerCommunication {
|
||||
if (this.#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.#enter.disabled = flag === true;
|
||||
this.#container.querySelector('.button-send-message').style.display = flag === true ? 'none' : '';
|
||||
const link = this.#container.querySelector('.check-status-link');
|
||||
if (flag === true) {
|
||||
link.classList.add('disabled');
|
||||
} else {
|
||||
link.classList.remove('disabled');
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,6 +270,7 @@ class CustomerCommunication {
|
||||
|
||||
create() {
|
||||
const option = this.#option;
|
||||
const readonly = option.readonly;
|
||||
// functions
|
||||
const checkAutoUpdate = createCheckbox({
|
||||
className: 'check-auto-update',
|
||||
@ -273,8 +283,12 @@ class CustomerCommunication {
|
||||
r('autoUpdateDisabled', 'Auto Updates Disabled'));
|
||||
}
|
||||
});
|
||||
if (option.autoUpdatesVisible === false) {
|
||||
checkAutoUpdate.style.display = 'none';
|
||||
}
|
||||
const checkLink = createCheckbox({
|
||||
className: 'check-status-link',
|
||||
enabled: !readonly,
|
||||
checked: option.statusLink,
|
||||
checkedNode: createIcon('fa-regular', 'link'),
|
||||
uncheckedNode: createIcon('fa-regular', 'unlink'),
|
||||
@ -284,6 +298,9 @@ class CustomerCommunication {
|
||||
r('statusLinkExcluded', 'Status Link Excluded'));
|
||||
}
|
||||
});
|
||||
if (option.statusLinkVisible === false) {
|
||||
checkLink.style.display = 'none';
|
||||
}
|
||||
const container = createBox(
|
||||
createElement('div', null,
|
||||
createElement('div', div => div.innerText = r('messages', 'Customer Communication')),
|
||||
@ -302,6 +319,62 @@ class CustomerCommunication {
|
||||
]
|
||||
);
|
||||
// contacts
|
||||
this.#contacts = this.#createContacts(container, option);
|
||||
// followers
|
||||
this.#followers = this.#createFollowers(container, option);
|
||||
// enter box
|
||||
const enter = createElement('textarea');
|
||||
enter.placeholder = r('typeMessage', 'Enter Message Here');
|
||||
enter.maxLength = 3000;
|
||||
// if (readonly === true) {
|
||||
// enter.disabled = true;
|
||||
// }
|
||||
enter.addEventListener('input', () => {
|
||||
const val = this.#enter.value;
|
||||
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/3000';
|
||||
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
});
|
||||
this.#enter = enter;
|
||||
container.appendChild(
|
||||
createElement('div', div => {
|
||||
div.className = 'message-bar';
|
||||
if (readonly === true) {
|
||||
div.style.display = 'none';
|
||||
}
|
||||
},
|
||||
enter,
|
||||
createElement('div', div => div.style.textAlign = 'right',
|
||||
createElement('div', 'prompt-count'),
|
||||
createElement('button', button => {
|
||||
button.className = 'roundbtn button-send-message';
|
||||
button.style.backgroundColor = 'rgb(19, 150, 204)';
|
||||
// if (readonly === true) {
|
||||
// button.style.display = 'none';
|
||||
// }
|
||||
button.appendChild(createIcon('fa-solid', 'paper-plane'));
|
||||
setTooltip(button, r('sendMessage', 'Send Message'));
|
||||
button.addEventListener('click', () => {
|
||||
const val = this.#enter.value;
|
||||
if (nullOrEmpty(val?.trim())) {
|
||||
showAlert(r('error', 'Error'), r('messageRequired', 'Please input the message.'), 'warn');
|
||||
return;
|
||||
}
|
||||
if (typeof this.#option.onAddMessage === 'function') {
|
||||
this.#option.onAddMessage(this.#enter.value);
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
const message = createElement('div', 'list-bar');
|
||||
this.#message = message;
|
||||
container.appendChild(message);
|
||||
return this.#container = container;
|
||||
}
|
||||
|
||||
#createContacts(container, option) {
|
||||
const readonly = option.readonly;
|
||||
const recordReadonly = option.recordReadonly;
|
||||
const contacts = createElement('div');
|
||||
@ -357,7 +430,7 @@ class CustomerCommunication {
|
||||
button.addEventListener('click', () => {
|
||||
const add = new Contact({
|
||||
company: !nullOrEmpty(this.#data.companyCode),
|
||||
onSave: (item) => {
|
||||
onSave: item => {
|
||||
const exists = this.#gridContact.source.some(s => s.Name === item.Name && s.MobilePhone === item.MobilePhone);
|
||||
if (exists) {
|
||||
showAlert(r('addContact', 'Add Contact'), r('contactUniqueRequired', 'Contact name and contact mobile must be a unique combination.'), 'warn');
|
||||
@ -367,8 +440,24 @@ 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);
|
||||
this.#gridWo.source = r.filter(c => c.Id < 0);
|
||||
this.#gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
if (typeof c.selected === 'undefined') {
|
||||
c.selected = true;
|
||||
}
|
||||
return c;
|
||||
});
|
||||
this.#gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
if (typeof c.selected === 'undefined') {
|
||||
c.selected = true;
|
||||
}
|
||||
return c;
|
||||
});
|
||||
return r;
|
||||
});
|
||||
}
|
||||
@ -456,7 +545,7 @@ class CustomerCommunication {
|
||||
const edit = new Contact({
|
||||
contact: this,
|
||||
company: !nullOrEmpty(This.#data.companyCode),
|
||||
onSave: item => {
|
||||
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);
|
||||
@ -468,8 +557,24 @@ 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);
|
||||
This.#gridWo.source = r.filter(c => c.Id < 0);
|
||||
This.#gridContact.source = r.filter(c => c.Id >= 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
if (typeof c.selected === 'undefined') {
|
||||
c.selected = true;
|
||||
}
|
||||
return c;
|
||||
});
|
||||
This.#gridWo.source = r.filter(c => c.Id < 0).map(c => {
|
||||
if (c.OptOut || c.OptOut_BC) {
|
||||
return c;
|
||||
}
|
||||
if (typeof c.selected === 'undefined') {
|
||||
c.selected = true;
|
||||
}
|
||||
return c;
|
||||
});
|
||||
return r;
|
||||
});
|
||||
}
|
||||
@ -504,7 +609,10 @@ class CustomerCommunication {
|
||||
showConfirm(
|
||||
r('remoteContact', 'Remove Contact'),
|
||||
createElement('div', null,
|
||||
createElement('div', div => div.innerText = r('removeFrom', 'Remove {name} from').replace('{name}', this.Name)),
|
||||
createElement('div', div => {
|
||||
div.style.paddingLeft = '16px';
|
||||
div.innerText = r('removeFrom', 'Remove {name} from').replace('{name}', this.Name);
|
||||
}),
|
||||
createElement('div', div => {
|
||||
div.style.display = 'flex';
|
||||
div.style.justifyContent = 'center';
|
||||
@ -525,21 +633,22 @@ class CustomerCommunication {
|
||||
[
|
||||
{ key: 'ok', text: r('ok', 'OK') },
|
||||
{ key: 'cancel', text: r('cancel', 'Cancel') }
|
||||
]).then(result => {
|
||||
if (result?.key === 'ok') {
|
||||
const isRecord = result.popup.container.querySelector('.radio-customer-record>input').checked;
|
||||
if (typeof option.onDelete === 'function') {
|
||||
option.onDelete(result.key, this, isRecord);
|
||||
}
|
||||
const index = grid.source.indexOf(this);
|
||||
if (index >= 0) {
|
||||
const source = grid.source;
|
||||
source.splice(index, 1);
|
||||
grid.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
grid.source = source;
|
||||
}
|
||||
]
|
||||
).then(result => {
|
||||
if (result?.key === 'ok') {
|
||||
const isRecord = result.popup.container.querySelector('.radio-customer-record>input').checked;
|
||||
if (typeof option.onDelete === 'function') {
|
||||
option.onDelete(result.key, this, isRecord);
|
||||
}
|
||||
});
|
||||
const index = grid.source.indexOf(this);
|
||||
if (index >= 0) {
|
||||
const source = grid.source;
|
||||
source.splice(index, 1);
|
||||
grid.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
grid.source = source;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -627,8 +736,12 @@ class CustomerCommunication {
|
||||
)
|
||||
)
|
||||
);
|
||||
this.#contacts = contacts;
|
||||
// followers
|
||||
return contacts;
|
||||
}
|
||||
|
||||
#createFollowers(container, option) {
|
||||
const readonly = option.readonly;
|
||||
const recordReadonly = option.recordReadonly;
|
||||
const followers = createElement('div');
|
||||
const buttonEditFollower = createElement('button', button => {
|
||||
button.className = 'roundbtn button-edit-followers';
|
||||
@ -681,7 +794,7 @@ class CustomerCommunication {
|
||||
}
|
||||
});
|
||||
add.show(container);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
setTooltip(button, r('addFollower', 'Add Follower'))
|
||||
@ -701,6 +814,12 @@ class CustomerCommunication {
|
||||
)
|
||||
);
|
||||
pop.show(container).then(() => {
|
||||
const buttonCol = {
|
||||
type: Grid.ColumnTypes.Icon,
|
||||
width: 40,
|
||||
align: 'center',
|
||||
iconType: 'fa-light'
|
||||
};
|
||||
const grid = new Grid();
|
||||
grid.height = 0;
|
||||
grid.allowHtml = true;
|
||||
@ -710,40 +829,132 @@ class CustomerCommunication {
|
||||
key: 'type',
|
||||
type: Grid.ColumnTypes.Icon,
|
||||
width: 50,
|
||||
filter: c => c.SendText ? 'comment-lines' : 'envelope',
|
||||
filter: c => c.SendText && c.SendEmail ? 'at' : (c.SendText ? 'comment-lines' : 'envelope'),
|
||||
className: 'icon-contact-type',
|
||||
iconType: 'fa-light'
|
||||
},
|
||||
{ key: 'Name', width: 160 },
|
||||
{ key: 'Email', width: 180 },
|
||||
{ key: 'MobilePhone', width: 130 },
|
||||
{
|
||||
key: 'edit',
|
||||
...buttonCol,
|
||||
text: 'edit',
|
||||
tooltip: r('edit', 'Edit'),
|
||||
events: {
|
||||
onclick: function () {
|
||||
if (typeof option.onInitFollower === 'function') {
|
||||
option.onInitFollower().then(data => {
|
||||
if (typeof data === 'string') {
|
||||
showAlert(r('customerRecord', 'Customer Record'), data, 'warn');
|
||||
return;
|
||||
}
|
||||
const contact = data.find(d => d.IID === this.UserIID);
|
||||
showConfirm(
|
||||
r('editContactMethod', 'Edit Contact Method'),
|
||||
createElement('div', 'wrapper-edit-method',
|
||||
createElement('div', div => {
|
||||
div.style.display = 'flex';
|
||||
div.style.justifyContent = 'center';
|
||||
div.style.marginTop = '20px';
|
||||
},
|
||||
createCheckbox({
|
||||
label: r('text', 'Text'),
|
||||
checked: this.SendText && !nullOrEmpty(contact?.Mobile),
|
||||
enabled: !nullOrEmpty(contact?.Mobile),
|
||||
className: 'check-method-text'
|
||||
}),
|
||||
createCheckbox({
|
||||
label: r('email', 'Email'),
|
||||
checked: this.SendEmail,
|
||||
className: 'check-method-email'
|
||||
})
|
||||
)
|
||||
),
|
||||
[
|
||||
{
|
||||
key: 'ok',
|
||||
text: r('ok', 'OK'),
|
||||
trigger: (popup, button) => {
|
||||
const text = popup.container.querySelector('.check-method-text>input').checked;
|
||||
const email = popup.container.querySelector('.check-method-email>input').checked;
|
||||
|
||||
if (!text && !email) {
|
||||
return showConfirm(r('editContactMethod', 'Edit Contact Method'), r('promptRemoveFollower', 'Contact method is required. If you continue, user will be removed as a follower.'), [
|
||||
{ key: 'update', text: r('updateContactMethod', 'Update Contact Method') },
|
||||
{ key: 'remove', text: r('removeFollower', 'Remove Follower') }
|
||||
], 'question').then(result => {
|
||||
if (result?.key === 'remove') {
|
||||
return {
|
||||
key: result.key,
|
||||
popup
|
||||
};
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
return {
|
||||
key: button.key,
|
||||
popup
|
||||
};
|
||||
}
|
||||
},
|
||||
{ key: 'cancel', text: r('cancel', 'Cancel') }
|
||||
],
|
||||
null
|
||||
).then(result => {
|
||||
const key = result?.key;
|
||||
if (key === 'remove') {
|
||||
if (typeof option.onDeleteFollower === 'function') {
|
||||
option.onDeleteFollower(result.key, this);
|
||||
}
|
||||
const index = grid.source.indexOf(this);
|
||||
if (index >= 0) {
|
||||
const source = grid.source;
|
||||
source.splice(index, 1);
|
||||
grid.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
grid.source = source;
|
||||
}
|
||||
} else if (key === 'ok') {
|
||||
const text = result.popup.container.querySelector('.check-method-text>input').checked;
|
||||
const email = result.popup.container.querySelector('.check-method-email>input').checked;
|
||||
if (typeof option.onChangeFollower === 'function') {
|
||||
option.onChangeFollower(result.key, this, text, email);
|
||||
}
|
||||
this.SendText = text;
|
||||
this.SendEmail = email;
|
||||
grid.refresh();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
type: Grid.ColumnTypes.Icon,
|
||||
width: 40,
|
||||
align: 'center',
|
||||
iconType: 'fa-light',
|
||||
...buttonCol,
|
||||
text: 'times',
|
||||
tooltip: r('delete', 'Delete'),
|
||||
events: {
|
||||
onclick: function () {
|
||||
showConfirm(
|
||||
r('deleteFollower', 'Delete Follower'),
|
||||
r('promptDeleteFollower', 'Do you want to delete this follower?'))
|
||||
.then(result => {
|
||||
if (result?.key === 'yes') {
|
||||
if (typeof option.onDeleteFollower === 'function') {
|
||||
option.onDeleteFollower(result.key, this);
|
||||
}
|
||||
const index = grid.source.indexOf(this);
|
||||
if (index >= 0) {
|
||||
const source = grid.source;
|
||||
source.splice(index, 1);
|
||||
grid.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
grid.source = source;
|
||||
}
|
||||
r('promptDeleteFollower', 'Do you want to delete this follower?')
|
||||
).then(result => {
|
||||
if (result?.key === 'yes') {
|
||||
if (typeof option.onDeleteFollower === 'function') {
|
||||
option.onDeleteFollower(result.key, this);
|
||||
}
|
||||
});
|
||||
const index = grid.source.indexOf(this);
|
||||
if (index >= 0) {
|
||||
const source = grid.source;
|
||||
source.splice(index, 1);
|
||||
grid.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
|
||||
grid.source = source;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -775,52 +986,7 @@ class CustomerCommunication {
|
||||
)
|
||||
)
|
||||
);
|
||||
this.#followers = followers;
|
||||
// enter box
|
||||
const enter = createElement('textarea');
|
||||
enter.placeholder = r('typeMessage', 'Enter Message Here');
|
||||
enter.maxLength = 3000;
|
||||
if (readonly === true) {
|
||||
enter.disabled = true;
|
||||
}
|
||||
enter.addEventListener('input', () => {
|
||||
const val = this.#enter.value;
|
||||
const s = String(nullOrEmpty(val) ? 0 : val.length) + '/3000';
|
||||
this.#container.querySelector('.message-bar .prompt-count').innerText = s;
|
||||
});
|
||||
this.#enter = enter;
|
||||
container.appendChild(
|
||||
createElement('div', 'message-bar',
|
||||
enter,
|
||||
createElement('div', div => div.style.textAlign = 'right',
|
||||
createElement('div', 'prompt-count'),
|
||||
createElement('button', button => {
|
||||
button.className = 'roundbtn button-send-message';
|
||||
button.style.backgroundColor = 'rgb(19, 150, 204)';
|
||||
if (readonly === true) {
|
||||
button.style.display = 'none';
|
||||
}
|
||||
button.appendChild(createIcon('fa-solid', 'paper-plane'));
|
||||
setTooltip(button, r('sendMessage', 'Send Message'));
|
||||
button.addEventListener('click', () => {
|
||||
const val = this.#enter.value;
|
||||
if (nullOrEmpty(val?.trim())) {
|
||||
showAlert(r('error', 'Error'), r('messageRequired', 'Please input the message.'), 'warn');
|
||||
return;
|
||||
}
|
||||
if (typeof this.#option.onAddMessage === 'function') {
|
||||
this.#option.onAddMessage(this.#enter.value);
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
const message = createElement('div', 'list-bar');
|
||||
this.#message = message;
|
||||
container.appendChild(message);
|
||||
return this.#container = container;
|
||||
return followers;
|
||||
}
|
||||
|
||||
load(data, contacts, followers) {
|
||||
|
@ -58,7 +58,7 @@ class Follower {
|
||||
caption: r('email', 'Email'),
|
||||
type: Grid.ColumnTypes.Checkbox,
|
||||
width: 70,
|
||||
enabled: item => !nullOrEmpty(item.ID)
|
||||
// enabled: item => !nullOrEmpty(item.ID)
|
||||
}
|
||||
];
|
||||
grid.init();
|
||||
|
@ -63,7 +63,7 @@ class InternalComment {
|
||||
createElement('button', button => {
|
||||
button.className = 'roundbtn button-send-message';
|
||||
button.style.backgroundColor = 'rgb(19, 150, 204)';
|
||||
if (readonly === true) {
|
||||
if (readonly === true || this.#option.noMessage === true) {
|
||||
button.style.display = 'none';
|
||||
}
|
||||
button.appendChild(createIcon('fa-solid', 'paper-plane'));
|
||||
|
@ -1,5 +1,13 @@
|
||||
@import '../../../css/variables/definition.scss';
|
||||
|
||||
.popup-mask .wrapper-edit-method {
|
||||
width: 100%;
|
||||
|
||||
.checkbox-wrapper {
|
||||
padding: 0 28px;
|
||||
}
|
||||
}
|
||||
|
||||
.comm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@ -207,6 +215,12 @@
|
||||
padding: 10px 10px 0;
|
||||
border: none;
|
||||
height: 70px;
|
||||
resize: none;
|
||||
|
||||
&:focus,
|
||||
&:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
>div {
|
||||
|
Reference in New Issue
Block a user