changeset 750:e46f43a8b8dd

Rework entry editing. Still needs cosmetic work, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Nov 2014 08:01:04 +0200
parents 56dc64256d31
children 025380b800a2
files admajax.php admin.js
diffstat 2 files changed, 101 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Nov 20 08:00:22 2014 +0200
+++ b/admajax.php	Thu Nov 20 08:01:04 2014 +0200
@@ -57,8 +57,8 @@
   $res = TRUE;
 
   stChkRequestItemFail("name", $fake, $res,
-    array(CHK_ISGT, VT_STR, 0, "Entry name too short."),
-    array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NAME, "Entry name too long."));
+    array(CHK_ISGT, VT_STR, 0, "Name too short."),
+    array(CHK_LTEQ, VT_STR, SET_LEN_ENTRY_NAME, "Name too long."));
 
   stChkRequestItemFail("compo_id", $compo_id, $res,
     array(CHK_TYPE, VT_INT, "Invalid compo ID."));
@@ -163,9 +163,9 @@
 }
 
 
-function stPrintEntryItemData($item, $row, $tr, $prefix, $ctype, $edit)
+function stPrintEntryItemData($item, $row, $tr, $prefix, $ctype, $mode)
 {
-  global $entryFlagsList;
+  global $entryFlagsList, $previewTypeList, $compoModeData;
 
   $eid = $item["id"];
   if ($ctype === FALSE)
@@ -174,39 +174,91 @@
   if ($tr)
   {
     echo
-      "  <tr class=\"".($row % 2 == 1 ? "rodd" : "reven").
-      "\" id=\"entry".$eid."\" onClick=\"activateEntry(".$eid.")\">\n";
+      "  <div class=\"entryRow ".($row % 2 == 1 ? "rodd" : "reven").
+      "\" id=\"entry".$eid."\"".($mode ? "" : " onClick=\"activateEntry(".$eid.")\"").">\n";
   }
 
-  echo
-    "   <td>".($item["show_id"] > 0 ? $item["show_id"] : "-")."</td>\n".
-    "   ".stGetTDFormTextInput($edit, 20, SET_LEN_ENTRY_NAME, "name", $eid, $prefix, $item["name"])."\n".
-    "   ".stGetTDFormTextInput($edit, 15, SET_LEN_ENTRY_AUTHOR, "author", $eid, $prefix, $item["author"])."\n";
-  
-  echo
-    "   ".stGetTDFormTextInput($edit, 20, SET_LEN_ENTRY_FILENAME, "filename", $eid, $prefix, $item["filename"])."\n";
-
-  echo
-    "   <td>".
-    stGetFormTextArea(2, 30, "info", $eid, $prefix, $item["info"])."<br />".
-    stGetFormTextArea(2, 30, "notes", $eid, $prefix, $item["notes"])."<br />".
-    // XXX TODO flags?
-    "</td>\n".
-    "   <td>".
-    "</td>\n";
-
-  if ($edit)
+  if ($mode != 2)
   {
     echo
-    "   <td>".
-    stGetFormButtonInput("delete", $eid, $prefix, "Del", "deleteEntry(".$item["compo_id"].",".$eid.")").
-    stGetFormTextInput(3, 3, "compo_id", $eid, $prefix, $item["compo_id"]).
-    stGetFormButtonInput("update", $eid, $prefix, "Upd", "updateEntry(".$item["compo_id"].",".$eid.")").
-    "</td>\n";
+      "   <div class=\"entryCell\">".($item["show_id"] > 0 ? $item["show_id"] : "-")."</div>\n";
+  }
+  
+  switch ($ctype)
+  {
+    case COMPO_NORMAL:
+      echo
+      "   <div class=\"entryCell\">\n".
+      "   ".stGetEditFormTextInput($mode, "Name", 20, SET_LEN_ENTRY_NAME, "name", $eid, $prefix, $item["name"])."\n".
+      "   ".stGetEditFormTextInput($mode, "Author", 15, SET_LEN_ENTRY_AUTHOR, "author", $eid, $prefix, $item["author"])."\n".
+      "   </div>\n".
+      "   <div class=\"entryCell\">\n".
+      "   ".stGetEditFormTextInput($mode, "Filename", 20, SET_LEN_ENTRY_FILENAME, "filename", $eid, $prefix, $item["filename"])."\n".
+      "   </div>\n";
+      // XXX TODO UPLOAD BUTTON or something
+
+      echo
+      "   <div class=\"entryCell\">\n".
+      "    ".stGetEditFormTextArea($mode, $mode == 2 ? "Info shown during compo" : "Info", 2, 30, "info", $eid, $prefix, $item["info"])."\n".
+      "    ".stGetEditFormTextArea($mode, $mode == 2 ? "Notes for internal use" : "Notes", 2, 30, "notes", $eid, $prefix, $item["notes"])."\n".
+      "   </div>\n";
+
+      if ($mode == 0 || $mode == 1)
+      {
+        echo "   <div class=\"entryCell\">\n";
+
+        if ($mode)
+          stGetFormOptionListFromArray($prefix."preview_type".$eid, "    ", FALSE, $previewTypeList, $item["preview_type"], 0);
+        else
+          echo "    ".$previewTypeList[$item["preview_type"]];
+
+        echo "   </div>\n";
+        break;
+        
+      }
+      break;
+    
+    case COMPO_POINTS:
+    case COMPO_ASSIGN:
+      echo
+      "   <div class=\"entryCell\">".stGetEditFormTextInput($mode, "Name", 15, SET_LEN_ENTRY_AUTHOR, "name", $eid, $prefix, $item["name"])."</div>\n".
+      "   <div class=\"entryCell\">".stGetEditFormTextInput($mode, $compoModeData[$ctype][2], 5, SET_LEN_ENTRY_AUTHOR, "evalue", $eid, $prefix, $item["evalue"])."</div>\n".
+      "   <div class=\"entryCell\">\n".
+      "    ".stGetEditFormTextArea($mode, "Notes", 2, 30, "notes", $eid, $prefix, $item["notes"])."\n".
+      "   </div>\n";
+      break;
+  }
+
+  if ($mode == 1 || $mode == 0)
+  {
+    echo "   <div class=\"entryCell\">";
+    foreach ($entryFlagsList as $flag => $fdata)
+    {
+      echo "     ".stGetFormCheckBoxInput("eflag".$flag, $eid, $prefix, ($item["flags"] & $flag), $fdata[0],
+        $mode ? "" : " disabled=\"disabled\" ")."\n";
+    }
+    echo "   </div>\n";
+  }
+
+  switch ($mode)
+  {
+    case 1:
+      echo
+      "   <div class=\"entryCell\">".
+      stGetFormButtonInput("delete", $eid, $prefix, "Del", "deleteEntry(".$item["compo_id"].",".$eid.")").
+      stGetFormTextInput(3, 3, "compo_id", $eid, $prefix, $item["compo_id"]).
+      stGetFormButtonInput("update", $eid, $prefix, "Upd", "updateEntry(".$item["compo_id"].",".$eid.")").
+      "</div>\n";
+      break;
+    
+    case 2:
+      echo
+      "   <div class=\"entryCell\">".stGetFormButtonInput("add", $item["compo_id"], $prefix, "Add new", "addEntry(".$item["compo_id"].")")."</div>\n";
+      break;
   }
 
   if ($tr)
-    echo "  </tr>\n";
+    echo "  </div>\n";
 }
 
 
@@ -1376,40 +1428,32 @@
               stGetFormButtonInput("regenerate", "", "", " ReGenerate show positions ", "generateEntryPositions(".$id.", 0)")."\n";
           }
 
-          echo
-            "<table class=\"entries\">\n".
-            "  <tr>\n".
-            "   <th style=\"width:4%;\">S#</th>\n".
-            "   <th>Name</th>\n".
-            "   <th>Author(s)</th>\n".
-            "   <th>Filename</th>\n".
-            "   <th>Info</th>\n".
-            "   <th>Actions</th>\n".
-            "  </tr>\n".
-            "  <tr>\n".
-            "   <td></td>\n".
-            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_NAME, "name", $id, $prefix, "")."</td>\n".
-            "   <td>".stGetFormTextInput(15, SET_LEN_ENTRY_AUTHOR, "author", $id, $prefix, "")."</td>\n".
-            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_FILENAME, "filename", $id, $prefix, "")."</td>\n".
-//            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_INFO, "info", $id, $prefix, "")."</td>\n".
-            "   <td>".stGetFormTextArea(2, 30, "info", $id, $prefix, "")."</td>\n".
-            "   <td>".stGetFormButtonInput("add", $id, $prefix, "Add new", "addEntry(".$id.")")."</td>\n".
-            "  </tr>\n".
-            "  <tr><td colspan=\"6\"><hr /></td></tr>\n";
-
+          stPrintEntryItemData(array(
+            "id" => $id,
+            "show_id" => 0,
+            "name" => "",
+            "author" => "",
+            "compo_id" => $id,
+            "filename" => "",
+            "info" => "",
+            "notes" => "",
+            "preview_type" => 0,
+            "flags" => 0,
+            "evalue" => 0,
+            ),
+            0, TRUE, "ne", $compo["ctype"], 2);
+          echo "<div class=\"entries\">\n";
           $row = 0;
           foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id." ORDER BY id ASC") as $entry)
-            stPrintEntryItemData($entry, $row++, TRUE, "en", $compo["ctype"], FALSE);
-
-          echo
-            "</table>\n";
+            stPrintEntryItemData($entry, $row++, TRUE, "en", $compo["ctype"], 0);
+          echo "</div>\n";
         }
         break;
 
       case "entry":
         $res = stFetchSQL(stPrepareSQL("SELECT * FROM entries WHERE id=%D", "id"));
         if ($res !== FALSE)
-          stPrintEntryItemData($res, -1, FALSE, "en", FALSE, stGetRequestItem("edit", FALSE));
+          stPrintEntryItemData($res, -1, FALSE, "en", FALSE, stGetRequestItem("edit", FALSE) ? 1 : 0);
         else
           stError("No such entry ID!");
         break;
--- a/admin.js	Thu Nov 20 08:00:22 2014 +0200
+++ b/admin.js	Thu Nov 20 08:01:04 2014 +0200
@@ -420,7 +420,7 @@
 
 function addEntry(id)
 {
-  var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1}, "ne", id);
+  var args = jsMakePostArgs({"name":1, "author":1, "filename":1, "info":1, "notes":1, "evalue":2}, "ne", id, true);
 
   var msuccess = function(txt)
   {