communication fix

This commit is contained in:
2023-04-13 17:36:42 +08:00
parent d9beb0d3b3
commit d702197a3f
11 changed files with 365 additions and 218 deletions

@@ -45,6 +45,38 @@ class Contact {
txt.maxLength = 2000;
txt.style.height = '100px';
});
const buttons = [];
if (this.#option.company) {
buttons.push({
text: c == null ? r('addContactRecord', 'Add Contact Record') : r('editContactRecord', 'Edit Contact Record'),
trigger: () => {
const item = this.prepare();
if (item == null) {
return false;
}
item.SaveToCustomer = 1;
if (typeof this.#option.onSave === 'function') {
return this.#option.onSave.call(this, item, c == null);
}
}
});
}
buttons.push(
{
text: r('workOrderOnly', 'Work Order Only'),
trigger: () => {
const item = this.prepare();
if (item == null) {
return false;
}
item.SaveToCustomer = 0;
if (typeof this.#option.onSave === 'function') {
return this.#option.onSave.call(this, item, c == null);
}
}
},
{ text: r('cancel', 'Cancel') }
);
const popup = createPopup(
c == null ? r('addContact', 'Add Contact') : r('editContact', 'Edit Contact'),
createElement('div', wrapper => {
@@ -76,33 +108,7 @@ class Contact {
contactNotes
)
),
{
text: c == null ? r('addContactRecord', 'Add Contact Record') : r('editContactRecord', 'Edit Contact Record'),
trigger: () => {
const item = this.prepare();
if (item == null) {
return false;
}
item.SaveToCustomer = 1;
if (typeof this.#option.onSave === 'function') {
return this.#option.onSave.call(this, item, c == null);
}
}
},
{
text: r('workOrderOnly', 'Work Order Only'),
trigger: () => {
const item = this.prepare();
if (item == null) {
return false;
}
item.SaveToCustomer = 0;
if (typeof this.#option.onSave === 'function') {
return this.#option.onSave.call(this, item, c == null);
}
}
},
{ text: r('cancel', 'Cancel') }
...buttons
)
if (c != null) {
contactName.value = c.Name;
@@ -128,35 +134,42 @@ class Contact {
}
prepare() {
const item = {
'Id': this.#option.contact?.Id,
'Name': this.#refs.contactName.value,
'ContactPreference': this.#refs.preferences.selected.value,
'Email': this.#refs.contactEmail.value,
'MobilePhone': this.#refs.contactMobile.value,
'OptOut': this.#refs.checkOpt.querySelector('input').checked,
'Notes': this.#refs.contactNotes.value
};
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('addContact', 'Add Contact') : r('editContact', 'Edit Contact');
if (nullOrEmpty(item.Name)) {
if (nullOrEmpty(name)) {
showAlert(title, r('contactNameRequired', 'Contact Name cannot be empty.'), 'warn')
.then(() => this.#refs.contactName.focus());
return null;
}
if (nullOrEmpty(item.Email) && nullOrEmpty(item.MobilePhone)) {
if (nullOrEmpty(email) && nullOrEmpty(phone)) {
showAlert(title, r('contactEmailPhoneRequired', 'Email and Mobile Phone cannot both be empty.'), 'warn')
.then(() => nullOrEmpty(item.Email) ?
.then(() => nullOrEmpty(email) ?
this.#refs.contactEmail.focus() :
this.#refs.contactMobile.focus());
return null;
}
if (!nullOrEmpty(item.Email) && !isEmail(item.Email)) {
if (!nullOrEmpty(email) && !isEmail(email)) {
showAlert(title, r('contactEmailInvalid', 'The email address is invalid.'), 'warn')
.then(() => this.#refs.contactEmail.focus());
return null;
}
return item;
let contact = this.#option.contact;
if (contact == null) {
contact = {};
}
contact.Name = name;
contact.ContactPreference = pref;
contact.Email = email;
contact.MobilePhone = phone;
contact.OptOut = opt;
contact.Notes = notes;
return contact;
}
}