rework label editor from inline to infobox

master
Andrew Dolgov 19 years ago
parent 68c1b64ff1
commit a4dbc5247a

@ -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>";

@ -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);
}
}
?>

@ -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";

@ -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;

Loading…
Cancel
Save