diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-12-01 16:17:28 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-12-01 16:20:44 +0100 |
commit | c02ef695217f42dff501e481a50f4669d1cb1f29 (patch) | |
tree | 98ef997af355d9fd050645a7ba5c827056c87392 /apps/files_sharing | |
parent | 8db4dd7585aa9daebb32a3f3305f4061b17c316d (diff) | |
download | nextcloud-server-c02ef695217f42dff501e481a50f4669d1cb1f29.tar.gz nextcloud-server-c02ef695217f42dff501e481a50f4669d1cb1f29.zip |
Simple Plugin system for Javascript
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/js/app.js | 3 | ||||
-rw-r--r-- | apps/files_sharing/js/public.js | 4 | ||||
-rw-r--r-- | apps/files_sharing/js/share.js | 74 | ||||
-rw-r--r-- | apps/files_sharing/js/sharedfilelist.js | 1 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/shareSpec.js | 2 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/sharedfilelistSpec.js | 5 |
6 files changed, 47 insertions, 42 deletions
diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js index 1314304c567..ff6997ab12f 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -30,6 +30,7 @@ OCA.Sharing.App = { this._inFileList = new OCA.Sharing.FileList( $el, { + id: 'shares.self', scrollContainer: $('#app-content'), sharedWithUser: true, fileActions: this._createFileActions() @@ -49,6 +50,7 @@ OCA.Sharing.App = { this._outFileList = new OCA.Sharing.FileList( $el, { + id: 'shares.others', scrollContainer: $('#app-content'), sharedWithUser: false, fileActions: this._createFileActions() @@ -68,6 +70,7 @@ OCA.Sharing.App = { this._linkFileList = new OCA.Sharing.FileList( $el, { + id: 'shares.link', scrollContainer: $('#app-content'), linksOnly: true, fileActions: this._createFileActions() diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 0627ed6ab54..2ddcd84d4c1 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -53,6 +53,7 @@ OCA.Sharing.PublicApp = { this.fileList = new OCA.Files.FileList( $el, { + id: 'files.public', scrollContainer: $(window), dragOptions: dragOptions, folderDropOptions: folderDropOptions, @@ -61,6 +62,9 @@ OCA.Sharing.PublicApp = { ); this.files = OCA.Files.Files; this.files.initialize(); + // TODO: move to PublicFileList.initialize() once + // the code was split into a separate class + OC.Plugins.attach('OCA.Sharing.PublicFileList', this.fileList); } var mimetype = $('#mimetype').val(); diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 8474c66d4b8..bbd107e070e 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -17,46 +17,47 @@ */ OCA.Sharing.Util = { /** - * Initialize the sharing app overrides of the default - * file list. + * Initialize the sharing plugin. * * Registers the "Share" file action and adds additional * DOM attributes for the sharing file info. * - * @param {OCA.Files.FileActions} fileActions file actions to extend + * @param {OCA.Files.FileList} fileList file list to be extended */ - initialize: function(fileActions) { - if (OCA.Files.FileList) { - var oldCreateRow = OCA.Files.FileList.prototype._createRow; - OCA.Files.FileList.prototype._createRow = function(fileData) { - var tr = oldCreateRow.apply(this, arguments); - var sharePermissions = fileData.permissions; - if (fileData.mountType && fileData.mountType === "external-root"){ - // for external storages we cant use the permissions of the mountpoint - // instead we show all permissions and only use the share permissions from the mountpoint to handle resharing - sharePermissions = sharePermissions | (OC.PERMISSION_ALL & ~OC.PERMISSION_SHARE); - } - if (fileData.type === 'file') { - // files can't be shared with delete permissions - sharePermissions = sharePermissions & ~OC.PERMISSION_DELETE; - } - tr.attr('data-share-permissions', sharePermissions); - if (fileData.shareOwner) { - tr.attr('data-share-owner', fileData.shareOwner); - // user should always be able to rename a mount point - if (fileData.isShareMountPoint) { - tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE); - } - } - if (fileData.recipientsDisplayName) { - tr.attr('data-share-recipients', fileData.recipientsDisplayName); - } - return tr; - }; + attach: function(fileList) { + if (fileList.id === 'trashbin') { + return; } + var fileActions = fileList.fileActions; + var oldCreateRow = fileList._createRow; + fileList._createRow = function(fileData) { + var tr = oldCreateRow.apply(this, arguments); + var sharePermissions = fileData.permissions; + if (fileData.mountType && fileData.mountType === "external-root"){ + // for external storages we cant use the permissions of the mountpoint + // instead we show all permissions and only use the share permissions from the mountpoint to handle resharing + sharePermissions = sharePermissions | (OC.PERMISSION_ALL & ~OC.PERMISSION_SHARE); + } + if (fileData.type === 'file') { + // files can't be shared with delete permissions + sharePermissions = sharePermissions & ~OC.PERMISSION_DELETE; + } + tr.attr('data-share-permissions', sharePermissions); + if (fileData.shareOwner) { + tr.attr('data-share-owner', fileData.shareOwner); + // user should always be able to rename a mount point + if (fileData.isShareMountPoint) { + tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE); + } + } + if (fileData.recipientsDisplayName) { + tr.attr('data-share-recipients', fileData.recipientsDisplayName); + } + return tr; + }; // use delegate to catch the case with multiple file lists - $('#content').delegate('#fileList', 'fileActionsReady', function(ev){ + fileList.$el.on('fileActionsReady', function(ev){ var fileList = ev.fileList; var $files = ev.$files; @@ -198,12 +199,5 @@ }; })(); -$(document).ready(function() { - // FIXME: HACK: do not init when running unit tests, need a better way - if (!window.TESTING) { - if (!_.isUndefined(OC.Share) && !_.isUndefined(OCA.Files)) { - OCA.Sharing.Util.initialize(OCA.Files.fileActions); - } - } -}); +OC.Plugins.register('OCA.Files.FileList', OCA.Sharing.Util); diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 7a7c24993c0..bd26b13b78a 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -55,6 +55,7 @@ if (options && options.linksOnly) { this._linksOnly = true; } + OC.Plugins.attach('OCA.Sharing.FileList', this); }, _renderRow: function() { diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index 2cf5dc47b63..d64d4ea8137 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -41,12 +41,12 @@ describe('OCA.Sharing.Util tests', function() { $('#content').append($div); var fileActions = new OCA.Files.FileActions(); - OCA.Sharing.Util.initialize(fileActions); fileList = new OCA.Files.FileList( $div, { fileActions : fileActions } ); + OCA.Sharing.Util.attach(fileList); testFiles = [{ id: 1, diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index dc6931af6e8..d85c0ab6dca 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -50,7 +50,6 @@ describe('OCA.Sharing.FileList tests', function() { // the sharing code oldFileListPrototype = _.extend({}, OCA.Files.FileList.prototype); fileActions = new OCA.Files.FileActions(); - OCA.Sharing.Util.initialize(fileActions); }); afterEach(function() { OCA.Files.FileList.prototype = oldFileListPrototype; @@ -72,6 +71,7 @@ describe('OCA.Sharing.FileList tests', function() { sharedWithUser: true } ); + OCA.Sharing.Util.attach(fileList); fileList.reload(); @@ -193,6 +193,7 @@ describe('OCA.Sharing.FileList tests', function() { sharedWithUser: false } ); + OCA.Sharing.Util.attach(fileList); fileList.reload(); @@ -433,6 +434,7 @@ describe('OCA.Sharing.FileList tests', function() { linksOnly: true } ); + OCA.Sharing.Util.attach(fileList); fileList.reload(); @@ -580,6 +582,7 @@ describe('OCA.Sharing.FileList tests', function() { fileActions: fileActions } ); + OCA.Sharing.Util.attach(fileList); }); it('external storage root folder', function () { |