diff options
author | Tom Needham <tom@owncloud.com> | 2016-02-18 20:30:11 +0000 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-19 14:33:57 +0100 |
commit | 102bb7e9116c0b6d6f6fd5cfaf56fa5cad3a90f6 (patch) | |
tree | d3c4e9c379f9d910bfa1d5b296899f5a9d42fe8d /js/services/addressBook_service.js | |
parent | a3205271a3985dabe0ba146b87313199b06dc579 (diff) |
Further work with AddressBookService.share and .unshare methods
Diffstat (limited to 'js/services/addressBook_service.js')
-rw-r--r-- | js/services/addressBook_service.js | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/js/services/addressBook_service.js b/js/services/addressBook_service.js index 8fada0da..dcbfcdc8 100644 --- a/js/services/addressBook_service.js +++ b/js/services/addressBook_service.js @@ -118,8 +118,71 @@ app.factory('AddressBookService', ['DavClient', 'DavService', 'SettingsService', var body = oShare.outerHTML; - DavClient.xhr.send(dav.request.basic({method: 'POST', data: body}), addressBook.url).then(function(response) { - // Push to sahredWith array and update the UI + DavClient.xhr.send( + dav.request.basic({method: 'POST', data: body}), + addressBook.url + ).then(function(response) { + if (response.status === 200) { + if (!existingShare) { + if (shareType === OC.Share.SHARE_TYPE_USER) { + addressBook.sharedWith.users.push({ + id: shareWith, + displayname: shareWith, + writable: writable + }); + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + addressBook.sharedWith.groups.push({ + id: shareWith, + displayname: shareWith, + writable: writable + }); + } + } + } + }); + + }, + + unshare: function(addressBook, shareType, shareWith) { + var xmlDoc = document.implementation.createDocument('', '', null); + var oShare = xmlDoc.createElement('o:share'); + oShare.setAttribute('xmlns:d', 'DAV:'); + oShare.setAttribute('xmlns:o', 'http://owncloud.org/ns'); + xmlDoc.appendChild(oShare); + + var oRemove = xmlDoc.createElement('o:remove'); + oShare.appendChild(oRemove); + + var dHref = xmlDoc.createElement('d:href'); + if (shareType === OC.Share.SHARE_TYPE_USER) { + dHref.textContent = 'principal:principals/users/'; + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + dHref.textContent = 'principal:principals/groups/'; + } + dHref.textContent += shareWith; + oRemove.appendChild(dHref); + var body = oShare.outerHTML; + + + DavClient.xhr.send( + dav.request.basic({method: 'POST', data: body}), + addressBook.url + ).then(function(response) { + if (response.status === 200) { + if (shareType === OC.Share.SHARE_TYPE_USER) { + addressBook.sharedWith.users = addressBook.sharedWith.users.filter(function(user) { + return user.id !== shareWith; + }); + } else if (shareType === OC.Share.SHARE_TYPE_GROUP) { + addressBook.sharedWith.groups = addressBook.sharedWith.groups.filter(function(groups) { + return groups.id !== shareWith; + }); + } + //todo - remove entry from addressbook object + return true; + } else { + return false; + } }); } |