diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-06-02 15:59:06 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-06-02 15:59:06 +0200 |
commit | d677e3860d22e3a779c0f01af1adc4e193127d1c (patch) | |
tree | e666f6a708b95e25ec13e25971cc0c1b15a71a07 /apps/files_sharing/js | |
parent | 7961d4a87e8734bbcfda98309e6b64797fc0bb42 (diff) | |
download | nextcloud-server-d677e3860d22e3a779c0f01af1adc4e193127d1c.tar.gz nextcloud-server-d677e3860d22e3a779c0f01af1adc4e193127d1c.zip |
Added unit tests for share.js and share icon
Diffstat (limited to 'apps/files_sharing/js')
-rw-r--r-- | apps/files_sharing/js/share.js | 22 | ||||
-rw-r--r-- | apps/files_sharing/js/sharedfilelist.js | 15 |
2 files changed, 16 insertions, 21 deletions
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index db770ad1509..9f47e785821 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -13,7 +13,7 @@ OCA.Sharing = {}; } OCA.Sharing.Util = { - initialize: function() { + initialize: function(fileActions) { if (!_.isUndefined(OC.Share) && !_.isUndefined(OCA.Files)) { // TODO: make a separate class for this or a hook or jQuery event ? if (OCA.Files.FileList) { @@ -28,6 +28,9 @@ tr.attr('data-reshare-permissions', fileData.permissions); } } + if (fileData.recipientsDisplayName) { + tr.attr('data-share-recipients', fileData.recipientsDisplayName); + } return tr; }; } @@ -72,7 +75,7 @@ } }); - OCA.Files.fileActions.register( + fileActions.register( 'all', 'Share', OC.PERMISSION_SHARE, @@ -109,11 +112,7 @@ // is called automatically after this event var userShares = ev.itemShares[OC.Share.SHARE_TYPE_USER] || []; var groupShares = ev.itemShares[OC.Share.SHARE_TYPE_GROUP] || []; - var linkShares = ev.itemShares[OC.Share.SHARE_TYPE_LINK] || []; var recipients = _.union(userShares, groupShares); - if (linkShares.length > 0) { - recipients.unshift(t('files_sharing', 'Public')); - } // only update the recipients if they existed before // (some file lists don't have them) if (!_.isUndefined($tr.attr('data-share-recipients'))) { @@ -131,7 +130,7 @@ }, /** - * Formats a recipient array to be displayed. + * Formats a recipients array to be displayed. * The first four recipients will be shown and the * other ones will be shown as "+x" where "x" is the number of * remaining recipients. @@ -146,7 +145,9 @@ if (!_.isNumber(count)) { count = recipients.length; } - text = _.first(recipients, maxRecipients).join(', '); + // TODO: use natural sort + recipients = _.first(recipients, maxRecipients).sort(); + text = recipients.join(', '); if (count > maxRecipients) { text += ', +' + (count - maxRecipients); } @@ -156,6 +157,9 @@ })(); $(document).ready(function() { - OCA.Sharing.Util.initialize(); + // FIXME: HACK: do not init when running unit tests, need a better way + if (!window.TESTING) { + OCA.Sharing.Util.initialize(OCA.Files.fileActions); + } }); diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 9cf74abf670..8a6c3169f9e 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -48,9 +48,6 @@ if (this._sharedWithUser) { $tr.attr('data-share-owner', fileData.shares[0].ownerDisplayName); } - if (fileData.recipientsDisplayName) { - $tr.attr('data-share-recipients', fileData.recipientsDisplayName); - } return $tr; }, @@ -201,11 +198,9 @@ data.shares.push(file.share); } - if (file.share.type === OC.Share.SHARE_TYPE_LINK) { - data.hasLinkShare = true; - } else if (recipient) { + if (recipient) { // limit counterparts for output - if (data.recipientsCount < 3) { + if (data.recipientsCount < 4) { // only store the first ones, they will be the only ones // displayed data.recipients[recipient] = true; @@ -222,11 +217,7 @@ .each(function(data) { // convert the recipients map to a flat // array of sorted names - data.recipients = _.chain(data.recipients).keys().sort().value(); - if (data.hasLinkShare) { - data.recipients.unshift(t('files_sharing', 'Public')); - delete data.hasLinkShare; - } + data.recipients = _.keys(data.recipients); data.recipientsDisplayName = OCA.Sharing.Util.formatRecipients( data.recipients, data.recipientsCount |