changeset 349:61c4dda0ec03

New message/confirmation boxes code done in JS + CSS instead of relying on the browser's internal ones.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 02 Dec 2013 05:52:29 +0200
parents e48abbbbb3b2
children 2a12f5c72b66
files admin.php main.css majax.php msitegen.inc.php
diffstat 4 files changed, 91 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/admin.php	Mon Dec 02 05:51:38 2013 +0200
+++ b/admin.php	Mon Dec 02 05:52:29 2013 +0200
@@ -136,14 +136,18 @@
   item.style.background = "red";
 
   // Ask confirmation for deletion
-  if (confirmBox("Are you sure you want to delete "+dsc+" #"+id+"?"))
+  var mcb_ok = function (data)
   {
-    // Okay, delete
     jsSendPOSTRequest("action=delete&type="+type+"&id="+id, msuccess);
+    item.style.background = tmp;
   }
-
-  // Restore background
-  item.style.background = tmp;
+  
+  var mcb_cancel = function (data)
+  {
+    item.style.background = tmp;
+  }
+  
+  jsConfirmBox("Are you sure you want to delete "+dsc+" #"+id+"?", mcb_ok, mcb_cancel, 0);
 }
 
 
@@ -431,10 +435,15 @@
 {
   var args = jsMakePostArgs({"key_id":2}, "vk", id);
 
-  if ((mode == 0 && confirmBox("Are you sure you want to clear vote key assign #"+id+"?")) || mode != 0)
+  var mcb_ok = function (data)
   {
     voteKeyRefresh(id, (mode ? "assign" : "clear"), args);
   }
+  
+  if (mode == 0)
+    jsConfirmBox("Are you sure you want to clear vote key assign #"+id+"?", mcb_ok, 0, 0);
+  else
+    mcb_ok(0);
 }
 
 
--- a/main.css	Mon Dec 02 05:51:38 2013 +0200
+++ b/main.css	Mon Dec 02 05:52:29 2013 +0200
@@ -203,3 +203,33 @@
 	font-weight: bold;
 	font-size: 2em;
 }
+
+#messageBox {
+	position: absolute;
+	top: 0px;
+	bottom: 0px;
+	left: 0px;
+	right: 0px;
+	z-index: 50;
+	display: none;
+}
+
+#messageBox div.messageBoxInner {
+	position: absolute;
+	top: 25%;
+	min-width: 25%;
+	height: auto;
+	left: 25%;
+	min-width: 50%;
+	z-index: 52;
+	background: black;
+	border: 1px solid green;
+	padding: 2em;
+
+	-moz-border-radius: 1em;
+	border-radius: 1em;
+}
+
+#messageBox div.messageBoxControls {
+	text-align: right;
+}
--- a/majax.php	Mon Dec 02 05:51:38 2013 +0200
+++ b/majax.php	Mon Dec 02 05:52:29 2013 +0200
@@ -12,15 +12,52 @@
   echo "<script type=\"text/javascript\">\n";
 
 ?>
+function closeMessageBox(callback, cb_data)
 {
-  alert(msg);
+  var nitem = document.getElementById("messageBox");
+  if (nitem && nitem.style.display != "none")
+  {
+    nitem.style.display = "none";
+  
+    if (callback && typeof(callback) === "function")
+      callback(cb_data);
+  }
 }
 
+
 function jsMessageBox(msg)
+{
+  var nitem = document.getElementById("messageBox");
+  if (nitem)
+  {
+    nitem.innerHTML = "<div class='messageBoxInner'>"+ msg +
+      "<div class='messageBoxControls'>"+
+      "<input id='msgBoxConfirmClose' type='button' value=' OK '>"+
+      "</div></div>";
 
-function confirmBox(msg)
+    document.getElementById("msgBoxConfirmClose").onclick = function () { closeMessageBox(0, 0); }
+
+    nitem.style.display = "block";
+  }
+}
+
+
+function jsConfirmBox(msg, cb_ok, cb_cancel, cb_data)
 {
-  return confirm(msg);
+  var nitem = document.getElementById("messageBox");
+  if (nitem)
+  {
+    nitem.innerHTML = "<div class='messageBoxInner'><h1>Confirmation</h1><p>"+ msg +"</p>"+
+      "<div class='messageBoxControls'>"+
+      "<input id='msgBoxConfirmCancel' type='button' value=' Cancel '>"+
+      "<input id='msgBoxConfirmOK' type='button' value=' OK '>"+
+      "</div></div>";
+
+    document.getElementById("msgBoxConfirmCancel").onclick = function () { closeMessageBox(cb_cancel, cb_data); }
+    document.getElementById("msgBoxConfirmOK").onclick = function () { closeMessageBox(cb_ok, cb_data); }
+    
+    nitem.style.display = "block";
+  }
 }
 
 
--- a/msitegen.inc.php	Mon Dec 02 05:51:38 2013 +0200
+++ b/msitegen.inc.php	Mon Dec 02 05:52:29 2013 +0200
@@ -66,9 +66,11 @@
     
   if ($errorSet)
   {
-    echo "Following errors occured:\n";
+    echo "<h1>Following errors occured</h1>\n".
+      "<ul>\n";
     foreach ($errorMsgs as $msg)
-      echo " - ".$msg."\n";
+      echo " <li>".chentities($msg)."</li>\n";
+    echo "</ul>\n";
   }
 }
 
@@ -623,6 +625,8 @@
     require_once $pageUrchin;
   else
     require_once "urchin.inc.php";
+
+  echo "<div id=\"messageBox\"></div>\n";
   
   if ($useContents)
     echo "<div id=\"contents\">\n";