changeset 201:a4be19c4d99d

Modularize admin pages tab system.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 17 Nov 2013 17:52:51 +0200
parents 4db14e5338d7
children 8993c88f0b47
files admajax.php admin.css admin.php desktop.css index.php
diffstat 5 files changed, 104 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Sun Nov 17 16:42:47 2013 +0200
+++ b/admajax.php	Sun Nov 17 17:52:51 2013 +0200
@@ -113,6 +113,7 @@
 
         echo
         "<h1>Site settings</h1>\n".
+        "<form method=\"post\" action=\"\" onsubmit=\"return updateSettings()\">\n".
         "<table>\n";
         foreach (stExecSQL("SELECT * FROM settings WHERE vtype<>".VT_TEXT) as $item)
         {
@@ -144,6 +145,7 @@
           stGetFormTextArea(10, 60, "", $item["key"], $prefix, $item["vtext"]).
           "\n<br />\n".saveButton();
         }
+        echo "</form>\n";
         break;
       
       case "entries":
@@ -207,6 +209,16 @@
     {
       if ($type == "news")
       {
+        echo
+          "<form method=\"post\" action=\"\" onsubmit=\"return addNews()\">\n".
+          "  <input id=\"nntitle\" type=\"text\" size=\"40\" /><br />\n".
+          "  <textarea id=\"nntext\" rows=\"5\" cols=\"60\"></textarea><br />\n".
+          "  <input id=\"nnauthor\" type=\"text\" value=\"orgaz\" />\n".
+          "  <input id=\"nnadd\" type=\"submit\" value=\" Add post \" />\n".
+          "  <input type=\"button\" value=\" Clear \" onClick=\"this.form.reset()\" />\n".
+          "</form>\n".
+          "<hr />\n";
+
         foreach ($res as $item)
         {
           $id = $item["id"];
@@ -292,6 +304,15 @@
       else
       if ($type == "compos")
       {
+        echo
+          "<form method=\"post\" action=\"\" onsubmit=\"return addCompo()\">\n".
+          "  <input id=\"ncname\" type=\"text\" size=\"64\" /><br />\n".
+          "  <textarea id=\"ncdescription\" rows=\"5\" cols=\"60\"></textarea><br />\n".
+          "  <input id=\"nccompo\" type=\"submit\" value=\" Add compo \" />\n".
+          "  <input type=\"button\" value=\" Clear \" onClick=\"this.form.reset()\" />\n".
+          "</form>\n".
+          "<hr />\n";
+
         foreach ($res as $item)
         {
           $id = $item["id"];
--- a/admin.css	Sun Nov 17 16:42:47 2013 +0200
+++ b/admin.css	Sun Nov 17 17:52:51 2013 +0200
@@ -1,10 +1,10 @@
-#pageTabs {
+div.tabHeaders {
 	margin-top: 10pt;
 	margin-bottom: 0px;
 	border-bottom: 5pt solid #595F23;
 }
 
-#pageTabs a {
+div.tabHeaders a {
 	text-decoration: none;
 	padding: 5pt;
 	margin: 5pt;
@@ -14,20 +14,32 @@
 	border-top-right-radius: 5pt;
 }
 
-#pageTabs a:hover {
+div.tabHeaders a:hover {
 	background: #C8D286;
 }
 
-#pageTabs a:active {
+div.tabHeaders a:active {
 	background: #C8D286;
 }
 
-#pageTabs a.admin {
+div.tabHeaders a.admin {
 	position: relative;
 	right: -2em;
 }
 
-#admCont {
+div.tabContents {
+	position: absolute;
+	left: 0em;
+	right: 0em;
+	top: 4em;
+	bottom: 0em;
+	padding: 1em;
+	margin: 0px;
+	color: #0f0;
+}
+
+
+#adminContent {
 	position: absolute;
 	top: 1em;
 	bottom: 1em;
@@ -39,14 +51,3 @@
 	background: rgba(0,0,0,0.7);
 	color: #0f0;
 }
-
-#admin {
-	position: absolute;
-	left: 0em;
-	right: 0em;
-	top: 4em;
-	bottom: 0em;
-	padding: 1em;
-	margin: 0px;
-	color: #0f0;
-}
--- a/admin.php	Sun Nov 17 16:42:47 2013 +0200
+++ b/admin.php	Sun Nov 17 17:52:51 2013 +0200
@@ -26,7 +26,7 @@
   " <meta http-equiv=\"Pragma\" content=\"no-cache\" />",
   FALSE);
 
-echo "<div id=\"admCont\">\n";
+echo "<div id=\"adminContent\">\n";
 
 // Initiate SQL database connection
 if (!stConnectSQLDB())
@@ -100,7 +100,7 @@
   var msuccess = function(txt)
   {
     var nitem = document.getElementById(id);
-    nitem.innerHTML = txt;
+    if (nitem) nitem.innerHTML = txt;
   }
 
   sendPOSTRequest("action=get&type="+name, msuccess);
@@ -133,39 +133,45 @@
 }
 
 
-function refreshSettings()
+function refreshCCSettings()
 {
-  refreshItems("nsettings", "settings", "General settings");
+  refreshItems("tabContCCSettings", "settings", "General settings");
 }
 
 
-function refreshNews()
+function refreshCCNews()
 {
-  refreshItems("nnews", "news", "News list");
+  refreshItems("tabContCCNews", "news", "News list");
+}
+
+
+function refreshCCAttendees()
+{
+  refreshItems("tabContCCAttendees", "attendees", "Attendees list");
 }
 
 
-function refreshAttendees()
+function refreshCCVoters()
 {
-  refreshItems("nattendees", "attendees", "Attendees list");
+  refreshItems("tabContCCVoters", "voters", "Voters list");
 }
 
 
-function refreshVoters()
+function refreshCCCompos()
 {
-  refreshItems("nvoters", "voters", "Voters list");
+  refreshItems("tabContCCCompos", "compos", "Compo list");
 }
 
 
-function refreshCompos()
+function refreshCCEntries()
 {
-  refreshItems("ncompos", "compos", "Compo list");
+  refreshItems("tabContCCEntries", "entries", "Entry list");
 }
 
 
-function refreshEntries()
+function refreshCCInfo()
 {
-  refreshItems("nentries", "entries", "Entry list");
+//  refreshItems("tabContCCInfo", "info", "Info system");
 }
 
 
@@ -304,52 +310,50 @@
 var registeredTabs = Object();
 
 
-function updateTabList()
+function updateTabList(tabset, extra)
 {
-  var item = document.getElementById("pageTabs");
-  var str = "";
-  for (var id in registeredTabs)
+  var tabs = "";
+  var content = "";
+
+  for (var id in registeredTabs[tabset])
   {
-    str += "<a id=\"cc"+id+
-      "\"href=\"#\" onClick=\"switchActiveTab('"+id+
-      "')\">"+registeredTabs[id]+"</a>";
+    tabs += "<a id=\"tabHead"+ tabset + id +
+      "\"href=\"#\" onClick=\"switchActiveTab('"+tabset+"', '"+id+
+      "')\">"+ registeredTabs[tabset][id] +"</a>";
+    
+    content += "<div id=\"tabCont"+ tabset + id +"\"></div>";
   }
-  
-  str += "<a class=\"admin\" href=\"admlogout.php\">Logout</a>";
-  str += "<a class=\"admin\" href=\"about\">Mainpage</a>";
-  
-  item.innerHTML = str;
+
+  var item = document.getElementById("tabHeaders"+ tabset);
+  if (item) item.innerHTML = tabs + extra;
+
+  item = document.getElementById("tabContents"+ tabset);
+  if (item) item.innerHTML = content;
 }
 
 
-function registerTab(id, name)
+function registerTab(tabset, id, name)
 {
-  registeredTabs[id] = name;
+  if (!registeredTabs[tabset])
+    registeredTabs[tabset] = Object();
+
+  registeredTabs[tabset][id] = name;
 }
 
 
-function refreshTabs()
+function switchActiveTab(tabset, tab)
 {
-  for (var id in registeredTabs)
+  for (var id in registeredTabs[tabset])
   {
-    setTimeout("refresh"+ registeredTabs[id] +"();", 10);
-  }
-}
-
-
-function switchActiveTab(tab)
-{
-  for (var id in registeredTabs)
-  {
-    var ob = document.getElementById(id);
-    var ccob = document.getElementById("cc"+id);
-    if (ob && ccob)
+    var tabContent = document.getElementById("tabCont"+ tabset + id);
+    var tabHead = document.getElementById("tabHead"+ tabset + id);
+    if (tabContent && tabHead)
     {
-      ob.style.display = (tab == id) ? "block" : "none";
-      ccob.style.borderTop = (tab == id) ? "4px solid white" : "none";
+      tabContent.style.display = (tab == id) ? "block" : "none";
+      tabHead.style.borderTop = (tab == id) ? "4px solid white" : "none";
       if (tab == id)
       {
-        setTimeout("refresh"+ registeredTabs[id] +"();", 10);
+        setTimeout("refresh"+ tabset + id +"();", 10);
       }
     }
   }
@@ -359,86 +363,21 @@
 <!-- ========================== -->
 
 <div id="nstatus">-</div>
-
-<div id="pageTabs"></div>
-
-<div id="admin">
-<div>
-
-<!-- ========================== -->
-
-<div id="tabSettings">
-  <form method="post" action="" onsubmit="return updateSettings()">
-    <div id="nsettings"></div>
-  </form>
-</div>
-
-<!-- ========================== -->
-
-<div id="tabNews">
-  <form method="post" action="" onsubmit="return addNews()">
-    <input id="nntitle" type="text" size="40" /><br />
-    <textarea id="nntext" rows="5" cols="60"></textarea><br />
-    <input id="nnauthor" type="text" value="orgaz" />
-    <input id="nnadd" type="submit" value=" Add post " />
-    <input type="button" value=" Clear " onClick="this.form.reset()" />
-  </form>
-  <hr />
-  <div id="nnews"></div>
-</div>
-
-<!-- ========================== -->
-
-<div id="tabAttendees">
-  <div id="nattendees"></div>
-</div>
-
-<!-- ========================== -->
-
-<div id="tabVoters">
-  <div id="nvoters"></div>
-</div>
-
-<!-- ========================== -->
-
-<div id="tabCompos">
-  <form method="post" action="" onsubmit="return addCompo()">
-    <input id="ncname" type="text" size="64" /><br />
-    <textarea id="ncdescription" rows="5" cols="60"></textarea><br />
-    <input id="nccompo" type="submit" value=" Add compo " />
-    <input type="button" value=" Clear " onClick="this.form.reset()" />
-  </form>
-  <hr />
-  <div id="ncompos"></div>
-</div>
-
-<!-- ========================== -->
-
-<div id="tabEntries">
-  <div id="nentries"></div>
-</div>
-
-<!-- ========================== -->
-
-<div id="tabInfo">
-  <div id="ninfo"></div>
-</div>
-
-<!-- ========================== -->
-
-</div>
-</div>
+<div id="tabHeadersCC" class="tabHeaders"></div>
+<div id="tabContentsCC" class="tabContents"></div>
 
 <script type="text/javascript">
-  registerTab("tabSettings", "Settings");
-  registerTab("tabNews", "News");
-  registerTab("tabAttendees", "Attendees");
-  registerTab("tabVoters", "Voters");
-  registerTab("tabCompos", "Compos");
-  registerTab("tabEntries", "Entries");
-  registerTab("tabInfo", "Party Info");
-  updateTabList();
-  switchActiveTab("tabSettings");
+  registerTab("CC", "Settings", "Settings");
+  registerTab("CC", "News", "News");
+  registerTab("CC", "Attendees", "Attendees");
+  registerTab("CC", "Voters", "Voters");
+  registerTab("CC", "Compos", "Compos");
+  registerTab("CC", "Entries", "Entries");
+  registerTab("CC", "Info", "Party Info");
+  updateTabList("CC",
+    "<a class=\"admin\" href=\"admlogout.php\">Logout</a>" +
+    "<a class=\"admin\" href=\"about\">Mainpage</a>");
+  switchActiveTab("CC", "Settings");
 </script>
 <?
 }
--- a/desktop.css	Sun Nov 17 16:42:47 2013 +0200
+++ b/desktop.css	Sun Nov 17 17:52:51 2013 +0200
@@ -157,7 +157,7 @@
 	text-shadow: 2px 2px 1px rgba(0,0,0,0.4);
 }
 
-#maincontent {
+#mainContent {
 	position: fixed;
 	left: 13em;
 	right: 1em;
@@ -177,7 +177,7 @@
 	color: white;
 }
 
-#maincontent > div, #admin > div {
+#mainContent > div, div.tabContents > div {
 	width: 100%;
 	height: 100%;
 	overflow-y: auto;
--- a/index.php	Sun Nov 17 16:42:47 2013 +0200
+++ b/index.php	Sun Nov 17 17:52:51 2013 +0200
@@ -90,7 +90,7 @@
 
 echo "<div id=\"infobox\">".strtoupper($pageBasename)."</div>\n";
 ?>
-<div id="maincontent">
+<div id="mainContent">
 <div>
 <?
 if (file_exists($pageBasename.".inc.php"))