MDL-13766, filemanager, don't download empty draft area
authorDongsheng Cai <unoter@gmail.com>
Mon, 3 May 2010 06:36:23 +0000 (06:36 +0000)
committerDongsheng Cai <unoter@gmail.com>
Mon, 3 May 2010 06:36:23 +0000 (06:36 +0000)
files/files_ajax.php
lang/en/repository.php
lib/form/filemanager.js
lib/weblib.php

index f46ffac..088ecc3 100755 (executable)
@@ -154,6 +154,11 @@ case 'zip':
 case 'downloaddir':
     $zipper = new zip_packer();
     $fs = get_file_storage();
+    $draftarea = file_get_draft_area_info($itemid);
+    if ($draftarea['filecount'] == 0) {
+        echo json_encode(false);
+        die;
+    }
 
     $stored_file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, '.');
     if ($filepath === '/') {
index 2b0a79d..2178c1e 100644 (file)
@@ -73,6 +73,7 @@ $string['disabled'] = 'Disabled';
 $string['download'] = 'Download';
 $string['downloadfolder'] = 'Download this folder';
 $string['downloadsucc'] = 'The file has been downloaded successfully';
+$string['draftareanofiles'] = 'Cannot be downloaed because there is no files attached';
 $string['editrepositoryinstance'] = 'Edit repository instance';
 $string['emptylist'] = 'Empty result';
 $string['emptytype'] = 'Cannot create repository type: type name is empty';
index 1afaa45..3975e11 100644 (file)
@@ -219,10 +219,14 @@ M.form_filemanager.init = function(Y, options) {
                     action: 'downloaddir',
                     scope: scope,
                     callback: function(id, obj, args) {
-                        scope.refresh(obj.filepath);
-                        var win = window.open(obj.fileurl, 'fm-download-folder');
-                        if (!win) {
-                            alert(M.str.repository.popupblockeddownload);
+                        if (obj) {
+                            scope.refresh(obj.filepath);
+                            var win = window.open(obj.fileurl, 'fm-download-folder');
+                            if (!win) {
+                                alert(M.str.repository.popupblockeddownload);
+                            }
+                        } else {
+                            alert(M.str.repository.draftareanofiles);
                         }
                     }
                 });
index 15913db..18a0b40 100644 (file)
@@ -2754,6 +2754,7 @@ function print_filemanager($options, $return = false) {
     $PAGE->requires->string_for_js('confirmdeletefile', 'repository');
     $PAGE->requires->string_for_js('nopathselected', 'repository');
     $PAGE->requires->string_for_js('popupblockeddownload', 'repository');
+    $PAGE->requires->string_for_js('draftareanofiles', 'repository');
     $PAGE->requires->string_for_js('path', 'moodle');
     // language strings
     $straddfile  = get_string('add', 'repository') . '...';