mirror of https://github.com/nextcloud/contacts
Fix http return and scope update
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
fa00a18136
commit
072f88cddc
|
@ -1,5 +1,5 @@
|
|||
angular.module('contactsApp')
|
||||
.controller('addressbookCtrl', function($scope, AddressBookService, ContactService) {
|
||||
.controller('addressbookCtrl', function($scope, AddressBookService) {
|
||||
var ctrl = this;
|
||||
|
||||
ctrl.t = {
|
||||
|
@ -193,7 +193,10 @@ angular.module('contactsApp')
|
|||
};
|
||||
|
||||
ctrl.toggleState = function() {
|
||||
ctrl.enabled = AddressBookService.toggleState(ctrl.addressBook).enabled;
|
||||
AddressBookService.toggleState(ctrl.addressBook).then(function(addressBook) {
|
||||
ctrl.enabled = addressBook.enabled;
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -122,6 +122,7 @@ angular.module('contactsApp')
|
|||
dSet.appendChild(dProp);
|
||||
|
||||
var oEnabled = xmlDoc.createElement('o:enabled');
|
||||
// Revert state to toggle
|
||||
oEnabled.textContent = !addressBook.enabled ? '1' : '0';
|
||||
dProp.appendChild(oEnabled);
|
||||
|
||||
|
@ -131,7 +132,7 @@ angular.module('contactsApp')
|
|||
dav.request.basic({method: 'PROPPATCH', data: body}),
|
||||
addressBook.url
|
||||
).then(function(response) {
|
||||
if (response.status === 200) {
|
||||
if (response.status === 207) {
|
||||
addressBook.enabled = !addressBook.enabled;
|
||||
}
|
||||
return addressBook;
|
||||
|
|
|
@ -44,23 +44,27 @@ angular.module('contactsApp')
|
|||
});
|
||||
// Get our full vCards
|
||||
addressBooks.forEach(function(addressBook) {
|
||||
if(angular.isArray(xhrAddressBooks[addressBook.displayName])) {
|
||||
var promise = DavClient.getContacts(addressBook, {}, xhrAddressBooks[addressBook.displayName]).then(
|
||||
function(vcards) {
|
||||
return vcards.map(function(vcard) {
|
||||
return new Contact(addressBook, vcard);
|
||||
// Only go through enabled addressbooks
|
||||
// Though xhrAddressBooks does not contains contacts from disabled ones
|
||||
if(addressBook.enabled) {
|
||||
if(angular.isArray(xhrAddressBooks[addressBook.displayName])) {
|
||||
var promise = DavClient.getContacts(addressBook, {}, xhrAddressBooks[addressBook.displayName]).then(
|
||||
function(vcards) {
|
||||
return vcards.map(function(vcard) {
|
||||
return new Contact(addressBook, vcard);
|
||||
});
|
||||
}).then(function(contacts_) {
|
||||
contacts_.map(function(contact) {
|
||||
// Validate some fields
|
||||
if(contact.fix()) {
|
||||
// Can't use this in those nested functions
|
||||
contactService.update(contact);
|
||||
}
|
||||
contactsCache.put(contact.uid(), contact);
|
||||
});
|
||||
});
|
||||
}).then(function(contacts_) {
|
||||
contacts_.map(function(contact) {
|
||||
// Validate some fields
|
||||
if(contact.fix()) {
|
||||
// Can't use this in those nested functions
|
||||
contactService.update(contact);
|
||||
}
|
||||
contactsCache.put(contact.uid(), contact);
|
||||
});
|
||||
});
|
||||
promises.push(promise);
|
||||
promises.push(promise);
|
||||
}
|
||||
}
|
||||
});
|
||||
$q.all(promises).then(function() {
|
||||
|
@ -74,19 +78,22 @@ angular.module('contactsApp')
|
|||
loadPromise = AddressBookService.getAll().then(function(addressBooks) {
|
||||
var promises = [];
|
||||
addressBooks.forEach(function(addressBook) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
// Only go through enabled addressbooks
|
||||
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);
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
return $q.all(promises).then(function() {
|
||||
cacheFilled = true;
|
||||
|
|
Loading…
Reference in New Issue