diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2014-05-30 13:42:24 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2014-05-30 13:42:24 +0200 |
commit | 517501ffbf369b24191d8b9a9f2ce44a9891fb97 (patch) | |
tree | f638ba7e2f3554b7b1a31f628496c7d0740fd2ac /apps/files/js | |
parent | 929882a32a020b6c05605f416fa55024b9a60d33 (diff) | |
parent | 7fac2b62e954b0f8a693516da1151c97efa2ee99 (diff) | |
download | nextcloud-server-517501ffbf369b24191d8b9a9f2ce44a9891fb97.tar.gz nextcloud-server-517501ffbf369b24191d8b9a9f2ce44a9891fb97.zip |
Merge pull request #8417 from owncloud/share-overview
Sharing overview page
Diffstat (limited to 'apps/files/js')
-rw-r--r-- | apps/files/js/app.js | 35 | ||||
-rw-r--r-- | apps/files/js/fileactions.js | 101 | ||||
-rw-r--r-- | apps/files/js/filelist.js | 60 |
3 files changed, 148 insertions, 48 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js index 9155fb38cdb..71802948a5c 100644 --- a/apps/files/js/app.js +++ b/apps/files/js/app.js @@ -24,20 +24,27 @@ initialize: function() { this.navigation = new OCA.Files.Navigation($('#app-navigation')); - // TODO: ideally these should be in a separate class / app (the embedded "all files" app) - this.fileActions = OCA.Files.FileActions; + var fileActions = new OCA.Files.FileActions(); + // default actions + fileActions.registerDefaultActions(); + // legacy actions + fileActions.merge(window.FileActions); + // regular actions + fileActions.merge(OCA.Files.fileActions); + this.files = OCA.Files.Files; + // TODO: ideally these should be in a separate class / app (the embedded "all files" app) this.fileList = new OCA.Files.FileList( $('#app-content-files'), { scrollContainer: $('#app-content'), dragOptions: dragOptions, - folderDropOptions: folderDropOptions + folderDropOptions: folderDropOptions, + fileActions: fileActions, + allowLegacyActions: true } ); this.files.initialize(); - this.fileActions.registerDefaultActions(this.fileList); - this.fileList.setFileActions(this.fileActions); // for backward compatibility, the global FileList will // refer to the one of the "files" view @@ -58,6 +65,22 @@ }, /** + * Sets the currently active view + * @param viewId view id + */ + setActiveView: function(viewId, options) { + this.navigation.setActiveItem(viewId, options); + }, + + /** + * Returns the view id of the currently active view + * @return view id + */ + getActiveView: function() { + return this.navigation.getActiveItem(); + }, + + /** * Setup events based on URL changes */ _setupEvents: function() { @@ -138,7 +161,7 @@ })(); $(document).ready(function() { - // wait for other apps/extensions to register their event handlers + // wait for other apps/extensions to register their event handlers and file actions // in the "ready" clause _.defer(function() { OCA.Files.App.initialize(); diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 085195e961d..3df62f37518 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -11,11 +11,40 @@ /* global trashBinApp */ (function() { - var FileActions = { + /** + * Construct a new FileActions instance + */ + var FileActions = function() { + this.initialize(); + } + FileActions.prototype = { actions: {}, defaults: {}, icons: {}, currentFile: null, + initialize: function() { + this.clear(); + }, + /** + * Merges the actions from the given fileActions into + * this instance. + * + * @param fileActions instance of OCA.Files.FileActions + */ + merge: function(fileActions) { + var self = this; + // merge first level to avoid unintended overwriting + _.each(fileActions.actions, function(sourceMimeData, mime) { + var targetMimeData = self.actions[mime]; + if (!targetMimeData) { + targetMimeData = {}; + } + self.actions[mime] = _.extend(targetMimeData, sourceMimeData); + }); + + this.defaults = _.extend(this.defaults, fileActions.defaults); + this.icons = _.extend(this.icons, fileActions.icons); + }, register: function (mime, name, permissions, icon, action, displayName) { if (!this.actions[mime]) { this.actions[mime] = {}; @@ -98,8 +127,13 @@ * @param parent "td" element of the file for which to display actions * @param triggerEvent if true, triggers the fileActionsReady on the file * list afterwards (false by default) + * @param fileList OCA.Files.FileList instance on which the action is + * done, defaults to OCA.Files.App.fileList */ - display: function (parent, triggerEvent) { + display: function (parent, triggerEvent, fileList) { + if (!fileList) { + console.warn('FileActions.display() MUST be called with a OCA.Files.FileList instance'); + } this.currentFile = parent; var self = this; var actions = this.getActions(this.getCurrentMimeType(), this.getCurrentType(), this.getCurrentPermissions()); @@ -120,9 +154,18 @@ event.preventDefault(); self.currentFile = event.data.elem; + // also set on global object for legacy apps + window.FileActions.currentFile = self.currentFile; + var file = self.getCurrentFile(); + var $tr = $(this).closest('tr'); - event.data.actionFunc(file); + event.data.actionFunc(file, { + $file: $tr, + fileList: fileList || OCA.Files.App.fileList, + fileActions: self, + dir: $tr.attr('data-path') || fileList.getCurrentDirectory() + }); }; var addAction = function (name, action, displayName) { @@ -189,7 +232,7 @@ } if (triggerEvent){ - $('#fileList').trigger(jQuery.Event("fileActionsReady")); + fileList.$fileList.trigger(jQuery.Event("fileActionsReady", {fileList: fileList})); } }, getCurrentFile: function () { @@ -208,29 +251,27 @@ /** * Register the actions that are used by default for the files app. */ - registerDefaultActions: function(fileList) { - // TODO: try to find a way to not make it depend on fileList, - // maybe get a handler or listener to trigger events on + registerDefaultActions: function() { this.register('all', 'Delete', OC.PERMISSION_DELETE, function () { return OC.imagePath('core', 'actions/delete'); - }, function (filename) { - fileList.do_delete(filename); + }, function (filename, context) { + context.fileList.do_delete(filename); $('.tipsy').remove(); }); // t('files', 'Rename') this.register('all', 'Rename', OC.PERMISSION_UPDATE, function () { return OC.imagePath('core', 'actions/rename'); - }, function (filename) { - fileList.rename(filename); + }, function (filename, context) { + context.fileList.rename(filename); }); - this.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename) { - var dir = fileList.getCurrentDirectory(); + this.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { + var dir = context.fileList.getCurrentDirectory(); if (dir !== '/') { dir = dir + '/'; } - fileList.changeDirectory(dir + filename); + context.fileList.changeDirectory(dir + filename); }); this.setDefault('dir', 'Open'); @@ -243,20 +284,38 @@ this.register(downloadScope, 'Download', OC.PERMISSION_READ, function () { return OC.imagePath('core', 'actions/download'); - }, function (filename) { - var url = fileList.getDownloadUrl(filename, fileList.getCurrentDirectory()); + }, function (filename, context) { + var dir = context.dir || context.fileList.getCurrentDirectory(); + var url = context.fileList.getDownloadUrl(filename, dir); if (url) { OC.redirect(url); } }); - - fileList.$fileList.trigger(jQuery.Event("fileActionsReady")); } }; OCA.Files.FileActions = FileActions; -})(); -// for backward compatibility -window.FileActions = OCA.Files.FileActions; + // global file actions to be used by all lists + OCA.Files.fileActions = new OCA.Files.FileActions(); + OCA.Files.legacyFileActions = new OCA.Files.FileActions(); + + // for backward compatibility + // + // legacy apps are expecting a stateful global FileActions object to register + // their actions on. Since legacy apps are very likely to break with other + // FileList views than the main one ("All files"), actions registered + // through window.FileActions will be limited to the main file list. + window.FileActions = OCA.Files.legacyFileActions; + window.FileActions.register = function (mime, name, permissions, icon, action, displayName) { + console.warn('FileActions.register() is deprecated, please use OCA.Files.fileActions.register() instead', arguments); + OCA.Files.FileActions.prototype.register.call( + window.FileActions, mime, name, permissions, icon, action, displayName + ); + }; + window.FileActions.setDefault = function (mime, name) { + console.warn('FileActions.setDefault() is deprecated, please use OCA.Files.fileActions.setDefault() instead', mime, name); + OCA.Files.FileActions.prototype.setDefault.call(window.FileActions, mime, name); + }; +})(); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 72e1a688041..68b22207144 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -125,7 +125,7 @@ this.$container = options.scrollContainer || $(window); this.$table = $el.find('table:first'); this.$fileList = $el.find('#fileList'); - this.fileActions = OCA.Files.FileActions; + this._initFileActions(options.fileActions); this.files = []; this._selectedFiles = {}; this._selectionSummary = new OCA.Files.FileSummary(); @@ -168,6 +168,14 @@ this.$container.on('scroll', _.bind(this._onScroll, this)); }, + _initFileActions: function(fileActions) { + this.fileActions = fileActions; + if (!this.fileActions) { + this.fileActions = new OCA.Files.FileActions(); + this.fileActions.registerDefaultActions(); + } + }, + /** * Event handler for when the URL changed */ @@ -248,7 +256,14 @@ var action = this.fileActions.getDefault(mime,type, permissions); if (action) { event.preventDefault(); - action(filename); + // also set on global object for legacy apps + window.FileActions.currentFile = this.fileActions.currentFile; + action(filename, { + $file: $tr, + fileList: this, + fileActions: this.fileActions, + dir: $tr.attr('data-path') || this.getCurrentDirectory() + }); } } } @@ -448,7 +463,7 @@ while (count > 0 && index < this.files.length) { fileData = this.files[index]; - tr = this._renderRow(fileData, {updateSummary: false}); + tr = this._renderRow(fileData, {updateSummary: false, silent: true}); this.$fileList.append(tr); if (isAllSelected || this._selectedFiles[fileData.id]) { tr.addClass('selected'); @@ -493,7 +508,7 @@ this.$el.find('thead').after(this.$fileList); this.updateEmptyContent(); - this.$fileList.trigger(jQuery.Event("fileActionsReady")); + this.$fileList.trigger($.Event('fileActionsReady', {fileList: this})); this.fileSummary.calculate(filesArray); @@ -515,6 +530,7 @@ type = fileData.type || 'file', mtime = parseInt(fileData.mtime, 10) || new Date().getTime(), mime = fileData.mimetype, + path = fileData.path, linkUrl; options = options || {}; @@ -534,6 +550,13 @@ "data-permissions": fileData.permissions || this.getDirectoryPermissions() }); + if (!_.isUndefined(path)) { + tr.attr('data-path', path); + } + else { + path = this.getCurrentDirectory(); + } + if (type === 'dir') { // use default folder icon icon = icon || OC.imagePath('core', 'filetypes/folder'); @@ -550,10 +573,10 @@ // linkUrl if (type === 'dir') { - linkUrl = this.linkTo(this.getCurrentDirectory() + '/' + name); + linkUrl = this.linkTo(path + '/' + name); } else { - linkUrl = this.getDownloadUrl(name, this.getCurrentDirectory()); + linkUrl = this.getDownloadUrl(name, path); } td.append('<input id="select-' + this.id + '-' + fileData.id + '" type="checkbox" /><label for="select-' + this.id + '-' + fileData.id + '"></label>'); @@ -621,7 +644,8 @@ * * @param fileData map of file attributes * @param options map of attributes: - * - "updateSummary" true to update the summary after adding (default), false otherwise + * - "updateSummary": true to update the summary after adding (default), false otherwise + * - "silent": true to prevent firing events like "fileActionsReady" * @return new tr element (not appended to the table) */ add: function(fileData, options) { @@ -693,6 +717,7 @@ options = options || {}; var type = fileData.type || 'file', mime = fileData.mimetype, + path = fileData.path || this.getCurrentDirectory(), permissions = parseInt(fileData.permissions, 10) || 0; if (fileData.isShareMountPoint) { @@ -723,13 +748,13 @@ } // display actions - this.fileActions.display(filenameTd, false); + this.fileActions.display(filenameTd, !options.silent, this); if (fileData.isPreviewAvailable) { // lazy load / newly inserted td ? if (!fileData.icon) { this.lazyLoadPreview({ - path: this.getCurrentDirectory() + '/' + fileData.name, + path: path + '/' + fileData.name, mime: mime, etag: fileData.etag, callback: function(url) { @@ -740,7 +765,7 @@ else { // set the preview URL directly var urlSpec = { - file: this.getCurrentDirectory() + '/' + fileData.name, + file: path + '/' + fileData.name, c: fileData.etag }; var previewUrl = this.generatePreviewUrl(urlSpec); @@ -784,13 +809,6 @@ }, /** - * Sets the file actions handler - */ - setFileActions: function(fileActions) { - this.fileActions = fileActions; - }, - - /** * Sets the current directory name and updates the breadcrumb. * @param targetDir directory to display * @param changeUrl true to also update the URL, false otherwise (default) @@ -1213,16 +1231,16 @@ // reinsert row self.files.splice(tr.index(), 1); tr.remove(); - self.add(fileInfo, {updateSummary: false}); - self.$fileList.trigger($.Event('fileActionsReady')); + self.add(fileInfo, {updateSummary: false, silent: true}); + self.$fileList.trigger($.Event('fileActionsReady', {fileList: self})); } }); } else { // add back the old file info when cancelled self.files.splice(tr.index(), 1); tr.remove(); - self.add(oldFileInfo, {updateSummary: false}); - self.$fileList.trigger($.Event('fileActionsReady')); + self.add(oldFileInfo, {updateSummary: false, silent: true}); + self.$fileList.trigger($.Event('fileActionsReady', {fileList: self})); } } catch (error) { input.attr('title', error); |