# HG changeset patch # User Matti Hamalainen # Date 1448118119 -7200 # Node ID fb5a468e647df9c8096a9556bc22b7ed7824205e # Parent 78449511df145cfb4d50dda5f4c76d44a1c76c12 Implement compo voting enable/disable in entry pages. diff -r 78449511df14 -r fb5a468e647d admajax.php --- 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 ? "" : ""). + stGetFormCheckBoxInput( + "votingbutton", $compo["id"], "co", $compo["voting"], "Voting ".($compo["voting"] ? "IS ACTIVE" : "disabled"), + "class=\"votingactive\" onChange=\"updateCompoVoting(".$compo["id"].")\"", ""). + ($outer ? "" : ""); +} + + 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 diff -r 78449511df14 -r fb5a468e647d admin.js --- 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);