diff ajax.js @ 857:70a8d52a8d00

Add new helper function jsErrorMessageBox() and use it where appropriate.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Nov 2014 10:02:41 +0200
parents a385ac651d22
children fa12a996e86b
line wrap: on
line diff
--- a/ajax.js	Wed Nov 26 09:31:41 2014 +0200
+++ b/ajax.js	Wed Nov 26 10:02:41 2014 +0200
@@ -36,6 +36,12 @@
 }
 
 
+function jsErrorMessageBox(msg)
+{
+  jsMessageBox("<h1>An error occured</h1><div>"+msg+"</div>");
+}
+
+
 function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data)
 {
   var nitem = document.getElementById("messageBox");
@@ -120,7 +126,7 @@
     var elem = document.getElementById(elname);
     if (!elem && !nofail)
     {
-      jsMessageBox("No such DOM element '"+ elname +"'.");
+      jsErrorMessageBox("No such DOM element '"+ elname +"'.");
       return "";
     }
 
@@ -152,7 +158,7 @@
           break;
 
         default:
-          jsMessageBox("Unsupported field type in "+ elname);
+          jsErrorMessageBox("Unsupported field type in "+ elname);
           return "";
       }
     }
@@ -166,7 +172,7 @@
   var elem = document.getElementById(elname);
   if (!elem)
   {
-    jsMessageBox("No such DOM element '"+ elname +"'.");
+    jsErrorMessageBox("No such DOM element '"+ elname +"'.");
     return "";
   }
 
@@ -190,7 +196,7 @@
         return null;
 
     default:
-      jsMessageBox("Unsupported field type in "+ elname);
+      jsErrorMessageBox("Unsupported field type in "+ elname);
       return "";
   }
 }
@@ -227,17 +233,23 @@
 
 function jsStartFileUpload(formID, formTarget, fileSelID, fileMaxSize, fileCallback)
 {
+  var formFile = document.getElementById(fileSelID).files[0];
+  if (!formFile || typeof(formFile) !== "object")
+  {
+    jsErrorMessageBox("No file selected.");
+    return;
+  }
 
   if (formFile.size > fileMaxSize)
   {
-    jsMessageBox("File size exceeds "+ jsFormatSize(maxSize) +".");
+    jsErrorMessageBox("File size exceeds "+ jsFormatSize(maxSize) +".");
     return;
   }
 
   var formElem = document.getElementById(formID);
   if (!formElem)
   {
-    jsMessageBox("File upload form '"+ formID +"' element not found!");
+    jsErrorMessageBox("File upload form '"+ formID +"' element not found!");
     return;
   }
 
@@ -270,7 +282,7 @@
 
 function jsUploadError(e)
 {
-  jsMessageBox("Error occured while uploading.");
+  jsErrorMessageBox("Error occured while uploading: ");
 }