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);
}
}
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) {
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}});
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);
}
//-------------------------------------------------------
$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', '<div id="'.$mainfile.'-label"></div>');
$mform->addElement('filemanager', 'files', get_string('file'), null, $options);
- $mform->addElement('text', 'mainfile', 'Main file');
+
//-------------------------------------------------------
$mform->addElement('header', 'optionssection', get_string('optionsheader', 'resource'));