MDL-31114 Alert when max files reached
authorDavo Smith <git@davosmith.co.uk>
Tue, 14 Feb 2012 09:49:49 +0000 (09:49 +0000)
committerDavo Smith <git@davosmith.co.uk>
Tue, 14 Feb 2012 09:49:49 +0000 (09:49 +0000)
lang/en/moodle.php
lib/form/dndupload.js
lib/outputrequirementslib.php

index eb14f76..f9371e3 100644 (file)
@@ -464,6 +464,7 @@ $string['downloadfile'] = 'Download file';
 $string['downloadods'] = 'Download in ODS format';
 $string['downloadtext'] = 'Download in text format';
 $string['doyouagree'] = 'Have you read these conditions and understood them?';
+$string['droptoupload'] = 'Drop files here to upload';
 $string['duplicate'] = 'Duplicate';
 $string['duplicateconfirm'] = 'Are you sure you want to duplicate {$a->modtype} \'{$a->modname}\' ?';
 $string['duplicatecontcourse'] = 'Return to the course';
@@ -969,6 +970,7 @@ $string['manageroles'] = 'Roles and permissions';
 $string['markedthistopic'] = 'This topic is highlighted as the current topic';
 $string['markthistopic'] = 'Highlight this topic as the current topic';
 $string['matchingsearchandrole'] = 'Matching \'{$a->search}\' and {$a->role}';
+$string['maxfilesreached'] = 'You are allowed to attach a maximum of {$a} file(s) to this item';
 $string['maximumgrade'] = 'Maximum grade';
 $string['maximumgradex'] = 'Maximum grade: {$a}';
 $string['maximumchars'] = 'Maximum of {$a} characters';
index e29e378..40018a3 100644 (file)
@@ -161,7 +161,7 @@ M.form_dndupload.init = function(Y, options) {
          * @param e event object
          * @return boolean true if a valid file drag event
          */
-        check_drag: function(e) {
+        check_drag: function(e, maxfilesalert) {
             if (!this.has_files(e)) {
                 return false;
             }
@@ -170,6 +170,9 @@ M.form_dndupload.init = function(Y, options) {
             e.stopPropagation();
 
             if (this.reached_maxfiles()) {
+                if (typeof(maxfilesalert) != 'undefined' && maxfilesalert) {
+                    alert(M.util.get_string('maxfilesreached', 'moodle', this.maxfiles));
+                }
                 return false;
             }
 
@@ -231,7 +234,7 @@ M.form_dndupload.init = function(Y, options) {
          * of the files (until we reach the file limit, or run out of files)
          */
         drop: function(e) {
-            if (!this.check_drag(e)) {
+            if (!this.check_drag(e, true)) {
                 return true;
             }
 
@@ -244,6 +247,7 @@ M.form_dndupload.init = function(Y, options) {
                 var currentfilecount = this.filemanager.filecount;
                 for (var i=0, f; f=files[i]; i++) {
                     if (currentfilecount >= this.maxfiles && this.maxfiles != -1) {
+                        alert(M.util.get_string('maxfilesreached', 'moodle', this.maxfiles));
                         break;
                     }
                     if (this.upload_file(f)) {
index 56fbe20..2737fe5 100644 (file)
@@ -468,7 +468,7 @@ class page_requirements_manager {
                     $module = array('name'     => 'core_dndupload',
                                     'fullpath' => '/lib/form/dndupload.js',
                                     'requires' => array('node', 'event', 'json'),
-                                    'strings'  => array(array('uploadformlimit', 'moodle')));
+                                    'strings'  => array(array('uploadformlimit', 'moodle'), array('droptoupload', 'moodle'), array('maxfilesreached', 'moodle')));
                     break;
             }