summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2006-08-16 08:28:10 +0100
committerAndrew Dolgov <[email protected]>2006-08-16 08:28:10 +0100
commita4dbc5247a35661f746f0f012c08a13db65713ee (patch)
treebda44b8ed6ad8820a2b2a5a51d9edc6320270c07
parent68c1b64ff1950963db69780dc15b33015cdece6f (diff)
rework label editor from inline to infobox
-rw-r--r--backend.php129
-rw-r--r--db.php9
-rw-r--r--prefs.js28
-rw-r--r--tt-rss.css14
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 "<div id=\"infoBoxTitle\">Label editor</div>";
+ print "<div class=\"infoBoxContents\">";
+
+ print "<form id=\"label_edit_form\">";
+
+ print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
+ print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
+ print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
+
+ print "<table width='100%'>";
+
+ print "<tr><td>Caption:</td>
+ <td><input onkeypress=\"return filterCR(event)\"
+ onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
+ name=\"description\" class=\"iedit\" value=\"$description\">";
+
+ print "</td></tr>";
+
+ print "<tr><td colspan=\"2\">
+ <p>SQL Expression:</p>";
+
+ print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
+ rows=\"4\" name=\"sql_exp\" class=\"iedit\">$sql_exp</textarea>";
+
+ print "</td></tr></table>";
+
+ print "</form>";
+
+ print "<div style=\"display : none\" id=\"label_test_result\"></div>";
+
+ print "<div align='right'>";
+
+ print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
+ ";
+
+ print "<input type=\"submit\"
+ id=\"infobox_submit\"
+ class=\"button\" onclick=\"return labelEditSave()\"
+ value=\"Save\"> ";
+
+ print "<input class=\"button\"
+ type=\"submit\" onclick=\"return labelEditCancel()\"
+ value=\"Cancel\">";
+
+ print "</div>";
+
+ return;
+ }
+
if ($subop == "test") {
$expr = db_unescape_string(trim($_GET["expr"]));
$descr = db_unescape_string(trim($_GET["descr"]));
- print "<div id=\"infoBoxTitle\">Test label: $descr</div>";
+ print "<div>";
- print "<div class='infoBoxContents'>";
-
-# print "<h1>Label &laquo;$descr&raquo;</h1>";
+ error_reporting(0);
-// print "<p><b>Expression</b>: $expr</p>";
$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 "<p>" . db_last_error($link) . "</p>";
+ print "</div>";
+ return;
+ }
$num_matches = db_fetch_result($result, 0, "num_matches");;
if ($num_matches > 0) {
- print "<p>Query returned <b>$num_matches</b> matches, showing first 15:</p>";
+ print "<p>Query returned <b>$num_matches</b> matches, showing up to first 10:</p>";
$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 "<ul class=\"filterTestResults\">";
+ print "<ul class=\"labelTestResults\">";
$row_class = "even";
@@ -2312,9 +2378,6 @@
print "</div>";
- print "<div align='center'>
- <input type='submit' class='button'
- onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
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 "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
+ print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
- print "<td><a href=\"javascript:editLabel($label_id);\">" .
- $line["sql_exp"] . "</td>";
+ print "<td><a href=\"javascript:editLabel($label_id);\">" .
+ $line["sql_exp"] . "</td>";
- print "<td><a href=\"javascript:editLabel($label_id);\">" .
- $line["description"] . "</td>";
-
- } else if ($label_id != $edit_label_id) {
-
- if (!$line["description"]) $line["description"] = "[No description]";
-
- print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
- id=\"LICHK-".$line["id"]."\"></td>";
-
- print "<td>".$line["sql_exp"]."</td>";
- print "<td>".$line["description"]."</td>";
-
- } else {
-
- print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
-
- print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
- print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
- print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
-
- print "</td>";
-
- print "<td><input onkeypress=\"return filterCR(event)\"
- class=\"iedit\" name=\"sql_exp\" value=\"".$line["sql_exp"]."\"></td>";
-
- print "<td><input onkeypress=\"return filterCR(event)\"
- class=\"iedit\" name=\"description\" value=\"".$line["description"]."\"></td>";
- }
-
+ print "<td><a href=\"javascript:editLabel($label_id);\">" .
+ $line["description"] . "</td>";
print "</tr>";
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 = "<p>Loading, please wait...</p>";
+
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;