rework filter dialog to make feed/category selection easier

master
Andrew Dolgov 12 years ago
parent 183ca8b940
commit 4c9d0490c6

@ -548,8 +548,8 @@ class Dlg extends Handler_Protected {
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
<label for=\"inverse\">".__('Inverse match')."</label><hr/>";
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\">
<label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
# print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\">
# <label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
print "</div>";

@ -225,8 +225,8 @@ class Pref_Filters extends Handler_Protected {
$reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
$filter_type = db_fetch_result($result, 0, "filter_type");
$feed_id = db_fetch_result($result, 0, "feed_id");
$cat_id = db_fetch_result($result, 0, "cat_id");
$feed_id = (int) db_fetch_result($result, 0, "feed_id");
$cat_id = (int) db_fetch_result($result, 0, "cat_id");
$action_id = db_fetch_result($result, 0, "action_id");
$action_param = db_fetch_result($result, 0, "action_param");
$filter_param = db_fetch_result($result, 0, "filter_param");
@ -289,21 +289,11 @@ class Pref_Filters extends Handler_Protected {
print __("in") . " ";
$hidden = $cat_filter ? "style='display:none'" : "";
print "<span id='filterDlg_feeds' $hidden>";
print_feed_select($this->link, "feed_id", $feed_id,
'dojoType="dijit.form.FilteringSelect"');
print "</span>";
$hidden = $cat_filter ? "" : "style='display:none'";
print "<span id='filterDlg_cats' $hidden>";
print_feed_cat_select($this->link, "cat_id", $cat_id,
print "<span id='filterDlg_feeds'>";
print_feed_select($this->link, "feed_id", ($cat_filter) ? "CAT:$cat_id" : $feed_id,
'dojoType="dijit.form.FilteringSelect"');
print "</span>";
print "</div>";
print "<div class=\"dlgSec\">".__("Perform Action")."</div>";
@ -369,14 +359,14 @@ class Pref_Filters extends Handler_Protected {
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
<label for=\"inverse\">".__('Inverse match')."</label><hr/>";
if ($cat_filter) {
$checked = "checked=\"1\"";
} else {
$checked = "";
}
# if ($cat_filter) {
# $checked = "checked=\"1\"";
# } else {
# $checked = "";
# }
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\" $checked>
<label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
# print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\" $checked>
# <label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
print "</div>";
print "</div>";
@ -412,23 +402,25 @@ class Pref_Filters extends Handler_Protected {
$action_param_label = db_escape_string($_REQUEST["action_param_label"]);
$enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
$inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
$cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
$cat_id = db_escape_string($_REQUEST['cat_id']);
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
if (!$feed_id) {
$feed_id = 'NULL';
if (strpos($feed_id, "CAT:") === 0) {
$cat_filter = true;
$cat_id = (int) substr($feed_id, 4);
$feed_id = "NULL";
} else {
$feed_id = sprintf("'%s'", db_escape_string($feed_id));
$cat_filter = false;
$feed_id = (int) $feed_id;
$cat_id = "NULL";
}
if (!$cat_id) {
$cat_id = 'NULL';
} else {
$cat_id = sprintf("'%d'", db_escape_string($cat_id));
}
$raw_feed_id = (int) $feed_id;
$raw_cat_id = (int) $cat_id;
if (!$feed_id) $feed_id = "NULL";
if (!$cat_id) $feed_id = "NULL";
/* When processing 'assign label' filters, action_param_label dropbox
* overrides action_param */
@ -450,7 +442,7 @@ class Pref_Filters extends Handler_Protected {
filter_type = '$filter_type',
enabled = $enabled,
inverse = $inverse,
cat_filter = $cat_filter,
cat_filter = ".bool_to_sql_bool($cat_filter).",
action_param = '$action_param',
filter_param = '$filter_param'
WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
@ -458,8 +450,7 @@ class Pref_Filters extends Handler_Protected {
$this->filter_test($filter_type, $reg_exp,
$action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
(int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'],
sql_bool_to_bool($cat_filter));
$raw_feed_id, $raw_cat_id, $cat_filter);
print "<div align='center'>";
print "<button dojoType=\"dijit.form.Button\"
@ -485,29 +476,33 @@ class Pref_Filters extends Handler_Protected {
$regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
$filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
$feed_id = db_escape_string($_REQUEST["feed_id"]);
$cat_id = db_escape_string($_REQUEST["cat_id"]);
# $cat_id = db_escape_string($_REQUEST["cat_id"]);
$action_id = db_escape_string($_REQUEST["action_id"]);
$action_param = db_escape_string($_REQUEST["action_param"]);
$action_param_label = db_escape_string($_REQUEST["action_param_label"]);
$inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
$cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
# $cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
if (!$regexp) return;
if (!$feed_id) {
$feed_id = 'NULL';
if (strpos($feed_id, "CAT:") === 0) {
$cat_filter = true;
$cat_id = (int) substr($feed_id, 4);
$feed_id = "NULL";
} else {
$feed_id = sprintf("'%s'", db_escape_string($feed_id));
$cat_filter = false;
$feed_id = (int) $feed_id;
$cat_id = "NULL";
}
if (!$cat_id) {
$cat_id = 'NULL';
} else {
$cat_id = sprintf("'%d'", db_escape_string($cat_id));
}
$raw_feed_id = (int) $feed_id;
$raw_cat_id = (int) $cat_id;
if (!$feed_id) $feed_id = "NULL";
if (!$cat_id) $feed_id = "NULL";
/* When processing 'assign label' filters, action_param_label dropbox
* overrides action_param */
@ -527,7 +522,7 @@ class Pref_Filters extends Handler_Protected {
VALUES
('$regexp', '$filter_type','".$_SESSION["uid"]."',
$feed_id, '$action_id', '$action_param', $inverse,
'$filter_param', $cat_id, $cat_filter)");
'$filter_param', $cat_id, ".bool_to_sql_bool($cat_filter).")");
if (db_affected_rows($this->link, $result) != 0) {
print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
@ -537,8 +532,8 @@ class Pref_Filters extends Handler_Protected {
$this->filter_test($filter_type, $regexp,
$action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
(int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'],
sql_bool_to_bool($cat_filter));
$raw_feed_id, $raw_cat_id,
$cat_filter);
print "<div align='center'>";
print "<button dojoType=\"dijit.form.Button\"

@ -1887,34 +1887,98 @@
}
function print_feed_select($link, $id, $default_id = "",
$attributes = "", $include_all_feeds = true) {
$attributes = "", $include_all_feeds = true,
$root_id = false, $nest_level = 0) {
print "<select id=\"$id\" name=\"$id\" $attributes>";
if ($include_all_feeds) {
print "<option value=\"0\">".__('All feeds')."</option>";
if (!$root_id) {
print "<select id=\"$id\" name=\"$id\" $attributes>";
if ($include_all_feeds) {
$is_selected = ("0" == $default_id) ? "selected=\"1\"" : "";
print "<option $is_selected value=\"0\">".__('All feeds')."</option>";
}
}
$result = db_query($link, "SELECT id,title FROM ttrss_feeds
WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
if (get_pref($link, 'ENABLE_FEED_CATS')) {
if (db_num_rows($result) > 0 && $include_all_feeds) {
print "<option disabled>--------</option>";
}
if ($root_id)
$parent_qpart = "parent_cat = '$root_id'";
else
$parent_qpart = "parent_cat IS NULL";
while ($line = db_fetch_assoc($result)) {
if ($line["id"] == $default_id) {
$is_selected = "selected=\"1\"";
} else {
$is_selected = "";
$result = db_query($link, "SELECT id,title,
(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
c2.parent_cat = ttrss_feed_categories.id) AS num_children
FROM ttrss_feed_categories
WHERE owner_uid = ".$_SESSION["uid"]." AND $parent_qpart ORDER BY title");
while ($line = db_fetch_assoc($result)) {
for ($i = 0; $i < $nest_level; $i++)
$line["title"] = " - " . $line["title"];
$is_selected = ("CAT:".$line["id"] == $default_id) ? "selected=\"1\"" : "";
printf("<option $is_selected value='CAT:%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
if ($line["num_children"] > 0)
print_feed_select($link, $id, $default_id, $attributes,
$include_all_feeds, $line["id"], $nest_level+1);
$feed_result = db_query($link, "SELECT id,title FROM ttrss_feeds
WHERE cat_id = '".$line["id"]."' AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title");
while ($fline = db_fetch_assoc($feed_result)) {
$is_selected = ($fline["id"] == $default_id) ? "selected=\"1\"" : "";
$fline["title"] = " + " . $fline["title"];
for ($i = 0; $i < $nest_level; $i++)
$fline["title"] = " - " . $fline["title"];
printf("<option $is_selected value='%d'>%s</option>",
$fline["id"], htmlspecialchars($fline["title"]));
}
}
$title = truncate_string(htmlspecialchars($line["title"]), 40);
if (!$root_id) {
$is_selected = ($default_id == "CAT:0") ? "selected=\"1\"" : "";
printf("<option $is_selected value='CAT:0'>%s</option>",
__("Uncategorized"));
$feed_result = db_query($link, "SELECT id,title FROM ttrss_feeds
WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"] . " ORDER BY title");
while ($fline = db_fetch_assoc($feed_result)) {
$is_selected = ($fline["id"] == $default_id && !$default_is_cat) ? "selected=\"1\"" : "";
printf("<option $is_selected value='%d'>%s</option>",
$line["id"], $title);
$fline["title"] = " + " . $fline["title"];
for ($i = 0; $i < $nest_level; $i++)
$fline["title"] = " - " . $fline["title"];
printf("<option $is_selected value='%d'>%s</option>",
$fline["id"], htmlspecialchars($fline["title"]));
}
}
} else {
$result = db_query($link, "SELECT id,title FROM ttrss_feeds
WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
while ($line = db_fetch_assoc($result)) {
$is_selected = ($line["id"] == $default_id) ? "selected=\"1\"" : "";
printf("<option $is_selected value='%d'>%s</option>",
$line["id"], htmlspecialchars($line["title"]));
}
}
print "</select>";
if (!$root_id) {
print "</select>";
}
}
function print_feed_cat_select($link, $id, $default_id,

@ -545,21 +545,6 @@ function fatalError(code, msg, ext_info) {
}
}
function filterDlgCheckCat(sender) {
try {
if (sender.checked) {
Element.show('filterDlg_cats');
Element.hide('filterDlg_feeds');
} else {
Element.show('filterDlg_feeds');
Element.hide('filterDlg_cats');
}
} catch (e) {
exception_error("filterDlgCheckCat", e);
}
}
function filterDlgCheckType(sender) {
try {

Loading…
Cancel
Save