sync working code, and import type-doc

This commit is contained in:
2023-07-17 17:24:49 +08:00
parent 7ab7a7094a
commit 3e9ee59178
43 changed files with 1024 additions and 1553 deletions

View File

@ -155,11 +155,14 @@ class Contact {
.then(() => this.#refs.contactName.focus());
return null;
}
if (nullOrEmpty(email) && nullOrEmpty(phone)) {
showAlert(title, r('contactEmailPhoneRequired', 'Email and Mobile Phone cannot both be empty.'), 'warn')
.then(() => nullOrEmpty(email) ?
this.#refs.contactEmail.focus() :
this.#refs.contactMobile.focus());
if ((pref == 0 || pref == 2) && nullOrEmpty(phone)) {
showAlert(title, r('contactPhoneRequired', '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')
.then(() => this.#refs.contactEmail.focus());
return null;
}
if (!nullOrEmpty(email) && !isEmail(email)) {
@ -176,6 +179,8 @@ class Contact {
contact.selected = !opt;
}
}
contact.OldName = contact.Name;
contact.OldMobilePhone = contact.MobilePhone;
contact.Name = name;
contact.ContactPreference = pref;
contact.Email = email;

View File

@ -10,6 +10,8 @@ interface InitConfig {
}
export class CustomerCommunication {
constructor (opt: InitConfig);
get autoUpdatesEnabled(): boolean;
set autoUpdatesEnabled(enabled: boolean);
get autoUpdates(): boolean;
@ -21,8 +23,4 @@ export class CustomerCommunication {
set statusLink(checked: boolean);
create(): HTMLElement;
}
declare var CustomerCommunication: {
new(opt: InitConfig): CustomerCommunication
}

View File

@ -1,10 +1,10 @@
import { Grid, createElement, setTooltip, createIcon, createCheckbox, createRadiobox, showAlert, showConfirm, Popup } from "../../ui";
import { Grid, GridColumn, createElement, setTooltip, createIcon, createCheckbox, createRadiobox, showAlert, showConfirm, Popup, createPicture, createAudio, createVideo, createPdf, createSmilefile, createVcard, createVideofile, createFile } from "../../ui";
import { r, nullOrEmpty, formatUrl, isEmail, isPhone } from "../../utility";
import { createBox } from "./lib";
import { Contact, CustomerRecordContact } from "./contact";
import Follower from "./follower";
class NoteCol extends Grid.GridColumn {
class NoteCol extends GridColumn {
static create() {
const wrapper = createElement('div', 'contact-wrapper',
createElement('div', 'contact-name'),
@ -19,7 +19,12 @@ class NoteCol extends Grid.GridColumn {
if (name.scrollWidth > name.offsetWidth) {
setTooltip(name, item.Name, false, grid.element);
}
element.querySelector('.contact-note').innerText = item.Notes;
const notes = element.querySelector('.contact-note');
notes.innerText = item.Notes;
if (notes.scrollWidth > notes.offsetWidth) {
setTooltip(notes, item.Notes, false, grid.element);
}
}
}
@ -243,14 +248,15 @@ class CustomerCommunication {
* @param {String} code
*/
set companyCode(code) {
this.#option.companyCode = code;
const option = this.#option;
option.companyCode = code;
const div = this.#container.querySelector('.title-company');
if (nullOrEmpty(this.#option.companyName)) {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
} else {
div.innerText = this.#option.companyName;
div.innerText = option.companyName;
if (!nullOrEmpty(code))
div.innerText = this.#option.companyName + "/" + code;
div.innerText = option.companyName + "/" + code;
div.style.display = '';
}
}
@ -432,11 +438,15 @@ class CustomerCommunication {
button.addEventListener('click', () => {
const val = this.#enter.value;
if (nullOrEmpty(val?.trim())) {
showAlert(r('error', 'Error'), r('messageRequired', 'Please input the message.'), 'warn');
const p = showAlert(r('error', 'Error'), r('messageRequired', 'Please input the message.'), 'warn');
if (typeof option.onMasking === 'function') {
option.onMasking(true);
p.then(() => option.onMasking(false));
}
return;
}
if (typeof this.#option.onAddMessage === 'function') {
this.#option.onAddMessage(this.#enter.value);
if (typeof option.onAddMessage === 'function') {
option.onAddMessage(this.#enter.value);
}
})
})
@ -514,12 +524,12 @@ class CustomerCommunication {
// onMasking: option.onMasking,
contacts: [],
onOk: list => {
if (typeof this.#option.onSelectCRContacts === 'function') {
if (typeof option.onSelectCRContacts === 'function') {
list?.map(c => {
delete c.selected;
return c;
});
const result = this.#option.onSelectCRContacts(list);
const result = option.onSelectCRContacts(list);
}
const r = this.#data.contacts;
this.#gridContact.source = r.filter(c => c.Id >= 0).map(c => {
@ -545,8 +555,8 @@ class CustomerCommunication {
var title = r('selectFromCustomerRecord', 'Select from Customer Record');
sel.show(title, container);
if (typeof this.#option.onOpenSelectCRContacts === 'function') {
const result = this.#option.onOpenSelectCRContacts();
if (typeof option.onOpenSelectCRContacts === 'function') {
const result = option.onOpenSelectCRContacts();
if (typeof result?.then === 'function') {
return result.then(r => {
r.map(c => {
@ -595,7 +605,7 @@ class CustomerCommunication {
button.addEventListener('click', () => {
const add = new Contact({
// onMasking: option.onMasking,
company: !nullOrEmpty(this.#option.companyName),
company: !nullOrEmpty(option.companyName),
onSave: item => {
const exists = this.#gridContact.source.some(s => s.Name === item.Name && s.MobilePhone === item.MobilePhone);
if (exists) {
@ -639,14 +649,14 @@ class CustomerCommunication {
}),
content: createElement('div', null,
createElement('div', div => {
if (nullOrEmpty(this.#option.companyName)) {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
}
div.style.fontWeight = 'bold';
div.innerText = r('contactFromRecord', 'Contacts from Customer Record');
}),
createElement('div', div => {
if (nullOrEmpty(this.#option.companyName)) {
if (nullOrEmpty(option.companyName)) {
div.style.display = 'none';
}
div.className = 'contacts-record';
@ -952,8 +962,8 @@ class CustomerCommunication {
button.appendChild(createIcon('fa-solid', 'pen'));
setTooltip(button, r('editFollower', 'Edit Followers'));
button.addEventListener('click', () => {
if (typeof this.#option.onInitFollower === 'function') {
this.#option.onInitFollower(this.#data.followers).then(data => {
if (typeof option.onInitFollower === 'function') {
option.onInitFollower(this.#data.followers).then(data => {
if (typeof data === 'string') {
showAlert(r('customerRecord', 'Customer Record'), data, 'warn');
return;
@ -962,8 +972,8 @@ class CustomerCommunication {
onMasking: option.onMasking,
followers: data,
onOk: list => {
if (typeof this.#option.onAddFollower === 'function') {
const result = this.#option.onAddFollower(list);
if (typeof option.onAddFollower === 'function') {
const result = option.onAddFollower(list);
if (typeof result?.then === 'function') {
return result.then(r => {
// this.followers = r;
@ -1060,6 +1070,38 @@ class CustomerCommunication {
span.innerText = comm.Message;
}
}));
if (comm.IsMMS && comm.MMSParts?.length > 0) {
for (let kv of comm.MMSParts) {
switch (kv.Key) {
case 'application/pdf':
content.appendChild(createPdf(kv.Value));
break;
case 'application/smil':
content.appendChild(createSmilefile(kv.Value));
break;
case 'audio/amr':
content.appendChild(createAudio(kv.Key));
break;
case 'image/gif':
case 'image/jpeg':
case 'image/png':
content.appendChild(createPicture(kv.Value));
break;
case 'text/x-vcard':
content.appendChild(createVcard(kv.Value));
break;
case 'video/3gpp':
content.appendChild(createVideofile(kv.Value));
break;
case 'video/mp4':
content.appendChild(createVideo(kv.Value));
break;
default:
content.appendChild(createFile(kv.Value));
break;
}
}
}
if (comm.IsReply) {
div.classList.add('item-other');
} else {