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

View file

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

View file

@ -11,28 +11,28 @@
<a class="btn fontastic" data-bind="command: deleteCommand">🗑</a>
<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">
<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>
<span data-i18n="CONTACTS/BUTTON_IMPORT"></span>
</a>
</li>
<li class="dividerbar" role="presentation">
<a href="#" tabindex="-1" data-bind="click: exportCsv">
<a href="#" data-bind="click: exportCsv">
<i class="icon-export"></i>
<span data-i18n="CONTACTS/BUTTON_EXPORT_CSV"></span>
</a>
</li>
<li role="presentation">
<a href="#" tabindex="-1" data-bind="click: exportVcf">
<a href="#" data-bind="click: exportVcf">
<i class="icon-export"></i>
<span data-i18n="CONTACTS/BUTTON_EXPORT_VCARD"></span>
</a>
</li>
<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>
<span data-i18n="CONTACTS/BUTTON_SYNC"></span>
</a>
@ -76,41 +76,41 @@
<!-- ko with: contact -->
<div class="btn-group">
<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_UPDATE_CONTACT" data-bind="visible: id"></span>
</button>
</div>
<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>
<menu class="dropdown-menu right-edge" style="text-align: left" tabindex="-1" role="menu" aria-labelledby="button-add-prop-dropdown-id">
<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" role="menu" aria-labelledby="button-add-prop-dropdown-id">
<li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addEmail">
<a href="#" data-bind="click: addEmail">
<i class="icon-none"></i>
<span data-i18n="GLOBAL/EMAIL"></span>
</a>
</li>
<li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addTel">
<a href="#" data-bind="click: addTel">
<i class="icon-none"></i>
<span data-i18n="CONTACTS/ADD_MENU_PHONE"></span>
</a>
</li>
<li role="presentation">
<a href="#" tabindex="-1" data-bind="click: addUrl">
<a href="#" data-bind="click: addUrl">
<i class="icon-none"></i>
<span data-i18n="CONTACTS/ADD_MENU_URL"></span>
</a>
</li>
<li class="dividerbar" role="presentation">
<a href="#" tabindex="-1" data-bind="click: addNickname">
<a href="#" data-bind="click: addNickname">
<i class="icon-none"></i>
<span data-i18n="CONTACTS/ADD_MENU_NICKNAME"></span>
</a>
</li>
<!--
<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>
</a>
</li>-->