diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 24f8279116dea8dde1dd9fc274cb6aa1998347aa..1f6d5f798a929f1145e934e0e341801c285e045b 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -256,6 +256,19 @@ return undefined; }, + /** + * Returns the default file action handler for the current file + * + * @return {OCA.Files.FileActions~actionSpec} action spec + * @since 8.2 + */ + getCurrentDefaultFileAction: function() { + var mime = this.getCurrentMimeType(); + var type = this.getCurrentType(); + var permissions = this.getCurrentPermissions(); + return this.getDefaultFileAction(mime, type, permissions); + }, + /** * Returns the default file action handler for the given conditions * @@ -263,7 +276,7 @@ * @param {string} type "dir" or "file" * @param {int} permissions permissions * - * @return {OCA.Files.FileActions~actionHandler} action handler + * @return {OCA.Files.FileActions~actionSpec} action spec * @since 8.2 */ getDefaultFileAction: function(mime, type, permissions) { diff --git a/apps/files/js/fileactionsmenu.js b/apps/files/js/fileactionsmenu.js index 16c4cc0d784a6f6e2d4d86ea267ff7012c0b5084..53dec693c1cbc8e1d04b60f3facfcfd6d4ead6da 100644 --- a/apps/files/js/fileactionsmenu.js +++ b/apps/files/js/fileactionsmenu.js @@ -77,11 +77,7 @@ fileActions.getCurrentPermissions() ); - var defaultAction = fileActions.getDefaultFileAction( - fileActions.getCurrentMimeType(), - fileActions.getCurrentType(), - fileActions.getCurrentPermissions() - ); + var defaultAction = fileActions.getCurrentDefaultFileAction(); var items = _.filter(actions, function(actionSpec) { return !defaultAction || actionSpec.name !== defaultAction.name; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 9973c92c8ece246fd41b48ce8dd65de068e5a786..e7d48d4bcd13ff7a76ad1c321743d5ccc5e40f7f 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -432,7 +432,7 @@ this.setupUploadEvents(this._uploader); } } - + this.triedActionOnce = false; OC.Plugins.attach('OCA.Files.FileList', this); @@ -874,16 +874,12 @@ if ($tr.hasClass('dragging')) { return; } - if (this._allowSelection && (event.ctrlKey || event.shiftKey)) { + if (this._allowSelection && event.shiftKey) { event.preventDefault(); - if (event.shiftKey) { - this._selectRange($tr); - } else { - this._selectSingle($tr); - } + this._selectRange($tr); this._lastChecked = $tr; this.updateSelectionSummary(); - } else { + } else if (!event.ctrlKey) { // clicked directly on the name if (!this._detailsView || $(event.target).is('.nametext, .name, .thumbnail') || $(event.target).closest('.nametext').length) { var filename = $tr.attr('data-file'); @@ -892,13 +888,10 @@ event.preventDefault(); } else if (!renaming) { this.fileActions.currentFile = $tr.find('td'); - var mime = this.fileActions.getCurrentMimeType(); - var type = this.fileActions.getCurrentType(); - var permissions = this.fileActions.getCurrentPermissions(); - var action = this.fileActions.getDefault(mime,type, permissions); - if (action) { + var spec = this.fileActions.getCurrentDefaultFileAction(); + if (spec && spec.action) { event.preventDefault(); - action(filename, { + spec.action(filename, { $file: $tr, fileList: this, fileActions: this.fileActions, @@ -1323,6 +1316,31 @@ }, 0); } + if(!this.triedActionOnce) { + var id = OC.Util.History.parseUrlQuery().openfile; + if (id) { + var $tr = this.$fileList.children().filterAttr('data-id', '' + id); + var filename = $tr.attr('data-file'); + this.fileActions.currentFile = $tr.find('td'); + var dir = $tr.attr('data-path') || this.getCurrentDirectory(); + var spec = this.fileActions.getCurrentDefaultFileAction(); + if (spec && spec.action) { + spec.action(filename, { + $file: $tr, + fileList: this, + fileActions: this.fileActions, + dir: dir + }); + + } + else { + var url = this.getDownloadUrl(filename, dir, true); + OCA.Files.Files.handleDownload(url); + } + } + this.triedActionOnce = true; + } + return newTrs; }, @@ -1527,10 +1545,14 @@ td = $('<td class="filename"></td>'); + var spec = this.fileActions.getDefaultFileAction(mime, type, permissions); // linkUrl if (mime === 'httpd/unix-directory') { linkUrl = this.linkTo(path + '/' + name); } + else if (spec && spec.action) { + linkUrl = this.getDefaultActionUrl(path, fileData.id); + } else { linkUrl = this.getDownloadUrl(name, path, type === 'dir'); } @@ -2149,6 +2171,10 @@ return OCA.Files.Files.getDownloadUrl(files, dir || this.getCurrentDirectory(), isDir); }, + getDefaultActionUrl: function(path, id) { + return this.linkTo(path) + "&openfile="+id; + }, + getUploadUrl: function(fileName, dir) { if (_.isUndefined(dir)) { dir = this.getCurrentDirectory(); diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index f9c1b5f31cd647c1e8b0f92b11b797a251352595..ee70a1452a9212b4c8f497c2c97e1726a0a5c6ac 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -239,6 +239,33 @@ describe('OCA.Files.FileList tests', function() { expect($tr.find('.date').text()).not.toEqual('?'); expect(fileList.findFileEl('testName.txt')[0]).toEqual($tr[0]); }); + it('generates file element with url for default action when one is defined', function() { + var actionStub = sinon.stub(); + fileList.setFiles(testFiles); + fileList.fileActions.registerAction({ + mime: 'text/plain', + name: 'Test', + type: OCA.Files.FileActions.TYPE_INLINE, + permissions: OC.PERMISSION_ALL, + icon: function() { + // Specify icon for hitory button + return OC.imagePath('core','actions/history'); + }, + actionHandler: actionStub + }); + fileList.fileActions.setDefault('text/plain', 'Test'); + var fileData = new FileInfo({ + id: 18, + name: 'testName.txt', + mimetype: 'text/plain', + size: 1234, + etag: 'a01234c', + mtime: 123456 + }); + var $tr = fileList.add(fileData); + expect($tr.find('a.name').attr('href')) + .toEqual(OC.getRootPath() + '/index.php/apps/files?dir=&openfile=18'); + }); it('generates dir element with correct attributes when calling add() with dir data', function() { var fileData = new FileInfo({ id: 19, @@ -1906,36 +1933,6 @@ describe('OCA.Files.FileList tests', function() { expect($tr.find('input:checkbox').prop('checked')).toEqual(true); }); - it('Selects/deselect a file when clicking on the name while holding Ctrl', function() { - var $tr = fileList.findFileEl('One.txt'); - var $tr2 = fileList.findFileEl('Three.pdf'); - var e; - expect($tr.find('input:checkbox').prop('checked')).toEqual(false); - expect($tr2.find('input:checkbox').prop('checked')).toEqual(false); - e = new $.Event('click'); - e.ctrlKey = true; - $tr.find('td.filename .name').trigger(e); - - expect($tr.find('input:checkbox').prop('checked')).toEqual(true); - expect($tr2.find('input:checkbox').prop('checked')).toEqual(false); - - // click on second entry, does not clear the selection - e = new $.Event('click'); - e.ctrlKey = true; - $tr2.find('td.filename .name').trigger(e); - expect($tr.find('input:checkbox').prop('checked')).toEqual(true); - expect($tr2.find('input:checkbox').prop('checked')).toEqual(true); - - expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual(['One.txt', 'Three.pdf']); - - // deselect now - e = new $.Event('click'); - e.ctrlKey = true; - $tr2.find('td.filename .name').trigger(e); - expect($tr.find('input:checkbox').prop('checked')).toEqual(true); - expect($tr2.find('input:checkbox').prop('checked')).toEqual(false); - expect(_.pluck(fileList.getSelectedFiles(), 'name')).toEqual(['One.txt']); - }); it('Selects a range when clicking on one file then Shift clicking on another one', function() { var $tr = fileList.findFileEl('One.txt'); var $tr2 = fileList.findFileEl('Three.pdf'); diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 042cc6c056e3c1d3c6d67373e56aded9c6102825..982f32dbdd9c201abe70d168e414031e84699ba3 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -113,9 +113,9 @@ OCA.Sharing.PublicApp = { // Show file preview if previewer is available, images are already handled by the template if (mimetype.substr(0, mimetype.indexOf('/')) !== 'image' && $('.publicpreview').length === 0) { // Trigger default action if not download TODO - var action = FileActions.getDefault(mimetype, 'file', OC.PERMISSION_READ); - if (typeof action !== 'undefined') { - action($('#filename').val()); + var spec = FileActions.getDefaultFileAction(mimetype, 'file', OC.PERMISSION_READ); + if (spec && spec.action) { + spec.action($('#filename').val()); } } } @@ -204,10 +204,6 @@ OCA.Sharing.PublicApp = { var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments); if (hideDownload === 'true') { this.fileActions.currentFile = $tr.find('td'); - var mime = this.fileActions.getCurrentMimeType(); - var type = this.fileActions.getCurrentType(); - var permissions = this.fileActions.getCurrentPermissions(); - var action = this.fileActions.getDefault(mime, type, permissions); // Remove the link. This means that files without a default action fail hard $tr.find('a.name').attr('href', '#'); @@ -252,7 +248,7 @@ OCA.Sharing.PublicApp = { }; this.fileList.linkTo = function (dir) { - return OC.generateUrl('/s/' + token + '', {dir: dir}); + return OC.generateUrl('/s/' + token + '') + '?' + OC.buildQueryString({path: dir}); }; this.fileList.generatePreviewUrl = function (urlSpec) { diff --git a/apps/files_trashbin/js/files_trashbin.js b/apps/files_trashbin/js/files_trashbin.js index f876350eb5ff6d423485b5ae884916ac8f719128..ca01787c5faa1f6a0669c5a67bf3d886add9d4f9 100644 Binary files a/apps/files_trashbin/js/files_trashbin.js and b/apps/files_trashbin/js/files_trashbin.js differ diff --git a/apps/files_trashbin/js/files_trashbin.js.map b/apps/files_trashbin/js/files_trashbin.js.map index 34fc21de649b04e4112f0c21ff5a48100d45559b..d6aec8c3f0dae90c3bb6ac85262c2624f6040918 100644 Binary files a/apps/files_trashbin/js/files_trashbin.js.map and b/apps/files_trashbin/js/files_trashbin.js.map differ diff --git a/apps/files_trashbin/src/filelist.js b/apps/files_trashbin/src/filelist.js index d499c108711c519e032547337d1dc65f5a15739f..8912789e752cfd7428719bd2f1e128657eb270c0 100644 --- a/apps/files_trashbin/src/filelist.js +++ b/apps/files_trashbin/src/filelist.js @@ -241,6 +241,11 @@ return '#' }, + getDefaultActionUrl: function() { + // no default action + return '#' + }, + updateStorageStatistics: function() { // no op because the trashbin doesn't have // storage info like free space / used space