diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 6db26cf09ca..be6b47995f1 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -16,10 +16,6 @@ var filemanager = (function(){ this.init = function(client_id, options) { this.client_id = client_id; var container = document.getElementById('filemanager-' + client_id); - fm_cfg[client_id] = {}; - fm_cfg[client_id] = options; - fm_cfg[client_id].mainfile = options.mainfile; - fm_cfg[client_id].currentpath = '/'; html_compiler(client_id, options); } } @@ -182,7 +178,7 @@ function html_compiler(client_id, options) { list[i].action = action; var url = "###"; var ismainfile = false; - if (fm_cfg[client_id].mainfilename && (fm_cfg[client_id].mainfilename == list[i].fullname)) { + if (fm_cfg[client_id].mainfilename && (fm_cfg[client_id].mainfilename.toLowerCase() == list[i].fullname.toLowerCase())) { ismainfile = true; } switch (list[i].type) { @@ -584,12 +580,13 @@ function create_menu(ev, menuid, menuitems, file, options) { if (fm_cfg[options.client_id].mainfile && (file.type!='folder')) { this.set_mainfile = function(type, ev, obj) { if (fm_cfg[obj.client_id].mainfile) { - var mainfile = document.getElementById(fm_cfg[obj.client_id].mainfile); + var mainfile = document.getElementById(fm_cfg[obj.client_id].mainfile+'-id'); mainfile.value = this.file.filepath+this.file.fullname; - //mainfile.disabled = true; + document.getElementById(fm_cfg[obj.client_id].mainfile+'-label').innerHTML = mainfile.value; } fm_cfg[obj.client_id].mainfilename = this.file.fullname; refresh_filemanager(fm_cfg[obj.client_id].currentpath, fm_cfg[obj.client_id]); + } this.set_mainfile.file = file; menu.addItem({text: mstr.resource.setmainfile, onclick: {fn: this.set_mainfile, obj: options, scope: this.set_mainfile}}); @@ -605,12 +602,27 @@ function setup_filebrowser(client_id, options) { if (!options) { options = {}; } - var fm = new filemanager(); - fm.init(client_id, options); + fm_cfg[client_id] = {}; + fm_cfg[client_id] = options; + fm_cfg[client_id].mainfile = options.mainfile; + fm_cfg[client_id].currentpath = '/'; + fm_cfg[client_id].currentfiles = 0; // XXX: When editing existing folder, currentfiles shouldn't // be 0 - fm_cfg[client_id].currentfiles = 0; fm_cfg[client_id].maxfiles = options.maxfiles; + if (options.mainfile) { + var mainfilename = document.getElementById(options.mainfile+'-id'); + if (mainfilename.value) { + var re = new RegExp(".*\/(.*)$", "i"); + var result = mainfilename.value.match(re); + document.getElementById(options.mainfile+'-label').innerHTML = mainfilename.value; + fm_cfg[client_id].mainfilename = result[1]; + } else { + fm_cfg[client_id].mainfilename = ''; + } + } + var fm = new filemanager(); + fm.init(client_id, options); setup_buttons(client_id, options); } diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php index f457b9c5008..33a86461cec 100644 --- a/mod/resource/mod_form.php +++ b/mod/resource/mod_form.php @@ -56,9 +56,14 @@ class mod_resource_mod_form extends moodleform_mod { //------------------------------------------------------- $mform->addElement('header', 'contentsection', get_string('contentheader', 'resource')); - $options = array('mainfile'=>'id_mainfile', 'subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'filetypes'=>'*', 'returnvalue'=>'*'); + $mainfile = 'mainfile'; + + $options = array('mainfile'=>$mainfile, 'subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'filetypes'=>'*', 'returnvalue'=>'*'); + + $mform->addElement('hidden', $mainfile, '', array('id'=>$mainfile.'-id')); + $mform->addElement('static', '', 'Main file', '
'); $mform->addElement('filemanager', 'files', get_string('file'), null, $options); - $mform->addElement('text', 'mainfile', 'Main file'); + //------------------------------------------------------- $mform->addElement('header', 'optionssection', get_string('optionsheader', 'resource'));