Cleanup some Contacts code

This commit is contained in:
djmaze 2022-07-25 10:13:50 +02:00
parent 052f34a9f5
commit 08ded5bb71
3 changed files with 20 additions and 37 deletions

View file

@ -43,7 +43,7 @@ export class ContactsPopupView extends AbstractViewPopup {
contactsPage: 1, contactsPage: 1,
viewSaving: false, isSaving: false,
hasChanges: false, hasChanges: false,
@ -103,7 +103,7 @@ export class ContactsPopupView extends AbstractViewPopup {
// close: self => !self.hasChanges(), // close: self => !self.hasChanges(),
deleteCommand: self => 0 < self.contactsCheckedOrSelected().length, deleteCommand: self => 0 < self.contactsCheckedOrSelected().length,
newMessageCommand: self => 0 < self.contactsCheckedOrSelected().length, newMessageCommand: self => 0 < self.contactsCheckedOrSelected().length,
saveCommand: self => !self.viewSaving() && !self.hasChanges(), saveCommand: self => !self.isSaving() && !self.hasChanges(),
syncCommand: self => !self.contacts.syncing() && !self.contacts.importing() syncCommand: self => !self.contacts.syncing() && !self.contacts.importing()
}); });
} }
@ -173,31 +173,17 @@ export class ContactsPopupView extends AbstractViewPopup {
} }
saveCommand() { saveCommand() {
this.viewSaving(true); this.isSaving(true);
const contact = this.contact();
const
contact = this.contact(),
requestUid = Jua.randomId();
Remote.request('ContactSave', Remote.request('ContactSave',
(iError, oData) => { (iError, oData) => {
let res = false; this.isSaving(false);
this.viewSaving(false); if (!iError && oData.Result.ResultID) {
if (!iError
&& oData.Result.RequestUid === requestUid
&& oData.Result.ResultID
) {
contact.id(oData.Result.ResultID); contact.id(oData.Result.ResultID);
this.reloadContactList(); // TODO: remove when e-contact-foreach is dynamic this.reloadContactList(); // TODO: remove when e-contact-foreach is dynamic
res = true;
}
if (res) {
this.hasChanges(false); this.hasChanges(false);
} }
}, { }, {
RequestUid: requestUid,
Contact: contact Contact: contact
// Uid: contact.id(), // Uid: contact.id(),
// jCard: contact.jCard // jCard: contact.jCard
@ -208,7 +194,6 @@ export class ContactsPopupView extends AbstractViewPopup {
syncCommand() { syncCommand() {
ContactUserStore.sync(iError => { ContactUserStore.sync(iError => {
iError && alert(getNotification(iError)); iError && alert(getNotification(iError));
this.reloadContactList(true); this.reloadContactList(true);
}); });
} }

View file

@ -98,8 +98,7 @@ trait Contacts
$bResult = false; $bResult = false;
$oAddressBookProvider = $this->AddressBookProvider($oAccount); $oAddressBookProvider = $this->AddressBookProvider($oAccount);
$sRequestUid = \trim($this->GetActionParam('RequestUid', '')); if ($oAddressBookProvider && $oAddressBookProvider->IsActive()) {
if ($oAddressBookProvider && $oAddressBookProvider->IsActive() && \strlen($sRequestUid)) {
$aContact = $this->GetActionParam('Contact'); $aContact = $this->GetActionParam('Contact');
if (\is_array($aContact) && isset($aContact['Uid'], $aContact['jCard'])) { if (\is_array($aContact) && isset($aContact['Uid'], $aContact['jCard'])) {
$vCard = \Sabre\VObject\Reader::readJson($aContact['jCard']); $vCard = \Sabre\VObject\Reader::readJson($aContact['jCard']);
@ -118,7 +117,6 @@ trait Contacts
} }
return $this->DefaultResponse(__FUNCTION__, array( return $this->DefaultResponse(__FUNCTION__, array(
'RequestUid' => $sRequestUid,
'ResultID' => $bResult ? $oContact->id : '', 'ResultID' => $bResult ? $oContact->id : '',
'Result' => $bResult 'Result' => $bResult
)); ));

View file

@ -11,28 +11,28 @@
<a class="btn fontastic" data-bind="command: deleteCommand">🗑</a> <a class="btn fontastic" data-bind="command: deleteCommand">🗑</a>
<div class="btn-group dropdown" data-bind="registerBootstrapDropdown: true, visible: !contacts.importing() && !contacts.syncing()"> <div class="btn-group dropdown" data-bind="registerBootstrapDropdown: true, visible: !contacts.importing() && !contacts.syncing()">
<a id="contacts-more-dropdown-id" class="btn dropdown-toggle fontastic" href="#" tabindex="-1"></a> <a id="contacts-more-dropdown-id" class="btn dropdown-toggle fontastic" href="#"></a>
<menu class="dropdown-menu right-edge" role="menu" aria-labelledby="contacts-more-dropdown-id"> <menu class="dropdown-menu right-edge" role="menu" aria-labelledby="contacts-more-dropdown-id">
<li role="presentation"> <li role="presentation">
<a href="#" tabindex="-1" data-bind="initDom: importButton"> <a href="#" data-bind="initDom: importButton">
<i data-bind="css: {'icon-import': !contacts.importing(), 'icon-spinner': contacts.importing}"></i> <i data-bind="css: {'icon-import': !contacts.importing(), 'icon-spinner': contacts.importing}"></i>
<span data-i18n="CONTACTS/BUTTON_IMPORT"></span> <span data-i18n="CONTACTS/BUTTON_IMPORT"></span>
</a> </a>
</li> </li>
<li class="dividerbar" role="presentation"> <li class="dividerbar" role="presentation">
<a href="#" tabindex="-1" data-bind="click: exportCsv"> <a href="#" data-bind="click: exportCsv">
<i class="icon-export"></i> <i class="icon-export"></i>
<span data-i18n="CONTACTS/BUTTON_EXPORT_CSV"></span> <span data-i18n="CONTACTS/BUTTON_EXPORT_CSV"></span>
</a> </a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a href="#" tabindex="-1" data-bind="click: exportVcf"> <a href="#" data-bind="click: exportVcf">
<i class="icon-export"></i> <i class="icon-export"></i>
<span data-i18n="CONTACTS/BUTTON_EXPORT_VCARD"></span> <span data-i18n="CONTACTS/BUTTON_EXPORT_VCARD"></span>
</a> </a>
</li> </li>
<li class="dividerbar" role="presentation" data-bind="visible: contactsSyncEnabled"> <li class="dividerbar" role="presentation" data-bind="visible: contactsSyncEnabled">
<a href="#" tabindex="-1" data-bind="command: syncCommand"> <a href="#" data-bind="command: syncCommand">
<i class="fontastic" data-bind="css: {'icon-spinner': contacts.syncing}"></i> <i class="fontastic" data-bind="css: {'icon-spinner': contacts.syncing}"></i>
<span data-i18n="CONTACTS/BUTTON_SYNC"></span> <span data-i18n="CONTACTS/BUTTON_SYNC"></span>
</a> </a>
@ -76,41 +76,41 @@
<!-- ko with: contact --> <!-- ko with: contact -->
<div class="btn-group"> <div class="btn-group">
<button class="btn button-save-contact" data-bind="visible: !readOnly(), command: $root.saveCommand, css: {'dirty': $root.hasChanges}"> <button class="btn button-save-contact" data-bind="visible: !readOnly(), command: $root.saveCommand, css: {'dirty': $root.hasChanges}">
<i data-bind="css: {'icon-ok': !$root.viewSaving(), 'icon-spinner': $root.viewSaving()}"></i> <i data-bind="css: {'icon-ok': !$root.isSaving(), 'icon-spinner': $root.isSaving()}"></i>
<span data-i18n="CONTACTS/BUTTON_CREATE_CONTACT" data-bind="visible: !id()"></span> <span data-i18n="CONTACTS/BUTTON_CREATE_CONTACT" data-bind="visible: !id()"></span>
<span data-i18n="CONTACTS/BUTTON_UPDATE_CONTACT" data-bind="visible: id"></span> <span data-i18n="CONTACTS/BUTTON_UPDATE_CONTACT" data-bind="visible: id"></span>
</button> </button>
</div> </div>
<div class="btn-group dropdown" data-bind="visible: !readOnly(), registerBootstrapDropdown: true"> <div class="btn-group dropdown" data-bind="visible: !readOnly(), registerBootstrapDropdown: true">
<a id="button-add-prop-dropdown-id" href="#" tabindex="-1" class="btn dropdown-toggle" data-i18n="CONTACTS/ADD_MENU_LABEL"></a> <a id="button-add-prop-dropdown-id" href="#" class="btn dropdown-toggle" data-i18n="CONTACTS/ADD_MENU_LABEL"></a>
<menu class="dropdown-menu right-edge" style="text-align: left" tabindex="-1" role="menu" aria-labelledby="button-add-prop-dropdown-id"> <menu class="dropdown-menu right-edge" style="text-align: left" role="menu" aria-labelledby="button-add-prop-dropdown-id">
<li role="presentation"> <li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addEmail"> <a href="#" data-bind="click: addEmail">
<i class="icon-none"></i> <i class="icon-none"></i>
<span data-i18n="GLOBAL/EMAIL"></span> <span data-i18n="GLOBAL/EMAIL"></span>
</a> </a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addTel"> <a href="#" data-bind="click: addTel">
<i class="icon-none"></i> <i class="icon-none"></i>
<span data-i18n="CONTACTS/ADD_MENU_PHONE"></span> <span data-i18n="CONTACTS/ADD_MENU_PHONE"></span>
</a> </a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addUrl"> <a href="#" data-bind="click: addUrl">
<i class="icon-none"></i> <i class="icon-none"></i>
<span data-i18n="CONTACTS/ADD_MENU_URL"></span> <span data-i18n="CONTACTS/ADD_MENU_URL"></span>
</a> </a>
</li> </li>
<li class="dividerbar" role="presentation"> <li class="dividerbar" role="presentation">
<a href="#" tabindex="-1" data-bind="click: addNickname"> <a href="#" data-bind="click: addNickname">
<i class="icon-none"></i> <i class="icon-none"></i>
<span data-i18n="CONTACTS/ADD_MENU_NICKNAME"></span> <span data-i18n="CONTACTS/ADD_MENU_NICKNAME"></span>
</a> </a>
</li> </li>
<!-- <!--
<li role="presentation"> <li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addNewAddress"> <a href="#" data-bind="click: addNewAddress">
<span data-i18n="CONTACTS/ADD_MENU_ADDRESS"></span> <span data-i18n="CONTACTS/ADD_MENU_ADDRESS"></span>
</a> </a>
</li>--> </li>-->