MDL-31901: filemanager/picker.js - match coding style

* No inline ifs
* Spacing between ternary operators
* Missing ;'s
This commit is contained in:
Dan Poltawski
2012-05-21 18:25:56 +08:00
parent 7d44f9c2a2
commit 6a0d7194f7
2 changed files with 124 additions and 59 deletions
+50 -21
View File
@@ -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)
+74 -38
View File
@@ -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('<option/>').
set('value', l[k].options[i].value).
setContent(l[k].options[i].label))
setContent(l[k].options[i].label));
}
}else if(l[k].type=='radio') {
} else if(l[k].type=='radio') {
// radio input element
node.all('label').setContent(l[k].label);
var list = l[k].value.split('|');
@@ -1355,7 +1381,7 @@ M.core_filepicker.init = function(Y, options) {
if (radionode == null) {
node.one('.fp-login-radio').remove();
}
}else {
} else {
// input element
if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) }
node.one('input').
@@ -1663,8 +1689,8 @@ M.core_filepicker.init = function(Y, options) {
// login button
enable_tb_control(toolbar.one('.fp-tb-logout'), !r.nologin);
if(!r.nologin) {
var label = r.logouttext?r.logouttext:M.str.repository.logout;
if (!r.nologin) {
var label = r.logouttext ? r.logouttext : M.str.repository.logout;
toolbar.one('.fp-tb-logout').one('a,button').setContent(label)
}
@@ -1677,16 +1703,26 @@ M.core_filepicker.init = function(Y, options) {
Y.one('#fp-tb-help-'+client_id+'-link').set('href', r.help);
},
print_path: function() {
if (!this.pathbar) { return; }
if (!this.pathbar) {
return;
}
this.pathbar.setContent('').addClass('empty');
var p = this.filepath;
if (p && p.length!=0 && this.viewmode != 2) {
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.all('.fp-path-folder-name').setContent(p[i].name);
el.on('click',
function(e, path) {