From d9ef6da2e49de52a694f1c7684624e68e4de6a21 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 28 Oct 2012 11:51:54 +0100 Subject: [PATCH] code style --- apps/files/js/fileactions.js | 194 ++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 93 deletions(-) diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 1cf80352be..fc7c117cfc 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -1,96 +1,98 @@ -var FileActions={ - actions:{}, - defaults:{}, - icons:{}, - currentFile:null, - register:function(mime,name,permissions,icon,action){ - if(!FileActions.actions[mime]){ - FileActions.actions[mime]={}; +var FileActions = { + actions: {}, + defaults: {}, + icons: {}, + currentFile: null, + register: function (mime, name, permissions, icon, action) { + if (!FileActions.actions[mime]) { + FileActions.actions[mime] = {}; } if (!FileActions.actions[mime][name]) { FileActions.actions[mime][name] = {}; } FileActions.actions[mime][name]['action'] = action; FileActions.actions[mime][name]['permissions'] = permissions; - FileActions.icons[name]=icon; + FileActions.icons[name] = icon; }, - setDefault:function(mime,name){ - FileActions.defaults[mime]=name; + setDefault: function (mime, name) { + FileActions.defaults[mime] = name; }, - get:function(mime,type,permissions){ - var actions={}; - if(FileActions.actions.all){ - actions=$.extend( actions, FileActions.actions.all ); + get: function (mime, type, permissions) { + var actions = {}; + if (FileActions.actions.all) { + actions = $.extend(actions, FileActions.actions.all); } - if(mime){ - if(FileActions.actions[mime]){ - actions=$.extend( actions, FileActions.actions[mime] ); + if (mime) { + if (FileActions.actions[mime]) { + actions = $.extend(actions, FileActions.actions[mime]); } - var mimePart=mime.substr(0,mime.indexOf('/')); - if(FileActions.actions[mimePart]){ - actions=$.extend( actions, FileActions.actions[mimePart] ); + var mimePart = mime.substr(0, mime.indexOf('/')); + if (FileActions.actions[mimePart]) { + actions = $.extend(actions, FileActions.actions[mimePart]); } } - if(type){//type is 'dir' or 'file' - if(FileActions.actions[type]){ - actions=$.extend( actions, FileActions.actions[type] ); + if (type) {//type is 'dir' or 'file' + if (FileActions.actions[type]) { + actions = $.extend(actions, FileActions.actions[type]); } } var filteredActions = {}; - $.each(actions, function(name, action) { + $.each(actions, function (name, action) { if (action.permissions & permissions) { filteredActions[name] = action.action; } }); return filteredActions; }, - getDefault:function(mime,type,permissions){ - if(mime){ - var mimePart=mime.substr(0,mime.indexOf('/')); + getDefault: function (mime, type, permissions) { + if (mime) { + var mimePart = mime.substr(0, mime.indexOf('/')); } - var name=false; - if(mime && FileActions.defaults[mime]){ - name=FileActions.defaults[mime]; - }else if(mime && FileActions.defaults[mimePart]){ - name=FileActions.defaults[mimePart]; - }else if(type && FileActions.defaults[type]){ - name=FileActions.defaults[type]; - }else{ - name=FileActions.defaults.all; + var name = false; + if (mime && FileActions.defaults[mime]) { + name = FileActions.defaults[mime]; + } else if (mime && FileActions.defaults[mimePart]) { + name = FileActions.defaults[mimePart]; + } else if (type && FileActions.defaults[type]) { + name = FileActions.defaults[type]; + } else { + name = FileActions.defaults.all; } - var actions=this.get(mime,type,permissions); + var actions = this.get(mime, type, permissions); return actions[name]; }, - display:function(parent){ - FileActions.currentFile=parent; + display: function (parent) { + FileActions.currentFile = parent; $('#fileList span.fileactions, #fileList td.date a.action').remove(); - var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); - var file=FileActions.getCurrentFile(); - if($('tr').filterAttr('data-file',file).data('renaming')){ + var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions()); + var file = FileActions.getCurrentFile(); + if ($('tr').filterAttr('data-file', file).data('renaming')) { return; } parent.children('a.name').append(''); - var defaultAction=FileActions.getDefault(FileActions.getCurrentMimeType(),FileActions.getCurrentType(), FileActions.getCurrentPermissions()); - for(name in actions){ + var defaultAction = FileActions.getDefault(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions()); + for (name in actions) { // NOTE: Temporary fix to prevent rename action in root of Shared directory if (name == 'Rename' && $('#dir').val() == '/Shared') { continue; } - if((name=='Download' || actions[name]!=defaultAction) && name!='Delete'){ - var img=FileActions.icons[name]; - if(img.call){ - img=img(file); + if ((name == 'Download' || actions[name] != defaultAction) && name != 'Delete') { + var img = FileActions.icons[name]; + if (img.call) { + img = img(file); } - var html=''; - var element=$(html); - element.data('action',name); - element.click(function(event){ + var html = ''; + var element = $(html); + element.data('action', name); + element.click(function (event) { event.stopPropagation(); event.preventDefault(); - var action=actions[$(this).data('action')]; - var currentFile=FileActions.getCurrentFile(); + var action = actions[$(this).data('action')]; + var currentFile = FileActions.getCurrentFile(); FileActions.hide(); action(currentFile); }); @@ -98,94 +100,100 @@ var FileActions={ parent.find('a.name>span.fileactions').append(element); } } - if(actions['Delete']){ - var img=FileActions.icons['Delete']; - if(img.call){ - img=img(file); + if (actions['Delete']) { + var img = FileActions.icons['Delete']; + if (img.call) { + img = img(file); } // NOTE: Temporary fix to allow unsharing of files in root of Shared folder if ($('#dir').val() == '/Shared') { var html = '