From: dongsheng Date: Fri, 12 Jun 2009 05:57:25 +0000 (+0000) Subject: "MDL-19002, implement attachment files limit in file picker" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6b0fae574d8125a9e1a726d14de183aaa788c764;p=moodle.git "MDL-19002, implement attachment files limit in file picker" --- diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 93283a34e2..7ab843a43d 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -182,7 +182,8 @@ EOD; var selected_file = null; var rm_cb = { success: function(o) { - if(o.responseText && o.responseText == 200){ + if(o.responseText){ + repository_client.files[o.responseText]--; selected_file.parentNode.removeChild(selected_file); } } @@ -192,7 +193,7 @@ function rm_file(id, name, context) { var trans = YAHOO.util.Connect.asyncRequest('POST', '{$CFG->httpswwwroot}/repository/ws.php?action=delete&itemid='+id, rm_cb, - 'title='+name + 'title='+name+'&client_id=$client_id' ); selected_file = context.parentNode; } @@ -213,8 +214,8 @@ function callpicker(el_id, client_id, itemid) { var el=document.getElementById(el_id); var params = {}; params.env = 'filemanager'; - params.maxbytes = $this->_options['maxbytes']; - params.maxfiles = $this->_options['maxfiles']; + params.maxbytes = {$this->_options['maxbytes']}; + params.maxfiles = {$this->_options['maxfiles']}; params.itemid = itemid; params.target = el; params.callback = fp_callback; @@ -228,7 +229,7 @@ function callpicker(el_id, client_id, itemid) { .btnaddfile{display:none} -Error +Error EOD; $CFG->filemanagerjsloaded = true; diff --git a/repository/repository.src.js b/repository/repository.src.js index ae8f785c70..2d5e81d3eb 100644 --- a/repository/repository.src.js +++ b/repository/repository.src.js @@ -563,6 +563,14 @@ repository_client.buildtree = function(client_id, node, level) { } } repository_client.select_file = function(oldname, url, icon, client_id, repo_id) { + if (repository_client.files[client_id] == undefined) { + repository_client.files[client_id] = 0; + } + if (repository_client.files[client_id] >= repository_client.fp[client_id].maxfiles) + { + alert('Only '+repository_client.fp[client_id].maxfiles+' files are allowed!'); + return false; + } var thumbnail = document.getElementById('fp-grid-panel-'+client_id); if(thumbnail){ thumbnail.style.display = 'none'; @@ -821,6 +829,9 @@ repository_client.view_as_icons = function(client_id, data) { } container.appendChild(panel); repository_client.print_footer(client_id); +} +repository_client.check_maxfiles = function(num) { + } repository_client.print_footer = function(client_id) { var fs = this.fp[client_id].fs; @@ -955,6 +966,11 @@ repository_client.download_cb = { panel.get('element').innerHTML = data.e; return; } + if(repository_client.files[data.client_id]==undefined) { + repository_client.files[data.client_id] = 0; + } else { + repository_client.files[data.client_id]++; + } repository_client.end(data.client_id, data); } } @@ -1122,6 +1138,7 @@ success: function(o) { dlg.show(); } } +repository_client.files = {}; var mdl_in_array = function(el, arr) { for(var i = 0, l = arr.length; i < l; i++) { if(arr[i] == el) { @@ -1169,5 +1186,10 @@ function open_filepicker(id, params) { } else { r.accepted_types = '*'; } + if (!params.maxfiles) { + // unlimited + params.maxfiles = -1; + } + r.maxfiles = params.maxfiles; return r; } diff --git a/repository/ws.php b/repository/ws.php index cc5992b2e4..37198f4d94 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -46,7 +46,7 @@ $fs = get_file_storage(); if ($file = $fs->get_file($contextid, 'user_draft', $itemid, '/', $title)) { if($result = $file->delete()) { - echo 200; + echo $client_id; } else { echo ''; }