summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/js/share.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-09-14 17:20:51 +0200
committerVincent Petry <pvince81@owncloud.com>2015-09-16 07:23:28 +0200
commite90065881d47a64b6c376208ece208932711c765 (patch)
tree7bbd578263150f5d64f11fdc74da6bb838763c0c /apps/files_sharing/js/share.js
parent8194d092e71b1c44a441dddc64b7e7533adbbfb9 (diff)
downloadnextcloud-server-e90065881d47a64b6c376208ece208932711c765.tar.gz
nextcloud-server-e90065881d47a64b6c376208ece208932711c765.zip
Bring back the share icon and update its status
Display share icon in file list row. Update share icon status when the sharing state changed.
Diffstat (limited to 'apps/files_sharing/js/share.js')
-rw-r--r--apps/files_sharing/js/share.js63
1 files changed, 56 insertions, 7 deletions
diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js
index c3d567fec86..5290dfbb7d1 100644
--- a/apps/files_sharing/js/share.js
+++ b/apps/files_sharing/js/share.js
@@ -32,6 +32,7 @@
if (fileList.id === 'trashbin' || fileList.id === 'files.public') {
return;
}
+ var fileActions = fileList.fileActions;
var oldCreateRow = fileList._createRow;
fileList._createRow = function(fileData) {
var tr = oldCreateRow.apply(this, arguments);
@@ -78,7 +79,9 @@
$files = fileList.$fileList.find('tr');
}
_.each($files, function(file) {
- OCA.Sharing.Util.updateFileActionIcon($(file));
+ var $tr = $(file);
+ var shareStatus = OC.Share.statuses[$tr.data('id')];
+ OCA.Sharing.Util._updateFileActionIcon($tr, !!shareStatus, shareStatus && shareStatus.link);
});
}
@@ -96,22 +99,66 @@
}
});
- fileList.registerTabView(new OCA.Sharing.ShareTabView('shareTabView'));
+ fileActions.registerAction({
+ name: 'Share',
+ displayName: '',
+ mime: 'all',
+ permissions: OC.PERMISSION_SHARE,
+ icon: OC.imagePath('core', 'actions/share'),
+ type: OCA.Files.FileActions.TYPE_INLINE,
+ actionHandler: function(fileName) {
+ fileList.showDetailsView(fileName, 'shareTabView');
+ }
+ });
+
+ var shareTab = new OCA.Sharing.ShareTabView('shareTabView');
+ // detect changes and change the matching list entry
+ shareTab.on('sharesChanged', function(shareModel) {
+ var fileInfoModel = shareModel.fileInfoModel;
+ var $tr = fileList.findFileEl(fileInfoModel.get('name'));
+ OCA.Sharing.Util._updateFileListDataAttributes(fileList, $tr, shareModel);
+ if (!OCA.Sharing.Util._updateFileActionIcon($tr, shareModel.hasUserShares(), shareModel.hasLinkShare())) {
+ // remove icon, if applicable
+ OC.Share.markFileAsShared($tr, false, false);
+ }
+ });
+ fileList.registerTabView(shareTab);
+ },
+
+ /**
+ * Update file list data attributes
+ */
+ _updateFileListDataAttributes: function(fileList, $tr, shareModel) {
+ // files app current cannot show recipients on load, so we don't update the
+ // icon when changed for consistency
+ if (fileList.id === 'files') {
+ return;
+ }
+ var recipients = _.pluck(shareModel.get('shares'), 'share_with_displayname');
+ // note: we only update the data attribute because updateIcon()
+ if (recipients.length) {
+ $tr.attr('data-share-recipients', OCA.Sharing.Util.formatRecipients(recipients));
+ }
+ else {
+ $tr.removeAttr('data-share-recipients');
+ }
},
/**
* Update the file action share icon for the given file
*
* @param $tr file element of the file to update
+ * @param {bool} hasUserShares true if a user share exists
+ * @param {bool} hasLinkShare true if a link share exists
+ *
+ * @return {bool} true if the icon was set, false otherwise
*/
- updateFileActionIcon: function($tr) {
+ _updateFileActionIcon: function($tr, hasUserShares, hasLinkShare) {
// if the statuses are loaded already, use them for the icon
// (needed when scrolling to the next page)
- var shareStatus = OC.Share.statuses[$tr.data('id')];
- if (shareStatus || $tr.attr('data-share-recipients') || $tr.attr('data-share-owner')) {
+ if (hasUserShares || hasLinkShare || $tr.attr('data-share-recipients') || $tr.attr('data-share-owner')) {
var permissions = $tr.data('permissions');
- var hasLink = !!(shareStatus && shareStatus.link);
- OC.Share.markFileAsShared($tr, true, hasLink);
+ OC.Share.markFileAsShared($tr, true, hasLinkShare);
if ((permissions & OC.PERMISSION_SHARE) === 0 && $tr.attr('data-share-owner')) {
// if no share action exists because the admin disabled sharing for this user
// we create a share notification action to inform the user about files
@@ -130,7 +177,9 @@
return $result;
});
}
+ return true;
}
+ return false;
},
/**