From 6a0d7194f7dc30cc26f810b4d0306cbbc311cdc8 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Wed, 16 May 2012 14:13:17 +0800 Subject: [PATCH] MDL-31901: filemanager/picker.js - match coding style * No inline ifs * Spacing between ternary operators * Missing ;'s --- lib/form/filemanager.js | 71 +++++++++++++++++-------- repository/filepicker.js | 112 ++++++++++++++++++++++++++------------- 2 files changed, 124 insertions(+), 59 deletions(-) diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 53a07c31b7e..881d1819e4b 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -193,11 +193,17 @@ M.form_filemanager.init = function(Y, options) { } }, check_buttons: function() { - if (this.filecount>0) {this.filemanager.removeClass('fm-nofiles');} - else {this.filemanager.addClass('fm-nofiles');} - if (this.filecount >= this.maxfiles && this.maxfiles!=-1) - {this.filemanager.addClass('fm-maxfiles');} - else {this.filemanager.removeClass('fm-maxfiles');} + if (this.filecount>0) { + this.filemanager.removeClass('fm-nofiles'); + } else { + this.filemanager.addClass('fm-nofiles'); + } + if (this.filecount >= this.maxfiles && this.maxfiles!=-1) { + this.filemanager.addClass('fm-maxfiles'); + } + else { + this.filemanager.removeClass('fm-maxfiles'); + } }, refresh: function(filepath) { var scope = this; @@ -372,9 +378,19 @@ M.form_filemanager.init = function(Y, options) { for(var i = 0; i < p.length; i++) { var el = this.pathnode.cloneNode(true); this.pathbar.appendChild(el); - if (i == 0) {el.addClass('first');} - if (i == p.length-1) {el.addClass('last');} - if (i%2) {el.addClass('even');} else {el.addClass('odd');} + + if (i == 0) { + el.addClass('first'); + } + if (i == p.length-1) { + el.addClass('last'); + } + + if (i%2) { + el.addClass('even'); + } else { + el.addClass('odd'); + } el.one('.fp-path-folder-name').setContent(p[i].name). on('click', function(e, path) { e.preventDefault(); @@ -420,8 +436,8 @@ M.form_filemanager.init = function(Y, options) { scope.currentpath = node.path?node.path:'/'; } node.highlight(false); - node.origlist = obj.list?obj.list:null; - node.origpath = obj.path?obj.path:null; + node.origlist = obj.list ? obj.list : null; + node.origpath = obj.path ? obj.path : null; node.children = []; for(k in list) { if (list[k].type == 'folder' && retrieved_children[list[k].filepath]) { @@ -546,12 +562,16 @@ M.form_filemanager.init = function(Y, options) { } }; } - if (!this.lazyloading) {this.lazyloading={};} + if (!this.lazyloading) { + this.lazyloading={}; + } this.filemanager.one('.fp-content').fp_display_filelist(options, list, this.lazyloading); this.content_scrolled(); }, populate_licenses_select: function(node) { - if (!node) {return;} + if (!node) { + return; + } node.setContent(''); var licenses = this.options.licenses; for (var i in licenses) { @@ -674,7 +694,7 @@ M.form_filemanager.init = function(Y, options) { buttons : {} }); this.confirm_dlg.plug(Y.Plugin.Drag,{handles:['#'+node.get('id')+' .yui3-widget-hd']}); - var handleConfirm = function(ev) { + var handle_confirm = function(ev) { var dlgopt = this.confirm_dlg.dlgopt; ev.preventDefault(); this.confirm_dlg.hide(); @@ -686,12 +706,12 @@ M.form_filemanager.init = function(Y, options) { } } } - var handleCancel = function(ev) { + var handle_cancel = function(ev) { ev.preventDefault(); this.confirm_dlg.hide(); } - node.one('.fp-dlg-butconfirm').on('click', handleConfirm, this); - node.one('.fp-dlg-butcancel').on('click', handleCancel, this); + node.one('.fp-dlg-butconfirm').on('click', handle_confirm, this); + node.one('.fp-dlg-butcancel').on('click', handle_cancel, this); } this.confirm_dlg.dlgopt = dialog_options; this.confirm_dlg_node.one('.fp-dlg-text').setContent(dialog_options.message); @@ -823,18 +843,25 @@ M.form_filemanager.init = function(Y, options) { }, this); }, get_parent_folder_name: function(node) { - if (node.type != 'folder' || node.filepath.length < node.fullname.length+1) { return node.filepath; } + if (node.type != 'folder' || node.filepath.length < node.fullname.length+1) { + return node.filepath; + } var basedir = node.filepath.substr(0, node.filepath.length - node.fullname.length - 1); var lastdir = node.filepath.substr(node.filepath.length - node.fullname.length - 2); - if (lastdir == '/' + node.fullname + '/') { return basedir; } + if (lastdir == '/' + node.fullname + '/') { + return basedir; + } return node.filepath; }, select_file: function(node) { var selectnode = this.selectnode; selectnode.removeClass('loading').removeClass('fp-folder'). removeClass('fp-file').removeClass('fp-zip').removeClass('fp-cansetmain'); - if (node.type == 'folder' || node.type == 'zip') {selectnode.addClass('fp-'+node.type);} - else {selectnode.addClass('fp-file');} + if (node.type == 'folder' || node.type == 'zip') { + selectnode.addClass('fp-'+node.type); + } else { + selectnode.addClass('fp-file'); + } if (this.enablemainfile && (node.sortorder != 1) && node.type == 'file') { selectnode.addClass('fp-cansetmain'); } @@ -846,7 +873,9 @@ M.form_filemanager.init = function(Y, options) { selectnode.all('.fp-license select option[value='+node.license+']').set('selected', true); selectnode.all('.fp-path select option[selected]').set('selected', false); selectnode.all('.fp-path select option').each(function(el){ - if (el.get('value') == foldername) {el.set('selected', true);} + if (el.get('value') == foldername) { + el.set('selected', true); + } }); selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':''); // display static information about a file (when known) diff --git a/repository/filepicker.js b/repository/filepicker.js index 6993bbc3598..3e6005a4847 100644 --- a/repository/filepicker.js +++ b/repository/filepicker.js @@ -251,9 +251,13 @@ YUI.add('moodle-core_filepicker', function(Y) { } /** sorting function for table view */ var sortFoldersFirst = function(a, b, desc) { - if (a.get('isfolder') && !b.get('isfolder')) {return -1;} - if (!a.get('isfolder') && b.get('isfolder')) {return 1;} - var aa = a.get(this.key), bb = b.get(this.key), dir = desc?-1:1; + if (a.get('isfolder') && !b.get('isfolder')) { + return -1; + } + if (!a.get('isfolder') && b.get('isfolder')) { + return 1; + } + var aa = a.get(this.key), bb = b.get(this.key), dir = desc ? -1 : 1; return (aa > bb) ? dir : ((aa < bb) ? -dir : 0); } /** initialize table view */ @@ -455,9 +459,9 @@ M.core_filepicker.init = function(Y, options) { }, request: function(args, redraw) { - var api = (args.api?args.api:this.api) + '?action='+args.action; + var api = (args.api ? args.api : this.api) + '?action='+args.action; var params = {}; - var scope = args['scope']?args['scope']:this; + var scope = args['scope'] ? args['scope'] : this; params['repo_id']=args.repository_id; params['p'] = args.path?args.path:''; params['page'] = args.page?args.page:''; @@ -733,7 +737,9 @@ M.core_filepicker.init = function(Y, options) { }, content_scrolled: function(e) { setTimeout(Y.bind(function() { - if (this.processingimages) {return;} + if (this.processingimages) { + return; + } this.processingimages = true; var scope = this, fpcontent = this.fpnode.one('.fp-content'), @@ -789,8 +795,8 @@ M.core_filepicker.init = function(Y, options) { scope.parse_repository_options(obj); } node.highlight(false); - node.origlist = obj.list?obj.list:null; - node.origpath = obj.path?obj.path:null; + node.origlist = obj.list ? obj.list : null; + node.origpath = obj.path ? obj.path : null; node.children = []; for(k in list) { if (list[k].children && retrieved_children[list[k].path]) { @@ -872,7 +878,9 @@ M.core_filepicker.init = function(Y, options) { filenode : element_template, callbackcontext : this, callback : function(e, node) { - if (e.preventDefault) {e.preventDefault();} + if (e.preventDefault) { + e.preventDefault(); + } if(node.children) { if (this.active_repo.dynload) { this.list({'path':node.path}); @@ -990,12 +998,12 @@ M.core_filepicker.init = function(Y, options) { for (var linktype in filelink) { var el = selectnode.one('.fp-linktype-'+linktype); el.addClassIf('uneditable', !(filelink[linktype] && filelinkcount>1)); - el.one('input').set('disabled', (filelink[linktype] && filelinkcount>1)?'':'disabled'). + el.one('input').set('disabled', (filelink[linktype] && filelinkcount>1) ? '' : 'disabled'). set('checked', (firstfilelink == linktype) ? 'checked' : '').simulate('change') } // TODO MDL-32532: attributes 'hasauthor' and 'haslicense' need to be obsolete, - selectnode.one('.fp-setauthor input').set('value', args.author?args.author:this.options.author); + selectnode.one('.fp-setauthor input').set('value', args.author ? args.author : this.options.author); this.set_selected_license(selectnode.one('.fp-setlicense'), args.license); selectnode.one('form #filesource-'+client_id).set('value', args.source); @@ -1046,7 +1054,9 @@ M.core_filepicker.init = function(Y, options) { if (license) { params['license'] = license.get('value'); var origlicense = selectnode.one('.fp-license .fp-value'); - if (origlicense) { origlicense = origlicense.getContent(); } + if (origlicense) { + origlicense = origlicense.getContent(); + } var newlicenseval = license.get('value'); if (newlicenseval && this.options.licenses[newlicenseval] != origlicense) { Y.Cookie.set('recentlicense', newlicenseval); @@ -1166,7 +1176,9 @@ M.core_filepicker.init = function(Y, options) { // allow to move the panel dragging it by it's header: this.mainui.plug(Y.Plugin.Drag,{handles:['#filepicker-'+client_id+' .yui3-widget-hd']}); this.mainui.show(); - if (this.mainui.get('y')<0) {this.mainui.set('y', 0);} + if (this.mainui.get('y') < 0) { + this.mainui.set('y', 0); + } // create panel for selecting a file (initially hidden) this.selectnode = Y.Node.create(M.core_filepicker.templates.selectlayout). set('id', 'filepicker-select-'+client_id); @@ -1200,11 +1212,11 @@ M.core_filepicker.init = function(Y, options) { // processing repository listing // Resort the repositories by sortorder - var sorted_repositories = [] + var sorted_repositories = []; for (var i in this.options.repositories) { - sorted_repositories[i] = this.options.repositories[i] + sorted_repositories[i] = this.options.repositories[i]; } - sorted_repositories.sort(function(a,b){return a.sortorder-b.sortorder}) + sorted_repositories.sort(function(a,b){return a.sortorder-b.sortorder}); // extract one repository template and repeat it for all repositories available, // set name and icon and assign callbacks var reponode = this.fpnode.one('.fp-repo'); @@ -1212,7 +1224,7 @@ M.core_filepicker.init = function(Y, options) { var list = reponode.get('parentNode'); list.removeChild(reponode); for (i in sorted_repositories) { - var repository = sorted_repositories[i] + var repository = sorted_repositories[i]; var node = reponode.cloneNode(true); list.appendChild(node); node. @@ -1223,11 +1235,19 @@ M.core_filepicker.init = function(Y, options) { this.hide_header(); this.list({'repo_id':repository_id}); }, this /*handler running scope*/, repository.id/*second argument of handler*/); - node.one('.fp-repo-name').setContent(repository.name) - node.one('.fp-repo-icon').set('src', repository.icon) - if (i==0) {node.addClass('first');} - if (i==sorted_repositories.length-1) {node.addClass('last');} - if (i%2) {node.addClass('even');} else {node.addClass('odd');} + node.one('.fp-repo-name').setContent(repository.name); + node.one('.fp-repo-icon').set('src', repository.icon); + if (i==0) { + node.addClass('first'); + } + if (i==sorted_repositories.length-1) { + node.addClass('last'); + } + if (i%2) { + node.addClass('even'); + } else { + node.addClass('odd'); + } } } // display error if no repositories found @@ -1240,7 +1260,9 @@ M.core_filepicker.init = function(Y, options) { parse_repository_options: function(data, appendtolist) { if (appendtolist) { if (data.list) { - if (!this.filelist) { this.filelist = []; } + if (!this.filelist) { + this.filelist = []; + } for (var i in data.list) { this.filelist[this.filelist.length] = data.list[i]; } @@ -1252,7 +1274,7 @@ M.core_filepicker.init = function(Y, options) { this.filepath = data.path?data.path:null; this.objecttag = data.object?data.object:null; this.active_repo = {}; - this.active_repo.issearchresult = data.issearchresult?true:false; + this.active_repo.issearchresult = data.issearchresult ? true : false; this.active_repo.dynload = data.dynload?data.dynload:false; this.active_repo.pages = Number(data.pages?data.pages:null); this.active_repo.page = Number(data.page?data.page:null); @@ -1291,7 +1313,7 @@ M.core_filepicker.init = function(Y, options) { for (var i in templates) { if (templates[i]) { container = templates[i].get('parentNode'); - container.removeChild(templates[i]) + container.removeChild(templates[i]); } } @@ -1318,21 +1340,25 @@ M.core_filepicker.init = function(Y, options) { }, this); loginform_node.all('.fp-login-submit').remove(); action = 'popup'; - }else if(l[k].type=='textarea') { + } else if(l[k].type=='textarea') { // textarea element - if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) } + if (node.one('label')) { + node.one('label').set('for', l[k].id).setContent(l[k].label); + } node.one('textarea').setAttrs({id:l[k].id, name:l[k].name}); - }else if(l[k].type=='select') { + } else if(l[k].type=='select') { // select element - if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) } + if (node.one('label')) { + node.one('label').set('for', l[k].id).setContent(l[k].label); + } node.one('select').setAttrs({id:l[k].id, name:l[k].name}).setContent(''); for (i in l[k].options) { node.one('select').appendChild( Y.Node.create('