summaryrefslogtreecommitdiffstats
path: root/js/services/addressBook_service.js
blob: 5ea3669a43d009541300890aef7dd4d400bd0c00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
app.service('AddressBookService', ['DavClient', 'DavService', 'AddressBook', 'Contact', function(DavClient, DavService, AddressBook, Contact){

	this.getAll = function() {
		return DavService.then(function(account) {
			return account.addressBooks.map(function(addressBook) {
				return new AddressBook(addressBook);
			});
		});
	};

	this.get = function(displayName) {
		return this.getAll().then(function(addressBooks){
			return addressBooks.filter(function (element) {
				return element.displayName === displayName;
			})[0];
		});
	};

	this.sync = function(addressBook) {
		return DavClient.syncAddressBook(addressBook).then(function(addressBook) {
			// parse contacts
			addressBook.contacts = [];
			for(var i in addressBook.objects) {
				addressBook.contacts.push(
					new Contact(addressBook.objects[i])
				);
			}
			return addressBook;
		});
	};

}]);