[Pkg-owncloud-commits] [owncloud] 157/199: Added "dir" in file actions handler context and fixed versions

David Prévot taffit at moszumanska.debian.org
Sun Jun 1 18:53:21 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 06e53b359ac806b9103cb617e7a6bad8cbadb519
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Tue May 20 11:44:18 2014 +0200

    Added "dir" in file actions handler context and fixed versions
    
    Added "dir" in file actions handler context so that handlers can know
    what the path of the file was without having to look it up from the file
    list.
    
    Fixed versions app to use the context.dir instead of the old $('#dir')
    element. This makes the versions popup work in the sharing overview.
---
 apps/files/js/fileactions.js           |  8 +++++---
 apps/files/js/filelist.js              |  3 ++-
 apps/files/tests/js/fileactionsSpec.js |  8 ++++++++
 apps/files/tests/js/filelistSpec.js    | 26 ++++++++++++++++++++++++++
 apps/files_versions/js/versions.js     | 33 +++++++++++++++++++++------------
 5 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 1242fea..a12b1f0 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -138,11 +138,13 @@
 
 				self.currentFile = event.data.elem;
 				var file = self.getCurrentFile();
+				var $tr = $(this).closest('tr');
 
 				event.data.actionFunc(file, {
-					$file: $(this).closest('tr'),
+					$file: $tr,
 					fileList: fileList || OCA.Files.App.fileList,
-					fileActions: self
+					fileActions: self,
+					dir: $tr.attr('data-path') || fileList.getCurrentDirectory()
 				});
 			};
 
@@ -210,7 +212,7 @@
 			}
 
 			if (triggerEvent){
-				$('#fileList').trigger(jQuery.Event("fileActionsReady"));
+				fileList.$fileList.trigger(jQuery.Event("fileActionsReady"));
 			}
 		},
 		getCurrentFile: function () {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index d969cb5..e1cbfc3 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -251,7 +251,8 @@
 						action(filename, {
 							$file: $tr,
 							fileList: this,
-							fileActions: this.fileActions
+							fileActions: this.fileActions,
+							dir: $tr.attr('data-path') || this.getCurrentDirectory()
 						});
 					}
 				}
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
index 519a31b..edd7e34 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -152,5 +152,13 @@ describe('OCA.Files.FileActions tests', function() {
 		expect(context.$file.is($tr)).toEqual(true);
 		expect(context.fileList).toBeDefined();
 		expect(context.fileActions).toBeDefined();
+		expect(context.dir).toEqual('/subdir');
+
+		// when data-path is defined
+		actionStub.reset();
+		$tr.attr('data-path', '/somepath');
+		$tr.find('.action-test').click();
+		context = actionStub.getCall(0).args[1];
+		expect(context.dir).toEqual('/somepath');
 	});
 });
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 3dd7152..739ae59 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -1526,6 +1526,32 @@ describe('OCA.Files.FileList tests', function() {
 			expect(fileList.getSelectedFiles()).toEqual([]);
 		});
 	});
+	describe('File actions', function() {
+		it('Clicking on a file name will trigger default action', function() {
+			var actionStub = sinon.stub();
+			fileList.setFiles(testFiles);
+			fileList.fileActions.register(
+				'text/plain',
+				'Test',
+				OC.PERMISSION_ALL,
+				function() {
+					// Specify icon for hitory button
+					return OC.imagePath('core','actions/history');
+				},
+				actionStub
+			);
+			fileList.fileActions.setDefault('text/plain', 'Test');
+			var $tr = fileList.findFileEl('One.txt');
+			$tr.find('td.filename>a.name').click();
+			expect(actionStub.calledOnce).toEqual(true);
+			expect(actionStub.getCall(0).args[0]).toEqual('One.txt');
+			var context = actionStub.getCall(0).args[1];
+			expect(context.$file.is($tr)).toEqual(true);
+			expect(context.fileList).toBeDefined();
+			expect(context.fileActions).toBeDefined();
+			expect(context.dir).toEqual('/subdir');
+		});
+	});
 	describe('Sorting files', function() {
 		it('Sorts by name by default', function() {
 			fileList.reload();
diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js
index b452bc2..a239354 100644
--- a/apps/files_versions/js/versions.js
+++ b/apps/files_versions/js/versions.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global FileActions, scanFiles, escapeHTML, formatDate */
 $(document).ready(function(){
 
 	if ($('#isPublic').val()){
@@ -10,18 +21,17 @@ $(document).ready(function(){
 	if (typeof FileActions !== 'undefined') {
 		// Add versions button to 'files/index.php'
 		FileActions.register(
-			'file'
-			, 'Versions'
-			, OC.PERMISSION_UPDATE
-			, function() {
+			'file',
+			'Versions',
+			OC.PERMISSION_UPDATE,
+			function() {
 				// Specify icon for hitory button
 				return OC.imagePath('core','actions/history');
-			}
-			,function(filename){
+			}, function(filename, context){
 				// Action to perform when clicked
 				if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback
 
-				var file = $('#dir').val().replace(/(?!<=\/)$|\/$/, '/' + filename);
+				var file = context.dir.replace(/(?!<=\/)$|\/$/, '/' + filename);
 				var createDropDown = true;
 				// Check if drop down is already visible for a different file
 				if (($('#dropdown').length > 0) ) {
@@ -33,10 +43,9 @@ $(document).ready(function(){
 				}
 
 				if(createDropDown === true) {
-					createVersionsDropdown(filename, file);
+					createVersionsDropdown(filename, file, context.fileList);
 				}
-			}
-			, t('files_versions', 'Versions')
+			}, t('files_versions', 'Versions')
 		);
 	}
 
@@ -75,7 +84,7 @@ function goToVersionPage(url){
 	window.location.assign(url);
 }
 
-function createVersionsDropdown(filename, files) {
+function createVersionsDropdown(filename, files, fileList) {
 
 	var start = 0;
 	var fileEl;
@@ -88,7 +97,7 @@ function createVersionsDropdown(filename, files) {
 	html += '<input type="button" value="'+ t('files_versions', 'More versions...') + '" name="show-more-versions" id="show-more-versions" style="display: none;" />';
 
 	if (filename) {
-		fileEl = FileList.findFileEl(filename);
+		fileEl = fileList.findFileEl(filename);
 		fileEl.addClass('mouseOver');
 		$(html).appendTo(fileEl.find('td.filename'));
 	} else {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list