initializer: function(options) {
this.options = options;
if (options.mainfile) {
- this.mainfile = options.mainfile;
+ this.enablemainfile = options.mainfile;
+ var mainid = '#id_'+this.enablemainfile;
+ var filename = Y.one(mainid).get('value');
+ this.mainfilename = '';
+ if (filename) {
+ var parts = filename.split('/');
+ this.mainfilename = parts[parts.length-1];
+ }
}
this.client_id = options.client_id;
this.currentpath = '/';
}, this);
},
empty_filelist: function(container) {
- container.set('innerHTML', '<div class="mdl-align">'+M.str.repository.emptylist+'</div>');
+ container.set('innerHTML', '<div class="mdl-align">'+M.str.repository.nofilesattached+'</div>');
},
render: function() {
var options = this.options;
list[i].action = action;
var url = "###";
- // check main file
- var ismainfile = false;
switch (list[i].type) {
case 'folder':
}
var fullname = list[i].fullname;
- html = html.replace('___fullname___', '<a href="'+url+'" id="'+fileid+'"><img src="'+list[i].icon+'" /> ' + fullname + '</a>');
+ if (this.mainfilename == fullname) {
+ html = html.replace('___fullname___', '<strong><a href="'+url+'" id="'+fileid+'"><img src="'+list[i].icon+'" /> ' + fullname + '</a></strong>');
+ } else {
+ html = html.replace('___fullname___', '<a href="'+url+'" id="'+fileid+'"><img src="'+list[i].icon+'" /> ' + fullname + '</a>');
+ }
html = html.replace('___action___', '<span class="fm-menuicon" id="'+action+'"><img alt="▶" src="'+M.util.image_url('i/menu')+'" /></span>');
html = '<li id="'+htmlid+'">'+html+'</li>';
listhtml += html;
var options = this.options;
var node = e.currentTarget;
var file = data[node.get('id')];
+ var scope = this;
var menuitems = [
{text: M.str.moodle.download, url:file.url}
];
function setmainfile(type, ev, obj) {
var file = obj[node.get('id')];
+ this.mainfilename = file.filename;
Y.one(mainid).set('value', file.filepath+file.filename);
+ scope.refresh(scope.currentpath);
}
- if (this.mainfile) {
- var mainid = '#id_'+this.mainfile;
+ if (this.enablemainfile && (file.filename != this.mainfilename)) {
+ var mainid = '#id_'+this.enablemainfile;
var menu = {text: M.str.repository.setmainfile, onclick:{fn: setmainfile, obj:data, scope:this}};
menuitems.push(menu);
}
return html_writer::tag('a', $output, $attributes);
}
-
/**
* Print the file picker
*
'strings' => array(array('loading', 'repository'), array('nomorefiles', 'repository'), array('confirmdeletefile', 'repository'),
array('add', 'repository'), array('accessiblefilepicker', 'repository'), array('move', 'moodle'),
array('cancel', 'moodle'), array('download', 'moodle'), array('ok', 'moodle'),
- array('emptylist', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
+ array('emptylist', 'repository'), array('nofilesattached', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'),
array('zip', 'editor'), array('unzip', 'moodle'), array('rename', 'moodle'), array('delete', 'moodle'),
array('cannotdeletefile', 'error'), array('confirmdeletefile', 'repository'),
array('nopathselected', 'repository'), array('popupblockeddownload', 'repository'),
$string['resourcecontent'] = 'Files and subfolders';
$string['resource:exportresource'] = 'Export resource';
$string['resource:view'] = 'View resource';
+$string['selectmainfile'] = 'Please select the main file by clicking the icon next to file name.';
$mform->addElement('filemanager', 'files', get_string('selectfiles'), null, $filemanager_options);
- //TODO: ohlala, it should be hidden when JS file manager loaded, the main file should be somehow highlighted directly in editor
- $mform->addElement('text', 'mainfile', get_string('areamainfile', 'repository'));
+ $mform->addElement('hidden', 'mainfile', get_string('areamainfile', 'repository'), array('id'=>'id_mainfile'));
$mform->setType('mainfile', PARAM_PATH);
//-------------------------------------------------------
$filepaths[] = $file->get_filepath().$file->get_filename();
}
if (!in_array($data['mainfile'], $filepaths)) {
- $errors['mainfile'] = 'Please type correct main file path'; //TODO: will not be needed, do NOT localize!
+ $errors['files'] = get_string('selectmainfile', 'resource');
}
return $errors;
}
}
-