diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js
index 2b176f63a7f..87b3599e304 100644
--- a/lib/form/filemanager.js
+++ b/lib/form/filemanager.js
@@ -468,6 +468,13 @@ M.form_filemanager.init = function(Y, options) {
rightclickcallback : function(e, node) {
if (e.preventDefault) { e.preventDefault(); }
this.select_file(node);
+ },
+ classnamecallback : function(node) {
+ var classname = '';
+ if (node.type == 'folder') { classname = classname + ' fp-folder';}
+ if (node.filepath) { classname = classname + ' fp-hascontextmenu';}
+ if (node.sortorder == 1) { classname = classname + ' fp-mainfile';}
+ return Y.Lang.trim(classname);
}
};
if (this.viewmode == 2) {
@@ -606,7 +613,9 @@ M.form_filemanager.init = function(Y, options) {
}, this);
selectnode.one('.fp-file-download').on('click', function(e) {
e.preventDefault();
- window.open(this.selectui.fileinfo.url, 'fm-download-file');
+ if (this.selectui.fileinfo.type != 'folder') {
+ window.open(this.selectui.fileinfo.url, 'fm-download-file');
+ }
}, this);
selectnode.one('.fp-file-delete').on('click', function(e) {
e.preventDefault();
@@ -644,6 +653,10 @@ M.form_filemanager.init = function(Y, options) {
e.preventDefault();
var params = {};
var fileinfo = this.selectui.fileinfo;
+ if (fileinfo.type != 'folder') {
+ // this button should not even be shown
+ return;
+ }
params['filepath'] = fileinfo.filepath;
params['filename'] = '.';
selectnode.addClass('loading');
@@ -661,6 +674,10 @@ M.form_filemanager.init = function(Y, options) {
e.preventDefault();
var params = {};
var fileinfo = this.selectui.fileinfo;
+ if (fileinfo.type != 'zip') {
+ // this button should not even be shown
+ return;
+ }
params['filepath'] = fileinfo.filepath;
params['filename'] = fileinfo.fullname;
selectnode.addClass('loading');
@@ -678,6 +695,10 @@ M.form_filemanager.init = function(Y, options) {
e.preventDefault();
var params = {};
var fileinfo = this.selectui.fileinfo;
+ if (fileinfo.type == 'folder') {
+ // this button should not even be shown for folders
+ return;
+ }
params['filepath'] = fileinfo.filepath;
params['filename'] = fileinfo.fullname;
selectnode.addClass('loading');
@@ -687,7 +708,7 @@ M.form_filemanager.init = function(Y, options) {
params: params,
callback: function(id, obj, args) {
args.scope.selectui.hide();
- args.scope.refresh(obj.filepath);
+ args.scope.refresh(fileinfo.filepath);
}
});
}, this);
@@ -710,7 +731,7 @@ M.form_filemanager.init = function(Y, options) {
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 (this.enablemainfile && (node.sortorder != 1)) {
+ if (this.enablemainfile && (node.sortorder != 1) && node.type == 'file') {
selectnode.addClass('fp-cansetmain');
}
this.selectui.fileinfo = node;
diff --git a/repository/filepicker.js b/repository/filepicker.js
index b1b0c3c4a44..9f9dc604f59 100644
--- a/repository/filepicker.js
+++ b/repository/filepicker.js
@@ -82,12 +82,12 @@ YUI.add('moodle-core_filepicker', function(Y) {
* filenode : Node element that contains template for displaying one file
* callback : On click callback. The element of the fileslist array will be passed as argument
* rightclickcallback : On right click callback (optional).
- * norootrightclick : No right click for top element in the tree
* callbackcontext : context where callbacks are executed
* sortable : whether content may be sortable (in table mode)
* dynload : allow dynamic load for tree view
* filepath : for pre-building of tree view - the path to the current directory in filepicker format
- * treeview_dynload : callback to ...
+ * treeview_dynload : callback to function to dynamically load the folder in tree view
+ * classnamecallback : callback to function that returns the class name for an element
* @param array fileslist array of files to show, each array element may have attributes:
* title or fullname : file name
* shorttitle (optional) : display file name
@@ -129,14 +129,8 @@ YUI.add('moodle-core_filepicker', function(Y) {
el.one('.fp-filename').setContent(file_get_displayname(node));
// TODO add tooltip with node.title or node.thumbnail_title
- var tmpnodedata = {className:''};
- if (file_is_folder(node)) {
- el.get('children').addClass('fp-folder');
- tmpnodedata.className = tmpnodedata.className + ' fp-folder';
- }
- if (options.rightclickcallback && !node.nocontextmenu) {
- tmpnodedata.className = tmpnodedata.className + ' fp-hascontextmenu';
- }
+ var tmpnodedata = {className:options.classnamecallback(node)};
+ el.get('children').addClass(tmpnodedata.className);
if (node.icon) {
el.one('.fp-icon').appendChild(Y.Node.create('').set('src', node.icon));
if (node.realicon) {
@@ -179,9 +173,6 @@ YUI.add('moodle-core_filepicker', function(Y) {
for (var i in options.filepath) {
if (mytreeel == null) {
mytreeel = mytree;
- if (options.norootrightclick) {
- mytreeel.nocontextmenu = true;
- }
} else {
mytreeel.children = [{}];
mytreeel = mytreeel.children[0];
@@ -243,9 +234,7 @@ YUI.add('moodle-core_filepicker', function(Y) {
var formatTitle = function(o) {
var el = Y.Node.create('