app change

This commit is contained in:
2023-04-11 17:34:13 +08:00
parent c38e486d7d
commit cc3d11f617
14 changed files with 385 additions and 98 deletions

View File

@ -5,7 +5,7 @@ import { nullOrEmpty } from "../../utility/strings";
import { formatUrl, isEmail, isPhone } from "../../utility";
import { setTooltip } from "../../ui/tooltip";
import { createIcon } from "../../ui/icon";
import { createCheckbox } from "../../ui/checkbox";
import { createCheckbox, createRadiobox } from "../../ui/checkbox";
import { createBox } from "./lib";
import { createPopup, showAlert, showConfirm } from "../../ui/popup";
import Grid from "../../ui/grid";
@ -13,9 +13,7 @@ import Contact from "./contact";
class NoteCol extends Grid.GridColumn {
static create() {
const wrapper = createElement('div', div => {
div.style.width = '100px';
},
const wrapper = createElement('div', 'contact-wrapper',
createElement('div', 'contact-name'),
createElement('div', 'contact-note')
);
@ -41,6 +39,8 @@ class CustomerCommunication {
#message;
#data = {};
#gridContact;
#gridWo;
#gridFollower;
constructor(opt) {
this.#option = opt ?? {};
@ -107,7 +107,7 @@ class CustomerCommunication {
}
#createContactItem(c) {
if (c.OptOut || c.OptOut_BC) {
if (c.OptOut || c.OptOut_BC || c.selected === false) {
return null;
}
const mp = String(c.MobilePhone).trim();
@ -160,6 +160,17 @@ class CustomerCommunication {
this.#enter.disabled = flag === true;
}
/**
* @param {boolean} flag
*/
set recordReadonly(flag) {
this.#option.recordReadonly = flag;
if (this.#container == null) {
return;
}
this.#container.querySelector('.button-edit-contacts').style.display = flag === true ? 'none' : '';
}
get followers() {
return [...this.#followers.children].map(el => {
const span = el.querySelector('span');
@ -167,6 +178,7 @@ class CustomerCommunication {
});
}
set followers(followers) {
this.#data.followers = followers;
this.#followers.replaceChildren();
if (followers?.length > 0) {
this.#container.querySelector('.follower-bar').style.display = '';
@ -243,7 +255,7 @@ class CustomerCommunication {
createElement('button', button => {
button.className = 'roundbtn button-edit-contacts';
button.style.backgroundColor = 'rgb(1, 199, 172)';
if (readonly === true) {
if (readonly === true || option.recordReadonly) {
button.style.display = 'none';
}
button.appendChild(createIcon('fa-solid', 'user-edit'));
@ -286,10 +298,14 @@ class CustomerCommunication {
}
if (typeof option.onSave === 'function') {
const result = option.onSave(item, true);
if (result !== false) {
this.#gridContact.reload();
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);
return r;
});
}
return result;
return false;
}
}
});
@ -321,11 +337,18 @@ class CustomerCommunication {
)
);
pop.show(container).then(() => {
const selectedCol = {
key: 'selected',
type: Grid.ColumnTypes.Checkbox,
width: 50,
enabled: item => !item.OptOut && !item.OptOut_BC
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.#gridContact.source.concat(This.#gridWo.source));
}
}
}
};
const iconCol = {
key: 'type',
@ -342,7 +365,7 @@ class CustomerCommunication {
align: 'center',
iconType: 'fa-light'
};
const createEditCol = grid => {
const createEditCol = (This) => {
return {
key: 'edit',
...buttonCol,
@ -353,17 +376,23 @@ class CustomerCommunication {
const edit = new Contact({
contact: this,
onSave: item => {
const exists = grid.source.some(s => s !== this && s.Name === item.Name && s.MobilePhone === item.MobilePhone);
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);
if (exists) {
showAlert(r('editContact', 'Edit Contact'), r('contactUniqueRequired', 'Contact name and contact mobile must be a unique combination.'), 'warn');
return false;
}
if (typeof option.onSave === 'function') {
const result = option.onSave(item);
if (result !== false) {
grid.refresh();
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);
return r;
});
}
return result;
return false;
}
}
});
@ -378,7 +407,7 @@ class CustomerCommunication {
grid.allowHtml = true;
grid.headerVisible = false;
grid.columns = [
selectedCol,
selectedCol(this),
iconCol,
nameCol,
{ key: 'Email', width: 180 },
@ -391,23 +420,45 @@ class CustomerCommunication {
tooltip: r('delete', 'Delete'),
events: {
onclick: function () {
showConfirm(r('remoteContact', 'Remove Contact'), r('removeFromCustomer', 'You are removing {name} from customer record.\n\nDo you want to Continue?').replace('{name}', this.Name), [
{ key: 'continue', text: r('continue', 'Continue') },
{ key: 'cancel', text: r('cancel', 'Cancel') }
]).then(result => {
if (result === 'continue') {
if (typeof option.onDelete === 'function') {
option.onDelete(result, this, true);
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.display = 'flex';
div.style.justifyContent = 'center';
div.style.marginTop = '10px';
},
createRadiobox({
name: 'remove-type',
label: r('customerRecord', 'Customer Record'),
checked: true,
className: 'radio-customer-record'
}),
createRadiobox({
name: 'remove-type',
label: r('workOrder', 'Work Order')
})
)
),
[
{ 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;
}
}
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;
}
}
});
});
}
}
}
@ -432,7 +483,7 @@ class CustomerCommunication {
gridWo.allowHtml = true;
gridWo.headerVisible = false;
gridWo.columns = [
selectedCol,
selectedCol(this),
iconCol,
nameCol,
{ key: 'Email', width: 180 },
@ -449,9 +500,9 @@ class CustomerCommunication {
{ key: 'continue', text: r('continue', 'Continue') },
{ key: 'cancel', text: r('cancel', 'Cancel') }
]).then(result => {
if (result === 'continue') {
if (result?.key === 'continue') {
if (typeof option.onDelete === 'function') {
option.onDelete(result, this);
option.onDelete(result.key, this);
}
const index = gridWo.source.indexOf(this);
if (index >= 0) {
@ -478,6 +529,7 @@ class CustomerCommunication {
});
gridWo.extraRows = workOrderOnly.filter(c => !nullOrEmpty(c.Notes)).length;
gridWo.source = workOrderOnly;
this.#gridWo = gridWo;
});
});
})
@ -512,7 +564,116 @@ class CustomerCommunication {
button.appendChild(createIcon('fa-solid', 'pen'));
setTooltip(button, r('editFollower', 'Edit Followers'));
button.addEventListener('click', () => {
// TODO:
const pop = createPopup(
createElement('div', div => {
div.style.display = 'flex';
div.style.alignItems = 'center';
div.append(
createElement('div', div => {
div.className = 'popup-move';
div.style.flex = '1 1 auto';
div.innerText = r('editContacts', 'Edit Contacts') + '\n' + r('followers', 'Followers');
}),
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-follower';
button.appendChild(createIcon('fa-solid', 'user-plus', {
width: '16px',
height: '16px'
}));
button.addEventListener('click', () => {
/*const add = new Contact({
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');
return false;
}
if (typeof option.onSave === 'function') {
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);
return r;
});
}
return false;
}
}
});
add.show(container);
*/
});
setTooltip(button, r('addFollower', 'Add Follower'))
})
)
}),
createElement('div', null,
createElement('div', div => {
div.style.fontWeight = 'bold';
div.innerText = r('contactFromRecord', 'Contacts from Customer Record');
}),
createElement('div', div => {
div.className = 'followers-record';
div.style.maxHeight = '400px';
div.style.width = '660px';
})
)
);
pop.show(container).then(() => {
const grid = new Grid();
grid.height = 0;
grid.allowHtml = true;
grid.headerVisible = false;
grid.columns = [
{
key: 'type',
type: Grid.ColumnTypes.Icon,
width: 50,
filter: c => String(c.ContactPreference) === '0' ? 'comment-lines' : 'envelope',
className: 'icon-contact-type',
iconType: 'fa-light'
},
{ key: 'Name', width: 160 },
{ key: 'Email', width: 180 },
{ key: 'MobilePhone', width: 130 },
{
key: 'delete',
type: Grid.ColumnTypes.Icon,
width: 40,
align: 'center',
iconType: 'fa-light',
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;
}
}
});
}
}
}
];
grid.init(pop.container.querySelector('.followers-record'));
grid.source = this.#data.followers;
this.#gridFollower = grid;
});
});
})
)

View File

@ -13,7 +13,6 @@
--dark-fore-opacity-color: rgba(255, 255, 255, .6);
--strong-color: #333;
--light-color: #ccc;
--medium-font-size: .875rem;
}
.roundbtn {
@ -179,7 +178,7 @@
>span {
flex: 1 1 auto;
color: var(--strong-color);
font-size: var(--medium-font-size);
font-size: var(--font-larger-size);
overflow: hidden;
text-overflow: ellipsis;
padding-right: 10px;
@ -318,11 +317,16 @@
.popup-mask .grid {
height: 100%;
min-height: 120px;
overflow: hidden;
>.grid-body .grid-body-content>.grid-row>td {
vertical-align: top;
.col-icon {
padding: 10px 4px 10px 8px;
}
.icon-contact-type {
cursor: unset;
@ -335,13 +339,18 @@
}
}
.contact-name {
overflow: hidden;
text-overflow: ellipsis;
}
.contact-wrapper {
width: 100px;
padding: var(--spacing-cell);
.contact-note {
color: #999;
.contact-name {
overflow: hidden;
text-overflow: ellipsis;
}
.contact-note {
color: #999;
}
}
}
}