From 052f34a9f59f3031a9081361806ed379941eaace Mon Sep 17 00:00:00 2001 From: djmaze <> Date: Fri, 22 Jul 2022 22:59:50 +0200 Subject: [PATCH] Some cleanups for new AddressBook --- dev/Model/Contact.js | 23 ++++--- dev/Styles/User/Contacts.less | 4 -- dev/View/Popup/Contacts.js | 64 ++++++------------- .../templates/Views/User/PopupsContacts.html | 24 ++++--- 4 files changed, 43 insertions(+), 72 deletions(-) diff --git a/dev/Model/Contact.js b/dev/Model/Contact.js index 61cfca038..a0d7bb92b 100644 --- a/dev/Model/Contact.js +++ b/dev/Model/Contact.js @@ -15,7 +15,6 @@ export class ContactModel extends AbstractModel { constructor() { super(); - this.properties = []; this.jCard = new JCard(); this.addObservables({ @@ -30,8 +29,7 @@ export class ContactModel extends AbstractModel { surName: '', // LastName middleName: '', // MiddleName namePrefix: '', // NamePrefix - nameSuffix: '', // NameSuffix - nickname: null + nameSuffix: '' // NameSuffix }); // this.email = koArrayWithDestroy(); this.email = ko.observableArray(); @@ -43,6 +41,15 @@ export class ContactModel extends AbstractModel { fullName: () => (this.givenName() + ' ' + this.surName()).trim(), + nickname: { + read: () => { + let prop = this.jCard.getOne('nickname'); + return prop && prop.value; + }, + write: value => + value ? this.jCard.set('nickname', value/*, params, group*/) : this.jCard.remove('nickname') + }, + display: () => { let a = this.jCard.getOne('fn')?.value, b = this.fullName(), @@ -85,17 +92,12 @@ export class ContactModel extends AbstractModel { static reviveFromJson(json) { const contact = super.reviveFromJson(json); if (contact) { - let list = []; - let jCard = new JCard(json.jCard), props = jCard.getOne('n')?.value; props && props.forEach((value, index) => value && contact[nProps[index]](value) ); - props = jCard.getOne('nickname'); - props && contact.nickname(props.value); - ['email', 'tel', 'url'].forEach(field => { props = jCard.get(field); props && props.forEach(prop => { @@ -106,7 +108,6 @@ export class ContactModel extends AbstractModel { }); }); - contact.properties = list; contact.jCard = jCard; } return contact; @@ -116,7 +117,7 @@ export class ContactModel extends AbstractModel { * @returns {string} */ generateUid() { - return ''+this.id; + return '' + this.id; } addEmail() { @@ -160,8 +161,6 @@ export class ContactModel extends AbstractModel { ]/*, params, group*/); // jCard.parseFullName({set:true}); - this.nickname() ? jCard.set('nickname', this.nickname()/*, params, group*/) : jCard.remove('nickname'); - ['email', 'tel', 'url'].forEach(field => { let values = this[field].map(item => item.value()); jCard.get(field).forEach(prop => { diff --git a/dev/Styles/User/Contacts.less b/dev/Styles/User/Contacts.less index 6be67be6c..84016aa7d 100644 --- a/dev/Styles/User/Contacts.less +++ b/dev/Styles/User/Contacts.less @@ -148,10 +148,6 @@ font-weight: bold; } } - - &.read-only .button-save-contact { - display: none; - } } .b-view-content { diff --git a/dev/View/Popup/Contacts.js b/dev/View/Popup/Contacts.js index 181d5795d..d94ef7d1d 100644 --- a/dev/View/Popup/Contacts.js +++ b/dev/View/Popup/Contacts.js @@ -23,7 +23,6 @@ import { AbstractViewPopup } from 'Knoin/AbstractViews'; import { AskPopupView } from 'View/Popup/Ask'; const - viewProperties = koArrayWithDestroy(), CONTACTS_PER_PAGE = 50, ScopeContacts = 'Contacts'; @@ -38,20 +37,15 @@ export class ContactsPopupView extends AbstractViewPopup { search: '', contactsCount: 0, - currentContact: null, + selectorContact: null, - importUploaderButton: null, + importButton: null, contactsPage: 1, - viewClearSearch: false, - - viewReadOnly: false, - viewSaving: false, - watchDirty: false, - watchHash: false, + hasChanges: false, contact: null }); @@ -62,7 +56,7 @@ export class ContactsPopupView extends AbstractViewPopup { this.selector = new Selector( ContactUserStore, - this.currentContact, + this.selectorContact, null, '.e-contact-item .actionHandle', '.e-contact-item .checkboxItem', @@ -87,7 +81,7 @@ export class ContactsPopupView extends AbstractViewPopup { contactsCheckedOrSelected: () => { const checked = ContactUserStore.filter(item => item.checked && item.checked()), - selected = this.currentContact(); + selected = this.selectorContact(); return selected ? [...checked, selected].unique() @@ -96,34 +90,27 @@ export class ContactsPopupView extends AbstractViewPopup { contactsCheckedOrSelectedUids: () => this.contactsCheckedOrSelected().map(contact => contact.id()), - contactsSyncEnabled: () => ContactUserStore.allowSync() && ContactUserStore.syncMode(), - - viewHash: () => '' + viewProperties.map(property => property.value && property.value()).join('') + contactsSyncEnabled: () => ContactUserStore.allowSync() && ContactUserStore.syncMode() }); this.search.subscribe(() => this.reloadContactList()); - this.viewHash.subscribe(() => { - if (this.watchHash() && !this.viewReadOnly() && !this.watchDirty()) { - this.watchDirty(true); - } - }); - this.saveCommand = this.saveCommand.bind(this); +// this.hasChanges(!!contact()?.toJSON().jCard); + decorateKoCommands(this, { -// close: self => !self.watchDirty(), +// close: self => !self.hasChanges(), deleteCommand: self => 0 < self.contactsCheckedOrSelected().length, newMessageCommand: self => 0 < self.contactsCheckedOrSelected().length, - saveCommand: self => !self.viewSaving() && !self.viewReadOnly() - && (self.contact()?.hasValidName() || self.contact()?.email().length), + saveCommand: self => !self.viewSaving() && !self.hasChanges(), syncCommand: self => !self.contacts.syncing() && !self.contacts.importing() }); } newContact() { this.populateViewContact(null); - this.currentContact(null); + this.selectorContact(null); } deleteCommand() { @@ -207,7 +194,7 @@ export class ContactsPopupView extends AbstractViewPopup { } if (res) { - this.watchDirty(false); + this.hasChanges(false); } }, { RequestUid: requestUid, @@ -237,14 +224,14 @@ export class ContactsPopupView extends AbstractViewPopup { removeCheckedOrSelectedContactsFromList() { const contacts = this.contactsCheckedOrSelected(); - let currentContact = this.currentContact(), + let selectorContact = this.selectorContact(), count = ContactUserStore.length; if (contacts.length) { contacts.forEach(contact => { - if (currentContact && currentContact.id() === contact.id()) { - currentContact = null; - this.currentContact(null); + if (selectorContact && selectorContact.id() === contact.id()) { + selectorContact = null; + this.selectorContact(null); } contact.deleted(true); @@ -282,18 +269,12 @@ export class ContactsPopupView extends AbstractViewPopup { * @param {?ContactModel} contact */ populateViewContact(contact) { - this.watchHash(false); - if (!contact) { contact = new ContactModel; } - this.viewReadOnly(contact.readOnly()); this.contact(contact); - viewProperties(contact.properties); - - this.watchDirty(false); - this.watchHash(true); + this.hasChanges(false); } /** @@ -330,7 +311,6 @@ export class ContactsPopupView extends AbstractViewPopup { ContactUserStore(list); ContactUserStore.loading(false); - this.viewClearSearch(!!this.search()); }, { Offset: offset, @@ -368,12 +348,12 @@ export class ContactsPopupView extends AbstractViewPopup { // initUploader - if (this.importUploaderButton()) { + if (this.importButton()) { const j = new Jua({ action: serverRequest('UploadContacts'), limit: 1, disableDocumentDropPrevent: true, - clickElement: this.importUploaderButton() + clickElement: this.importButton() }); if (j) { @@ -391,7 +371,7 @@ export class ContactsPopupView extends AbstractViewPopup { } onClose() { - if (this.watchDirty() && AskPopupView.hidden()) { + if (this.hasChanges() && AskPopupView.hidden()) { showScreenPopup(AskPopupView, [ i18n('POPUPS_ASK/DESC_WANT_CLOSE_THIS_WINDOW'), () => this.close() @@ -408,17 +388,15 @@ export class ContactsPopupView extends AbstractViewPopup { onHide() { this.contact(null); - this.currentContact(null); + this.selectorContact(null); this.search(''); this.contactsCount(0); ContactUserStore([]); this.sLastComposeFocusedField = ''; - if (this.bBackToCompose) { this.bBackToCompose = false; - showMessageComposer(); } } diff --git a/snappymail/v/0.0.0/app/templates/Views/User/PopupsContacts.html b/snappymail/v/0.0.0/app/templates/Views/User/PopupsContacts.html index 34c89abdc..e7b1bac12 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/PopupsContacts.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/PopupsContacts.html @@ -14,7 +14,7 @@
  • - + @@ -48,7 +48,7 @@
    -
    +
    -
    +
    -
    - -
    +
    -
    -
    + +
    +
    -
    -
    -
    @@ -191,8 +189,8 @@
    -
    +