From 2561d6346c1696b377899551fe69367e1ac4fc25 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Thu, 23 Feb 2012 20:00:00 +0000 Subject: [PATCH] MDL-31643 dndupload - prevent file upload when total file count would exceed the specified limit --- lib/form/dndupload.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/form/dndupload.js b/lib/form/dndupload.js index b09e1a56ed0..20fd98498a1 100644 --- a/lib/form/dndupload.js +++ b/lib/form/dndupload.js @@ -294,21 +294,22 @@ M.form_dndupload.init = function(Y, options) { this.pageentercount = 0; this.hide_upload_ready(); this.hide_drop_target(); - this.show_progress_spinner(); var files = e._event.dataTransfer.files; if (this.filemanager) { var currentfilecount = this.filemanager.filecount; + if (((currentfilecount + files.length) > this.maxfiles) && (this.maxfiles != -1)) { + alert(M.util.get_string('maxfilesreached', 'moodle', this.maxfiles)); + return false; + } + this.show_progress_spinner(); 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)) { currentfilecount++; } } } else { + this.show_progress_spinner(); if (files.length >= 1) { this.upload_file(files[0]); }