diff options
-rw-r--r-- | js/components/addressBookList/addressBookList_controller.js | 7 | ||||
-rw-r--r-- | js/dav/dav.js | 22 | ||||
-rw-r--r-- | js/dav/lib/client.js | 5 | ||||
-rw-r--r-- | js/dav/lib/contacts.js | 18 | ||||
-rw-r--r-- | js/public/script.js | 20 | ||||
-rw-r--r-- | js/services/addressBook_service.js | 13 |
6 files changed, 83 insertions, 2 deletions
diff --git a/js/components/addressBookList/addressBookList_controller.js b/js/components/addressBookList/addressBookList_controller.js index 6fe7089d..8a6c40e2 100644 --- a/js/components/addressBookList/addressBookList_controller.js +++ b/js/components/addressBookList/addressBookList_controller.js @@ -7,7 +7,12 @@ app.controller('addressbooklistCtrl', ['$scope', 'AddressBookService', 'Settings ctrl.createAddressBook = function() { if(ctrl.newAddressBookName) { - AddressBookService.create(ctrl.newAddressBookName); + AddressBookService.create(ctrl.newAddressBookName).then(function() { + AddressBookService.getAddressBook(ctrl.newAddressBookName).then(function(addressBook) { + ctrl.addressBooks.push(addressBook); + scope.$apply(); + }); + }); } }; }]); diff --git a/js/dav/dav.js b/js/dav/dav.js index 476d35ff..efafcb68 100644 --- a/js/dav/dav.js +++ b/js/dav/dav.js @@ -1476,6 +1476,14 @@ var Client = (function () { return calendars.syncCaldavAccount(account, options); } }, { + key: 'getAddressBook', + value: function getAddressBook() { + var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; + + options.xhr = options.xhr || this.xhr; + return contacts.getAddressBook(options); + } + }, { key: 'createAddressBook', value: function createAddressBook() { var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; @@ -1551,6 +1559,7 @@ exports.Client = Client; Object.defineProperty(exports, '__esModule', { value: true }); +exports.getAddressBook = getAddressBook; exports.createAddressBook = createAddressBook; exports.deleteAddressBook = deleteAddressBook; exports.renameAddressBook = renameAddressBook; @@ -1656,6 +1665,19 @@ var listAddressBooks = _co2['default'].wrap(regeneratorRuntime.mark(function cal })); exports.listAddressBooks = listAddressBooks; + +function getAddressBook(options) { + var addressBookUrl = _url2['default'].resolve(options.url, options.displayName); + var req = request.propfind({ + props: [{ name: 'displayname', namespace: ns.DAV }, { name: 'owner', namespace: ns.DAV }, { name: 'getctag', namespace: ns.CALENDAR_SERVER }, { name: 'resourcetype', namespace: ns.DAV }, { name: 'sync-token', namespace: ns.DAV }, + //{ name: 'groups', namespace: ns.OC }, + { name: 'invite', namespace: ns.OC }], + depth: 1 + }); + + return options.xhr.send(req, addressBookUrl); +} + /** * @return {Promise} promise will resolve when the addressBook has been created. * diff --git a/js/dav/lib/client.js b/js/dav/lib/client.js index 3226d3d8..2846278f 100644 --- a/js/dav/lib/client.js +++ b/js/dav/lib/client.js @@ -73,6 +73,11 @@ export class Client { return calendars.syncCaldavAccount(account, options); } + getAddressBook(options={}) { + options.xhr = options.xhr || this.xhr; + return contacts.getAddressBook(options); + } + createAddressBook(options={}) { options.xhr = options.xhr || this.xhr; return contacts.createAddressBook(options); diff --git a/js/dav/lib/contacts.js b/js/dav/lib/contacts.js index e20acf6b..719eb08e 100644 --- a/js/dav/lib/contacts.js +++ b/js/dav/lib/contacts.js @@ -56,6 +56,24 @@ export let listAddressBooks = co.wrap(function *(account, options) { return addressBooks; }); +export function getAddressBook(options) { + let addressBookUrl = url.resolve(options.url, options.displayName); + var req = request.propfind({ + props: [ + { name: 'displayname', namespace: ns.DAV }, + { name: 'owner', namespace: ns.DAV }, + { name: 'getctag', namespace: ns.CALENDAR_SERVER }, + { name: 'resourcetype', namespace: ns.DAV }, + { name: 'sync-token', namespace: ns.DAV }, + //{ name: 'groups', namespace: ns.OC }, + { name: 'invite', namespace: ns.OC } + ], + depth: 1 + }); + + return options.xhr.send(req, addressBookUrl); +} + /** * @return {Promise} promise will resolve when the addressBook has been created. * diff --git a/js/public/script.js b/js/public/script.js index 48248bcb..392211d2 100644 --- a/js/public/script.js +++ b/js/public/script.js @@ -177,7 +177,12 @@ app.controller('addressbooklistCtrl', ['$scope', 'AddressBookService', 'Settings ctrl.createAddressBook = function() { if(ctrl.newAddressBookName) { - AddressBookService.create(ctrl.newAddressBookName); + AddressBookService.create(ctrl.newAddressBookName).then(function() { + AddressBookService.getAddressBook(ctrl.newAddressBookName).then(function(addressBook) { + ctrl.addressBooks.push(addressBook); + scope.$apply(); + }); + }); } }; }]); @@ -800,6 +805,19 @@ app.factory('AddressBookService', ['DavClient', 'DavService', 'SettingsService', return addressBooks[0]; }, + getAddressBook: function(displayName) { + return DavService.then(function(account) { + return DavClient.getAddressBook({displayName:displayName, url:account.homeUrl}).then(function(addressBook) { + addressBook = new AddressBook({ + url: addressBook[0].href, + data: addressBook[0] + }); + addressBook.displayName = displayName; + return addressBook; + }); + }); + }, + create: function(displayName) { return DavService.then(function(account) { return DavClient.createAddressBook({displayName:displayName, url:account.homeUrl}); diff --git a/js/services/addressBook_service.js b/js/services/addressBook_service.js index e3952eae..7cc4225a 100644 --- a/js/services/addressBook_service.js +++ b/js/services/addressBook_service.js @@ -40,6 +40,19 @@ app.factory('AddressBookService', ['DavClient', 'DavService', 'SettingsService', return addressBooks[0]; }, + getAddressBook: function(displayName) { + return DavService.then(function(account) { + return DavClient.getAddressBook({displayName:displayName, url:account.homeUrl}).then(function(addressBook) { + addressBook = new AddressBook({ + url: addressBook[0].href, + data: addressBook[0] + }); + addressBook.displayName = displayName; + return addressBook; + }); + }); + }, + create: function(displayName) { return DavService.then(function(account) { return DavClient.createAddressBook({displayName:displayName, url:account.homeUrl}); |