sync
This commit is contained in:
@ -4,11 +4,10 @@ import { isEmail, nullOrEmpty, r as lang } from "../../utility";
|
||||
let r = lang;
|
||||
|
||||
export class Contact {
|
||||
#option;
|
||||
#refs;
|
||||
_var = {};
|
||||
|
||||
constructor(option = {}) {
|
||||
this.#option = option;
|
||||
this._var.option = option;
|
||||
const getText = option?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
@ -18,7 +17,7 @@ export class Contact {
|
||||
async show(parent = document.body) {
|
||||
const tabIndex = Math.max.apply(null, [...document.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0)) + 3;
|
||||
|
||||
const c = this.#option.contact;
|
||||
const c = this._var.option.contact;
|
||||
const contactName = createElement('input', input => {
|
||||
input.type = 'text';
|
||||
input.className = 'ui-input';
|
||||
@ -54,7 +53,7 @@ export class Contact {
|
||||
txt.style.height = '100px';
|
||||
});
|
||||
const buttons = [];
|
||||
if (this.#option.company) {
|
||||
if (this._var.option.company) {
|
||||
buttons.push({
|
||||
text: c == null ? r('P_WO_ADDCONTACTRECORD', 'Add Contact Record') : r('P_WO_EDITCONTACTRECORD', 'Edit Contact Record'),
|
||||
// tabIndex: tabIndex + 7,
|
||||
@ -64,8 +63,8 @@ export class Contact {
|
||||
return false;
|
||||
}
|
||||
item.SaveToCustomer = 1;
|
||||
if (typeof this.#option.onSave === 'function') {
|
||||
return this.#option.onSave.call(this, item, 'customerrecord');
|
||||
if (typeof this._var.option.onSave === 'function') {
|
||||
return this._var.option.onSave.call(this, item, 'customerrecord');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -81,8 +80,8 @@ export class Contact {
|
||||
}
|
||||
//item.Id = -1;
|
||||
item.SaveToCustomer = 0;
|
||||
if (typeof this.#option.onSave === 'function') {
|
||||
return this.#option.onSave.call(this, item, 'workorder');
|
||||
if (typeof this._var.option.onSave === 'function') {
|
||||
return this._var.option.onSave.call(this, item, 'workorder');
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -92,7 +91,7 @@ export class Contact {
|
||||
}
|
||||
);
|
||||
const popup = new Popup({
|
||||
onMasking: this.#option.onMasking,
|
||||
onMasking: this._var.option.onMasking,
|
||||
title: c == null ? r('P_CR_ADDCONTACT', 'Add Contact') : r('P_CR_EDITCONTACT', 'Edit Contact'),
|
||||
content: createElement('div', wrapper => {
|
||||
wrapper.className = 'setting-wrapper';
|
||||
@ -135,7 +134,7 @@ export class Contact {
|
||||
} else {
|
||||
preferences.select('0');
|
||||
}
|
||||
this.#refs = {
|
||||
this._var.refs = {
|
||||
contactName,
|
||||
preferences,
|
||||
contactEmail,
|
||||
@ -149,35 +148,35 @@ export class Contact {
|
||||
}
|
||||
|
||||
prepare() {
|
||||
const name = this.#refs.contactName.value;
|
||||
const pref = this.#refs.preferences.selected.value;
|
||||
const email = this.#refs.contactEmail.value;
|
||||
const phone = this.#refs.contactMobile.value;
|
||||
const opt = this.#refs.checkOpt.querySelector('input').checked;
|
||||
const notes = this.#refs.contactNotes.value;
|
||||
const title = this.#option.contact == null ? r('P_CR_ADDCONTACT', 'Add Contact') : r('P_CR_EDITCONTACT', 'Edit Contact');
|
||||
const name = this._var.refs.contactName.value;
|
||||
const pref = this._var.refs.preferences.selected.value;
|
||||
const email = this._var.refs.contactEmail.value;
|
||||
const phone = this._var.refs.contactMobile.value;
|
||||
const opt = this._var.refs.checkOpt.querySelector('input').checked;
|
||||
const notes = this._var.refs.contactNotes.value;
|
||||
const title = this._var.option.contact == null ? r('P_CR_ADDCONTACT', 'Add Contact') : r('P_CR_EDITCONTACT', 'Edit Contact');
|
||||
if (nullOrEmpty(name)) {
|
||||
showAlert(title, r('P_CR_CONTACTNAMECANNOTBEEMPTY', 'Contact Name cannot be empty.'), 'warn')
|
||||
.then(() => this.#refs.contactName.focus());
|
||||
.then(() => this._var.refs.contactName.focus());
|
||||
return null;
|
||||
}
|
||||
if ((pref == 0 || pref == 2) && nullOrEmpty(phone)) {
|
||||
showAlert(title, r('P_CR_MOBILECANNOTBEEMPTY', 'Mobile cannot be empty.'), 'warn')
|
||||
.then(() => this.#refs.contactMobile.focus());
|
||||
.then(() => this._var.refs.contactMobile.focus());
|
||||
return null;
|
||||
}
|
||||
if (pref == 1 && nullOrEmpty(email)) {
|
||||
showAlert(title, r('P_CU_EMAILCANNOTBEEMPTY', 'Email cannot be empty.'), 'warn')
|
||||
.then(() => this.#refs.contactEmail.focus());
|
||||
.then(() => this._var.refs.contactEmail.focus());
|
||||
return null;
|
||||
}
|
||||
if (!nullOrEmpty(email) && !isEmail(email)) {
|
||||
showAlert(title, r('P_CR_EMAILISNOTAVALIDEMAILADDRESS', 'The email address is invalid.'), 'warn')
|
||||
.then(() => this.#refs.contactEmail.focus());
|
||||
.then(() => this._var.refs.contactEmail.focus());
|
||||
return null;
|
||||
}
|
||||
|
||||
let contact = this.#option.contact;
|
||||
let contact = this._var.option.contact;
|
||||
if (contact == null) {
|
||||
contact = {};
|
||||
} else if (contact.OptOut !== opt) {
|
||||
@ -198,11 +197,10 @@ export class Contact {
|
||||
}
|
||||
|
||||
export class CustomerRecordContact {
|
||||
#option;
|
||||
#grid;
|
||||
_var = {};
|
||||
|
||||
constructor(option = {}) {
|
||||
this.#option = option;
|
||||
this._var.option = option;
|
||||
const getText = option?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
@ -214,7 +212,7 @@ export class CustomerRecordContact {
|
||||
|
||||
const gridContainer = createElement('div', 'selcontact-grid');
|
||||
const popup = new Popup({
|
||||
onMasking: this.#option.onMasking,
|
||||
onMasking: this._var.option.onMasking,
|
||||
title,
|
||||
content: createElement('div', 'selcontact-wrapper',
|
||||
gridContainer
|
||||
@ -224,8 +222,8 @@ export class CustomerRecordContact {
|
||||
text: r('P_WO_OK', 'OK'),
|
||||
key: 'ok',
|
||||
trigger: () => {
|
||||
if (typeof this.#option.onOk === 'function') {
|
||||
return this.#option.onOk.call(this, this.#grid.source.filter(f => f.selected));
|
||||
if (typeof this._var.option.onOk === 'function') {
|
||||
return this._var.option.onOk.call(this, this._var.grid.source.filter(f => f.selected));
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -250,16 +248,16 @@ export class CustomerRecordContact {
|
||||
{ key: 'Notes', caption: r("P_CR_NOTES", "Notes"), width: 120 }
|
||||
];
|
||||
grid.init();
|
||||
grid.source = this.#option.contacts.sort(function (a, b) { return ((b.Text || b.Email) ? 1 : 0) - ((a.Text || a.Email) ? 1 : 0) });
|
||||
this.#grid = grid;
|
||||
grid.source = this._var.option.contacts.sort(function (a, b) { return ((b.Text || b.Email) ? 1 : 0) - ((a.Text || a.Email) ? 1 : 0) });
|
||||
this._var.grid = grid;
|
||||
return result;
|
||||
}
|
||||
|
||||
set source(contacts) {
|
||||
this.#option.contacts = contacts;
|
||||
const grid = this.#grid;
|
||||
this._var.option.contacts = contacts;
|
||||
const grid = this._var.grid;
|
||||
if (grid != null) {
|
||||
this.#grid.source = contacts;
|
||||
this._var.grid.source = contacts;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user