* filters: remove duplicate code, overall cleanup
* check if some tres exist before trying to reload them
This commit is contained in:
parent
699186f430
commit
8f8675a26a
|
@ -2,7 +2,7 @@
|
||||||
class Pref_Filters extends Handler_Protected {
|
class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
function csrf_ignore($method) {
|
function csrf_ignore($method) {
|
||||||
$csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
|
$csrf_ignored = array("index", "getfiltertree", "newrule",
|
||||||
"newaction", "savefilterorder");
|
"newaction", "savefilterorder");
|
||||||
|
|
||||||
return array_search($method, $csrf_ignored) !== false;
|
return array_search($method, $csrf_ignored) !== false;
|
||||||
|
@ -313,24 +313,30 @@ class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
function edit() {
|
function edit() {
|
||||||
|
|
||||||
$filter_id = clean($_REQUEST["id"]);
|
$filter_id = (int) clean($_REQUEST["id"] ?? 0);
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2
|
$sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2
|
||||||
WHERE id = ? AND owner_uid = ?");
|
WHERE id = ? AND owner_uid = ?");
|
||||||
$sth->execute([$filter_id, $_SESSION['uid']]);
|
$sth->execute([$filter_id, $_SESSION['uid']]);
|
||||||
|
|
||||||
if ($row = $sth->fetch()) {
|
if (empty($filter_id) || $row = $sth->fetch()) {
|
||||||
|
|
||||||
$enabled = $row["enabled"];
|
$enabled = $row["enabled"] ?? true;
|
||||||
$match_any_rule = $row["match_any_rule"];
|
$match_any_rule = $row["match_any_rule"] ?? false;
|
||||||
$inverse = $row["inverse"];
|
$inverse = $row["inverse"] ?? false;
|
||||||
$title = htmlspecialchars($row["title"]);
|
$title = htmlspecialchars($row["title"] ?? "");
|
||||||
|
|
||||||
print "<form id='filter_edit_form' onsubmit='return false'>";
|
print "<form onsubmit='return false'>";
|
||||||
|
|
||||||
print_hidden("op", "pref-filters");
|
print_hidden("op", "pref-filters");
|
||||||
print_hidden("id", "$filter_id");
|
|
||||||
print_hidden("method", "editSave");
|
if ($filter_id) {
|
||||||
|
print_hidden("id", "$filter_id");
|
||||||
|
print_hidden("method", "editSave");
|
||||||
|
} else {
|
||||||
|
print_hidden("method", "add");
|
||||||
|
}
|
||||||
|
|
||||||
print_hidden("csrf_token", $_SESSION['csrf_token']);
|
print_hidden("csrf_token", $_SESSION['csrf_token']);
|
||||||
|
|
||||||
print "<header>".__("Caption")."</header>
|
print "<header>".__("Caption")."</header>
|
||||||
|
@ -358,35 +364,37 @@ class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
print "<ul id='filterDlg_Matches'>";
|
print "<ul id='filterDlg_Matches'>";
|
||||||
|
|
||||||
$rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules
|
if ($filter_id) {
|
||||||
WHERE filter_id = ? ORDER BY reg_exp, id");
|
$rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules
|
||||||
$rules_sth->execute([$filter_id]);
|
WHERE filter_id = ? ORDER BY reg_exp, id");
|
||||||
|
$rules_sth->execute([$filter_id]);
|
||||||
|
|
||||||
while ($line = $rules_sth->fetch()) {
|
while ($line = $rules_sth->fetch()) {
|
||||||
if ($line["match_on"]) {
|
if ($line["match_on"]) {
|
||||||
$line["feed_id"] = json_decode($line["match_on"], true);
|
$line["feed_id"] = json_decode($line["match_on"], true);
|
||||||
} else {
|
|
||||||
if ($line["cat_filter"]) {
|
|
||||||
$feed_id = "CAT:" . (int)$line["cat_id"];
|
|
||||||
} else {
|
} else {
|
||||||
$feed_id = (int)$line["feed_id"];
|
if ($line["cat_filter"]) {
|
||||||
|
$feed_id = "CAT:" . (int)$line["cat_id"];
|
||||||
|
} else {
|
||||||
|
$feed_id = (int)$line["feed_id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$line["feed_id"] = ["" . $feed_id]; // set item type to string for in_array()
|
||||||
}
|
}
|
||||||
|
|
||||||
$line["feed_id"] = ["" . $feed_id]; // set item type to string for in_array()
|
unset($line["cat_filter"]);
|
||||||
|
unset($line["cat_id"]);
|
||||||
|
unset($line["filter_id"]);
|
||||||
|
unset($line["id"]);
|
||||||
|
if (!$line["inverse"]) unset($line["inverse"]);
|
||||||
|
unset($line["match_on"]);
|
||||||
|
|
||||||
|
$data = htmlspecialchars((string)json_encode($line));
|
||||||
|
|
||||||
|
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
|
||||||
|
<span onclick='App.dialogOf(this).editRule(this)'>".$this->getRuleName($line)."</span>".
|
||||||
|
format_hidden("rule[]", $data)."</li>";
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($line["cat_filter"]);
|
|
||||||
unset($line["cat_id"]);
|
|
||||||
unset($line["filter_id"]);
|
|
||||||
unset($line["id"]);
|
|
||||||
if (!$line["inverse"]) unset($line["inverse"]);
|
|
||||||
unset($line["match_on"]);
|
|
||||||
|
|
||||||
$data = htmlspecialchars((string)json_encode($line));
|
|
||||||
|
|
||||||
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>".
|
|
||||||
"<span onclick='console.log(this);App.dialogOf(this).editRule(this)'>".$this->getRuleName($line)."</span>".
|
|
||||||
"<input type='hidden' name='rule[]' value=\"$data\"/></li>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</ul>
|
print "</ul>
|
||||||
|
@ -412,79 +420,66 @@ class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
print "<ul id='filterDlg_Actions'>";
|
print "<ul id='filterDlg_Actions'>";
|
||||||
|
|
||||||
$actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions
|
if ($filter_id) {
|
||||||
WHERE filter_id = ? ORDER BY id");
|
$actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions
|
||||||
$actions_sth->execute([$filter_id]);
|
WHERE filter_id = ? ORDER BY id");
|
||||||
|
$actions_sth->execute([$filter_id]);
|
||||||
|
|
||||||
while ($line = $actions_sth->fetch()) {
|
while ($line = $actions_sth->fetch()) {
|
||||||
$line["action_param_label"] = $line["action_param"];
|
$line["action_param_label"] = $line["action_param"];
|
||||||
|
|
||||||
unset($line["filter_id"]);
|
unset($line["filter_id"]);
|
||||||
unset($line["id"]);
|
unset($line["id"]);
|
||||||
|
|
||||||
$data = htmlspecialchars((string)json_encode($line));
|
$data = htmlspecialchars((string)json_encode($line));
|
||||||
|
|
||||||
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>".
|
print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
|
||||||
"<span onclick='App.dialogOf(this).editAction(this)'>".$this->getActionName($line)."</span>".
|
<span onclick='App.dialogOf(this).editAction(this)'>".$this->getActionName($line)."</span>".
|
||||||
"<input type='hidden' name='action[]' value=\"$data\"/></li>";
|
format_hidden("action[]", $data)."</li>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</ul>";
|
print "</ul>";
|
||||||
|
|
||||||
print "</section>";
|
print "</section>";
|
||||||
|
|
||||||
print "<header>".__("Options")."</header>";
|
print "<header>".__("Options")."</header>
|
||||||
print "<section>";
|
<section>";
|
||||||
|
|
||||||
if ($enabled) {
|
print "<fieldset class='narrow'>
|
||||||
$checked = "checked=\"1\"";
|
<label class='checkbox'>".format_checkbox('enabled', $enabled)." ".__('Enabled')."</label></fieldset>";
|
||||||
|
|
||||||
|
print "<fieldset class='narrow'>
|
||||||
|
<label class='checkbox'>".format_checkbox('match_any_rule', $match_any_rule)." ".__('Match any rule')."</label>
|
||||||
|
</fieldset>";
|
||||||
|
|
||||||
|
print "<fieldset class='narrow'><label class='checkbox'>".format_checkbox('inverse', $inverse)." ".__('Inverse matching')."</label>
|
||||||
|
</fieldset>";
|
||||||
|
|
||||||
|
print "</section>
|
||||||
|
<footer>";
|
||||||
|
|
||||||
|
if ($filter_id) {
|
||||||
|
print "<div style='float : left'>
|
||||||
|
<button dojoType='dijit.form.Button' class='alt-danger' onclick='App.dialogOf(this).removeFilter()'>".
|
||||||
|
__('Remove')."</button>
|
||||||
|
</div>
|
||||||
|
<button dojoType='dijit.form.Button' class='alt-info' onclick='App.dialogOf(this).test()'>".
|
||||||
|
__('Test')."</button>
|
||||||
|
<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>".
|
||||||
|
__('Save')."</button>
|
||||||
|
<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
|
||||||
|
__('Cancel')."</button>";
|
||||||
} else {
|
} else {
|
||||||
$checked = "";
|
print "<button dojoType='dijit.form.Button' class='alt-info' onclick='App.dialogOf(this).test()'>".
|
||||||
|
__('Test')."</button>
|
||||||
|
<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>".
|
||||||
|
__('Create')."</button>
|
||||||
|
<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
|
||||||
|
__('Cancel')."</button>";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "<fieldset class='narrow'>";
|
print "</footer></form>";
|
||||||
print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
|
|
||||||
".__('Enabled')."</label>";
|
|
||||||
|
|
||||||
if ($match_any_rule) {
|
|
||||||
$checked = "checked=\"1\"";
|
|
||||||
} else {
|
|
||||||
$checked = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "</fieldset><fieldset class='narrow'>";
|
|
||||||
|
|
||||||
print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"match_any_rule\" id=\"match_any_rule\" $checked>
|
|
||||||
".__('Match any rule')."</label>";
|
|
||||||
|
|
||||||
print "</fieldset><fieldset class='narrow'>";
|
|
||||||
|
|
||||||
if ($inverse) {
|
|
||||||
$checked = "checked=\"1\"";
|
|
||||||
} else {
|
|
||||||
$checked = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
|
|
||||||
".__('Inverse matching')."</label>";
|
|
||||||
|
|
||||||
print "</fieldset>";
|
|
||||||
|
|
||||||
print "</section>";
|
|
||||||
|
|
||||||
print "<footer>
|
|
||||||
<div style='float : left'>
|
|
||||||
<button dojoType='dijit.form.Button' class='alt-danger' onclick='App.dialogOf(this).removeFilter()'>".
|
|
||||||
__('Remove')."</button>
|
|
||||||
</div>
|
|
||||||
<button dojoType='dijit.form.Button' class='alt-info' onclick='App.dialogOf(this).test()'>".
|
|
||||||
__('Test')."</button>
|
|
||||||
<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>".
|
|
||||||
__('Save')."</button>
|
|
||||||
<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
|
|
||||||
__('Cancel')."</button>
|
|
||||||
</footer>
|
|
||||||
</form>";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +731,7 @@ class Pref_Filters extends Handler_Protected {
|
||||||
dojoType=\"dijit.MenuItem\">".__('None')."</div>";
|
dojoType=\"dijit.MenuItem\">".__('None')."</div>";
|
||||||
print "</div></div>";
|
print "</div></div>";
|
||||||
|
|
||||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.quickAddFilter()\">".
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.edit()\">".
|
||||||
__('Create filter')."</button> ";
|
__('Create filter')."</button> ";
|
||||||
|
|
||||||
print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').joinSelectedFilters()\">".
|
print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').joinSelectedFilters()\">".
|
||||||
|
@ -779,7 +774,7 @@ class Pref_Filters extends Handler_Protected {
|
||||||
var bare_id = id.substr(id.indexOf(':')+1);
|
var bare_id = id.substr(id.indexOf(':')+1);
|
||||||
|
|
||||||
if (id.match('FILTER:')) {
|
if (id.match('FILTER:')) {
|
||||||
dijit.byId('filterTree').editFilter(bare_id);
|
Filters.edit(bare_id);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -793,112 +788,6 @@ class Pref_Filters extends Handler_Protected {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function newfilter() {
|
|
||||||
|
|
||||||
print "<form name='filter_new_form' id='filter_new_form' onsubmit='return false'>";
|
|
||||||
|
|
||||||
print_hidden("op", "pref-filters");
|
|
||||||
print_hidden("method", "add");
|
|
||||||
print_hidden("csrf_token", $_SESSION['csrf_token']);
|
|
||||||
|
|
||||||
print "<header>".__("Caption")."</header>";
|
|
||||||
|
|
||||||
print "<section>";
|
|
||||||
print "<input required='true' dojoType='dijit.form.ValidationTextBox' style='width : 20em;' name='title' value=''>";
|
|
||||||
print "</section>";
|
|
||||||
|
|
||||||
print "<header class='horizontal'>".__("Match")."</header >";
|
|
||||||
print "<section>";
|
|
||||||
|
|
||||||
print "<div dojoType='fox.Toolbar'>";
|
|
||||||
|
|
||||||
print "<div dojoType='fox.form.DropDownButton'>".
|
|
||||||
"<span>" . __('Select')."</span>";
|
|
||||||
print "<div dojoType='dijit.Menu' style='display: none'>";
|
|
||||||
print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(true)\"
|
|
||||||
dojoType='dijit.MenuItem'>".__('All')."</div>";
|
|
||||||
print "<div onclick=\"dijit.byId('filterEditDlg').selectRules(false)\"
|
|
||||||
dojoType='dijit.MenuItem'>".__('None')."</div>";
|
|
||||||
print "</div></div>";
|
|
||||||
|
|
||||||
print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').addRule()\">".
|
|
||||||
__('Add')."</button> ";
|
|
||||||
|
|
||||||
print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').deleteRule()\">".
|
|
||||||
__('Delete')."</button> ";
|
|
||||||
|
|
||||||
print "</div>";
|
|
||||||
|
|
||||||
print "<ul id='filterDlg_Matches'>";
|
|
||||||
# print "<li>No rules</li>";
|
|
||||||
print "</ul>";
|
|
||||||
|
|
||||||
print "</section>";
|
|
||||||
|
|
||||||
print "<header class='horizontal'>".__("Apply actions")."</header>";
|
|
||||||
|
|
||||||
print "<section>";
|
|
||||||
|
|
||||||
print "<div dojoType='fox.Toolbar'>";
|
|
||||||
|
|
||||||
print "<div dojoType='fox.form.DropDownButton'>".
|
|
||||||
"<span>" . __('Select')."</span>";
|
|
||||||
print "<div dojoType='dijit.Menu' style='display: none'>";
|
|
||||||
print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(true)\"
|
|
||||||
dojoType='dijit.MenuItem'>".__('All')."</div>";
|
|
||||||
print "<div onclick=\"dijit.byId('filterEditDlg').selectActions(false)\"
|
|
||||||
dojoType='dijit.MenuItem'>".__('None')."</div>";
|
|
||||||
print "</div></div>";
|
|
||||||
|
|
||||||
print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').addAction()\">".
|
|
||||||
__('Add')."</button> ";
|
|
||||||
|
|
||||||
print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').deleteAction()\">".
|
|
||||||
__('Delete')."</button> ";
|
|
||||||
|
|
||||||
print "</div>";
|
|
||||||
|
|
||||||
print "<ul id='filterDlg_Actions'>";
|
|
||||||
# print "<li>No actions</li>";
|
|
||||||
print "</ul>";
|
|
||||||
|
|
||||||
print "</section>";
|
|
||||||
|
|
||||||
print "<header>".__("Options")."</header>";
|
|
||||||
|
|
||||||
print "<section>";
|
|
||||||
print "<fieldset class='narrow'>";
|
|
||||||
|
|
||||||
print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='enabled' id='enabled' checked='1'>
|
|
||||||
".__('Enabled')."</label>";
|
|
||||||
|
|
||||||
print "</fieldset><fieldset class='narrow'>";
|
|
||||||
|
|
||||||
print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='match_any_rule' id='match_any_rule'>
|
|
||||||
".__('Match any rule')."</label>";
|
|
||||||
|
|
||||||
print "</fieldset><fieldset class='narrow'>";
|
|
||||||
|
|
||||||
print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' name='inverse' id='inverse'>
|
|
||||||
".__('Inverse matching')."</label>";
|
|
||||||
|
|
||||||
print "</fieldset>";
|
|
||||||
|
|
||||||
print "</section>";
|
|
||||||
|
|
||||||
print "<footer>";
|
|
||||||
|
|
||||||
print "<button dojoType='dijit.form.Button' class='alt-info' onclick=\"return dijit.byId('filterEditDlg').test()\">".
|
|
||||||
__('Test')."</button> ";
|
|
||||||
print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"return dijit.byId('filterEditDlg').execute()\">".
|
|
||||||
__('Create')."</button> ";
|
|
||||||
print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('filterEditDlg').hide()\">".
|
|
||||||
__('Cancel')."</button>";
|
|
||||||
|
|
||||||
print "</footer>";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function newrule() {
|
function newrule() {
|
||||||
$rule = json_decode(clean($_REQUEST["rule"]), true);
|
$rule = json_decode(clean($_REQUEST["rule"]), true);
|
||||||
|
|
||||||
|
|
|
@ -35,15 +35,23 @@ function print_select_hash($id, $default, $values, $attributes = "", $name = "")
|
||||||
print "</select>";
|
print "</select>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_hidden($name, $value) {
|
function format_hidden($name, $value) {
|
||||||
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
|
return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"$name\" value=\"$value\">";
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_checkbox($id, $checked, $value = "", $attributes = "") {
|
function print_hidden($name, $value) {
|
||||||
|
print format_hidden($name, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_checkbox($id, $checked, $value = "", $attributes = "") {
|
||||||
$checked_str = $checked ? "checked" : "";
|
$checked_str = $checked ? "checked" : "";
|
||||||
$value_str = $value ? "value=\"$value\"" : "";
|
$value_str = $value ? "value=\"$value\"" : "";
|
||||||
|
|
||||||
print "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
|
return "<input dojoType=\"dijit.form.CheckBox\" id=\"$id\" $value_str $checked_str $attributes name=\"$id\">";
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_checkbox($id, $checked, $value = "", $attributes = "") {
|
||||||
|
print format_checkbox($id, $checked, $value, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_button($type, $value, $attributes = "") {
|
function print_button($type, $value, $attributes = "") {
|
||||||
|
|
|
@ -18,7 +18,7 @@ const App = {
|
||||||
LABEL_BASE_INDEX: -1024,
|
LABEL_BASE_INDEX: -1024,
|
||||||
FormFields: {
|
FormFields: {
|
||||||
hidden: function(name, value) {
|
hidden: function(name, value) {
|
||||||
return `<input dojoType="dijit.form.TextBox" style="display : none" name="${name}" value="${value}"></input>`
|
return `<input dojoType="dijit.form.TextBox" style="display : none" name="${name}" value="${App.escapeHtml(value)}"></input>`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Scrollable: {
|
Scrollable: {
|
||||||
|
@ -884,7 +884,7 @@ const App = {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hotkey_actions["create_filter"] = () => {
|
this.hotkey_actions["create_filter"] = () => {
|
||||||
Filters.quickAddFilter();
|
Filters.edit();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hotkey_actions["help_dialog"] = () => {
|
this.hotkey_actions["help_dialog"] = () => {
|
||||||
|
@ -1115,7 +1115,7 @@ const App = {
|
||||||
CommonDialogs.addLabel();
|
CommonDialogs.addLabel();
|
||||||
};
|
};
|
||||||
this.hotkey_actions["create_filter"] = () => {
|
this.hotkey_actions["create_filter"] = () => {
|
||||||
Filters.quickAddFilter();
|
Filters.edit();
|
||||||
};
|
};
|
||||||
this.hotkey_actions["collapse_sidebar"] = () => {
|
this.hotkey_actions["collapse_sidebar"] = () => {
|
||||||
Feeds.toggle();
|
Feeds.toggle();
|
||||||
|
|
|
@ -35,33 +35,17 @@ const Filters = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
createNewRuleElement: function(parentNode, replaceNode) {
|
createNewRuleElement: function(parentNode, replaceNode) {
|
||||||
const form = document.forms["filter_new_rule_form"];
|
const rule = dojo.formToJson("filter_new_rule_form");
|
||||||
const query = {op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form)};
|
|
||||||
|
|
||||||
xhrPost("backend.php", query, (transport) => {
|
xhrPost("backend.php", {op: "pref-filters", method: "printrulename", rule: rule}, (transport) => {
|
||||||
try {
|
try {
|
||||||
const li = dojo.create("li");
|
const li = document.createElement('li');
|
||||||
|
|
||||||
const cb = dojo.create("input", {type: "checkbox"}, li);
|
li.innerHTML = `<input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
|
||||||
|
<span onclick='App.dialogOf(this).editRule(this)'>${transport.responseText}</span>
|
||||||
|
${App.FormFields.hidden("rule[]", rule)}`;
|
||||||
|
|
||||||
new dijit.form.CheckBox({
|
dojo.parser.parse(li);
|
||||||
onChange: function () {
|
|
||||||
Lists.onRowChecked(this);
|
|
||||||
},
|
|
||||||
}, cb);
|
|
||||||
|
|
||||||
dojo.create("input", {
|
|
||||||
type: "hidden",
|
|
||||||
name: "rule[]",
|
|
||||||
value: dojo.formToJson(form)
|
|
||||||
}, li);
|
|
||||||
|
|
||||||
dojo.create("span", {
|
|
||||||
onclick: function () {
|
|
||||||
dijit.byId('filterEditDlg').editRule(this);
|
|
||||||
},
|
|
||||||
innerHTML: transport.responseText
|
|
||||||
}, li);
|
|
||||||
|
|
||||||
if (replaceNode) {
|
if (replaceNode) {
|
||||||
parentNode.replaceChild(li, replaceNode);
|
parentNode.replaceChild(li, replaceNode);
|
||||||
|
@ -82,35 +66,17 @@ const Filters = {
|
||||||
form.action_param.value = form.action_param_plugin.value;
|
form.action_param.value = form.action_param_plugin.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = {
|
const action = dojo.formToJson(form);
|
||||||
op: "pref-filters", method: "printactionname",
|
|
||||||
action: dojo.formToJson(form)
|
|
||||||
};
|
|
||||||
|
|
||||||
xhrPost("backend.php", query, (transport) => {
|
xhrPost("backend.php", { op: "pref-filters", method: "printactionname", action: action }, (transport) => {
|
||||||
try {
|
try {
|
||||||
const li = dojo.create("li");
|
const li = document.createElement('li');
|
||||||
|
|
||||||
const cb = dojo.create("input", {type: "checkbox"}, li);
|
li.innerHTML = `<input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
|
||||||
|
<span onclick='App.dialogOf(this).editAction(this)'>${transport.responseText}</span>
|
||||||
|
${App.FormFields.hidden("action[]", action)}`;
|
||||||
|
|
||||||
new dijit.form.CheckBox({
|
dojo.parser.parse(li);
|
||||||
onChange: function () {
|
|
||||||
Lists.onRowChecked(this);
|
|
||||||
},
|
|
||||||
}, cb);
|
|
||||||
|
|
||||||
dojo.create("input", {
|
|
||||||
type: "hidden",
|
|
||||||
name: "action[]",
|
|
||||||
value: dojo.formToJson(form)
|
|
||||||
}, li);
|
|
||||||
|
|
||||||
dojo.create("span", {
|
|
||||||
onclick: function () {
|
|
||||||
dijit.byId('filterEditDlg').editAction(this);
|
|
||||||
},
|
|
||||||
innerHTML: transport.responseText
|
|
||||||
}, li);
|
|
||||||
|
|
||||||
if (replaceNode) {
|
if (replaceNode) {
|
||||||
parentNode.replaceChild(li, replaceNode);
|
parentNode.replaceChild(li, replaceNode);
|
||||||
|
@ -170,7 +136,7 @@ const Filters = {
|
||||||
|
|
||||||
rule_dlg.show();
|
rule_dlg.show();
|
||||||
},
|
},
|
||||||
editFilterTest: function(params) {
|
test: function(params) {
|
||||||
|
|
||||||
if (dijit.byId("filterTestDlg"))
|
if (dijit.byId("filterTestDlg"))
|
||||||
dijit.byId("filterTestDlg").destroyRecursive();
|
dijit.byId("filterTestDlg").destroyRecursive();
|
||||||
|
@ -268,123 +234,143 @@ const Filters = {
|
||||||
|
|
||||||
test_dlg.show();
|
test_dlg.show();
|
||||||
},
|
},
|
||||||
quickAddFilter: function() {
|
edit: function(id) { // if no id, new filter dialog
|
||||||
let query;
|
let query;
|
||||||
|
|
||||||
if (!App.isPrefs()) {
|
if (!App.isPrefs()) {
|
||||||
query = {
|
query = {
|
||||||
op: "pref-filters", method: "newfilter",
|
op: "pref-filters", method: "edit",
|
||||||
feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()
|
feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
query = {op: "pref-filters", method: "newfilter"};
|
query = {op: "pref-filters", method: "edit", id: id};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('quickAddFilter', query);
|
console.log('Filters.edit', query);
|
||||||
|
|
||||||
if (dijit.byId("feedEditDlg"))
|
xhrPost("backend.php", query, function (transport) {
|
||||||
dijit.byId("feedEditDlg").destroyRecursive();
|
if (dijit.byId("feedEditDlg"))
|
||||||
|
dijit.byId("feedEditDlg").destroyRecursive();
|
||||||
|
|
||||||
if (dijit.byId("filterEditDlg"))
|
if (dijit.byId("filterEditDlg"))
|
||||||
dijit.byId("filterEditDlg").destroyRecursive();
|
dijit.byId("filterEditDlg").destroyRecursive();
|
||||||
|
|
||||||
const dialog = new dijit.Dialog({
|
const dialog = new dijit.Dialog({
|
||||||
id: "filterEditDlg",
|
id: "filterEditDlg",
|
||||||
title: __("Create Filter"),
|
title: __("Create Filter"),
|
||||||
test: function () {
|
test: function () {
|
||||||
Filters.editFilterTest(dojo.formToObject("filter_new_form"));
|
Filters.test(this.attr('value'));
|
||||||
},
|
},
|
||||||
selectRules: function (select) {
|
selectRules: function (select) {
|
||||||
Lists.select("filterDlg_Matches", select);
|
Lists.select("filterDlg_Matches", select);
|
||||||
},
|
},
|
||||||
selectActions: function (select) {
|
selectActions: function (select) {
|
||||||
Lists.select("filterDlg_Actions", select);
|
Lists.select("filterDlg_Actions", select);
|
||||||
},
|
},
|
||||||
editRule: function (e) {
|
editRule: function (e) {
|
||||||
const li = e.parentNode;
|
const li = e.closest('li');
|
||||||
const rule = li.getElementsByTagName("INPUT")[1].value;
|
const rule = li.querySelector('input[name="rule[]"]').value
|
||||||
Filters.addFilterRule(li, rule);
|
|
||||||
},
|
|
||||||
editAction: function (e) {
|
|
||||||
const li = e.parentNode;
|
|
||||||
const action = li.getElementsByTagName("INPUT")[1].value;
|
|
||||||
Filters.addFilterAction(li, action);
|
|
||||||
},
|
|
||||||
addAction: function () {
|
|
||||||
Filters.addFilterAction();
|
|
||||||
},
|
|
||||||
addRule: function () {
|
|
||||||
Filters.addFilterRule();
|
|
||||||
},
|
|
||||||
deleteAction: function () {
|
|
||||||
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
|
|
||||||
e.parentNode.removeChild(e)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
deleteRule: function () {
|
|
||||||
$$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
|
|
||||||
e.parentNode.removeChild(e)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
execute: function () {
|
|
||||||
if (this.validate()) {
|
|
||||||
|
|
||||||
const query = dojo.formToQuery("filter_new_form");
|
Filters.addFilterRule(li, rule);
|
||||||
|
},
|
||||||
|
editAction: function (e) {
|
||||||
|
const li = e.closest('li');
|
||||||
|
const action = li.querySelector('input[name="action[]"]').value
|
||||||
|
|
||||||
xhrPost("backend.php", query, () => {
|
Filters.addFilterAction(li, action);
|
||||||
if (App.isPrefs()) {
|
},
|
||||||
dijit.byId("filterTree").reload();
|
removeFilter: function () {
|
||||||
}
|
const msg = __("Remove filter?");
|
||||||
|
|
||||||
dialog.hide();
|
if (confirm(msg)) {
|
||||||
|
this.hide();
|
||||||
|
|
||||||
|
Notify.progress("Removing filter...");
|
||||||
|
|
||||||
|
const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id};
|
||||||
|
|
||||||
|
xhrPost("backend.php", query, () => {
|
||||||
|
const tree = dijit.byId("filterTree");
|
||||||
|
|
||||||
|
if (tree) tree.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addAction: function () {
|
||||||
|
Filters.addFilterAction();
|
||||||
|
},
|
||||||
|
addRule: function () {
|
||||||
|
Filters.addFilterRule();
|
||||||
|
},
|
||||||
|
deleteAction: function () {
|
||||||
|
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
|
||||||
|
e.parentNode.removeChild(e)
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
},
|
deleteRule: function () {
|
||||||
href: "backend.php?" + dojo.objectToQuery(query)
|
$$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
|
||||||
});
|
e.parentNode.removeChild(e)
|
||||||
|
|
||||||
if (!App.isPrefs()) {
|
|
||||||
/* global getSelectionText */
|
|
||||||
const selectedText = getSelectionText();
|
|
||||||
|
|
||||||
const lh = dojo.connect(dialog, "onLoad", function () {
|
|
||||||
dojo.disconnect(lh);
|
|
||||||
|
|
||||||
if (selectedText != "") {
|
|
||||||
|
|
||||||
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
|
||||||
Feeds.getActive();
|
|
||||||
|
|
||||||
const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
|
|
||||||
|
|
||||||
Filters.addFilterRule(null, dojo.toJson(rule));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()};
|
|
||||||
|
|
||||||
xhrPost("backend.php", query, (transport) => {
|
|
||||||
const reply = JSON.parse(transport.responseText);
|
|
||||||
|
|
||||||
let title = false;
|
|
||||||
|
|
||||||
if (reply && reply.title) title = reply.title;
|
|
||||||
|
|
||||||
if (title || Feeds.getActive() || Feeds.activeIsCat()) {
|
|
||||||
|
|
||||||
console.log(title + " " + Feeds.getActive());
|
|
||||||
|
|
||||||
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
|
||||||
Feeds.getActive();
|
|
||||||
|
|
||||||
const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
|
|
||||||
|
|
||||||
Filters.addFilterRule(null, dojo.toJson(rule));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
execute: function () {
|
||||||
|
if (this.validate()) {
|
||||||
|
|
||||||
|
Notify.progress("Saving data...", true);
|
||||||
|
|
||||||
|
xhrPost("backend.php", this.attr('value'), () => {
|
||||||
|
dialog.hide();
|
||||||
|
|
||||||
|
const tree = dijit.byId("filterTree");
|
||||||
|
if (tree) tree.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
content: transport.responseText
|
||||||
});
|
});
|
||||||
}
|
|
||||||
dialog.show();
|
if (!App.isPrefs()) {
|
||||||
|
/* global getSelectionText */
|
||||||
|
const selectedText = getSelectionText();
|
||||||
|
|
||||||
|
const lh = dojo.connect(dialog, "onLoad", function () {
|
||||||
|
dojo.disconnect(lh);
|
||||||
|
|
||||||
|
if (selectedText != "") {
|
||||||
|
|
||||||
|
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
||||||
|
Feeds.getActive();
|
||||||
|
|
||||||
|
const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
|
||||||
|
|
||||||
|
Filters.addFilterRule(null, dojo.toJson(rule));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()};
|
||||||
|
|
||||||
|
xhrPost("backend.php", query, (transport) => {
|
||||||
|
const reply = JSON.parse(transport.responseText);
|
||||||
|
|
||||||
|
let title = false;
|
||||||
|
|
||||||
|
if (reply && reply.title) title = reply.title;
|
||||||
|
|
||||||
|
if (title || Feeds.getActive() || Feeds.activeIsCat()) {
|
||||||
|
|
||||||
|
console.log(title + " " + Feeds.getActive());
|
||||||
|
|
||||||
|
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
||||||
|
Feeds.getActive();
|
||||||
|
|
||||||
|
const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
|
||||||
|
|
||||||
|
Filters.addFilterRule(null, dojo.toJson(rule));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dialog.show();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -297,7 +297,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
|
||||||
|
|
||||||
xhrPost("backend.php", query, () => {
|
xhrPost("backend.php", query, () => {
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
dijit.byId("feedTree").reload();
|
|
||||||
|
const tree = dijit.byId("feedTree");
|
||||||
|
|
||||||
|
if (tree) tree.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -351,7 +354,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
|
||||||
|
|
||||||
xhrPost("backend.php", this.attr('value'), () => {
|
xhrPost("backend.php", this.attr('value'), () => {
|
||||||
Notify.close();
|
Notify.close();
|
||||||
dijit.byId("feedTree").reload();
|
|
||||||
|
const tree = dijit.byId("feedTree");
|
||||||
|
if (tree) tree.reload();
|
||||||
|
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -387,7 +393,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
|
||||||
|
|
||||||
xhrPost("backend.php", query, () => {
|
xhrPost("backend.php", query, () => {
|
||||||
Notify.close();
|
Notify.close();
|
||||||
dijit.byId("feedTree").reload();
|
|
||||||
|
const tree = dijit.byId("feedTree");
|
||||||
|
if (tree) tree.reload();
|
||||||
|
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,85 +134,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
|
||||||
|
|
||||||
this.editFilter(rows[0]);
|
this.editFilter(rows[0]);
|
||||||
},
|
},
|
||||||
editFilter: function(id) {
|
|
||||||
|
|
||||||
const query = "backend.php?op=pref-filters&method=edit&id=" + encodeURIComponent(id);
|
|
||||||
|
|
||||||
if (dijit.byId("feedEditDlg"))
|
|
||||||
dijit.byId("feedEditDlg").destroyRecursive();
|
|
||||||
|
|
||||||
if (dijit.byId("filterEditDlg"))
|
|
||||||
dijit.byId("filterEditDlg").destroyRecursive();
|
|
||||||
|
|
||||||
const dialog = new dijit.Dialog({
|
|
||||||
id: "filterEditDlg",
|
|
||||||
title: __("Edit Filter"),
|
|
||||||
test: function () {
|
|
||||||
Filters.editFilterTest(dojo.formToObject("filter_edit_form"));
|
|
||||||
},
|
|
||||||
selectRules: function (select) {
|
|
||||||
Lists.select("filterDlg_Matches", select);
|
|
||||||
},
|
|
||||||
selectActions: function (select) {
|
|
||||||
Lists.select("filterDlg_Actions", select);
|
|
||||||
},
|
|
||||||
editRule: function (e) {
|
|
||||||
const li = e.parentNode;
|
|
||||||
const rule = li.getElementsByTagName("INPUT")[1].value;
|
|
||||||
Filters.addFilterRule(li, rule);
|
|
||||||
},
|
|
||||||
editAction: function (e) {
|
|
||||||
const li = e.parentNode;
|
|
||||||
const action = li.getElementsByTagName("INPUT")[1].value;
|
|
||||||
Filters.addFilterAction(li, action);
|
|
||||||
},
|
|
||||||
removeFilter: function () {
|
|
||||||
const msg = __("Remove filter?");
|
|
||||||
|
|
||||||
if (confirm(msg)) {
|
|
||||||
this.hide();
|
|
||||||
|
|
||||||
Notify.progress("Removing filter...");
|
|
||||||
|
|
||||||
const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id};
|
|
||||||
|
|
||||||
xhrPost("backend.php", query, () => {
|
|
||||||
dijit.byId("filterTree").reload();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addAction: function () {
|
|
||||||
Filters.addFilterAction();
|
|
||||||
},
|
|
||||||
addRule: function () {
|
|
||||||
Filters.addFilterRule();
|
|
||||||
},
|
|
||||||
deleteAction: function () {
|
|
||||||
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
|
|
||||||
e.parentNode.removeChild(e)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
deleteRule: function () {
|
|
||||||
$$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
|
|
||||||
e.parentNode.removeChild(e)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
execute: function () {
|
|
||||||
if (this.validate()) {
|
|
||||||
|
|
||||||
Notify.progress("Saving data...", true);
|
|
||||||
|
|
||||||
xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => {
|
|
||||||
dialog.hide();
|
|
||||||
dijit.byId("filterTree").reload();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
href: query
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
},
|
|
||||||
removeSelectedFilters: function() {
|
removeSelectedFilters: function() {
|
||||||
const sel_rows = this.getSelectedFilters();
|
const sel_rows = this.getSelectedFilters();
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f
|
||||||
};
|
};
|
||||||
|
|
||||||
xhrPost("backend.php", query, () => {
|
xhrPost("backend.php", query, () => {
|
||||||
dijit.byId("filterTree").reload(); // maybe there's labels in there
|
const tree = dijit.byId("filterTree");
|
||||||
|
if (tree) tree.reload(); // maybe there's labels in there
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -111,7 +112,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f
|
||||||
this.hide();
|
this.hide();
|
||||||
|
|
||||||
xhrPost("backend.php", this.attr('value'), () => {
|
xhrPost("backend.php", this.attr('value'), () => {
|
||||||
dijit.byId("filterTree").reload(); // maybe there's labels in there
|
const tree = dijit.byId("filterTree");
|
||||||
|
if (tree) tree.reload(); // maybe there's labels in there
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue