diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-09-28 15:38:49 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-09-28 15:38:49 +0200 |
commit | bf1057143cdff8ec289d9d766ab100d64d7ea45d (patch) | |
tree | 6c35d0d99a72f27a981a07c93f0ecbf600764cd4 /core/js/share.js | |
parent | 3efe1d3b24e65ed76d521c24b0cfe4e0ff2e7af5 (diff) | |
parent | 5144d26088b98685a37c73c776a9a47203efa68a (diff) | |
download | nextcloud-server-bf1057143cdff8ec289d9d766ab100d64d7ea45d.tar.gz nextcloud-server-bf1057143cdff8ec289d9d766ab100d64d7ea45d.zip |
Merge branch 'master' into routing
Conflicts:
apps/files/js/filelist.js
core/js/js.js
lib/ocs.php
Diffstat (limited to 'core/js/share.js')
-rw-r--r-- | core/js/share.js | 223 |
1 files changed, 151 insertions, 72 deletions
diff --git a/core/js/share.js b/core/js/share.js index b5e8b0e6613..36ee39d8eab 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -35,21 +35,29 @@ OC.Share={ } } var shares = false; + var link = false; + var image = OC.imagePath('core', 'actions/share'); $.each(OC.Share.itemShares, function(index) { - if (OC.Share.itemShares[index].length > 0) { - shares = true; - return; + if (OC.Share.itemShares[index]) { + if (index == OC.Share.SHARE_TYPE_LINK) { + if (OC.Share.itemShares[index] == true) { + shares = true; + image = OC.imagePath('core', 'actions/public'); + link = true; + return; + } + } else if (OC.Share.itemShares[index].length > 0) { + shares = true; + image = OC.imagePath('core', 'actions/shared'); + } } }); + if (itemType != 'file' && itemType != 'folder') { + $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center'); + } if (shares) { - $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/shared')+') no-repeat center'); - if (typeof OC.Share.statuses[itemSource] === 'undefined') { - OC.Share.statuses[itemSource] = false; - } + OC.Share.statuses[itemSource] = link; } else { - if (itemType != 'file' && itemType != 'folder') { - $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+OC.imagePath('core', 'actions/share')+') no-repeat center'); - } delete OC.Share.statuses[itemSource]; } }, @@ -71,7 +79,8 @@ OC.Share={ var item = itemSource; } if (typeof OC.Share.statuses[item] === 'undefined') { - checkShares = false; + // NOTE: Check does not always work and misses some shares, fix later + checkShares = true; } else { checkShares = true; } @@ -91,7 +100,7 @@ OC.Share={ callback(result.data); } } else { - OC.dialogs.alert(result.data.message, 'Error while sharing'); + OC.dialogs.alert(result.data.message, t('core', 'Error while sharing')); } }); }, @@ -102,14 +111,14 @@ OC.Share={ callback(); } } else { - OC.dialogs.alert('Error', 'Error while unsharing'); + OC.dialogs.alert(t('core', 'Error'), t('core', 'Error while unsharing')); } }); }, setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) { $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) { if (!result || result.status !== 'success') { - OC.dialogs.alert('Error', 'Error while changing permissions'); + OC.dialogs.alert(t('core', 'Error'), t('core', 'Error while changing permissions')); } }); }, @@ -118,28 +127,30 @@ OC.Share={ var html = '<div id="dropdown" class="drop" data-item-type="'+itemType+'" data-item-source="'+itemSource+'">'; if (data.reshare) { if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) { - html += '<span class="reshare">Shared with you and the group '+data.reshare.share_with+' by '+data.reshare.uid_owner+'</span>'; + html += '<span class="reshare">'+t('core', 'Shared with you and the group %s by %s', data.reshare.share_with, data.reshare.uid_owner)+'</span>'; } else { - html += '<span class="reshare">Shared with you by '+data.reshare.uid_owner+'</span>'; + html += '<span class="reshare">'+t('core', 'Shared with you by %s', data.reshare.uid_owner)+'</span>'; } html += '<br />'; } if (possiblePermissions & OC.PERMISSION_SHARE) { - html += '<input id="shareWith" type="text" placeholder="Share with" />'; + html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Share with')+'" />'; html += '<ul id="shareWithList">'; html += '</ul>'; if (link) { html += '<div id="link">'; - html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">Share with link</label>'; - // TODO Change to lock/unlock icon? - html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="Password protect" src="'+OC.imagePath('core', 'actions/triangle-n')+'"/></a>'; + html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share with link')+'</label>'; + html += '<a href="#" id="showPassword" style="display:none;"><img class="svg" alt="'+t('core', 'Password protect')+'" src="'+OC.imagePath('core', 'actions/lock')+'"/></a>'; html += '<br />'; html += '<input id="linkText" type="text" readonly="readonly" />'; html += '<div id="linkPass">'; - html += '<input id="linkPassText" type="password" placeholder="Password" />'; + html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Password')+'" />'; html += '</div>'; html += '</div>'; } + html += '<div id="expiration">'; + html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>'; + html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />'; html += '</div>'; $(html).appendTo(appendTo); // Reset item shares @@ -149,7 +160,14 @@ OC.Share={ if (share.share_type == OC.Share.SHARE_TYPE_LINK) { OC.Share.showLink(itemSource, share.share_with); } else { - OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions); + if (share.collection) { + OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, share.collection); + } else { + OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions, false); + } + } + if (share.expiration.length > 0) { + OC.Share.showExpirationDate(share.expiration); } }); } @@ -162,12 +180,12 @@ OC.Share={ response(result.data); } else { // Suggest sharing via email if valid email address - var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i); - if (pattern.test(search.term)) { - response([{label: 'Share via email: '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]); - } else { - response(['No people found']); - } +// var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i); +// if (pattern.test(search.term)) { +// response([{label: t('core', 'Share via email: %s', search.term), value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]); +// } else { + response([t('core', 'No people found')]); +// } } }); // } @@ -176,6 +194,7 @@ OC.Share={ event.preventDefault(); }, select: function(event, selected) { + event.stopPropagation(); var itemType = $('#dropdown').data('item-type'); var itemSource = $('#dropdown').data('item-source'); var shareType = selected.item.value.shareType; @@ -192,7 +211,7 @@ OC.Share={ } }); } else { - html += '<input id="shareWith" type="text" placeholder="Resharing is not allowed" style="width:90%;" disabled="disabled"/>'; + html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>'; html += '</div>'; $(html).appendTo(appendTo); } @@ -213,58 +232,74 @@ OC.Share={ } }); }, - addShareWith:function(shareType, shareWith, permissions, possiblePermissions) { + addShareWith:function(shareType, shareWith, permissions, possiblePermissions, collection) { if (!OC.Share.itemShares[shareType]) { OC.Share.itemShares[shareType] = []; } OC.Share.itemShares[shareType].push(shareWith); - var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = ''; - if (permissions & OC.PERMISSION_CREATE) { - createChecked = 'checked="checked"'; - editChecked = 'checked="checked"'; - } - if (permissions & OC.PERMISSION_UPDATE) { - updateChecked = 'checked="checked"'; - editChecked = 'checked="checked"'; - } - if (permissions & OC.PERMISSION_DELETE) { - deleteChecked = 'checked="checked"'; - editChecked = 'checked="checked"'; - } - if (permissions & OC.PERMISSION_SHARE) { - shareChecked = 'checked="checked"'; - } - var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'">'; - html += shareWith; - if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) { - if (editChecked == '') { - html += '<label style="display:none;">'; + if (collection) { + if (collection.item_type == 'file' || collection.item_type == 'folder') { + var item = collection.path; } else { - html += '<label>'; + var item = collection.item_source; } - html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />can edit</label>'; - } - html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>'; - html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>'; - html += '<div class="cruds" style="display:none;">'; - if (possiblePermissions & OC.PERMISSION_CREATE) { - html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />create</label>'; + var collectionList = $('#shareWithList li').filterAttr('data-collection', item); + if (collectionList.length > 0) { + $(collectionList).append(', '+shareWith); + } else { + var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in %s with %s', item, shareWith)+'</li>'; + $('#shareWithList').prepend(html); } - if (possiblePermissions & OC.PERMISSION_UPDATE) { - html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />update</label>'; + } else { + var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = ''; + if (permissions & OC.PERMISSION_CREATE) { + createChecked = 'checked="checked"'; + editChecked = 'checked="checked"'; } - if (possiblePermissions & OC.PERMISSION_DELETE) { - html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />delete</label>'; + if (permissions & OC.PERMISSION_UPDATE) { + updateChecked = 'checked="checked"'; + editChecked = 'checked="checked"'; } - if (possiblePermissions & OC.PERMISSION_SHARE) { - html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />share</label>'; + if (permissions & OC.PERMISSION_DELETE) { + deleteChecked = 'checked="checked"'; + editChecked = 'checked="checked"'; } - html += '</div>'; - html += '</li>'; - $(html).appendTo('#shareWithList'); - + if (permissions & OC.PERMISSION_SHARE) { + shareChecked = 'checked="checked"'; + } + var html = '<li style="clear: both;" data-share-type="'+shareType+'" data-share-with="'+shareWith+'">'; + html += '<a href="#" class="unshare" style="display:none;"><img class="svg" alt="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>'; + html += shareWith; + if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) { + if (editChecked == '') { + html += '<label style="display:none;">'; + } else { + html += '<label>'; + } + html += '<input type="checkbox" name="edit" class="permissions" '+editChecked+' />'+t('core', 'can edit')+'</label>'; + } + html += '<a href="#" class="showCruds" style="display:none;"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>'; + html += '<div class="cruds" style="display:none;">'; + if (possiblePermissions & OC.PERMISSION_CREATE) { + html += '<label><input type="checkbox" name="create" class="permissions" '+createChecked+' data-permissions="'+OC.PERMISSION_CREATE+'" />'+t('core', 'create')+'</label>'; + } + if (possiblePermissions & OC.PERMISSION_UPDATE) { + html += '<label><input type="checkbox" name="update" class="permissions" '+updateChecked+' data-permissions="'+OC.PERMISSION_UPDATE+'" />'+t('core', 'update')+'</label>'; + } + if (possiblePermissions & OC.PERMISSION_DELETE) { + html += '<label><input type="checkbox" name="delete" class="permissions" '+deleteChecked+' data-permissions="'+OC.PERMISSION_DELETE+'" />'+t('core', 'delete')+'</label>'; + } + if (possiblePermissions & OC.PERMISSION_SHARE) { + html += '<label><input type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'+t('core', 'share')+'</label>'; + } + html += '</div>'; + html += '</li>'; + $(html).appendTo('#shareWithList'); + $('#expiration').show(); + } }, showLink:function(itemSource, password) { + OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true; $('#linkCheckbox').attr('checked', true); var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file'); if ($('#dir').val() == '/') { @@ -279,8 +314,9 @@ OC.Share={ $('#showPassword').show(); if (password != null) { $('#linkPass').show('blind'); - $('#linkPassText').attr('placeholder', 'Password protected'); + $('#linkPassText').attr('placeholder', t('core', 'Password protected')); } + $('#expiration').show(); }, hideLink:function() { $('#linkText').hide('blind'); @@ -289,6 +325,15 @@ OC.Share={ }, dirname:function(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); + }, + showExpirationDate:function(date) { + $('#expirationCheckbox').attr('checked', true); + $('#expirationDate').before('<br />'); + $('#expirationDate').val(date); + $('#expirationDate').show(); + $('#expirationDate').datepicker({ + dateFormat : 'dd-mm-yy' + }); } } @@ -358,6 +403,9 @@ $(document).ready(function() { var index = OC.Share.itemShares[shareType].indexOf(shareWith); OC.Share.itemShares[shareType].splice(index, 1); OC.Share.updateIcon(itemType, itemSource); + if (typeof OC.Share.statuses[itemSource] === 'undefined') { + $('#expiration').hide(); + } }); }); @@ -395,12 +443,17 @@ $(document).ready(function() { // Create a link OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, function() { OC.Share.showLink(itemSource); - // TODO Change icon + OC.Share.updateIcon(itemType, itemSource); }); } else { // Delete private link OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { OC.Share.hideLink(); + OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false; + OC.Share.updateIcon(itemType, itemSource); + if (typeof OC.Share.statuses[itemSource] === 'undefined') { + $('#expiration').hide(); + } }); } }); @@ -420,8 +473,34 @@ $(document).ready(function() { var itemSource = $('#dropdown').data('item-source'); OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $(this).val(), OC.PERMISSION_READ, function() { $('#linkPassText').val(''); - $('#linkPassText').attr('placeholder', 'Password protected'); + $('#linkPassText').attr('placeholder', t('core', 'Password protected')); + }); + } + }); + + $('#expirationCheckbox').live('click', function() { + if (this.checked) { + OC.Share.showExpirationDate(''); + } else { + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) { + if (!result || result.status !== 'success') { + OC.dialogs.alert(t('core', 'Error'), t('core', 'Error unsetting expiration date')); + } + $('#expirationDate').hide(); }); } }); + + $('#expirationDate').live('change', function() { + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) { + if (!result || result.status !== 'success') { + OC.dialogs.alert(t('core', 'Error'), t('core', 'Error setting expiration date')); + } + }); + }); + }); |