From: Dongsheng Cai Date: Mon, 7 Dec 2009 05:01:09 +0000 (+0000) Subject: "MDL-16597, added more docs, clean up code and added maxbytes support" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=494bf5c8cfa40dd40ccbece8887c93cb7fe3ea56;p=moodle.git "MDL-16597, added more docs, clean up code and added maxbytes support" --- diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 6dbab8ff00..77525635e8 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -1,70 +1,133 @@ +// 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 . + +/** + * This file contains javascript code used to manage files in draft area + * + * @since 2.0 + * @package filemanager + * @copyright 2009 Dongsheng Cai + * @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 - * @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 = '
'+mstr.repository.nopathselected+'
'; + + 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; @@ -75,9 +138,10 @@ function mkdir(e, client_id, itemid) { 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'; @@ -85,7 +149,7 @@ function mkdir(e, client_id, itemid) { 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, @@ -94,14 +158,15 @@ function mkdir(e, client_id, itemid) { }); } - 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 = ''; @@ -112,7 +177,9 @@ function html_compiler(client_id, options) { 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) { @@ -124,40 +191,47 @@ function html_compiler(client_id, options) { 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 = '
    '; + 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 @@ -170,12 +244,17 @@ function html_compiler(client_id, options) { 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); @@ -184,11 +263,14 @@ function html_compiler(client_id, options) { 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); @@ -212,46 +294,38 @@ function html_compiler(client_id, options) { break; } var fullname = list[i].fullname; + + // add green tick to main file if (ismainfile) { fullname = ""+list[i].fullname+" "; } + html = html.replace('___fullname___', ' ' + fullname + ''); - html = html.replace('___action___', ''); + html = html.replace('___action___', ''); html = '
  • '+html+'
  • '; listhtml += html; } - container.innerHTML = (listhtml+'
'); - options.client_id=client_id; + container.innerHTML = '
    ' + listhtml + '
'; - 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); @@ -264,22 +338,33 @@ function click_breadcrumb(ev, args) { 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); @@ -292,20 +377,26 @@ function refresh_filemanager(path, args) { 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]); } } } @@ -318,32 +409,32 @@ function create_foldermenu(e, data) { 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]); } } } @@ -355,7 +446,7 @@ function create_zipmenu(e, data) { 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; @@ -363,10 +454,10 @@ function create_zipmenu(e, data) { {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}); @@ -387,7 +478,7 @@ function create_menu(ev, menuid, menuitems, file, options) { 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; @@ -400,11 +491,17 @@ function create_menu(ev, menuid, menuitems, file, options) { 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
'; 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, @@ -470,9 +567,9 @@ function create_menu(ev, menuid, menuitems, file, options) { 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(); @@ -496,7 +593,7 @@ function create_menu(ev, menuid, menuitems, file, options) { 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(); } } @@ -516,13 +613,13 @@ function create_menu(ev, menuid, menuitems, file, options) { 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) { @@ -554,13 +651,13 @@ function create_menu(ev, menuid, menuitems, file, options) { 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 = '
'+mstr.repository.nopathselected+'
'; @@ -574,8 +671,8 @@ function create_menu(ev, menuid, menuitems, file, options) { }, 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 = [ @@ -593,7 +690,7 @@ function create_menu(ev, menuid, menuitems, file, options) { 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; @@ -606,18 +703,24 @@ function create_menu(ev, menuid, menuitems, file, options) { }); } -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) { @@ -629,77 +732,72 @@ function setup_filebrowser(client_id, options) { 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 = '
'+mstr.repository.nopathselected+'
'; - - 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)) { diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 1625cd7578..9a8522f646 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -210,7 +210,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $CFG->filemanagerjsloaded = true; // print html template $html .= <<