sync
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import { Grid, Dropdown, createElement, createCheckbox, Popup, showAlert } from "../../ui";
|
||||
import { isEmail, nullOrEmpty, r } from "../../utility";
|
||||
import { isEmail, nullOrEmpty, r as lang } from "../../utility";
|
||||
|
||||
let r = lang;
|
||||
|
||||
export class Contact {
|
||||
#option;
|
||||
@ -7,6 +9,10 @@ export class Contact {
|
||||
|
||||
constructor(option = {}) {
|
||||
this.#option = option;
|
||||
const getText = option?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
}
|
||||
}
|
||||
|
||||
async show(parent = document.body) {
|
||||
@ -22,9 +28,9 @@ export class Contact {
|
||||
});
|
||||
const preferences = new Dropdown({ tabIndex: tabIndex + 2 });
|
||||
preferences.source = [
|
||||
{ value: '0', text: r('text', 'Text') },
|
||||
{ value: '1', text: r('email', 'Email') },
|
||||
{ value: '2', text: r('phone', 'Phone') }
|
||||
{ value: '0', text: r('P_CR_TEXT', 'Text') },
|
||||
{ value: '1', text: r('P_CR_EMAIL', 'Email') },
|
||||
{ value: '2', text: r('P_CR_PHONE', 'Phone') }
|
||||
];
|
||||
const contactEmail = createElement('input', input => {
|
||||
input.type = 'email';
|
||||
@ -50,7 +56,7 @@ export class Contact {
|
||||
const buttons = [];
|
||||
if (this.#option.company) {
|
||||
buttons.push({
|
||||
text: c == null ? r('addContactRecord', 'Add Contact Record') : r('editContactRecord', 'Edit Contact Record'),
|
||||
text: c == null ? r('P_WO_ADDCONTACTRECORD', 'Add Contact Record') : r('P_WO_EDITCONTACTRECORD', 'Edit Contact Record'),
|
||||
// tabIndex: tabIndex + 7,
|
||||
trigger: () => {
|
||||
const item = this.prepare();
|
||||
@ -66,7 +72,7 @@ export class Contact {
|
||||
}
|
||||
buttons.push(
|
||||
{
|
||||
text: r('workOrderOnly', 'Work Order Only'),
|
||||
text: r('P_WO_WORKORDERONLY', 'Work Order Only'),
|
||||
// tabIndex: tabIndex + 8,
|
||||
trigger: () => {
|
||||
const item = this.prepare();
|
||||
@ -81,39 +87,39 @@ export class Contact {
|
||||
}
|
||||
},
|
||||
{
|
||||
text: r('cancel', 'Cancel'),
|
||||
text: r('P_WO_CANCEL', 'Cancel'),
|
||||
// tabIndex: tabIndex + 9
|
||||
}
|
||||
);
|
||||
const popup = new Popup({
|
||||
onMasking: this.#option.onMasking,
|
||||
title: c == null ? r('addContact', 'Add Contact') : r('editContact', 'Edit Contact'),
|
||||
title: c == null ? r('P_CR_ADDCONTACT', 'Add Contact') : r('P_CR_EDITCONTACT', 'Edit Contact'),
|
||||
content: createElement('div', wrapper => {
|
||||
wrapper.className = 'setting-wrapper';
|
||||
wrapper.style.width = '500px';
|
||||
},
|
||||
createElement('div', 'setting-item',
|
||||
createElement('span', 'setting-label setting-required', r('contactNameColon', 'Contact Name:')),
|
||||
createElement('span', 'setting-label setting-required', r('P_CR_CONTACTNAME_COLON', 'Contact Name:')),
|
||||
contactName
|
||||
),
|
||||
createElement('div', 'setting-item',
|
||||
createElement('span', 'setting-label', r('contactPreferencesColon', 'Contact Preferences:')),
|
||||
createElement('span', 'setting-label', r('P_CR_CONTACTPREFERENCES_COLON', 'Contact Preferences:')),
|
||||
preferences.create()
|
||||
),
|
||||
createElement('div', 'setting-item',
|
||||
createElement('span', 'setting-label', r('contactEmailColon', 'Email Address:')),
|
||||
createElement('span', 'setting-label', r('P_CR_EMAILADDRESS_COLON', 'Email Address:')),
|
||||
contactEmail
|
||||
),
|
||||
createElement('div', 'setting-item',
|
||||
createElement('span', 'setting-label', r('contactMobileColon', 'Mobile:')),
|
||||
createElement('span', 'setting-label', r('P_WO_MOBILE_COLON', 'Mobile:')),
|
||||
contactMobile
|
||||
),
|
||||
createElement('div', 'setting-item',
|
||||
createElement('span', 'setting-label', r('contactOptColon', 'Opt Out:')),
|
||||
createElement('span', 'setting-label', r('P_CR_OPTOUT_COLON', 'Opt Out:')),
|
||||
checkOpt
|
||||
),
|
||||
createElement('div', 'setting-item',
|
||||
createElement('span', 'setting-label', r('contactNotesColon', 'Notes:')),
|
||||
createElement('span', 'setting-label', r('P_CR_NOTES_COLON', 'Notes:')),
|
||||
contactNotes
|
||||
)
|
||||
),
|
||||
@ -149,24 +155,24 @@ export class Contact {
|
||||
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('addContact', 'Add Contact') : r('editContact', 'Edit Contact');
|
||||
const title = this.#option.contact == null ? r('P_CR_ADDCONTACT', 'Add Contact') : r('P_CR_EDITCONTACT', 'Edit Contact');
|
||||
if (nullOrEmpty(name)) {
|
||||
showAlert(title, r('contactNameRequired', 'Contact Name cannot be empty.'), 'warn')
|
||||
showAlert(title, r('P_CR_CONTACTNAMECANNOTBEEMPTY', 'Contact Name cannot be empty.'), 'warn')
|
||||
.then(() => this.#refs.contactName.focus());
|
||||
return null;
|
||||
}
|
||||
if ((pref == 0 || pref == 2) && nullOrEmpty(phone)) {
|
||||
showAlert(title, r('contactPhoneRequired', 'Mobile cannot be empty.'), 'warn')
|
||||
showAlert(title, r('P_CR_MOBILECANNOTBEEMPTY', 'Mobile cannot be empty.'), 'warn')
|
||||
.then(() => this.#refs.contactMobile.focus());
|
||||
return null;
|
||||
}
|
||||
if (pref == 1 && nullOrEmpty(email)) {
|
||||
showAlert(title, r('contactEmailRequired', 'Email cannot be empty.'), 'warn')
|
||||
showAlert(title, r('P_CU_EMAILCANNOTBEEMPTY', 'Email cannot be empty.'), 'warn')
|
||||
.then(() => this.#refs.contactEmail.focus());
|
||||
return null;
|
||||
}
|
||||
if (!nullOrEmpty(email) && !isEmail(email)) {
|
||||
showAlert(title, r('contactEmailInvalid', 'The email address is invalid.'), 'warn')
|
||||
showAlert(title, r('P_CR_EMAILISNOTAVALIDEMAILADDRESS', 'The email address is invalid.'), 'warn')
|
||||
.then(() => this.#refs.contactEmail.focus());
|
||||
return null;
|
||||
}
|
||||
@ -197,6 +203,10 @@ export class CustomerRecordContact {
|
||||
|
||||
constructor(option = {}) {
|
||||
this.#option = option;
|
||||
const getText = option?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
}
|
||||
}
|
||||
|
||||
async show(title, parent = document.body) {
|
||||
@ -211,7 +221,7 @@ export class CustomerRecordContact {
|
||||
),
|
||||
buttons: [
|
||||
{
|
||||
text: r('ok', 'OK'),
|
||||
text: r('P_WO_OK', 'OK'),
|
||||
key: 'ok',
|
||||
trigger: () => {
|
||||
if (typeof this.#option.onOk === 'function') {
|
||||
@ -219,7 +229,7 @@ export class CustomerRecordContact {
|
||||
}
|
||||
}
|
||||
},
|
||||
{ text: r('cancel', 'Cancel'), key: 'cancel' }
|
||||
{ text: r('P_WO_CANCEL', 'Cancel'), key: 'cancel' }
|
||||
]
|
||||
});
|
||||
const result = await popup.show(parent);
|
||||
|
Reference in New Issue
Block a user