diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-05-28 18:39:29 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-06-02 12:12:57 +0200 |
commit | 7961d4a87e8734bbcfda98309e6b64797fc0bb42 (patch) | |
tree | b8562ba8b2a5f7319d1b57ca74e6356d45a9c999 /core/js | |
parent | f931df2dac6466568ffdc52bed01d3f781430f9e (diff) | |
download | nextcloud-server-7961d4a87e8734bbcfda98309e6b64797fc0bb42.tar.gz nextcloud-server-7961d4a87e8734bbcfda98309e6b64797fc0bb42.zip |
Update share action text to display owner/recipients
- when a share was changed, update the share action text
- added file data attribute "data-share-recipients"
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/share.js | 95 |
1 files changed, 63 insertions, 32 deletions
diff --git a/core/js/share.js b/core/js/share.js index 0c6d39e446c..d8020531763 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -56,20 +56,14 @@ OC.Share={ image = OC.imagePath('core', 'actions/public'); } if (itemType !== 'file' && itemType !== 'folder') { - $fileList.find('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center'); + $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center'); } else { + // TODO: ultimately this part should be moved to files_sharing app var file = $fileList.find('tr[data-id="'+item+'"]'); var shareFolder = OC.imagePath('core', 'filetypes/folder-shared'); var img; if (file.length > 0) { - var type = file.data('type'); - if (type === 'dir') { - file.children('.filename').css('background-image', 'url('+shareFolder+')'); - } - var action = $(file).find('.fileactions .action[data-action="Share"]'); - img = action.find('img').attr('src', image); - action.addClass('permanent'); - action.html(' <span>'+t('core', 'Shared')+'</span>').prepend(img); + this.markFileAsShared(file, true, image); } else { var dir = currentDir; if (dir.length > 1) { @@ -82,6 +76,7 @@ OC.Share={ var files = $fileList.find('.filename'); var i; for (i = 0; i < actions.length; i++) { + // TODO: use this.markFileAsShared() img = $(actions[i]).find('img'); if (img.attr('src') !== OC.imagePath('core', 'actions/public')) { img.attr('src', image); @@ -125,29 +120,9 @@ OC.Share={ if (itemType != 'file' && itemType != 'folder') { $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center'); } else { - var file = $('tr').filterAttr('data-id', String(itemSource)); - if (file.length > 0) { - var type = file.data('type'); - var shareFolder = OC.imagePath('core', 'filetypes/folder'); - if (type === 'dir' && shares) { - shareFolder = OC.imagePath('core', 'filetypes/folder-shared'); - file.children('.filename').css('background-image', 'url('+shareFolder+')'); - } else if (type === 'dir') { - file.children('.filename').css('background-image', 'url('+shareFolder+')'); - } - var action = $(file).find('.fileactions .action').filterAttr('data-action', 'Share'); - // in case of multiple lists/rows, there might be more than one visible - action.each(function() { - var action = $(this); - var img = action.find('img').attr('src', image); - if (shares) { - action.addClass('permanent'); - action.html(' <span>'+ escapeHTML(t('core', 'Shared'))+'</span>').prepend(img); - } else { - action.removeClass('permanent'); - action.html(' <span>'+ escapeHTML(t('core', 'Share'))+'</span>').prepend(img); - } - }); + var $tr = $('tr').filterAttr('data-id', String(itemSource)); + if ($tr.length > 0) { + this.markFileAsShared($tr, shares, image); } } if (shares) { @@ -157,6 +132,59 @@ OC.Share={ delete OC.Share.statuses[itemSource]; } }, + /** + * Marks/unmarks a given file as shared + * + * @param $tr file element to mark as shared + * @param state true to mark as shared, false to unmark + * @param image image to use for the icon + */ + markFileAsShared: function($tr, state, image) { + var action = $tr.find('.fileactions .action[data-action="Share"]'); + var type = $tr.data('type'); + var img = action.find('img'); + var message; + var recipients; + var owner; + var shareFolderIcon; + if (type === 'dir' && state) { + shareFolderIcon = OC.imagePath('core', 'filetypes/folder-shared'); + $tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')'); + } else if (type === 'dir') { + shareFolderIcon = OC.imagePath('core', 'filetypes/folder'); + $tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')'); + } + if (state) { + recipients = $tr.attr('data-share-recipients'); + owner = $tr.attr('data-share-owner'); + + action.addClass('permanent'); + message = t('core', 'Shared'); + if (owner && !recipients) { + message = t('files_sharing', 'Shared by {owner}', {owner: owner}); + image = image || OC.imagePath('core', 'actions/share'); + } + if (recipients) { + image = image || OC.imagePath('core', 'actions/shared'); + if (owner) { + message = ' ' + t( + 'files_sharing', + 'Shared by {owner} with You, {recipients}', + {owner: owner, recipients: recipients} + ); + } + else { + message = t('core', 'Shared with {recipients}', {recipients: recipients}); + } + } + action.html(' <span>'+ message + '</span>').prepend(img); + } + else { + action.removeClass('permanent'); + action.html(' <span>'+ escapeHTML(t('core', 'Share'))+'</span>').prepend(img); + } + img.attr('src', image); + }, loadItem:function(itemType, itemSource) { var data = ''; var checkReshare = true; @@ -384,6 +412,7 @@ OC.Share={ OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, function() { OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, possiblePermissions); $('#shareWith').val(''); + $('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: OC.Share.itemShares})); OC.Share.updateIcon(itemType, itemSource); }); return false; @@ -665,6 +694,7 @@ $(document).ready(function() { $li.remove(); var index = OC.Share.itemShares[shareType].indexOf(shareWith); OC.Share.itemShares[shareType].splice(index, 1); + $('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: OC.Share.itemShares})); OC.Share.updateIcon(itemType, itemSource); if (typeof OC.Share.statuses[itemSource] === 'undefined') { $('#expiration').hide('blind'); @@ -723,6 +753,7 @@ $(document).ready(function() { if (oc_appconfig.core.enforcePasswordForPublicLink === false) { OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, itemSourceName, expirationDate, function(data) { OC.Share.showLink(data.token, null, itemSource); + $('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: OC.Share.itemShares})); OC.Share.updateIcon(itemType, itemSource); }); } else { |