+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains javascript code used to manage files in draft area
+ *
+ * @since 2.0
+ * @package filemanager
+ * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
/**
- * This file is part of Moodle - http://moodle.org/
- * File manager
- * @copyright 1999 onwards Dongsheng Cai <dongsheng@moodle.com>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * Namespaces used by filemanager
*/
+YAHOO.namespace('moodle.filemanager');
+// three dialog box we will used later
+YAHOO.moodle.filemanager.movefile_dialog = null;
+YAHOO.moodle.filemanager.rename_dialog = null;
+YAHOO.moodle.filemanager.mkdir_dialog = null;
+
+
+// an object used to record filemanager instances' data,
+// we use it quite often
var fm_cfg = {};
-var fm_move_dlg = null;
-var fm_rename_dlg = null;
-var fm_mkdir_dlg = null;
+fm_cfg.api = moodle_cfg.wwwroot + '/files/files_ajax.php';
// initialize file manager
var filemanager = (function(){
function _filemanager() {
this.init = function(client_id, options) {
this.client_id = client_id;
+
+ // setup move file dialog
+ var dialog = null;
+ if (!YAHOO.moodle.filemanager.movefile_dialog) {
+ dialog = document.createElement('DIV');
+ dialog.id = 'fm-move-dlg';
+ document.body.appendChild(dialog);
+ YAHOO.moodle.filemanager.movefile_dialog = new YAHOO.widget.Dialog("fm-move-dlg", {
+ width : "600px",
+ fixedcenter : true,
+ visible : false,
+ constraintoviewport : true
+ });
+ } else {
+ dialog = document.getElementById('fm-move-div');
+ }
+
+ dialog.innerHTML = '<div class="hd"></div><div class="bd"><div id="fm-move-div">'+mstr.repository.nopathselected+'</div><div id="fm-tree"></div></div>';
+
+ YAHOO.moodle.filemanager.movefile_dialog.render();
+ // generate filemanager html
html_compiler(client_id, options);
}
}
return _filemanager;
})();
-filemanager.url = moodle_cfg.wwwroot + '/files/files_ajax.php';
-filemanager.fileicon = moodle_cfg.wwwroot + '/pix/i/settings.gif';
-
-// callback function for file picker
-function filemanager_callback(obj) {
- refresh_filemanager(obj.filepath, fm_cfg[obj.client_id]);
- fm_cfg[obj.client_id].currentfiles++;
- if (fm_cfg[obj.client_id].currentfiles>=fm_cfg[obj.client_id].maxfiles && fm_cfg[obj.client_id].maxfiles!=-1) {
- var btn = document.getElementById('btnadd-'+obj.client_id);
- if (btn)
- btn.style.display = 'none';
+/**
+ * This function will be called by filepicker once it got the file successfully
+ */
+function filemanager_callback(params) {
+ var client_id = params.client_id;
+ fm_refresh(params.filepath, fm_cfg[client_id]);
+ fm_cfg[client_id].currentfiles++;
+ console.info(fm_cfg[client_id].currentfiles);
+
+ if (fm_cfg[client_id].currentfiles>=fm_cfg[client_id].maxfiles
+ && fm_cfg[client_id].maxfiles!=-1) {
+ var addfilebutton = document.getElementById('btnadd-'+client_id);
+ if (addfilebutton) {
+ addfilebutton.style.display = 'none';
+ }
}
}
-// setup options for file picker
-function fm_launch_filepicker(el_id, options) {
+/**
+ * Setup options to launch file picker.
+ * Fired by add file button.
+ */
+function fm_launch_filepicker(target, options) {
var picker = document.createElement('DIV');
picker.id = 'file-picker-'+options.client_id;
picker.className = 'file-picker';
document.body.appendChild(picker);
- var el=document.getElementById(el_id);
+
+ var target=document.getElementById(target);
var params = {};
params.env = 'filemanager';
params.itemid = options.itemid;
params.maxfiles = options.maxfiles;
params.maxbytes = options.maxbytes;
params.savepath = options.savepath;
- params.target = el;
+ params.target = target;
+ // setup filemanager callback
params.callback = filemanager_callback;
var fp = open_filepicker(options.client_id, params);
return false;
}
-// create a new folder in draft area
-function mkdir(e, client_id, itemid) {
- var mkdir_cb = {
+/**
+ * This function will create a dialog of creating new folder
+ * Fired by 'make a folder' button
+ */
+function fm_create_folder(e, client_id, itemid) {
+ // deal with ajax response
+ var mkdir_ajax_callback = {
success: function(o) {
var result = json_decode(o.responseText);
- fm_mkdir_dlg.hide();
- refresh_filemanager(result.filepath, fm_cfg[client_id]);
+ YAHOO.moodle.filemanager.mkdir_dialog.hide();
+ fm_refresh(result.filepath, fm_cfg[client_id]);
}
}
- var perform = function(e) {
+ // a function used to perform an ajax request
+ var perform_ajax_mkdir = function(e) {
var foldername = document.getElementById('fm-newname').value;
if (!foldername) {
return;
params['sesskey'] = moodle_cfg.sesskey;
params['filepath'] = fm_cfg[client_id].currentpath;
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=mkdir', mkdir_cb, build_querystring(params));
+ fm_cfg.api+'?action=mkdir', mkdir_ajax_callback, build_querystring(params));
YAHOO.util.Event.preventDefault(e);
}
+ // create dialog html element
if (!document.getElementById('fm-mkdir-dlg')) {
var el = document.createElement('DIV');
el.id = 'fm-mkdir-dlg';
document.body.appendChild(el);
var x = YAHOO.util.Event.getPageX(e);
var y = YAHOO.util.Event.getPageY(e);
- fm_mkdir_dlg = new YAHOO.widget.Dialog("fm-mkdir-dlg", {
+ YAHOO.moodle.filemanager.mkdir_dialog = new YAHOO.widget.Dialog("fm-mkdir-dlg", {
width: "300px",
visible: true,
x:y,
});
}
- var buttons = [ { text:mstr.moodle.ok, handler:perform, isDefault:true },
+ var buttons = [ { text:mstr.moodle.ok, handler:perform_ajax_mkdir, isDefault:true },
{ text:mstr.moodle.cancel, handler:function(){this.cancel();}}];
- fm_mkdir_dlg.cfg.queueProperty("buttons", buttons);
- fm_mkdir_dlg.render();
- fm_mkdir_dlg.show();
+ YAHOO.moodle.filemanager.mkdir_dialog.cfg.queueProperty("buttons", buttons);
+ YAHOO.moodle.filemanager.mkdir_dialog.render();
+ YAHOO.moodle.filemanager.mkdir_dialog.show();
- var k1 = new YAHOO.util.KeyListener(document.getElementById('fm-mkdir-dlg'), {keys:13}, {fn:function(){perform();}, correctScope: true});
+ // presss 'enter' key to perform ajax request
+ var k1 = new YAHOO.util.KeyListener(document.getElementById('fm-mkdir-dlg'), {keys:13}, {fn:function(){perform_ajax_mkdir();}, correctScope: true});
k1.enable();
document.getElementById('fm-newname').value = '';
var list = options.list;
var breadcrumb = document.getElementById('fm-path-'+client_id);
var count = 0;
+ // build breadcrumb
if (options.path) {
+ // empty breadcrumb
breadcrumb.innerHTML = '';
var count = 0;
for(var p in options.path) {
sep.innerHTML = ' ▶ ';
}
count++;
+
var pathid = 'fm-path-node-'+client_id;
pathid += ('-'+count);
- var el = document.createElement('A');
- el.id = pathid;
- el.innerHTML = options.path[p].name;
- el.href = '###';
+ var pathnode = document.createElement('A');
+ pathnode.id = pathid;
+ pathnode.innerHTML = options.path[p].name;
+ pathnode.href = '###';
breadcrumb.appendChild(sep);
- breadcrumb.appendChild(el);
+ breadcrumb.appendChild(pathnode);
var args = {};
args.itemid = options.itemid;
args.requestpath = options.path[p].path;
args.client_id = client_id;
- YAHOO.util.Event.addListener(pathid, 'click', click_breadcrumb, args);
+ YAHOO.util.Event.addListener(pathid, 'click', fm_click_breadcrumb, args);
}
}
- var template = document.getElementById('fm-tmpl');
+ var template = document.getElementById('fm-template');
var container = document.getElementById('filemanager-' + client_id);
- var listhtml = '<ul id="draftfiles-'+client_id+'">';
+ var listhtml = '';
+ // folder list items
var folder_ids = [];
+ var folder_data = {};
+ // normal file list items
var file_ids = [];
var file_data = {};
- var folder_data = {};
+
+ // archives list items
+ var zip_ids = [];
+ var zip_data = {};
+
var html_ids = [];
var html_data = {};
- var zip_data = {};
+
file_data.itemid = folder_data.itemid = zip_data.itemid = options.itemid;
file_data.client_id = folder_data.client_id = zip_data.client_id = options.client_id;
- var zip_ids = [];
var foldername_ids = [];
if (list.length == 0) {
// hide file browser and breadcrumb
container.style.display='block';
breadcrumb.style.display='block';
}
- count = 0;
+
+ var count = 0;
for(var i in list) {
count++;
+ // the li html element
var htmlid = 'fileitem-'+client_id+'-'+count;
+ // link to file
var fileid = 'filename-'+client_id+'-'+count;
+ // file menu
var action = 'action-' +client_id+'-'+count;
+
var html = template.innerHTML;
html_ids.push(htmlid);
list[i].htmlid = htmlid;
list[i].fileid = fileid;
list[i].action = action;
+
var url = "###";
+ // check main file
var ismainfile = false;
if (fm_cfg[client_id].mainfilename && (fm_cfg[client_id].mainfilename.toLowerCase() == list[i].fullname.toLowerCase())) {
ismainfile = true;
}
+
switch (list[i].type) {
case 'folder':
foldername_ids.push(fileid);
break;
}
var fullname = list[i].fullname;
+
+ // add green tick to main file
if (ismainfile) {
fullname = "<strong>"+list[i].fullname+"</strong> <img src='"+moodle_cfg.wwwroot+"/pix/i/tick_green_small.gif"+"' />";
}
+
html = html.replace('___fullname___', '<a href="'+url+'" id="'+fileid+'"><img src="'+list[i].icon+'" /> ' + fullname + '</a>');
- html = html.replace('___action___', '<a style="display:none" href="###" id="'+action+'"><img alt="▶" src="'+filemanager.fileicon+'" /></a>');
+ html = html.replace('___action___', '<a style="display:none" href="###" id="'+action+'"><img alt="▶" src="'+moodle_cfg.wwwroot+'/pix/i/settings.gif'+'" /></a>');
html = '<li id="'+htmlid+'">'+html+'</li>';
listhtml += html;
}
- container.innerHTML = (listhtml+'</ul>');
- options.client_id=client_id;
+ container.innerHTML = '<ul id="draftfiles-'+client_id+'">' + listhtml + '</ul>';
- YAHOO.util.Event.addListener(file_ids, 'click', create_filemenu, file_data);
- YAHOO.util.Event.addListener(folder_ids, 'click', create_foldermenu, folder_data);
- YAHOO.util.Event.addListener(zip_ids, 'click', create_zipmenu, zip_data);
+ // click normal file menu
+ YAHOO.util.Event.addListener(file_ids, 'click', fm_create_filemenu, file_data);
+ // click folder menu
+ YAHOO.util.Event.addListener(folder_ids, 'click', fm_create_foldermenu, folder_data);
+ // click archievs menu
+ YAHOO.util.Event.addListener(zip_ids, 'click', fm_create_zipmenu, zip_data);
+ // when mouse moveover every menu
YAHOO.util.Event.addListener(html_ids, 'mouseover', fm_mouseover_menu, html_data);
YAHOO.util.Event.addListener(html_ids, 'mouseout', fm_mouseout_menu, html_data);
-
- YAHOO.util.Event.addListener(foldername_ids,'click', click_folder, folder_data);
-}
-
-function fm_mouseover_menu(ev, args) {
- this.style.backgroundColor = '#0066EE';
- var menu = args[this.id];
- menu = document.getElementById(menu);
- menu.style.display = 'inline';
+ // click folder name
+ YAHOO.util.Event.addListener(foldername_ids,'click', fm_click_folder, folder_data);
}
-function fm_mouseout_menu(ev, args) {
- this.style.backgroundColor = 'transparent';
- var menu = args[this.id];
- menu = document.getElementById(menu);
- menu.style.display = 'none';
-}
-
-function click_breadcrumb(ev, args) {
+function fm_refresh(path, args) {
var params = [];
params['itemid'] = args.itemid;
+ params['filepath'] = path;
params['sesskey'] = moodle_cfg.sesskey;
- params['filepath'] = args.requestpath;
this.cb = {
success: function(o) {
var data = json_decode(o.responseText);
this.cb.options = args;
this.cb.client_id = args.client_id;
- fm_cfg[args.client_id].currentpath = args.requestpath;
+ fm_cfg[args.client_id].currentpath = params['filepath'];
fm_loading('filemanager-'+args.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=list', this.cb, build_querystring(params));
+ fm_cfg.api+'?action=list', this.cb, build_querystring(params));
}
-function click_folder(ev, args) {
- var file = args[this.id];
- refresh_filemanager(file.filepath, args);
+// display menu when mouse over
+function fm_mouseover_menu(ev, args) {
+ this.style.backgroundColor = '#0066EE';
+ var menu = args[this.id];
+ menu = document.getElementById(menu);
+ menu.style.display = 'inline';
+}
+
+// hide menu when mouse over
+function fm_mouseout_menu(ev, args) {
+ this.style.backgroundColor = 'transparent';
+ var menu = args[this.id];
+ menu = document.getElementById(menu);
+ menu.style.display = 'none';
}
-function refresh_filemanager(path, args) {
+function fm_click_breadcrumb(ev, args) {
var params = [];
params['itemid'] = args.itemid;
- params['filepath'] = path;
params['sesskey'] = moodle_cfg.sesskey;
+ params['filepath'] = args.requestpath;
this.cb = {
success: function(o) {
var data = json_decode(o.responseText);
this.cb.options = args;
this.cb.client_id = args.client_id;
- fm_cfg[args.client_id].currentpath = params['filepath'];
+ fm_cfg[args.client_id].currentpath = args.requestpath;
fm_loading('filemanager-'+args.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=list', this.cb, build_querystring(params));
+ fm_cfg.api+'?action=list', this.cb, build_querystring(params));
}
-function create_foldermenu(e, data) {
+function fm_click_folder(ev, args) {
+ var file = args[this.id];
+ fm_refresh(file.filepath, args);
+}
+
+function fm_create_foldermenu(e, data) {
var file = data[this.id];
+ // an extra menu item for folder to zip it
this.zip = function(type, ev, obj) {
this.cb = {
success: function(o) {
var result = json_decode(o.responseText);
if (result) {
- refresh_filemanager(result.filepath, fm_cfg[this.client_id]);
+ fm_refresh(result.filepath, fm_cfg[this.client_id]);
}
}
}
params['sesskey'] = moodle_cfg.sesskey;
fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=zip', this.cb, build_querystring(params));
+ fm_cfg.api+'?action=zip', this.cb, build_querystring(params));
}
this.zip.file = file;
var menuitems = [
{text: mstr.editor.zip, onclick: {fn: this.zip, obj: data, scope: this.zip}},
];
- create_menu(e, 'foldermenu', menuitems, file, data);
+ fm_create_menu(e, 'foldermenu', menuitems, file, data);
}
-function create_filemenu(e, data) {
+function fm_create_filemenu(e, data) {
var file = data[this.id];
var menuitems = [
{text: mstr.moodle.download, url:file.url}
];
- create_menu(e, 'filemenu', menuitems, file, data);
+ fm_create_menu(e, 'filemenu', menuitems, file, data);
}
-function create_zipmenu(e, data) {
+function fm_create_zipmenu(e, data) {
var file = data[this.id];
this.unzip = function(type, ev, obj) {
this.cb = {
success:function(o) {
var result = json_decode(o.responseText);
if (result) {
- refresh_filemanager(result.filepath, fm_cfg[this.client_id]);
+ fm_refresh(result.filepath, fm_cfg[this.client_id]);
}
}
}
params['sesskey'] = moodle_cfg.sesskey;
fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=unzip', this.cb, build_querystring(params));
+ fm_cfg.api+'?action=unzip', this.cb, build_querystring(params));
}
this.unzip.file = file;
{text: mstr.moodle.download, url:file.url},
{text: mstr.moodle.unzip, onclick: {fn: this.unzip, obj: data, scope: this.unzip}}
];
- create_menu(e, 'zipmenu', menuitems, file, data);
+ fm_create_menu(e, 'zipmenu', menuitems, file, data);
}
-function create_menu(ev, menuid, menuitems, file, options) {
+function fm_create_menu(ev, menuid, menuitems, file, options) {
var position = YAHOO.util.Event.getXY(ev);
var el = document.getElementById(menuid);
var menu = new YAHOO.widget.Menu(menuid, {xy:position});
params['sesskey'] = moodle_cfg.sesskey;
fm_loading('filemanager-'+this.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=delete', this.cb, build_querystring(params));
+ fm_cfg.api+'?action=delete', this.cb, build_querystring(params));
}
var dlg = confirm_dialog(ev, args);
dlg.file = file;
alert(mstr.error.cannotdeletefile);
}
fm_cfg[this.client_id].currentfiles--;
+ console.info('delete callback: '+fm_cfg[this.client_id].currentfiles);
if (fm_cfg[this.client_id].currentfiles<fm_cfg[this.client_id].maxfiles) {
var btn = document.getElementById('btnadd-'+this.client_id);
btn.style.display = 'inline';
+ btn.onclick = function(e) {
+ this.options.savepath = this.options.currentpath;
+ fm_launch_filepicker(this.options.target, this.options);
+ }
+ btn.options = fm_cfg[this.client_id];
}
- refresh_filemanager(result.filepath, fm_cfg[this.client_id]);
+ fm_refresh(result.filepath, fm_cfg[this.client_id]);
}
}
dlg.cb.file = this.file;
// update filename
file.fullname = this.newfilename;
file.filepath = result.filepath;
- fm_rename_dlg.hide();
+ YAHOO.moodle.filemanager.rename_dialog.hide();
}
}
}
params['sesskey'] = moodle_cfg.sesskey;
rename_cb.newfilename = newfilename;
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action='+action, rename_cb, build_querystring(params));
+ fm_cfg.api+'?action='+action, rename_cb, build_querystring(params));
}
var scope = document.getElementById('fm-rename-dlg');
el.id = 'fm-rename-dlg';
el.innerHTML = '<div class="hd">'+mstr.repository.enternewname+'</div><div class="bd"><input type="text" id="fm-rename-input" /></div>';
document.body.appendChild(el);
- fm_rename_dlg = new YAHOO.widget.Dialog("fm-rename-dlg", {
+ YAHOO.moodle.filemanager.rename_dialog = new YAHOO.widget.Dialog("fm-rename-dlg", {
width: "300px",
fixedcenter: true,
visible: true,
var buttons = [ { text:mstr.moodle.rename, handler:perform, isDefault:true },
{ text:mstr.moodle.cancel, handler:function(){this.cancel();}}];
- fm_rename_dlg.cfg.queueProperty("buttons", buttons);
- fm_rename_dlg.render();
- fm_rename_dlg.show();
+ YAHOO.moodle.filemanager.rename_dialog.cfg.queueProperty("buttons", buttons);
+ YAHOO.moodle.filemanager.rename_dialog.render();
+ YAHOO.moodle.filemanager.rename_dialog.show();
var k1 = new YAHOO.util.KeyListener(scope, {keys:13}, {fn:function(){perform();}, correctScope: true});
k1.enable();
if (result) {
p = result.filepath;
}
- refresh_filemanager(result.filepath, fm_cfg[obj.client_id]);
+ fm_refresh(result.filepath, fm_cfg[obj.client_id]);
this.dlg.cancel();
}
}
params['newfilepath'] = tree.targetpath;
fm_loading('filemanager-'+obj.client_id, 'fm-prgressbar');
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action='+action, cb, build_querystring(params));
+ fm_cfg.api+'?action='+action, cb, build_querystring(params));
}
var buttons = [ { text:mstr.moodle.move, handler:this.asyncMove, isDefault:true },
{ text:mstr.moodle.cancel, handler:function(){this.cancel();}}];
- fm_move_dlg.cfg.queueProperty("buttons", buttons);
+ YAHOO.moodle.filemanager.movefile_dialog.cfg.queueProperty("buttons", buttons);
tree.subscribe("dblClickEvent", function(e) {
params['filepath'] = node.data.path;
params['sesskey'] = moodle_cfg.sesskey;
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=dir', this.cb, build_querystring(params));
+ fm_cfg.api+'?action=dir', this.cb, build_querystring(params));
this.cb.complete = onCompleteCallback;
this.cb.itemid = node.data.itemid;
}
this.loadDataForNode.itemid = obj.itemid;
- fm_move_dlg.subscribe('show', function(){
+ YAHOO.moodle.filemanager.movefile_dialog.subscribe('show', function(){
var el = document.getElementById('fm-move-div');
el.innerHTML = '<div class="hd"></div><div class="bd"><div id="fm-move-div">'+mstr.repository.nopathselected+'</div><div id="fm-tree"></div></div>';
}, this, true);
- fm_move_dlg.render();
- fm_move_dlg.show();
+ YAHOO.moodle.filemanager.movefile_dialog.render();
+ YAHOO.moodle.filemanager.movefile_dialog.show();
}
this.move.file = file;
var shared_items = [
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]);
+ fm_refresh(fm_cfg[obj.client_id].currentpath, fm_cfg[obj.client_id]);
}
this.set_mainfile.file = file;
});
}
-function setup_filebrowser(client_id, options) {
+/**
+ * setup file manager options and initialize filemanger itself
+ */
+function launch_filemanager(client_id, options) {
+ // setup options & parameters
if (!options) {
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].maxfiles = options.maxfiles;
+ if (fm_cfg[client_id].filecount) {
+ fm_cfg[client_id].currentfiles = fm_cfg[client_id].filecount;
+ } else {
+ fm_cfg[client_id].currentfiles = 0;
+ }
+ //
+ console.info(fm_cfg[client_id].currentfiles);
if (options.mainfile) {
var mainfilename = document.getElementById(options.mainfile+'-id');
if (mainfilename.value) {
fm_cfg[client_id].mainfilename = '';
}
}
+ // setup filemanager
var fm = new filemanager();
fm.init(client_id, options);
- setup_buttons(client_id, options);
+ // setup toolbar
+ fm_setup_buttons(client_id, options);
}
-function setup_buttons(client_id, options) {
- //var fileadd = new YAHOO.widget.Button("btnadd-"+client_id);
- var fileadd = document.getElementById("btnadd-"+client_id);;
- var foldercreate = document.getElementById("btncrt-"+client_id);
- var folderdownload = document.getElementById("btndwn-"+client_id);
-
- var el = null;
- if (!fm_move_dlg) {
- el = document.createElement('DIV');
- el.id = 'fm-move-dlg';
- document.body.appendChild(el);
- fm_move_dlg = new YAHOO.widget.Dialog("fm-move-dlg", {
- width : "600px",
- fixedcenter : true,
- visible : false,
- constraintoviewport : true
- });
- } else {
- el = document.getElementById('fm-move-div');
- }
-
- el.innerHTML = '<div class="hd"></div><div class="bd"><div id="fm-move-div">'+mstr.repository.nopathselected+'</div><div id="fm-tree"></div></div>';
-
- fm_move_dlg.render();
+/**
+ * Set up buttons
+ */
+function fm_setup_buttons(client_id, options) {
+ var button_download = document.getElementById("btndwn-"+client_id);
+ var button_create = document.getElementById("btncrt-"+client_id);
+ var button_addfile = document.getElementById("btnadd-"+client_id);
+ // setup 'add file' button
// if maxfiles == -1, the no limit
- if (fm_cfg[client_id].filecount >= fm_cfg[client_id].maxfiles && fm_cfg[client_id].maxfiles!=-1) {
- fileadd.style.display = 'none';
+ if (fm_cfg[client_id].filecount >= fm_cfg[client_id].maxfiles
+ && fm_cfg[client_id].maxfiles!=-1) {
+ button_addfile.style.display = 'none';
} else {
- fm_cfg[client_id].currentfiles = fm_cfg[client_id].filecount;
- fileadd.onclick = function(e) {
+ button_addfile.onclick = function(e) {
this.options.savepath = this.options.currentpath;
fm_launch_filepicker(this.options.target, this.options);
}
- fileadd.options = fm_cfg[client_id];
+ button_addfile.options = fm_cfg[client_id];
}
+
+ // setup 'make a folder' button
if (fm_cfg[client_id].subdirs) {
- foldercreate.onclick = function(e) {
- mkdir(e, this.options.client_id, this.options.itemid);
+ button_create.onclick = function(e) {
+ fm_create_folder(e, this.options.client_id, this.options.itemid);
}
- foldercreate.options = fm_cfg[client_id];
+ button_create.options = fm_cfg[client_id];
} else {
- foldercreate.style.display = 'none';
+ button_create.style.display = 'none';
}
- folderdownload.onclick = function() {
- var cb = {
+
+ // setup 'download this folder' button
+ // NOTE: popup window must be enabled to perform download process
+ button_download.onclick = function() {
+ var downloaddir_callback = {
success:function(o) {
var result = json_decode(o.responseText);
- refresh_filemanager(result.filepath, fm_cfg[this.client_id]);
+ fm_refresh(result.filepath, fm_cfg[this.client_id]);
var win = window.open(result.fileurl, 'fm-download-folder');
if (!win) {
alert(mstr.repository.popupblockeddownload);
}
}
};
- cb.client_id = this.options.client_id;
+ downloaddir_callback.client_id = this.options.client_id;
var params = [];
params['itemid'] = this.options.itemid;
params['sesskey'] = moodle_cfg.sesskey;
params['filepath'] = this.options.currentpath;
+ // perform downloaddir ajax request
var trans = YAHOO.util.Connect.asyncRequest('POST',
- filemanager.url+'?action=downloaddir', cb, build_querystring(params));
+ fm_cfg.api+'?action=downloaddir', downloaddir_callback, build_querystring(params));
}
- folderdownload.options = fm_cfg[client_id];
+ button_download.options = fm_cfg[client_id];
}
+/**
+ * Print a progress bar
+ */
function fm_loading(container, id) {
if (!document.getElementById(id)) {