some more code reuse for fileactions

also fixes an issue where some fileactions always worked on the last file in the list
This commit is contained in:
Robin Appelman 2012-11-04 20:48:38 +01:00
parent 555dd5c261
commit f187aa6c93
1 changed files with 13 additions and 16 deletions

View File

@ -70,6 +70,16 @@ var FileActions = {
} }
parent.children('a.name').append('<span class="fileactions" />'); parent.children('a.name').append('<span class="fileactions" />');
var defaultAction = FileActions.getDefault(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions()); var defaultAction = FileActions.getDefault(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var actionHandler = function (parent, action, event) {
event.stopPropagation();
event.preventDefault();
if(action)
FileActions.currentFile = parent;
file = FileActions.getCurrentFile();
console.log(file);
console.log(file);
action(file);
};
for (name in actions) { for (name in actions) {
// NOTE: Temporary fix to prevent rename action in root of Shared directory // NOTE: Temporary fix to prevent rename action in root of Shared directory
if (name === 'Rename' && $('#dir').val() === '/Shared') { if (name === 'Rename' && $('#dir').val() === '/Shared') {
@ -87,14 +97,7 @@ var FileActions = {
html += t('files', name) + '</a>'; html += t('files', name) + '</a>';
var element = $(html); var element = $(html);
element.data('action', name); element.data('action', name);
element.click(function (event) { element.click(actionHandler.bind(null, parent, actions[name]));
FileActions.currentFile = $(this).parent().parent().parent();
event.stopPropagation();
event.preventDefault();
var action = actions[$(this).data('action')];
var currentFile = FileActions.getCurrentFile();
action(currentFile);
});
parent.find('a.name>span.fileactions').append(element); parent.find('a.name>span.fileactions').append(element);
} }
} }
@ -113,14 +116,8 @@ var FileActions = {
if (img) { if (img) {
element.append($('<img class ="svg" src="' + img + '"/>')); element.append($('<img class ="svg" src="' + img + '"/>'));
} }
element.data('action', 'Delete'); element.data('action', actions['Delete']);
element.click(function (event) { element.click(actionHandler.bind(null, parent, actions['Delete']));
event.stopPropagation();
event.preventDefault();
var action = actions[$(this).data('action')];
var currentFile = FileActions.getCurrentFile();
action(currentFile);
});
parent.parent().children().last().append(element); parent.parent().children().last().append(element);
} }
}, },