From ea8705bac8ae10b0c3c11258e83d8fb80ee616e9 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 17 Mar 2014 20:15:10 +0100 Subject: additional class is added to the file actions called e.g. 'action-share', 'action-rename' in order to allow proper translations of the action's display name an additional parameter has been added to the register function --- apps/files/js/fileactions.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'apps/files/js/fileactions.js') diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 9a69d7b3688..a7d1fa9d8a2 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -15,21 +15,33 @@ var FileActions = { defaults: {}, icons: {}, currentFile: null, - register: function (mime, name, permissions, icon, action) { + register: function (mime, name, permissions, icon, action, displayName) { if (!FileActions.actions[mime]) { FileActions.actions[mime] = {}; } if (!FileActions.actions[mime][name]) { FileActions.actions[mime][name] = {}; } + if (!displayName) { + displayName = t('files', name); + } FileActions.actions[mime][name]['action'] = action; FileActions.actions[mime][name]['permissions'] = permissions; + FileActions.actions[mime][name]['displayName'] = displayName; FileActions.icons[name] = icon; }, setDefault: function (mime, name) { FileActions.defaults[mime] = name; }, get: function (mime, type, permissions) { + var actions = this.getActions(mime, type, permissions); + var filteredActions = {}; + $.each(actions, function (name, action) { + filteredActions[name] = action.action; + }); + return filteredActions; + }, + getActions: function (mime, type, permissions) { var actions = {}; if (FileActions.actions.all) { actions = $.extend(actions, FileActions.actions.all); @@ -51,7 +63,7 @@ var FileActions = { var filteredActions = {}; $.each(actions, function (name, action) { if (action.permissions & permissions) { - filteredActions[name] = action.action; + filteredActions[name] = action; } }); return filteredActions; @@ -82,7 +94,7 @@ var FileActions = { */ display: function (parent, triggerEvent) { FileActions.currentFile = parent; - var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions()); + var actions = FileActions.getActions(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions()); var file = FileActions.getCurrentFile(); var nameLinks; if (FileList.findFileEl(file).data('renaming')) { @@ -105,15 +117,16 @@ var FileActions = { event.data.actionFunc(file); }; - var addAction = function (name, action) { + var addAction = function (name, action, displayName) { // NOTE: Temporary fix to prevent rename action in root of Shared directory if (name === 'Rename' && $('#dir').val() === '/Shared') { return true; } if ((name === 'Download' || action !== defaultAction) && name !== 'Delete') { + var img = FileActions.icons[name], - actionText = t('files', name), + actionText = displayName, actionContainer = 'a.name>span.fileactions'; if (name === 'Rename') { @@ -125,7 +138,7 @@ var FileActions = { if (img.call) { img = img(file); } - var html = ''; + var html = ''; if (img) { html += ''; } @@ -133,8 +146,7 @@ var FileActions = { var element = $(html); element.data('action', name); - //alert(element); - element.on('click', {a: null, elem: parent, actionFunc: actions[name]}, actionHandler); + element.on('click', {a: null, elem: parent, actionFunc: actions[name].action}, actionHandler); parent.find(actionContainer).append(element); } @@ -142,12 +154,15 @@ var FileActions = { $.each(actions, function (name, action) { if (name !== 'Share') { - addAction(name, action); + displayName = action.displayName; + ah = action.action; + + addAction(name, ah, displayName); } }); if(actions.Share && !($('#dir').val() === '/' && file === 'Shared')){ - // t('files', 'Share') - addAction('Share', actions.Share); + displayName = t('files', 'Share'); + addAction('Share', actions.Share, displayName); } // remove the existing delete action -- cgit v1.2.3 From aaa8d6ec026f3ab243b177956ee9eab461a2515e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 1 Apr 2014 16:09:48 +0200 Subject: Fixed broken delete file action --- apps/files/js/fileactions.js | 2 +- apps/files/tests/js/fileactionsSpec.js | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'apps/files/js/fileactions.js') diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index a7d1fa9d8a2..732690f047a 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -180,7 +180,7 @@ var FileActions = { } var element = $(html); element.data('action', actions['Delete']); - element.on('click', {a: null, elem: parent, actionFunc: actions['Delete']}, actionHandler); + element.on('click', {a: null, elem: parent, actionFunc: actions['Delete'].action}, actionHandler); parent.parent().children().last().append(element); } diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js index ef7ddcb874a..80c04b5b242 100644 --- a/apps/files/tests/js/fileactionsSpec.js +++ b/apps/files/tests/js/fileactionsSpec.js @@ -38,15 +38,17 @@ describe('FileActions tests', function() { var $tr = FileList.addFile('testName.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'}); // no actions before call - expect($tr.find('.action[data-action=Download]').length).toEqual(0); - expect($tr.find('.action[data-action=Rename]').length).toEqual(0); + expect($tr.find('.action.action-download').length).toEqual(0); + expect($tr.find('.action.action-rename').length).toEqual(0); expect($tr.find('.action.delete').length).toEqual(0); FileActions.display($tr.find('td.filename'), true); // actions defined after cal - expect($tr.find('.action[data-action=Download]').length).toEqual(1); - expect($tr.find('.nametext .action[data-action=Rename]').length).toEqual(1); + expect($tr.find('.action.action-download').length).toEqual(1); + expect($tr.find('.action.action-download').attr('data-action')).toEqual('Download'); + expect($tr.find('.nametext .action.action-rename').length).toEqual(1); + expect($tr.find('.nametext .action.action-rename').attr('data-action')).toEqual('Rename'); expect($tr.find('.action.delete').length).toEqual(1); }); it('calling display() twice correctly replaces file actions', function() { @@ -56,8 +58,8 @@ describe('FileActions tests', function() { FileActions.display($tr.find('td.filename'), true); // actions defined after cal - expect($tr.find('.action[data-action=Download]').length).toEqual(1); - expect($tr.find('.nametext .action[data-action=Rename]').length).toEqual(1); + expect($tr.find('.action.action-download').length).toEqual(1); + expect($tr.find('.nametext .action.action-rename').length).toEqual(1); expect($tr.find('.action.delete').length).toEqual(1); }); it('redirects to download URL when clicking download', function() { @@ -66,10 +68,20 @@ describe('FileActions tests', function() { var $tr = FileList.addFile('test download File.txt', 1234, new Date(), false, false, {download_url: 'test/download/url'}); FileActions.display($tr.find('td.filename'), true); - $tr.find('.action[data-action=Download]').click(); + $tr.find('.action-download').click(); expect(redirectStub.calledOnce).toEqual(true); expect(redirectStub.getCall(0).args[0]).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files=test%20download%20File.txt'); redirectStub.restore(); }); + it('deletes file when clicking delete', function() { + var deleteStub = sinon.stub(FileList, 'do_delete'); + var $tr = FileList.addFile('test delete File.txt', 1234, new Date()); + FileActions.display($tr.find('td.filename'), true); + + $tr.find('.action.delete').click(); + + expect(deleteStub.calledOnce).toEqual(true); + deleteStub.restore(); + }); }); -- cgit v1.2.3