Enabling function

Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ 2017-11-01 17:52:48 +01:00 committed by John Molakvoæ (skjnldsv)
parent 162f4a9984
commit 9574097117
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
2 changed files with 26 additions and 9 deletions

View File

@ -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;

View File

@ -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();
}
};
});