updates for stage 2
[edumed.git] / stage2 / static / js / checkfile.js
index f15c134..19db762 100644 (file)
@@ -8,13 +8,21 @@ $(function() {
                 var ext = this.getAttribute('data-ext');
                 var re = new RegExp('\\.(' + ext + ')$', 'i');
                 if (!re.exec(name)) {
-                    alert('Błędne rozszerzenie! Powinno być jedno z: ' + ext.replace(/\|/g, ', '));
+                    if (/\|/.exec(ext))
+                        alert('Błędne rozszerzenie! Powinno być jedno z: ' + ext.replace(/\|/g, ', '));
+                    else
+                        alert('Błędne rozszerzenie! Powinno być: ' + ext);
+                    ok = false;
+                }
+                if (name.length > 65) {
+                    alert('Za długa nazwa pliku! Maksymalna długość: 65 znaków (jest: ' + name.length + ')');
                     ok = false;
                 }
             }
+            var max_size = this.getAttribute('data-max') || 20;
             var size = this.files[0].size;
-            if (size > 10 * 1024 * 1024) {
-                alert('Rozmiar pliku nie może przekraczać 10 MB!');
+            if (size > max_size * 1024 * 1024) {
+                alert('Rozmiar pliku nie może przekraczać ' + max_size + ' MB!');
                 ok = false;
             }
             if (!ok) {