From 715889769dd388600fd6ab31fb84ab565dd5bb0e Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 29 Jul 2009 03:28:36 +0000 Subject: [PATCH] "MDL-16597, disable add button once reach max files limit" --- lang/en_utf8/repository.php | 1 + lib/form/filemanager.js | 7 ++++++- lib/form/filemanager.php | 1 + repository/repository.src.js | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index 46f1f4e01c..ed39d8fb36 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -73,6 +73,7 @@ $string['manageuserrepository'] = 'Manage individual repository'; $string['noenter'] = 'Nothing entered'; $string['nofilesattached'] = 'No files attached'; $string['nopermissiontoaccess'] = 'No permission to access this repository'; +$string['nomorefiles'] = 'No more attachments allowed'; $string['notyourinstances'] = 'You can not view/edit repository instances of another user'; $string['noresult'] = 'No search result'; $string['operation'] = 'Operation'; diff --git a/lib/form/filemanager.js b/lib/form/filemanager.js index 5e5e552bf2..0fcd96309c 100644 --- a/lib/form/filemanager.js +++ b/lib/form/filemanager.js @@ -22,6 +22,11 @@ function fp_callback(obj) { var html = '
  • '+obj['file']+' '; html += ''; html += '
  • '; + if(obj.maxfileslimit){ + var btn = document.getElementById('btnadd-'+obj.client_id); + btn.onclick = function(){return false;}; + btn.innerHTML = mstr.repository.nomorefiles; + } list.innerHTML += html; } function callpicker(el_id, client_id, itemid) { @@ -39,4 +44,4 @@ function callpicker(el_id, client_id, itemid) { params.callback = fp_callback; var fp = open_filepicker(client_id, params); return false; -} \ No newline at end of file +} diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 88036cba6d..f12dc563a0 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -176,6 +176,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element { $straddfile EOD; $PAGE->requires->yui_lib('dom'); + $PAGE->requires->string_for_js('nomorefiles', 'repository'); $PAGE->requires->js_function_call('YAHOO.util.Dom.setStyle', Array("btnadd-{$client_id}", 'display', 'inline')); if (empty($CFG->filemanagerjsloaded)) { $jsvars = Array('clientid' => $client_id, diff --git a/repository/repository.src.js b/repository/repository.src.js index 49066c9aa2..abfbb91dbd 100644 --- a/repository/repository.src.js +++ b/repository/repository.src.js @@ -1028,6 +1028,9 @@ repository_client.download_cb = { } repository_client.end = function(client_id, obj) { var fp = repository_client.fp[client_id]; + if (repository_client.files[client_id] == undefined) { + repository_client.files[client_id] = 0; + } if(fp.env=='filepicker') { fp.target.value = obj['id']; }else if(fp.env=='editor'){ @@ -1038,6 +1041,7 @@ repository_client.end = function(client_id, obj) { } fp.target.onchange(); } + obj.maxfileslimit = (repository_client.files[client_id]>=fp.maxfiles); fp.formcallback(obj); fp.hide(); repository_client.viewfiles(client_id); -- 2.39.5