changeset 1052:fb5a468e647d

Implement compo voting enable/disable in entry pages.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Nov 2015 17:01:59 +0200
parents 78449511df14
children c050354b0270
files admajax.php admin.js
diffstat 2 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Sat Nov 21 16:23:35 2015 +0200
+++ b/admajax.php	Sat Nov 21 17:01:59 2015 +0200
@@ -227,6 +227,17 @@
 }
 
 
+function stGetCompoVoting($compo, $outer)
+{
+  return
+    ($outer ? "<span id=\"covoting".$compo["id"]."\">" : "").
+    stGetFormCheckBoxInput(
+    "votingbutton", $compo["id"], "co", $compo["voting"], "Voting ".($compo["voting"] ? "IS ACTIVE" : "disabled"),
+    "class=\"votingactive\" onChange=\"updateCompoVoting(".$compo["id"].")\"", "").
+    ($outer ? "</span>" : "");
+}
+
+
 function stPrintEntryItemData($item, $row, $tr, $prefix, $compo, $mode)
 {
   global $entryFlagsList, $previewTypeList, $compoModeData;
@@ -1608,6 +1619,12 @@
         }
         break;
 
+      case "compovoting":
+        $id = intval(stGetRequestItem("id", 0));
+        if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$id)) !== false)
+          echo stGetCompoVoting($compo, FALSE);
+        break;
+
       case "entries":
         $id = intval(stGetRequestItem("id", 0));
         if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$id)) !== false)
@@ -1621,7 +1638,8 @@
           {
             echo
               stGetFormButtonInput("generate", "", "", " Add missing show positions ", "generateEntryPositions(".$id.", 1)")."\n".
-              stGetFormButtonInput("regenerate", "", "", " ReGenerate show positions ", "generateEntryPositions(".$id.", 0)")."\n";
+              stGetFormButtonInput("regenerate", "", "", " ReGenerate show positions ", "generateEntryPositions(".$id.", 0)")."\n".
+              stGetCompoVoting($compo, TRUE)."\n";
           }
 
           stPrintEntryItemData(array(
@@ -1825,6 +1843,15 @@
         stExecSQLCond($sql, "OK, compo updated.");
       }
       else
+      if ($type == "compovoting" &&
+        stChkRequestItem("voting", $compovoting, $qres,
+          array(CHK_TYPE, VT_BOOL, "Invalid data.")
+        ))
+      {
+        $sql = stPrepareSQL("UPDATE compos SET voting=%b WHERE id=%d", $compovoting, $id);
+        stExecSQLCond($sql, "OK, compo updated.");
+      }
+      else
       if ($type == "compo")
       {
         // Check if compo ID exists
--- a/admin.js	Sat Nov 21 16:23:35 2015 +0200
+++ b/admin.js	Sat Nov 21 17:01:59 2015 +0200
@@ -385,6 +385,17 @@
 }
 
 
+function updateCompoVoting(id)
+{
+  var msuccess = function(txt)
+  {
+    jsRefreshItems("covoting"+id, "compovoting", "&id="+id);
+  }
+
+  jsSendPOSTRequest("action=update&type=compovoting&id="+id+"&voting="+jsGetValue("covotingbutton"+id, 3), msuccess);
+}
+
+
 function updateCompo(id)
 {
   var args = jsMakePostArgs({"name":1, "description":1, "notes":1, "visible":3, "voting":3, "show_authors":3, "cpath":1, "preview_type":4}, "co", id, true);