summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-01 22:39:29 +0300
committerAndrew Dolgov <[email protected]>2018-12-01 22:39:29 +0300
commit1e2d4410d320fcee644add76293f229741a163cb (patch)
tree11228eaba3165f1ef5503c7ffa23e577d1fc886b
parent4b492cc93ef2a15a4d5dfe51d38164884464d1a9 (diff)
move some more shared stuff to CommonDialogs, Filters, and Utils
-rw-r--r--classes/dlg.php2
-rwxr-xr-xclasses/pref/feeds.php8
-rwxr-xr-xclasses/pref/filters.php4
-rwxr-xr-xjs/FeedTree.js2
-rw-r--r--js/PrefFeedTree.js4
-rwxr-xr-xjs/functions.js877
-rwxr-xr-xjs/prefs.js6
-rw-r--r--js/tt-rss.js8
-rwxr-xr-xjs/viewfeed.js2
-rw-r--r--plugins/af_psql_trgm/init.php2
-rwxr-xr-xplugins/af_readability/init.php2
-rw-r--r--tests/functional/BasicTest.php2
12 files changed, 463 insertions, 456 deletions
diff --git a/classes/dlg.php b/classes/dlg.php
index 50cbd12dd..02249ea96 100644
--- a/classes/dlg.php
+++ b/classes/dlg.php
@@ -174,7 +174,7 @@ class Dlg extends Handler_Protected {
print "<div align='center'>";
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return genUrlChangeKey('$feed_id', '$is_cat')\">".
+ print "<button dojoType=\"dijit.form.Button\" onclick=\"return CommonDialogs.genUrlChangeKey('$feed_id', '$is_cat')\">".
__('Generate new URL')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">".
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index c061243ee..2184a0b42 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -765,7 +765,7 @@ class Pref_Feeds extends Handler_Protected {
print "<div class='dlgButtons'>
<div style=\"float : left\">
- <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
+ <button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick='return CommonDialogs.unsubscribeFeed($feed_id, \"$title\")'>".
__('Unsubscribe')."</button>";
print "</div>";
@@ -1247,7 +1247,7 @@ class Pref_Feeds extends Handler_Protected {
var bare_id = id.substr(id.indexOf(':')+1);
if (id.match('FEED:')) {
- editFeed(bare_id);
+ CommonDialogs.editFeed(bare_id);
} else if (id.match('CAT:')) {
editCat(bare_id, item);
}
@@ -1441,7 +1441,7 @@ class Pref_Feeds extends Handler_Protected {
print "<a class=\"visibleLink\" href=\"#\" ".
"title=\"".__("Click to edit feed")."\" ".
- "onclick=\"editFeed(".$line["id"].")\">".
+ "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">".
htmlspecialchars($line["title"])."</a>";
print "</td><td class=\"insensitive\" align='right'>";
@@ -1506,7 +1506,7 @@ class Pref_Feeds extends Handler_Protected {
print "<a class=\"visibleLink\" href=\"#\" ".
"title=\"".__("Click to edit feed")."\" ".
- "onclick=\"editFeed(".$line["id"].")\">".
+ "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">".
htmlspecialchars($line["title"])."</a>: ";
print "<span class=\"insensitive\">";
diff --git a/classes/pref/filters.php b/classes/pref/filters.php
index e3503d545..e60628f8f 100755
--- a/classes/pref/filters.php
+++ b/classes/pref/filters.php
@@ -797,7 +797,7 @@ class Pref_Filters extends Handler_Protected {
dojoType=\"dijit.MenuItem\">".__('None')."</div>";
print "</div></div>";
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return quickAddFilter()\">".
+ print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.quickAddFilter()\">".
__('Create filter')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
@@ -1044,7 +1044,7 @@ class Pref_Filters extends Handler_Protected {
print "<div class=\"dlgSecCont\">";
print "<select name=\"action_id\" dojoType=\"dijit.form.Select\"
- onchange=\"filterDlgCheckAction(this)\">";
+ onchange=\"Filters.filterDlgCheckAction(this)\">";
$res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions
ORDER BY name");
diff --git a/js/FeedTree.js b/js/FeedTree.js
index 55eb3dc30..4a28bd2b0 100755
--- a/js/FeedTree.js
+++ b/js/FeedTree.js
@@ -48,7 +48,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
menu.addChild(new dijit.MenuItem({
label: __("Edit feed"),
onClick: function() {
- editFeed(this.getParent().row_id, false);
+ CommonDialogs.editFeed(this.getParent().row_id, false);
}}));
/* menu.addChild(new dijit.MenuItem({
diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js
index 9d6a9e86c..afa644251 100644
--- a/js/PrefFeedTree.js
+++ b/js/PrefFeedTree.js
@@ -55,13 +55,13 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
menu.addChild(new dijit.MenuItem({
label: __("Edit feed"),
onClick: function() {
- editFeed(this.getParent().row_id);
+ CommonDialogs.editFeed(this.getParent().row_id);
}}));
menu.addChild(new dijit.MenuItem({
label: __("Unsubscribe"),
onClick: function() {
- unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
+ CommonDialogs.unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
}}));
menu.bindDomNode(tnode.domNode);
diff --git a/js/functions.js b/js/functions.js
index f4e422aec..21fe8c190 100755
--- a/js/functions.js
+++ b/js/functions.js
@@ -291,7 +291,7 @@ const Utils = {
}
if (k == "daemon_is_running" && v != 1) {
- notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
+ notify_error("<span onclick=\"Utils.explainError(1)\">Update daemon is not running.</span>", true);
return;
}
@@ -306,7 +306,7 @@ const Utils = {
}
if (k == "daemon_stamp_ok" && v != 1) {
- notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
+ notify_error("<span onclick=\"Utils.explainError(3)\">Update daemon is not updating feeds.</span>", true);
return;
}
@@ -376,7 +376,10 @@ const Utils = {
}
App.initSecondStage();
- }
+ },
+ explainError: function(code) {
+ return this.displayDlg(__("Error explained"), "explainError", code);
+ },
};
const CommonDialogs = {
@@ -674,6 +677,97 @@ const CommonDialogs = {
}
});
}
+ },
+ unsubscribeFeed: function(feed_id, title) {
+
+ const msg = __("Unsubscribe from %s?").replace("%s", title);
+
+ if (title == undefined || confirm(msg)) {
+ notify_progress("Removing feed...");
+
+ const query = {op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id};
+
+ xhrPost("backend.php", query, (transport) => {
+ if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
+
+ if (App.isPrefs()) {
+ Feeds.reload();
+ } else {
+ if (feed_id == Feeds.getActiveFeedId())
+ setTimeout(() => {
+ Feeds.viewfeed({feed: -5})
+ },
+ 100);
+
+ if (feed_id < 0) Feeds.reload();
+ }
+ });
+ }
+
+ return false;
+ },
+ editFeed: function (feed) {
+ if (feed <= 0)
+ return alert(__("You can't edit this kind of feed."));
+
+ const query = {op: "pref-feeds", method: "editfeed", id: feed};
+
+ console.log("editFeed", query);
+
+ if (dijit.byId("filterEditDlg"))
+ dijit.byId("filterEditDlg").destroyRecursive();
+
+ if (dijit.byId("feedEditDlg"))
+ dijit.byId("feedEditDlg").destroyRecursive();
+
+ const dialog = new dijit.Dialog({
+ id: "feedEditDlg",
+ title: __("Edit Feed"),
+ style: "width: 600px",
+ execute: function () {
+ if (this.validate()) {
+ notify_progress("Saving data...", true);
+
+ xhrPost("backend.php", dialog.attr('value'), () => {
+ dialog.hide();
+ notify('');
+ Feeds.reload();
+ });
+ }
+ },
+ href: "backend.php?" + dojo.objectToQuery(query)
+ });
+
+ dialog.show();
+ },
+ genUrlChangeKey: function(feed, is_cat) {
+ if (confirm(__("Generate new syndication address for this feed?"))) {
+
+ notify_progress("Trying to change address...", true);
+
+ const query = {op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat};
+
+ xhrJson("backend.php", query, (reply) => {
+ const new_link = reply.link;
+ const e = $('gen_feed_url');
+
+ if (new_link) {
+ e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
+ "&amp;key=" + new_link);
+
+ e.href = e.href.replace(/\&key=.*$/,
+ "&key=" + new_link);
+
+ new Effect.Highlight(e);
+
+ notify('');
+
+ } else {
+ notify_error("Could not change feed URL.");
+ }
+ });
+ }
+ return false;
}
};
@@ -994,463 +1088,433 @@ function fatalError(code, msg, ext_info) {
}
-// noinspection JSUnusedGlobalSymbols
-function filterDlgCheckAction(sender) {
- const action = sender.value;
-
- const action_param = $("filterDlg_paramBox");
+const Filters = {
+ filterDlgCheckAction: function(sender) {
+ const action = sender.value;
- if (!action_param) {
- console.log("filterDlgCheckAction: can't find action param box!");
- return;
- }
-
- // if selected action supports parameters, enable params field
- if (action == 4 || action == 6 || action == 7 || action == 9) {
- new Effect.Appear(action_param, {duration : 0.5});
+ const action_param = $("filterDlg_paramBox");
- Element.hide(dijit.byId("filterDlg_actionParam").domNode);
- Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
- Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
-
- if (action == 7) {
- Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
- } else if (action == 9) {
- Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode);
- } else {
- Element.show(dijit.byId("filterDlg_actionParam").domNode);
+ if (!action_param) {
+ console.log("filterDlgCheckAction: can't find action param box!");
+ return;
}
- } else {
- Element.hide(action_param);
- }
-}
-
+ // if selected action supports parameters, enable params field
+ if (action == 4 || action == 6 || action == 7 || action == 9) {
+ new Effect.Appear(action_param, {duration: 0.5});
-function explainError(code) {
- return Utils.displayDlg(__("Error explained"), "explainError", code);
-}
+ Element.hide(dijit.byId("filterDlg_actionParam").domNode);
+ Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
+ Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
-function strip_tags(s) {
- return s.replace(/<\/?[^>]+(>|$)/g, "");
-}
-
-// noinspection JSUnusedGlobalSymbols
-function uploadIconHandler(rc) {
- switch (rc) {
- case 0:
- notify_info("Upload complete.");
- if (App.isPrefs()) {
- Feeds.reload();
+ if (action == 7) {
+ Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
+ } else if (action == 9) {
+ Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode);
} else {
- setTimeout('Feeds.reload(false, false)', 50);
+ Element.show(dijit.byId("filterDlg_actionParam").domNode);
}
- break;
- case 1:
- notify_error("Upload failed: icon is too big.");
- break;
- case 2:
- notify_error("Upload failed.");
- break;
- }
-}
-
-// noinspection JSUnusedGlobalSymbols
-function removeFeedIcon(id) {
- if (confirm(__("Remove stored feed icon?"))) {
-
- notify_progress("Removing feed icon...", true);
- const query = { op: "pref-feeds", method: "removeicon", feed_id: id };
+ } else {
+ Element.hide(action_param);
+ }
+ },
+ createNewRuleElement: function(parentNode, replaceNode) {
+ const form = document.forms["filter_new_rule_form"];
+ const query = {op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form)};
xhrPost("backend.php", query, (transport) => {
- notify_info("Feed icon removed.");
- if (App.isPrefs()) {
- Feeds.reload();
- } else {
- setTimeout('Feeds.reload(false, false)', 50);
+ try {
+ const li = dojo.create("li");
+
+ const cb = dojo.create("input", {type: "checkbox"}, li);
+
+ new dijit.form.CheckBox({
+ onChange: function () {
+ toggleSelectListRow2(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) {
+ parentNode.replaceChild(li, replaceNode);
+ } else {
+ parentNode.appendChild(li);
+ }
+ } catch (e) {
+ exception_error(e);
}
});
- }
-
- return false;
-}
-
-// noinspection JSUnusedGlobalSymbols
-function uploadFeedIcon() {
- const file = $("icon_file");
+ },
+ createNewActionElement: function(parentNode, replaceNode) {
+ const form = document.forms["filter_new_action_form"];
- if (file.value.length == 0) {
- alert(__("Please select an image file to upload."));
- } else if (confirm(__("Upload new icon for this feed?"))) {
- notify_progress("Uploading, please wait...", true);
- return true;
+ if (form.action_id.value == 7) {
+ form.action_param.value = form.action_param_label.value;
+ } else if (form.action_id.value == 9) {
+ form.action_param.value = form.action_param_plugin.value;
}
- return false;
-}
-
-function createNewRuleElement(parentNode, replaceNode) {
- const form = document.forms["filter_new_rule_form"];
- const query = { op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form) };
-
- xhrPost("backend.php", query, (transport) => {
- try {
- const li = dojo.create("li");
-
- const cb = dojo.create("input", { type: "checkbox" }, li);
-
- new dijit.form.CheckBox({
- onChange: function() {
- toggleSelectListRow2(this) },
- }, cb);
-
- dojo.create("input", { type: "hidden",
- name: "rule[]",
- value: dojo.formToJson(form) }, li);
+ const query = {
+ op: "pref-filters", method: "printactionname",
+ action: dojo.formToJson(form)
+ };
- dojo.create("span", {
- onclick: function() {
- dijit.byId('filterEditDlg').editRule(this);
- },
- innerHTML: transport.responseText }, li);
+ xhrPost("backend.php", query, (transport) => {
+ try {
+ const li = dojo.create("li");
+
+ const cb = dojo.create("input", {type: "checkbox"}, li);
+
+ new dijit.form.CheckBox({
+ onChange: function () {
+ toggleSelectListRow2(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) {
+ parentNode.replaceChild(li, replaceNode);
+ } else {
+ parentNode.appendChild(li);
+ }
- if (replaceNode) {
- parentNode.replaceChild(li, replaceNode);
- } else {
- parentNode.appendChild(li);
+ } catch (e) {
+ exception_error(e);
}
- } catch (e) {
- exception_error(e);
- }
- });
-}
-
-function createNewActionElement(parentNode, replaceNode) {
- const form = document.forms["filter_new_action_form"];
-
- if (form.action_id.value == 7) {
- form.action_param.value = form.action_param_label.value;
- } else if (form.action_id.value == 9) {
- form.action_param.value = form.action_param_plugin.value;
- }
-
- const query = { op: "pref-filters", method: "printactionname",
- action: dojo.formToJson(form) };
-
- xhrPost("backend.php", query, (transport) => {
- try {
- const li = dojo.create("li");
-
- const cb = dojo.create("input", { type: "checkbox" }, li);
-
- new dijit.form.CheckBox({
- onChange: function() {
- toggleSelectListRow2(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);
+ });
+ },
+ addFilterRule: function(replaceNode, ruleStr) {
+ if (dijit.byId("filterNewRuleDlg"))
+ dijit.byId("filterNewRuleDlg").destroyRecursive();
- if (replaceNode) {
- parentNode.replaceChild(li, replaceNode);
- } else {
- parentNode.appendChild(li);
- }
+ const query = "backend.php?op=pref-filters&method=newrule&rule=" +
+ param_escape(ruleStr);
- } catch (e) {
- exception_error(e);
- }
- });
-}
+ const rule_dlg = new dijit.Dialog({
+ id: "filterNewRuleDlg",
+ title: ruleStr ? __("Edit rule") : __("Add rule"),
+ style: "width: 600px",
+ execute: function () {
+ if (this.validate()) {
+ Filters.createNewRuleElement($("filterDlg_Matches"), replaceNode);
+ this.hide();
+ }
+ },
+ href: query
+ });
+ rule_dlg.show();
+ },
+ addFilterAction: function(replaceNode, actionStr) {
+ if (dijit.byId("filterNewActionDlg"))
+ dijit.byId("filterNewActionDlg").destroyRecursive();
-function addFilterRule(replaceNode, ruleStr) {
- if (dijit.byId("filterNewRuleDlg"))
- dijit.byId("filterNewRuleDlg").destroyRecursive();
+ const query = "backend.php?op=pref-filters&method=newaction&action=" +
+ param_escape(actionStr);
- const query = "backend.php?op=pref-filters&method=newrule&rule=" +
- param_escape(ruleStr);
+ const rule_dlg = new dijit.Dialog({
+ id: "filterNewActionDlg",
+ title: actionStr ? __("Edit action") : __("Add action"),
+ style: "width: 600px",
+ execute: function () {
+ if (this.validate()) {
+ Filters.createNewActionElement($("filterDlg_Actions"), replaceNode);
+ this.hide();
+ }
+ },
+ href: query
+ });
- const rule_dlg = new dijit.Dialog({
- id: "filterNewRuleDlg",
- title: ruleStr ? __("Edit rule") : __("Add rule"),
- style: "width: 600px",
- execute: function() {
- if (this.validate()) {
- createNewRuleElement($("filterDlg_Matches"), replaceNode);
- this.hide();
- }
- },
- href: query});
+ rule_dlg.show();
+ },
+ editFilterTest: function(query) {
- rule_dlg.show();
-}
+ if (dijit.byId("filterTestDlg"))
+ dijit.byId("filterTestDlg").destroyRecursive();
-function addFilterAction(replaceNode, actionStr) {
- if (dijit.byId("filterNewActionDlg"))
- dijit.byId("filterNewActionDlg").destroyRecursive();
-
- const query = "backend.php?op=pref-filters&method=newaction&action=" +
- param_escape(actionStr);
-
- const rule_dlg = new dijit.Dialog({
- id: "filterNewActionDlg",
- title: actionStr ? __("Edit action") : __("Add action"),
- style: "width: 600px",
- execute: function() {
- if (this.validate()) {
- createNewActionElement($("filterDlg_Actions"), replaceNode);
- this.hide();
- }
- },
- href: query});
+ const test_dlg = new dijit.Dialog({
+ id: "filterTestDlg",
+ title: "Test Filter",
+ style: "width: 600px",
+ results: 0,
+ limit: 100,
+ max_offset: 10000,
+ getTestResults: function (query, offset) {
+ const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
- rule_dlg.show();
-}
+ console.log("getTestResults:" + offset);
-function editFilterTest(query) {
+ xhrPost("backend.php", updquery, (transport) => {
+ try {
+ const result = JSON.parse(transport.responseText);
- if (dijit.byId("filterTestDlg"))
- dijit.byId("filterTestDlg").destroyRecursive();
+ if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
+ test_dlg.results += result.length;
- const test_dlg = new dijit.Dialog({
- id: "filterTestDlg",
- title: "Test Filter",
- style: "width: 600px",
- results: 0,
- limit: 100,
- max_offset: 10000,
- getTestResults: function(query, offset) {
- const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
+ console.log("got results:" + result.length);
- console.log("getTestResults:" + offset);
+ $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
+ .replace("%f", test_dlg.results)
+ .replace("%d", offset);
- xhrPost("backend.php", updquery, (transport) => {
- try {
- const result = JSON.parse(transport.responseText);
+ console.log(offset + " " + test_dlg.max_offset);
- if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
- test_dlg.results += result.length;
+ for (let i = 0; i < result.length; i++) {
+ const tmp = new Element("table");
+ tmp.innerHTML = result[i];
+ dojo.parser.parse(tmp);
- console.log("got results:" + result.length);
+ $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
+ }
- $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
- .replace("%f", test_dlg.results)
- .replace("%d", offset);
+ if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
- console.log(offset + " " + test_dlg.max_offset);
+ // get the next batch
+ window.setTimeout(function () {
+ test_dlg.getTestResults(query, offset + test_dlg.limit);
+ }, 0);
- for (let i = 0; i < result.length; i++) {
- const tmp = new Element("table");
- tmp.innerHTML = result[i];
- dojo.parser.parse(tmp);
+ } else {
+ // all done
- $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
- }
+ Element.hide("prefFilterLoadingIndicator");
- if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
+ if (test_dlg.results == 0) {
+ $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
+ $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
+ } else {
+ $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
+ .replace("%d", test_dlg.results);
+ }
- // get the next batch
- window.setTimeout(function () {
- test_dlg.getTestResults(query, offset + test_dlg.limit);
- }, 0);
+ }
- } else {
- // all done
+ } else if (!result) {
+ console.log("getTestResults: can't parse results object");
Element.hide("prefFilterLoadingIndicator");
- if (test_dlg.results == 0) {
- $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
- $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
- } else {
- $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
- .replace("%d", test_dlg.results);
- }
+ notify_error("Error while trying to get filter test results.");
+ } else {
+ console.log("getTestResults: dialog closed, bailing out.");
}
+ } catch (e) {
+ exception_error(e);
+ }
- } else if (!result) {
- console.log("getTestResults: can't parse results object");
-
- Element.hide("prefFilterLoadingIndicator");
-
- notify_error("Error while trying to get filter test results.");
+ });
+ },
+ href: query
+ });
- } else {
- console.log("getTestResults: dialog closed, bailing out.");
- }
- } catch (e) {
- exception_error(e);
- }
+ dojo.connect(test_dlg, "onLoad", null, function (e) {
+ test_dlg.getTestResults(query, 0);
+ });
- });
- },
- href: query});
+ test_dlg.show();
+ },
+ quickAddFilter: function() {
+ let query;
+
+ if (!App.isPrefs()) {
+ query = {
+ op: "pref-filters", method: "newfilter",
+ feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()
+ };
+ } else {
+ query = {op: "pref-filters", method: "newfilter"};
+ }
- dojo.connect(test_dlg, "onLoad", null, function(e) {
- test_dlg.getTestResults(query, 0);
- });
+ console.log('quickAddFilter', query);
- test_dlg.show();
+ if (dijit.byId("feedEditDlg"))
+ dijit.byId("feedEditDlg").destroyRecursive();
-}
+ if (dijit.byId("filterEditDlg"))
+ dijit.byId("filterEditDlg").destroyRecursive();
-function quickAddFilter() {
- let query;
+ const dialog = new dijit.Dialog({
+ id: "filterEditDlg",
+ title: __("Create Filter"),
+ style: "width: 600px",
+ test: function () {
+ const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
- if (!App.isPrefs()) {
- query = { op: "pref-filters", method: "newfilter",
- feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() };
- } else {
- query = { op: "pref-filters", method: "newfilter" };
- }
+ Filters.editFilterTest(query);
+ },
+ selectRules: function (select) {
+ $$("#filterDlg_Matches input[type=checkbox]").each(function (e) {
+ e.checked = select;
+ if (select)
+ e.parentNode.addClassName("Selected");
+ else
+ e.parentNode.removeClassName("Selected");
+ });
+ },
+ selectActions: function (select) {
+ $$("#filterDlg_Actions input[type=checkbox]").each(function (e) {
+ e.checked = select;
- console.log('quickAddFilter', query);
+ if (select)
+ e.parentNode.addClassName("Selected");
+ else
+ e.parentNode.removeClassName("Selected");
- if (dijit.byId("feedEditDlg"))
- dijit.byId("feedEditDlg").destroyRecursive();
+ });
+ },
+ 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);
+ },
+ 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()) {
- if (dijit.byId("filterEditDlg"))
- dijit.byId("filterEditDlg").destroyRecursive();
+ const query = dojo.formToQuery("filter_new_form");
- const dialog = new dijit.Dialog({
- id: "filterEditDlg",
- title: __("Create Filter"),
- style: "width: 600px",
- test: function() {
- const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test";
+ xhrPost("backend.php", query, () => {
+ if (App.isPrefs()) {
+ updateFilterList();
+ }
- editFilterTest(query);
- },
- selectRules: function(select) {
- $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
- e.checked = select;
- if (select)
- e.parentNode.addClassName("Selected");
- else
- e.parentNode.removeClassName("Selected");
- });
- },
- selectActions: function(select) {
- $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
- e.checked = select;
+ dialog.hide();
+ });
+ }
+ },
+ href: "backend.php?" + dojo.objectToQuery(query)
+ });
- if (select)
- e.parentNode.addClassName("Selected");
- else
- e.parentNode.removeClassName("Selected");
+ if (!App.isPrefs()) {
+ const selectedText = getSelectionText();
- });
- },
- editRule: function(e) {
- const li = e.parentNode;
- const rule = li.getElementsByTagName("INPUT")[1].value;
- addFilterRule(li, rule);
- },
- editAction: function(e) {
- const li = e.parentNode;
- const action = li.getElementsByTagName("INPUT")[1].value;
- addFilterAction(li, action);
- },
- addAction: function() { addFilterAction(); },
- addRule: function() { 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");
-
- xhrPost("backend.php", query, (transport) => {
- if (App.isPrefs()) {
- updateFilterList();
- }
+ const lh = dojo.connect(dialog, "onLoad", function () {
+ dojo.disconnect(lh);
- dialog.hide();
- });
- }
- },
- href: "backend.php?" + dojo.objectToQuery(query)});
+ if (selectedText != "") {
- if (!App.isPrefs()) {
- const selectedText = getSelectionText();
+ const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) :
+ Feeds.getActiveFeedId();
- const lh = dojo.connect(dialog, "onLoad", function(){
- dojo.disconnect(lh);
+ const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
- if (selectedText != "") {
+ Filters.addFilterRule(null, dojo.toJson(rule));
- const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) :
- Feeds.getActiveFeedId();
+ } else {
- const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 };
+ const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId()};
- addFilterRule(null, dojo.toJson(rule));
+ xhrPost("backend.php", query, (transport) => {
+ const reply = JSON.parse(transport.responseText);
- } else {
+ let title = false;
- const query = { op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId() };
+ if (reply && reply.title) title = reply.title;
- xhrPost("backend.php", query, (transport) => {
- const reply = JSON.parse(transport.responseText);
+ if (title || Feeds.getActiveFeedId() || Feeds.activeFeedIsCat()) {
- let title = false;
+ console.log(title + " " + Feeds.getActiveFeedId());
- if (reply && reply.title) title = reply.title;
+ const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) :
+ Feeds.getActiveFeedId();
- if (title || Feeds.getActiveFeedId() || Feeds.activeFeedIsCat()) {
+ const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
- console.log(title + " " + Feeds.getActiveFeedId());
+ Filters.addFilterRule(null, dojo.toJson(rule));
+ }
+ });
+ }
+ });
+ }
- const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) :
- Feeds.getActiveFeedId();
+ dialog.show();
+ },
+};
- const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 };
+/* function strip_tags(s) {
+ return s.replace(/<\/?[^>]+(>|$)/g, "");
+} */
- addFilterRule(null, dojo.toJson(rule));
- }
- });
+// noinspection JSUnusedGlobalSymbols
+function uploadIconHandler(rc) {
+ switch (rc) {
+ case 0:
+ notify_info("Upload complete.");
+ if (App.isPrefs()) {
+ Feeds.reload();
+ } else {
+ setTimeout('Feeds.reload(false, false)', 50);
}
- });
+ break;
+ case 1:
+ notify_error("Upload failed: icon is too big.");
+ break;
+ case 2:
+ notify_error("Upload failed.");
+ break;
}
-
- dialog.show();
-
}
-function unsubscribeFeed(feed_id, title) {
-
- const msg = __("Unsubscribe from %s?").replace("%s", title);
+// noinspection JSUnusedGlobalSymbols
+function removeFeedIcon(id) {
+ if (confirm(__("Remove stored feed icon?"))) {
- if (title == undefined || confirm(msg)) {
- notify_progress("Removing feed...");
+ notify_progress("Removing feed icon...", true);
- const query = { op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id };
+ const query = { op: "pref-feeds", method: "removeicon", feed_id: id };
xhrPost("backend.php", query, (transport) => {
- if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
-
+ notify_info("Feed icon removed.");
if (App.isPrefs()) {
Feeds.reload();
} else {
- if (feed_id == Feeds.getActiveFeedId())
- setTimeout(() => { Feeds.viewfeed({feed:-5}) },
- 100);
-
- if (feed_id < 0) Feeds.reload();
+ setTimeout('Feeds.reload(false, false)', 50);
}
});
}
@@ -1459,33 +1523,16 @@ function unsubscribeFeed(feed_id, title) {
}
// noinspection JSUnusedGlobalSymbols
-function genUrlChangeKey(feed, is_cat) {
- if (confirm(__("Generate new syndication address for this feed?"))) {
-
- notify_progress("Trying to change address...", true);
-
- const query = { op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat };
-
- xhrJson("backend.php", query, (reply) => {
- const new_link = reply.link;
- const e = $('gen_feed_url');
-
- if (new_link) {
- e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
- "&amp;key=" + new_link);
-
- e.href = e.href.replace(/\&key=.*$/,
- "&key=" + new_link);
-
- new Effect.Highlight(e);
+function uploadFeedIcon() {
+ const file = $("icon_file");
- notify('');
+ if (file.value.length == 0) {
+ alert(__("Please select an image file to upload."));
+ } else if (confirm(__("Upload new icon for this feed?"))) {
+ notify_progress("Uploading, please wait...", true);
+ return true;
+ }
- } else {
- notify_error("Could not change feed URL.");
- }
- });
- }
return false;
}
@@ -1541,7 +1588,6 @@ function selectTableRows(id, mode) {
}
}
}
-
}
function getSelectedTableRowIds(id) {
@@ -1559,45 +1605,6 @@ function getSelectedTableRowIds(id) {
return rows;
}
-function editFeed(feed) {
- if (feed <= 0)
- return alert(__("You can't edit this kind of feed."));
-
- const query = { op: "pref-feeds", method: "editfeed", id: feed };
-
- console.log("editFeed", query);
-
- if (dijit.byId("filterEditDlg"))
- dijit.byId("filterEditDlg").destroyRecursive();
-
- if (dijit.byId("feedEditDlg"))
- dijit.byId("feedEditDlg").destroyRecursive();
-
- const dialog = new dijit.Dialog({
- id: "feedEditDlg",
- title: __("Edit Feed"),
- style: "width: 600px",
- execute: function() {
- if (this.validate()) {
- notify_progress("Saving data...", true);
-
- xhrPost("backend.php", dialog.attr('value'), () => {
- dialog.hide();
- notify('');
- Feeds.reload();
- });
- }
- },
- href: "backend.php?" + dojo.objectToQuery(query)});
-
- dialog.show();
-}
-
-function get_timestamp() {
- const date = new Date();
- return Math.round(date.getTime() / 1000);
-}
-
// noinspection JSUnusedGlobalSymbols
function label_to_feed_id(label) {
return _label_base_index - 1 - Math.abs(label);
diff --git a/js/prefs.js b/js/prefs.js
index 67be0b474..0d35355d2 100755
--- a/js/prefs.js
+++ b/js/prefs.js
@@ -82,7 +82,7 @@ const App = {
const param = getURLParam('methodparam');
window.setTimeout(function () {
- editFeed(param)
+ CommonDialogs.editFeed(param)
}, 100);
}
},
@@ -100,7 +100,7 @@ const App = {
CommonDialogs.addLabel();
return false;
case "create_filter":
- quickAddFilter();
+ Filters.quickAddFilter();
return false;
case "help_dialog":
Utils.helpDialog("main");
@@ -575,7 +575,7 @@ function editSelectedFeed() {
notify("");
- editFeed(rows[0], {});
+ CommonDialogs.editFeed(rows[0], {});
}
diff --git a/js/tt-rss.js b/js/tt-rss.js
index 6dd4a91eb..9c5a78ce2 100644
--- a/js/tt-rss.js
+++ b/js/tt-rss.js
@@ -360,7 +360,7 @@ const App = {
if (Feeds.activeFeedIsCat())
alert(__("You can't edit this kind of feed."));
else
- editFeed(Feeds.getActiveFeedId());
+ CommonDialogs.editFeed(Feeds.getActiveFeedId());
};
this.hotkey_actions["feed_catchup"] = function () {
if (Feeds.getActiveFeedId() != undefined) {
@@ -424,7 +424,7 @@ const App = {
CommonDialogs.addLabel();
};
this.hotkey_actions["create_filter"] = function () {
- quickAddFilter();
+ Filters.quickAddFilter();
};
this.hotkey_actions["collapse_sidebar"] = function () {
Feeds.viewCurrentFeed();
@@ -501,7 +501,7 @@ const App = {
if (Feeds.activeFeedIsCat())
alert(__("You can't edit this kind of feed."));
else
- editFeed(Feeds.getActiveFeedId());
+ CommonDialogs.editFeed(Feeds.getActiveFeedId());
break;
case "qmcRemoveFeed":
var actid = Feeds.getActiveFeedId();
@@ -521,7 +521,7 @@ const App = {
var pr = __("Unsubscribe from %s?").replace("%s", fn);
if (confirm(pr)) {
- unsubscribeFeed(actid);
+ CommonDialogs.unsubscribeFeed(actid);
}
break;
case "qmcCatchupAll":
diff --git a/js/viewfeed.js b/js/viewfeed.js
index 1821c4853..3fb9f0749 100755
--- a/js/viewfeed.js
+++ b/js/viewfeed.js
@@ -1560,7 +1560,7 @@ const Headlines = {
menu.addChild(new dijit.MenuItem({
label: __("Edit feed"),
onClick: function () {
- editFeed(this.getParent().currentTarget.getAttribute("data-feed-id"));
+ CommonDialogs.editFeed(this.getParent().currentTarget.getAttribute("data-feed-id"));
}
}));
diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php
index ff11c1201..362b9771f 100644
--- a/plugins/af_psql_trgm/init.php
+++ b/plugins/af_psql_trgm/init.php
@@ -202,7 +202,7 @@ class Af_Psql_Trgm extends Plugin {
print "<li>" .
"<img src='images/pub_set.png'
style='vertical-align : middle'> <a href='#'
- onclick='editFeed($f)'>" .
+ onclick='CommonDialogs.editFeed($f)'>" .
Feeds::getFeedTitle($f) . "</a></li>";
}
print "</ul>";
diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php
index cccdf8af7..e0c57d093 100755
--- a/plugins/af_readability/init.php
+++ b/plugins/af_readability/init.php
@@ -94,7 +94,7 @@ class Af_Readability extends Plugin {
print "<li>" .
"<img src='images/pub_set.png'
style='vertical-align : middle'> <a href='#'
- onclick='editFeed($f)'>".
+ onclick='CommonDialogs.editFeed($f)'>".
Feeds::getFeedTitle($f) . "</a></li>";
}
print "</ul>";
diff --git a/tests/functional/BasicTest.php b/tests/functional/BasicTest.php
index c5bc70b4e..eba8a2c89 100644
--- a/tests/functional/BasicTest.php
+++ b/tests/functional/BasicTest.php
@@ -25,7 +25,7 @@ class BasicTest extends PHPUnit_Extensions_Selenium2TestCase {
public function testBasicDialogs() {
$this->testLogin();
- $this->execute(["script" => "quickAddFilter()", "args" => []]);
+ $this->execute(["script" => "Filters.quickAddFilter()", "args" => []]);
$this->byCssSelector("#filterEditDlg")->displayed();
$this->execute(["script" => "dijit.byId('filterEditDlg').hide();", "args" => []]);