diff options
author | Tom Needham <tom@owncloud.com> | 2016-02-18 19:08:04 +0000 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-19 14:33:57 +0100 |
commit | a3205271a3985dabe0ba146b87313199b06dc579 (patch) | |
tree | 769cbf563ee27743fec5df123375212454d3b185 /js/services/addressBook_service.js | |
parent | 719840fdd6dc0a90455beadf0ed0b86394de4315 (diff) |
AddressBookService.share implementation first steps
Diffstat (limited to 'js/services/addressBook_service.js')
-rw-r--r-- | js/services/addressBook_service.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/js/services/addressBook_service.js b/js/services/addressBook_service.js index 7302098c..8fada0da 100644 --- a/js/services/addressBook_service.js +++ b/js/services/addressBook_service.js @@ -83,7 +83,48 @@ app.factory('AddressBookService', ['DavClient', 'DavService', 'SettingsService', } return addressBook; });*/ + }, + + share: function(addressBook, shareType, shareWith, writable, existingShare) { + 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 oSet = xmlDoc.createElement('o:set'); + oShare.appendChild(oSet); + + 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; + oSet.appendChild(dHref); + + var oSummary = xmlDoc.createElement('o:summary'); + oSummary.textContent = t('contacts', '{addressbook} shared by {owner}', { + addressbook: addressBook.displayName, + owner: addressBook.owner + }); + oSet.appendChild(oSummary); + + if (writable) { + var oRW = xmlDoc.createElement('o:read-write'); + oSet.appendChild(oRW); + } + + 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 + }); + } + + }; }]); |