This commit is contained in:
2024-06-07 16:15:42 +08:00
parent ea7f4f538a
commit 614a983aa8
15 changed files with 834 additions and 464 deletions

View File

@ -276,6 +276,7 @@ export default class CustomerCommunication {
}
link.querySelector('input').disabled = flag;
const display = flag === true ? 'none' : '';
this._var.container.querySelector('.title-company').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;
@ -291,8 +292,13 @@ export default class CustomerCommunication {
if (this._var.container == null) {
return;
}
this._var.container.querySelector('.button-edit-contacts').style.display = flag === true ? 'none' : '';
this._var.container.querySelector('.button-edit-followers').style.display = flag === true ? 'none' : '';
const display = flag === true ? 'none' : '';
const companySelector = this._var.container.querySelector('.title-company .title-company-selector');
if (companySelector != null) {
companySelector.querySelector('.title-company-selector').style.display = display;
}
this._var.container.querySelector('.button-edit-contacts').style.display = display;
this._var.container.querySelector('.button-edit-followers').style.display = display;
}
/**
@ -301,12 +307,18 @@ export default class CustomerCommunication {
set companyName(name) {
this._var.option.companyName = name;
const div = this._var.container.querySelector('.title-company');
if (nullOrEmpty(name)) {
div.style.display = 'none';
} else {
div.innerText = name;
div.style.display = '';
const companyCode = div.querySelector('.title-company-code');
if (companyCode != null) {
if (nullOrEmpty(name)) {
div.querySelector('.title-company-name').innerText = r('P_WO_NOCUSTOMERASSIGNED', 'No Customer Assigned');
companyCode.innerText = ' /\n' + r('P_WO_SELECTCUSTOMER', 'Select Customer');
companyCode.style.display = '';
} else {
div.querySelector('.title-company-name').innerText = name;
companyCode.style.display = 'none';
}
}
div.style.display = '';
}
/**
* @param {String} code
@ -315,14 +327,23 @@ export default class CustomerCommunication {
const option = this._var.option;
option.companyCode = code;
const div = this._var.container.querySelector('.title-company');
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
} else {
div.innerText = option.companyName;
if (!nullOrEmpty(code))
div.innerText = option.companyName + "/" + code;
div.style.display = '';
const companyCode = div.querySelector('.title-company-code');
if (companyCode != null) {
if (nullOrEmpty(option.companyName)) {
div.querySelector('.title-company-name').innerText = r('P_WO_NOCUSTOMERASSIGNED', 'No Customer Assigned');
companyCode.innerText = ' /\n' + r('P_WO_SELECTCUSTOMER', 'Select Customer');
companyCode.style.display = '';
} else {
div.querySelector('.title-company-name').innerText = option.companyName;
if (nullOrEmpty(code)) {
companyCode.style.display = 'none';
} else {
companyCode.innerText = ' / ' + code;
companyCode.style.display = '';
}
}
}
div.style.display = '';
}
get followers() {
@ -436,18 +457,42 @@ export default class CustomerCommunication {
},
createHideMessageTitleButton(this, 'showMessageHidden')
),
// option.allowCustomer === false ? createElement('div', 'title-company') :
createElement('div', div => {
div.className = 'title-company';
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
} else {
if (nullOrEmpty(option.companyCode)) {
div.innerText = option.companyName;
// div.style.display = 'none';
},
createElement('span', span => {
span.className = 'title-company-name';
if (nullOrEmpty(option.companyName)) {
span.innerText = r('P_WO_NOCUSTOMERASSIGNED', 'No Customer Assigned');
} else {
div.innerText = option.companyName + "/" + option.companyCode;
span.innerText = option.companyName;
}
}
})
}),
createElement('span', span => {
span.className = 'title-company-code';
if (nullOrEmpty(option.companyName)) {
span.innerText = ' /\n' + r('P_WO_SELECTCUSTOMER', 'Select Customer');
} else if (!nullOrEmpty(option.companyCode)) {
span.innerText = ' / ' + option.companyCode;
} else {
span.style.display = 'none';
}
}),
createElement('span', span => {
span.className = 'title-company-selector';
if (option.recordReadonly) {
span.style.display = 'none';
}
setTooltip(span, r('P_WO_SELECTCUSTOMER', 'Select Customer'));
if (typeof option.onAddCompany === 'function') {
span.addEventListener('click', () => option.onAddCompany.call(this));
}
},
createIcon('fa-light', 'search')
)
)
),
[
setTooltip(checkAutoUpdate, r('P_CU_AUTOUPDATESENABLED', 'Auto Updates Enabled')),
@ -626,98 +671,67 @@ export default class CustomerCommunication {
button.appendChild(createIcon('fa-solid', 'user-edit'));
setTooltip(button, r('P_CU_EDITCONTACTS', 'Edit Contacts'));
button.addEventListener('click', () => {
const pop = new Popup({
onMasking: option.onMasking,
title: createElement('div', div => {
div.style.display = 'flex';
div.style.alignItems = 'center';
div.style.padding = '10px 0 6px 12px';
div.append(
createElement('div', div => {
div.className = 'ui-popup-move';
div.style.flex = '1 1 auto';
},
createElement('div', div => div.innerText = r('P_CU_EDITCONTACTS', 'Edit Contacts')),
const editContacts = () => {
const pop = new Popup({
onMasking: option.onMasking,
title: createElement('div', div => {
div.style.display = 'flex';
div.style.alignItems = 'center';
div.style.padding = '10px 0 6px 12px';
div.append(
createElement('div', div => {
div.className = 'title-company';
div.style.maxWidth = '540px';
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
} else {
if (nullOrEmpty(option.companyCode)) {
div.innerText = option.companyName;
} else {
div.innerText = option.companyName + "/" + option.companyCode;
div.className = 'ui-popup-move';
div.style.flex = '1 1 auto';
},
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';
}
}
})
),
createElement('button', button => {
button.style.flex = '0 0 auto';
button.style.backgroundColor = 'rgb(1, 199, 172)';
button.style.marginRight = '10px';
button.className = 'roundbtn button-from-customer-record';
if (recordReadonly) {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'handshake', {
width: '16px',
height: '16px'
}));
button.addEventListener('click', () => {
const sel = new CustomerRecordContact({
getText: option.getText,
// onMasking: option.onMasking,
contacts: [],
onOk: list => {
if (typeof option.onSelectCRContacts === 'function') {
list?.map(c => {
delete c.selected;
return c;
});
const result = option.onSelectCRContacts(list);
},
createElement('span', span => {
span.className = 'title-company-name';
if (!nullOrEmpty(option.companyName)) {
span.innerText = option.companyName;
}
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;
}),
createElement('span', span => {
span.className = 'title-company-code';
if (!nullOrEmpty(option.companyCode)) {
span.innerText = '/' + option.companyCode;
}
})
)
),
createElement('button', button => {
button.style.flex = '0 0 auto';
button.style.backgroundColor = 'rgb(1, 199, 172)';
button.style.marginRight = '10px';
button.className = 'roundbtn button-from-customer-record';
if (recordReadonly || nullOrEmpty(option.companyName)) {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'handshake', {
width: '16px',
height: '16px'
}));
button.addEventListener('click', () => {
const sel = new CustomerRecordContact({
getText: option.getText,
// onMasking: option.onMasking,
contacts: [],
onOk: list => {
if (typeof option.onSelectCRContacts === 'function') {
list?.map(c => {
delete c.selected;
return c;
});
const result = option.onSelectCRContacts(list);
}
if (typeof c.selected === 'undefined') {
c.selected = true;
}
return c;
});
this._var.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;
});
}
});
var title = r('P_CU_SELECTFROMCUSTOMERRECORD', 'Select from Customer Record');
sel.show(title, container);
if (typeof option.onOpenSelectCRContacts === 'function') {
const result = option.onOpenSelectCRContacts();
if (typeof result?.then === 'function') {
return result.then(r => {
r.map(c => {
for (let cc of this._var.data.contacts) {
if (c.Id === cc.Id) {
c.selected = true;
break;
}
}
if (typeof c.selected === 'undefined') {
c.selected = false;
}
return c;
});
this._var.data.contacts.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;
}
@ -726,339 +740,402 @@ export default class CustomerCommunication {
}
return c;
});
this._var.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;
});
}
});
var title = r('P_CU_SELECTFROMCUSTOMERRECORD', 'Select from Customer Record');
sel.show(title, container);
sel.source = r;
return r;
});
}
return false;
}
});
setTooltip(button, r('P_CU_SELECTFROMCUSTOMERRECORD', 'Select from Customer Record'))
}),
createElement('button', button => {
button.style.flex = '0 0 auto';
button.style.backgroundColor = 'rgb(1, 199, 172)';
button.style.marginRight = '10px';
button.className = 'roundbtn button-add-contact';
if (recordReadonly) {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'user-plus', {
width: '16px',
height: '16px'
}));
button.addEventListener('click', () => {
const add = new Contact({
getText: option.getText,
// onMasking: option.onMasking,
company: !nullOrEmpty(option.companyName),
onSave: item => {
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;
}
if (typeof option.onSave === 'function') {
const result = option.onSave(item, true);
if (typeof result?.then === 'function') {
return result.then(r => {
this._var.gridContact.source = r.filter(c => c.Id >= 0).map(c => {
if (c.OptOut || c.OptOut_BC) {
return c;
}
if (typeof c.selected === 'undefined') {
if (typeof option.onOpenSelectCRContacts === 'function') {
const result = option.onOpenSelectCRContacts();
if (typeof result?.then === 'function') {
return result.then(r => {
r.map(c => {
for (let cc of this._var.data.contacts) {
if (c.Id === cc.Id) {
c.selected = true;
break;
}
return c;
});
this._var.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;
}
if (typeof c.selected === 'undefined') {
c.selected = false;
}
return c;
});
}
return false;
this._var.data.contacts.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;
});
sel.source = r;
return r;
});
}
return false;
}
});
add.show(container);
});
setTooltip(button, r('P_CR_ADDCONTACT', 'Add Contact'))
setTooltip(button, r('P_CU_SELECTFROMCUSTOMERRECORD', 'Select from Customer Record'))
}),
createElement('button', button => {
button.style.flex = '0 0 auto';
button.style.backgroundColor = 'rgb(1, 199, 172)';
button.style.marginRight = '10px';
button.className = 'roundbtn button-add-contact';
if (recordReadonly) {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'user-plus', {
width: '16px',
height: '16px'
}));
button.addEventListener('click', () => {
const add = new Contact({
getText: option.getText,
// onMasking: option.onMasking,
company: !nullOrEmpty(option.companyName),
onSave: item => {
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;
}
if (typeof option.onSave === 'function') {
const result = option.onSave(item, true);
if (typeof result?.then === 'function') {
return result.then(r => {
this._var.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._var.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;
});
}
return false;
}
}
});
add.show(container);
});
setTooltip(button, r('P_CR_ADDCONTACT', 'Add Contact'))
})
)
}),
content: createElement('div', null,
createElement('div', div => {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
}
div.style.fontWeight = 'bold';
div.innerText = r('P_CU_CONTACTSFROMCUSTOMERRECORD', 'Contacts from Customer Record');
}),
createElement('div', div => {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
}
div.className = 'contacts-record';
// div.style.maxHeight = '200px';
div.style.width = '675px';
// div.style.overflow = 'auto';
}),
createElement('div', div => {
div.style.fontWeight = 'bold';
div.innerText = r('P_CU_CONTACTSNOTCUSTOMERRECORD', 'Contacts not on Customer Record');
}),
createElement('div', div => {
div.className = 'contacts-wo';
// div.style.maxHeight = '200px';
div.style.width = '675px';
// div.style.overflow = 'auto';
})
)
}),
content: createElement('div', null,
createElement('div', div => {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
});
pop.show(container).then(() => {
const selectedCol = This => {
return {
key: 'selected',
type: Grid.ColumnTypes.Checkbox,
width: 50,
enabled: item => !item.OptOut && !item.OptOut_BC,
onChanged: function () {
if (typeof option.onChanged === 'function') {
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')
}
div.style.fontWeight = 'bold';
div.innerText = r('P_CU_CONTACTSFROMCUSTOMERRECORD', 'Contacts from Customer Record');
}),
createElement('div', div => {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
}
div.className = 'contacts-record';
// div.style.maxHeight = '200px';
div.style.width = '675px';
// div.style.overflow = 'auto';
}),
createElement('div', div => {
div.style.fontWeight = 'bold';
div.innerText = r('P_CU_CONTACTSNOTCUSTOMERRECORD', 'Contacts not on Customer Record');
}),
createElement('div', div => {
div.className = 'contacts-wo';
// div.style.maxHeight = '200px';
div.style.width = '675px';
// div.style.overflow = 'auto';
})
)
});
pop.show(container).then(() => {
const selectedCol = This => {
return {
key: 'selected',
type: Grid.ColumnTypes.Checkbox,
};
const iconCol = {
key: 'type',
type: Grid.ColumnTypes.Icon,
width: 50,
enabled: item => !item.OptOut && !item.OptOut_BC,
onChanged: function () {
if (typeof option.onChanged === 'function') {
option.onChanged([...This._var.gridContact.source, ...This._var.gridWo.source]);
filter: c => {
switch (String(c.ContactPreference)) {
case '0': return 'comment-lines';
case '2': return 'mobile';
default: return 'envelope';
}
},
tooltip: item => item.selected ? r('P_CU_OPTEDIN', 'Opted In') : r('P_CU_OPTEDOUT', 'Opted Out')
}
};
const iconCol = {
key: 'type',
type: Grid.ColumnTypes.Icon,
width: 50,
filter: c => {
switch (String(c.ContactPreference)) {
case '0': return 'comment-lines';
case '2': return 'mobile';
default: return 'envelope';
}
},
className: 'icon-contact-type',
iconType: 'fa-light'
};
const nameCol = { key: 'Name', type: NoteCol, width: 160 };
const buttonCol = {
type: Grid.ColumnTypes.Icon,
width: 40,
visible: !recordReadonly,
align: 'center',
iconType: 'fa-light'
};
const createEditCol = (This) => {
return {
key: 'edit',
...buttonCol,
text: 'edit',
tooltip: r('P_WO_EDIT', 'Edit'),
events: {
onclick: function () {
const edit = new Contact({
getText: option.getText,
// onMasking: option.onMasking,
contact: this,
company: !nullOrEmpty(option.companyName),
onSave: (item, _op) => {
const exists =
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;
}
if (typeof option.onSave === 'function') {
const result = option.onSave(item);
if (typeof result?.then === 'function') {
return result.then(r => {
This._var.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._var.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;
});
className: 'icon-contact-type',
iconType: 'fa-light'
};
const nameCol = { key: 'Name', type: NoteCol, width: 160 };
const buttonCol = {
type: Grid.ColumnTypes.Icon,
width: 40,
visible: !recordReadonly,
align: 'center',
iconType: 'fa-light'
};
const createEditCol = (This) => {
return {
key: 'edit',
...buttonCol,
text: 'edit',
tooltip: r('P_WO_EDIT', 'Edit'),
events: {
onclick: function () {
const edit = new Contact({
getText: option.getText,
// onMasking: option.onMasking,
contact: this,
company: !nullOrEmpty(option.companyName),
onSave: (item, _op) => {
const exists =
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;
}
if (typeof option.onSave === 'function') {
const result = option.onSave(item);
if (typeof result?.then === 'function') {
return result.then(r => {
This._var.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._var.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;
});
}
return false;
}
return false;
}
}
});
edit.show(container);
});
edit.show(container);
}
}
}
}
};
// contacts from customer record
const grid = new Grid();
grid.height = 0;
grid.allowHtml = true;
grid.headerVisible = false;
grid.columns = [
selectedCol(this),
iconCol,
nameCol,
{ key: 'Email', width: 180 },
{ key: 'MobilePhoneDisplayText', width: 130 },
createEditCol(this),
{
key: 'delete',
...buttonCol,
text: 'times',
tooltip: r('P_WO_DELETE', 'Delete'),
events: {
onclick: function () {
showConfirm(
r('P_CU_REMOVECONTACT', 'Remove Contact'),
createElement('div', null,
createElement('div', div => {
div.style.paddingLeft = '16px';
div.innerText = r('P_CU_REMOVEFROM', 'Remove {name} from').replace('{name}', this.Name);
}),
createElement('div', div => {
div.style.display = 'flex';
div.style.justifyContent = 'center';
div.style.marginTop = '10px';
},
createRadiobox({
name: 'remove-type',
label: r('P_CUSTOMERRECORD', 'Customer Record'),
checked: true,
className: 'radio-customer-record'
};
// contacts from customer record
const grid = new Grid();
grid.height = 0;
grid.allowHtml = true;
grid.headerVisible = false;
grid.columns = [
selectedCol(this),
iconCol,
nameCol,
{ key: 'Email', width: 180 },
{ key: 'MobilePhoneDisplayText', width: 130 },
createEditCol(this),
{
key: 'delete',
...buttonCol,
text: 'times',
tooltip: r('P_WO_DELETE', 'Delete'),
events: {
onclick: function () {
showConfirm(
r('P_CU_REMOVECONTACT', 'Remove Contact'),
createElement('div', null,
createElement('div', div => {
div.style.paddingLeft = '16px';
div.innerText = r('P_CU_REMOVEFROM', 'Remove {name} from').replace('{name}', this.Name);
}),
createRadiobox({
name: 'remove-type',
label: r('P_WORKORDER', 'Work Order')
})
)
),
[
{ key: 'ok', text: r('P_WO_OK', 'OK') },
{ key: 'cancel', text: r('P_WO_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);
createElement('div', div => {
div.style.display = 'flex';
div.style.justifyContent = 'center';
div.style.marginTop = '10px';
},
createRadiobox({
name: 'remove-type',
label: r('P_CUSTOMERRECORD', 'Customer Record'),
checked: true,
className: 'radio-customer-record'
}),
createRadiobox({
name: 'remove-type',
label: r('P_WORKORDER', 'Work Order')
})
)
),
[
{ key: 'ok', text: r('P_WO_OK', 'OK') },
{ key: 'cancel', text: r('P_WO_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;
}
}
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;
}
}
});
});
}
}
}
}
];
grid.init(pop.container.querySelector('.contacts-record'));
const customerRecords = this._var.data.contacts.filter(c => c.Id >= 0).map(c => {
if (c.OptOut || c.OptOut_BC) {
];
grid.init(pop.container.querySelector('.contacts-record'));
const customerRecords = this._var.data.contacts.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;
}
if (typeof c.selected === 'undefined') {
c.selected = true;
}
return c;
});
grid.extraRows = customerRecords.filter(c => !nullOrEmpty(c.Notes)).length;
grid.source = customerRecords;
grid.onSelectedRowChanged = index => {
if (index >= 0 && this._var.gridWo.selectedIndexes?.length > 0) {
this._var.gridWo.selectedIndexes = [];
}
};
this._var.gridContact = grid;
});
grid.extraRows = customerRecords.filter(c => !nullOrEmpty(c.Notes)).length;
grid.source = customerRecords;
grid.onSelectedRowChanged = index => {
if (index >= 0 && this._var.gridWo.selectedIndexes?.length > 0) {
this._var.gridWo.selectedIndexes = [];
}
};
this._var.gridContact = grid;
// contacts from work order only
const gridWo = new Grid();
gridWo.height = 0;
gridWo.allowHtml = true;
gridWo.headerVisible = false;
gridWo.columns = [
selectedCol(this),
iconCol,
nameCol,
{ key: 'Email', width: 180 },
{ key: 'MobilePhoneDisplayText', width: 130 },
createEditCol(this),
{
key: 'delete',
...buttonCol,
text: 'times',
tooltip: r('P_WO_DELETE', 'Delete'),
events: {
onclick: function () {
showConfirm(r('P_CU_REMOVECONTACT', 'Remove Contact'), r('P_CU_REMOVEFROMWORKORDER', 'You are removing {name} from work order.\n\nDo you want to Continue?').replace('{name}', this.Name), [
{ key: 'continue', text: r('P_JS_CONTINUE', 'Continue') },
{ key: 'cancel', text: r('P_WO_CANCEL', 'Cancel') }
]).then(result => {
if (result?.key === 'continue') {
if (typeof option.onDelete === 'function') {
option.onDelete(result.key, this);
// contacts from work order only
const gridWo = new Grid();
gridWo.height = 0;
gridWo.allowHtml = true;
gridWo.headerVisible = false;
gridWo.columns = [
selectedCol(this),
iconCol,
nameCol,
{ key: 'Email', width: 180 },
{ key: 'MobilePhoneDisplayText', width: 130 },
createEditCol(this),
{
key: 'delete',
...buttonCol,
text: 'times',
tooltip: r('P_WO_DELETE', 'Delete'),
events: {
onclick: function () {
showConfirm(r('P_CU_REMOVECONTACT', 'Remove Contact'), r('P_CU_REMOVEFROMWORKORDER', 'You are removing {name} from work order.\n\nDo you want to Continue?').replace('{name}', this.Name), [
{ key: 'continue', text: r('P_JS_CONTINUE', 'Continue') },
{ key: 'cancel', text: r('P_WO_CANCEL', 'Cancel') }
]).then(result => {
if (result?.key === 'continue') {
if (typeof option.onDelete === 'function') {
option.onDelete(result.key, this);
}
const index = gridWo.source.indexOf(this);
if (index >= 0) {
const source = gridWo.source;
source.splice(index, 1);
gridWo.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
gridWo.source = source;
}
}
const index = gridWo.source.indexOf(this);
if (index >= 0) {
const source = gridWo.source;
source.splice(index, 1);
gridWo.extraRows = source.filter(c => !nullOrEmpty(c.Notes)).length;
gridWo.source = source;
}
}
});
});
}
}
}
}
];
gridWo.init(pop.container.querySelector('.contacts-wo'));
const workOrderOnly = this._var.data.contacts.filter(c => c.Id < 0).map(c => {
if (c.OptOut || c.OptOut_BC) {
];
gridWo.init(pop.container.querySelector('.contacts-wo'));
const workOrderOnly = this._var.data.contacts.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;
}
if (typeof c.selected === 'undefined') {
c.selected = true;
}
return c;
});
gridWo.extraRows = workOrderOnly.filter(c => !nullOrEmpty(c.Notes)).length;
gridWo.source = workOrderOnly;
gridWo.onSelectedRowChanged = index => {
if (index >= 0 && this._var.gridContact.selectedIndexes?.length > 0) {
this._var.gridContact.selectedIndexes = [];
}
};
this._var.gridWo = gridWo;
});
gridWo.extraRows = workOrderOnly.filter(c => !nullOrEmpty(c.Notes)).length;
gridWo.source = workOrderOnly;
gridWo.onSelectedRowChanged = index => {
if (index >= 0 && this._var.gridContact.selectedIndexes?.length > 0) {
this._var.gridContact.selectedIndexes = [];
};
if (nullOrEmpty(option.companyName)) {
showConfirm(
r('P_CU_EDITCONTACTS', 'Edit Contacts'),
r('P_CUSTOMER_ADDCOMPANYPROMPT', 'There is no company associated with this work order. Would you like to add one?\n\nIf no company is indicated, contacts must be added as "Work Order Only".'),
[
{ key: 'add', text: r('P_CUSTOMER_ADDCOMPANY', 'Add Company') },
{ key: 'skip', text: r('P_CUSTOMER_SKIPTHISSTEP', 'Skip This Step') }
]
).then(r => {
if (r == null) {
return;
}
};
this._var.gridWo = gridWo;
});
if (r.key === 'add') {
if (typeof option.onAddCompany === 'function') {
option.onAddCompany.call(this);
}
} else {
editContacts();
}
});
} else {
editContacts();
}
});
})
),

View File

@ -90,6 +90,33 @@
>div {
flex: 1 1 auto;
>.title-company {
line-height: 1rem;
padding: 2px 10px;
// background-color: rgba(0, 0, 0, .15);
>.title-company-name {
font-weight: bold;
}
>.title-company-selector {
cursor: pointer;
vertical-align: middle;
&:hover {
background-color: #ccc;
}
>svg {
width: 14px;
height: 14px;
fill: rgb(123, 28, 33);
margin: 0 5px 3px;
vertical-align: middle;
}
}
}
}
>.title-functions {