From a4dbc5247a35661f746f0f012c08a13db65713ee Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 16 Aug 2006 08:28:10 +0100 Subject: [PATCH] rework label editor from inline to infobox --- backend.php | 129 +++++++++++++++++++++++++++++++++------------------- db.php | 9 ++++ prefs.js | 28 ++++++++---- tt-rss.css | 14 ++++++ 4 files changed, 123 insertions(+), 57 deletions(-) diff --git a/backend.php b/backend.php index d4914710b..860fec181 100644 --- a/backend.php +++ b/backend.php @@ -2257,18 +2257,76 @@ $subop = $_GET["subop"]; + if ($subop == "edit") { + + $label_id = db_escape_string($_GET["id"]); + + $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE + owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description"); + + $line = db_fetch_assoc($result); + + $sql_exp = htmlspecialchars(db_unescape_string($line["sql_exp"])); + $description = htmlspecialchars(db_unescape_string($line["description"])); + + print "
Label editor
"; + print "
"; + + print "
"; + + print ""; + print ""; + print ""; + + print ""; + + print " + "; + + print "
Caption:"; + + print "
+

SQL Expression:

"; + + print ""; + + print "
"; + + print "
"; + + print "
"; + + print "
"; + + print " + "; + + print " "; + + print ""; + + print "
"; + + return; + } + if ($subop == "test") { $expr = db_unescape_string(trim($_GET["expr"])); $descr = db_unescape_string(trim($_GET["descr"])); - print "
Test label: $descr
"; + print "
"; - print "
"; - -# print "

Label «$descr»

"; + error_reporting(0); -// print "

Expression: $expr

"; $result = db_query($link, "SELECT count(ttrss_entries.id) AS num_matches @@ -2276,13 +2334,21 @@ WHERE ($expr) AND ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.feed_id = ttrss_feeds.id AND - ttrss_user_entries.owner_uid = " . $_SESSION["uid"]); + ttrss_user_entries.owner_uid = " . $_SESSION["uid"], false); + + error_reporting (DEFAULT_ERROR_LEVEL); + + if (!$result) { + print "

" . db_last_error($link) . "

"; + print "
"; + return; + } $num_matches = db_fetch_result($result, 0, "num_matches");; if ($num_matches > 0) { - print "

Query returned $num_matches matches, showing first 15:

"; + print "

Query returned $num_matches matches, showing up to first 10:

"; $result = db_query($link, "SELECT ttrss_entries.title, @@ -2292,9 +2358,9 @@ ttrss_user_entries.ref_id = ttrss_entries.id AND ttrss_user_entries.feed_id = ttrss_feeds.id AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . " - ORDER BY date_entered DESC LIMIT 15"); + ORDER BY date_entered DESC LIMIT 10", false); - print "
    "; + print "
      "; $row_class = "even"; @@ -2312,9 +2378,6 @@ print "
"; - print "
-
"; return; } @@ -2417,46 +2480,16 @@ $line["description"] = htmlspecialchars( db_unescape_string($line["description"])); - if (!$edit_label_id || $subop != "edit") { + if (!$line["description"]) $line["description"] = "[No caption]"; - if (!$line["description"]) $line["description"] = "[No caption]"; - - print ""; - print "" . - $line["sql_exp"] . ""; + print "" . + $line["sql_exp"] . ""; - print "" . - $line["description"] . ""; - - } else if ($label_id != $edit_label_id) { - - if (!$line["description"]) $line["description"] = "[No description]"; - - print ""; - - print "".$line["sql_exp"].""; - print "".$line["description"].""; - - } else { - - print ""; - - print ""; - print ""; - print ""; - - print ""; - - print ""; - - print ""; - } - + print "" . + $line["description"] . ""; print ""; diff --git a/db.php b/db.php index 7766c0563..8b1c5a380 100644 --- a/db.php +++ b/db.php @@ -134,4 +134,13 @@ function db_affected_rows($link, $result) { return mysql_affected_rows($link); } } + +function db_last_error($link) { + if (DB_TYPE == "pgsql") { + return pg_last_error($link); + } else if (DB_TYPE == "mysql") { + return mysql_error($link); + } +} + ?> diff --git a/prefs.js b/prefs.js index 11743d2cc..28e54ee4f 100644 --- a/prefs.js +++ b/prefs.js @@ -82,6 +82,14 @@ function labellist_callback() { } } +function labeltest_callback() { + var container = document.getElementById('label_test_result'); + if (xmlhttp.readyState == 4) { + container.innerHTML=xmlhttp.responseText; + notify(""); + } +} + function feed_browser_callback() { var container = document.getElementById('prefContent'); if (xmlhttp.readyState == 4) { @@ -309,9 +317,12 @@ function editLabel(id) { active_label = id; + selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false); + selectTableRowById('LILRR-'+id, 'LICHK-'+id, true); + xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" + param_escape(id), true); - xmlhttp.onreadystatechange=labellist_callback; + xmlhttp.onreadystatechange=infobox_callback; xmlhttp.send(null); } @@ -663,6 +674,10 @@ function feedCatEditSave() { function labelTest() { + var container = document.getElementById('label_test_result'); + container.style.display = "block"; + container.innerHTML = "

Loading, please wait...

"; + var form = document.forms['label_edit_form']; var sql_exp = form.sql_exp.value; @@ -671,7 +686,7 @@ function labelTest() { xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" + param_escape(sql_exp) + "&descr=" + param_escape(description), true); - xmlhttp.onreadystatechange=infobox_callback; + xmlhttp.onreadystatechange=labeltest_callback; xmlhttp.send(null); return false; @@ -696,14 +711,9 @@ function labelEditCancel() { active_label = false; -// notify("Operation cancelled."); - + selectPrefRows('label', false); // cleanup feed selection closeInfoBox(); - xmlhttp.open("GET", "backend.php?op=pref-labels", true); - xmlhttp.onreadystatechange=labellist_callback; - xmlhttp.send(null); - return false; } @@ -1452,7 +1462,7 @@ function selectPrefRows(kind, select) { } else if (kind == "label") { opbarid = "labelOpToolbar"; nrow = "LILRR-"; - nchk = "LCHK-"; + nchk = "LICHK-"; lname = "prefLabelList"; } else if (kind == "user") { opbarid = "userOpToolbar"; diff --git a/tt-rss.css b/tt-rss.css index c92b388ff..f8f155b73 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -287,6 +287,10 @@ a:hover { background-color : #f0fff0; } +textarea.iedit { + width : 100%; +} + input.iedit { width : 100%; padding-left : 2px; @@ -956,6 +960,16 @@ ul.userFeedList { -moz-border-radius : 5px; } */ +ul.labelTestResults { + height : 100px; + overflow : auto; + list-style-type : none; + margin : 0px 0px 5px 0px; + padding : 0px; + border : 1px solid #88b0f0; + background-color : white; +} + ul.filterTestResults { height : 300px; overflow : auto;