changeset 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 4df97b9e6125
children fa12a996e86b
files admin.js ajax.js
diffstat 2 files changed, 30 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/admin.js	Wed Nov 26 09:31:41 2014 +0200
+++ b/admin.js	Wed Nov 26 10:02:41 2014 +0200
@@ -184,7 +184,7 @@
           jsSwitchActiveTab(id, set_default);
       }
       catch (err) {
-        jsMessageBox("JSON.parse("+ txt +") failure: "+ err);
+        jsErrorMessageBox("JSON.parse("+ txt +") failure: "+ err);
       }
     }
   }
@@ -682,7 +682,7 @@
   if (id > 0)
     jsSendPOSTRequest("action=ctrl&type=setActiveRotationList&id="+id, refreshActiveRotationList);
   else
-    jsMessageBox("No rotation list selected?");
+    jsErrorMessageBox("No rotation list selected?");
 }
 
 
@@ -708,7 +708,7 @@
       "&slide_id="+parseInt(str[0])+"&order_num="+parseInt(str[1])+"&dir="+dir, msuccess);
   }
   else
-    jsMessageBox("No slide selected?");
+    jsErrorMessageBox("No slide selected?");
 }
 
 
@@ -723,7 +723,7 @@
   if (slide_id > 0)
     jsSendPOSTRequest("action=ctrl&type=addRotationListSlide&list_id="+list_id+"&slide_id="+slide_id, msuccess);
   else
-    jsMessageBox("No slide selected?");
+    jsErrorMessageBox("No slide selected?");
 }
 
 
@@ -742,7 +742,7 @@
       "&slide_id="+parseInt(str[0])+"&order_num="+parseInt(str[1]), msuccess);
   }
   else
-    jsMessageBox("No slide selected?");
+    jsErrorMessageBox("No slide selected?");
 }
 
 
@@ -752,7 +752,7 @@
   if (id > 0)
     jsSendPOSTRequest("action=get&type=infoRotationListEdit&id="+id, jsOpenAdminPopup);
   else
-    jsMessageBox("No rotation list selected?");
+    jsErrorMessageBox("No rotation list selected?");
 }
 
 
@@ -782,7 +782,7 @@
       mcb_ok, 0, 0);
   }
   else
-    jsMessageBox("No rotation list selected?");
+    jsErrorMessageBox("No rotation list selected?");
 }
 
 
@@ -811,7 +811,7 @@
   if (id > 0)
     jsSendPOSTRequest("action=get&type=infoDisplaySlideEdit&id="+id, jsOpenAdminPopup);
   else
-    jsMessageBox("No display slide selected?");
+    jsErrorMessageBox("No display slide selected?");
 }
 
 
@@ -827,7 +827,7 @@
   if (id > 0)
     jsSendPOSTRequest("action=ctrl&type=copyDisplaySlide&id="+id, msuccess);
   else
-    jsMessageBox("No display slide selected?");
+    jsErrorMessageBox("No display slide selected?");
 }
 
 
@@ -863,7 +863,7 @@
       mcb_ok, 0, 0);
   }
   else
-    jsMessageBox("No display slide selected?");
+    jsErrorMessageBox("No display slide selected?");
 }
 
 
@@ -874,7 +874,7 @@
   if (id > 0)
     jsSendPOSTRequest("action=ctrl&type=setTempSlide&id="+id+"&duration="+duration, jsMessageBox);
   else
-    jsMessageBox("No slide selected?");
+    jsErrorMessageBox("No slide selected?");
 }
 
 
--- 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: ");
 }