create label now uses dialog, code cleanups

This commit is contained in:
Andrew Dolgov 2006-08-17 05:54:57 +01:00
parent 60a2080f9a
commit f156fd00ee
2 changed files with 72 additions and 52 deletions

View File

@ -2395,22 +2395,21 @@
if (!WEB_DEMO_MODE) {
// no escaping is done here on purpose
$exp = trim($_GET["exp"]);
$sql_exp = trim($_GET["sql_exp"]);
$description = db_escape_string($_GET["description"]);
$result = db_query($link,
"INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')");
}
}
print "<div class=\"prefGenericAddBox\">
<input size=\"40\"
onkeyup=\"toggleSubmitNotEmpty(this, 'label_create_btn')\"
id=\"ladd_expr\">&nbsp;";
print "<div class=\"prefGenericAddBox\">";
print"<input type=\"submit\" class=\"button\"
disabled=\"true\" id=\"label_create_btn\"
onclick=\"javascript:addLabel()\" value=\"Create label\"></div>";
id=\"label_create_btn\"
onclick=\"return displayDlg('quickAddLabel', false)\"
value=\"Create label\"></div>";
$result = db_query($link, "SELECT
id,sql_exp,description
@ -2665,6 +2664,52 @@
}
if ($id == "quickAddLabel") {
print "<div id=\"infoBoxTitle\">Create label</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=\"subop\" value=\"add\">";
print "<table width='100%'>";
print "<tr><td>Caption:</td>
<td><input onkeypress=\"return filterCR(event)\"
onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
name=\"description\" class=\"iedit\">";
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\"></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\"
disabled=\"true\"
class=\"button\" onclick=\"return addLabel()\"
value=\"Create\"> ";
print "<input class=\"button\"
type=\"submit\" onclick=\"return labelEditCancel()\"
value=\"Cancel\">";
}
if ($id == "quickAddFilter") {
$active_feed_id = db_escape_string($_GET["param"]);

View File

@ -63,8 +63,8 @@ function filterlist_callback() {
function labellist_callback() {
var container = document.getElementById('prefContent');
if (xmlhttp.readyState == 4) {
closeInfoBox();
container.innerHTML=xmlhttp.responseText;
if (active_label) {
var row = document.getElementById("LILRR-" + active_label);
if (row) {
@ -181,55 +181,26 @@ function addLabel() {
return
}
var sqlexp = document.getElementById("ladd_expr");
var form = document.forms['label_edit_form'];
if (sqlexp.value.length == 0) {
alert("Can't add label: missing SQL expression.");
} else {
notify("Adding label...");
var sql_exp = form.sql_exp.value;
var description = form.description.value;
xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
param_escape(sqlexp.value), true);
if (sql_exp == "") {
alert("Can't create label: missing SQL expression.");
return false;
}
xmlhttp.onreadystatechange=labellist_callback;
if (description == "") {
alert("Can't create label: missing caption.");
return false;
}
var query = Form.serialize("label_edit_form");
xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
xmlhttp.onreadystatechange=infobox_submit_callback;
xmlhttp.send(null);
sqlexp.value = "";
}
}
function addFilter() {
if (!xmlhttp_ready(xmlhttp)) {
printLockingError();
return
}
var regexp = document.getElementById("fadd_regexp");
var match = document.getElementById("fadd_match");
var feed = document.getElementById("fadd_feed");
var action = document.getElementById("fadd_action");
if (regexp.value.length == 0) {
alert("Can't add filter: missing filter expression.");
} else {
notify("Adding filter...");
var v_match = match[match.selectedIndex].text;
var feed_id = feed[feed.selectedIndex].id;
var action_id = action[action.selectedIndex].id;
xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
param_escape(regexp.value) + "&match=" + v_match +
"&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
xmlhttp.onreadystatechange=filterlist_callback;
xmlhttp.send(null);
regexp.value = "";
}
}
function addFeed() {
@ -315,6 +286,8 @@ function editLabel(id) {
return
}
document.getElementById("label_create_btn").disabled = true;
active_label = id;
selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
@ -709,6 +682,8 @@ function labelEditCancel() {
return
}
document.getElementById("label_create_btn").disabled = false;
active_label = false;
selectPrefRows('label', false); // cleanup feed selection