diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2017-11-01 17:52:48 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2017-11-21 15:55:06 +0100 |
commit | 95740971172d576b8a06aed7fe1b712c713db318 (patch) | |
tree | ab55602c70823219616ff0008045ba99ec66b5bc /js | |
parent | 162f4a99841666753dd6dbb6321ce7daab0876f8 (diff) |
Enabling function
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'js')
-rw-r--r-- | js/components/contactList/contactList_controller.js | 10 | ||||
-rw-r--r-- | js/services/contact_service.js | 25 |
2 files changed, 26 insertions, 9 deletions
diff --git a/js/components/contactList/contactList_controller.js b/js/components/contactList/contactList_controller.js index ef11ab65..d0710483 100644 --- a/js/components/contactList/contactList_controller.js +++ b/js/components/contactList/contactList_controller.js @@ -108,6 +108,16 @@ angular.module('contactsApp') }); }); break; + case 'enable': + ctrl.loading = true; + ContactService.appendContactsFromAddressbook(ev.addressBook, function() { + ContactService.getAll().then(function(contacts) { + ctrl.contactList = contacts; + ctrl.loading = false; + ctrl.selectNearestContact(ctrl.getSelectedId()); + }); + }); + break; default: // unknown event -> leave callback without action return; diff --git a/js/services/contact_service.js b/js/services/contact_service.js index d44244ba..88052df4 100644 --- a/js/services/contact_service.js +++ b/js/services/contact_service.js @@ -82,15 +82,7 @@ angular.module('contactsApp') if(addressBook.enabled) { promises.push( AddressBookService.sync(addressBook).then(function(addressBook) { - addressBook.objects.forEach(function(vcard) { - try { - var contact = new Contact(addressBook, vcard); - contactsCache.put(contact.uid(), contact); - } catch(error) { - // eslint-disable-next-line no-console - console.log('Invalid contact received: ', vcard); - } - }); + contactService.appendContactsFromAddressbook(addressBook); }) ); } @@ -343,4 +335,19 @@ angular.module('contactsApp') notifyObservers('groupsUpdate'); }; + this.appendContactsFromAddressbook = function(addressBook, callback) { + addressBook.objects.forEach(function(vcard) { + try { + var contact = new Contact(addressBook, vcard); + contactsCache.put(contact.uid(), contact); + } catch(error) { + // eslint-disable-next-line no-console + console.log('Invalid contact received: ', vcard); + } + }); + if (typeof callback === 'function') { + callback(); + } + }; + }); |