don't use declare() for static objects with no inheritance because apparently it's not actually needed by AMD

This commit is contained in:
Andrew Dolgov 2020-06-04 19:50:13 +03:00
parent 06cc6e3a2a
commit e37f8cfa78
7 changed files with 2539 additions and 2563 deletions

View File

@ -1,355 +1,351 @@
'use strict'
/* global __, ngettext */
define(["dojo/_base/declare"], function (declare) {
Article = {
_scroll_reset_timeout: false,
getScoreClass: function (score) {
if (score > 500) {
return "score-high";
} else if (score > 0) {
return "score-half-high";
} else if (score < -100) {
return "score-low";
} else if (score < 0) {
return "score-half-low";
} else {
return "score-neutral";
const Article = {
_scroll_reset_timeout: false,
getScoreClass: function (score) {
if (score > 500) {
return "score-high";
} else if (score > 0) {
return "score-half-high";
} else if (score < -100) {
return "score-low";
} else if (score < 0) {
return "score-half-low";
} else {
return "score-neutral";
}
},
getScorePic: function (score) {
if (score > 500) {
return "trending_up";
} else if (score > 0) {
return "trending_up";
} else if (score < 0) {
return "trending_down";
} else {
return "trending_neutral";
}
},
selectionSetScore: function () {
const ids = Headlines.getSelected();
if (ids.length > 0) {
const score = prompt(__("Please enter new score for selected articles:"));
if (!isNaN(parseInt(score))) {
ids.each((id) => {
const row = $("RROW-" + id);
if (row) {
row.setAttribute("data-score", score);
const pic = row.select(".icon-score")[0];
pic.innerHTML = Article.getScorePic(score);
pic.setAttribute("title", score);
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
.each(function(scl) {
if (row.hasClassName(scl))
row.removeClassName(scl);
});
row.addClassName(Article.getScoreClass(score));
}
});
}
},
getScorePic: function (score) {
if (score > 500) {
return "trending_up";
} else if (score > 0) {
return "trending_up";
} else if (score < 0) {
return "trending_down";
} else {
return "trending_neutral";
} else {
alert(__("No articles selected."));
}
},
setScore: function (id, pic) {
const row = pic.up("div[id*=RROW]");
if (row) {
const score_old = row.getAttribute("data-score");
const score = prompt(__("Please enter new score for this article:"), score_old);
if (!isNaN(parseInt(score))) {
row.setAttribute("data-score", score);
const pic = row.select(".icon-score")[0];
pic.innerHTML = Article.getScorePic(score);
pic.setAttribute("title", score);
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
.each(function(scl) {
if (row.hasClassName(scl))
row.removeClassName(scl);
});
row.addClassName(Article.getScoreClass(score));
}
},
selectionSetScore: function () {
const ids = Headlines.getSelected();
}
},
cdmUnsetActive: function (event) {
const row = $("RROW-" + Article.getActive());
if (ids.length > 0) {
const score = prompt(__("Please enter new score for selected articles:"));
if (row) {
row.removeClassName("active");
if (!isNaN(parseInt(score))) {
ids.each((id) => {
const row = $("RROW-" + id);
if (event)
event.stopPropagation();
if (row) {
row.setAttribute("data-score", score);
return false;
}
},
close: function () {
if (dijit.byId("content-insert"))
dijit.byId("headlines-wrap-inner").removeChild(
dijit.byId("content-insert"));
const pic = row.select(".icon-score")[0];
Article.setActive(0);
},
displayUrl: function (id) {
const query = {op: "rpc", method: "getlinktitlebyid", id: id};
pic.innerHTML = Article.getScorePic(score);
pic.setAttribute("title", score);
xhrJson("backend.php", query, (reply) => {
if (reply && reply.link) {
prompt(__("Article URL:"), reply.link);
}
});
},
openInNewWindow: function (id) {
const w = window.open("");
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
.each(function(scl) {
if (row.hasClassName(scl))
row.removeClassName(scl);
});
if (w) {
w.opener = null;
w.location = "backend.php?op=article&method=redirect&id=" + id;
row.addClassName(Article.getScoreClass(score));
Headlines.toggleUnread(id, 0);
}
},
render: function (article) {
App.cleanupMemory("content-insert");
dijit.byId("headlines-wrap-inner").addChild(
dijit.byId("content-insert"));
const c = dijit.byId("content-insert");
try {
c.domNode.scrollTop = 0;
} catch (e) {
}
c.attr('content', article);
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
//Headlines.correctHeadlinesOffset(Article.getActive());
try {
c.focus();
} catch (e) {
}
},
formatComments: function(hl) {
let comments = "";
if (hl.comments || hl.num_comments > 0) {
let comments_msg = __("comments");
if (hl.num_comments > 0) {
comments_msg = hl.num_comments + " " + ngettext("comment", "comments", hl.num_comments)
}
comments = `<a href="${escapeHtml(hl.comments ? hl.comments : hl.link)}">(${comments_msg})</a>`;
}
return comments;
},
formatOriginallyFrom: function(hl) {
return hl.orig_feed ? `<span>
${__('Originally from:')} <a target="_blank" rel="noopener noreferrer" href="${escapeHtml(hl.orig_feed[1])}">${hl.orig_feed[0]}</a>
</span>` : "";
},
unpack: function(row) {
if (row.hasAttribute("data-content")) {
console.log("unpacking: " + row.id);
const container = row.querySelector(".content-inner");
container.innerHTML = row.getAttribute("data-content").trim();
// blank content element might screw up onclick selection and keyboard moving
if (container.textContent.length == 0)
container.innerHTML += "&nbsp;";
// in expandable mode, save content for later, so that we can pack unfocused rows back
if (App.isCombinedMode() && $("main").hasClassName("expandable"))
row.setAttribute("data-content-original", row.getAttribute("data-content"));
row.removeAttribute("data-content");
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row);
}
},
pack: function(row) {
if (row.hasAttribute("data-content-original")) {
console.log("packing", row.id);
row.setAttribute("data-content", row.getAttribute("data-content-original"));
row.removeAttribute("data-content-original");
row.querySelector(".content-inner").innerHTML = "&nbsp;";
}
},
view: function (id, no_expand) {
this.setActive(id);
Headlines.scrollToArticleId(id);
if (!no_expand) {
const hl = Headlines.objectById(id);
if (hl) {
const comments = this.formatComments(hl);
const originally_from = this.formatOriginallyFrom(hl);
const article = `<div class="post post-${hl.id}" data-article-id="${hl.id}">
<div class="header">
<div class="row">
<div class="title"><a target="_blank" rel="noopener noreferrer"
title="${escapeHtml(hl.title)}"
href="${escapeHtml(hl.link)}">${hl.title}</a></div>
<div class="date">${hl.updated_long}</div>
</div>
<div class="row">
<div class="buttons left">${hl.buttons_left}</div>
<div class="comments">${comments}</div>
<div class="author">${hl.author}</div>
<i class="material-icons">label_outline</i>
<span id="ATSTR-${hl.id}">${hl.tags_str}</span>
&nbsp;<a title="${__("Edit tags for this article")}" href="#"
onclick="Article.editTags(${hl.id})">(+)</a>
<div class="buttons right">${hl.buttons}</div>
</div>
</div>
<div id="POSTNOTE-${hl.id}">${hl.note}</div>
<div class="content" lang="${hl.lang ? hl.lang : 'en'}">
${originally_from}
${hl.content}
${hl.enclosures}
</div>
</div>`;
Headlines.toggleUnread(id, 0);
this.render(article);
}
}
return false;
},
editTags: function (id) {
const query = "backend.php?op=article&method=editArticleTags&param=" + encodeURIComponent(id);
if (dijit.byId("editTagsDlg"))
dijit.byId("editTagsDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "editTagsDlg",
title: __("Edit article Tags"),
style: "width: 600px",
execute: function () {
if (this.validate()) {
Notify.progress("Saving article tags...", true);
xhrPost("backend.php", this.attr('value'), (transport) => {
try {
Notify.close();
dialog.hide();
const data = JSON.parse(transport.responseText);
if (data) {
const id = data.id;
const tags = $("ATSTR-" + id);
const tooltip = dijit.byId("ATSTRTIP-" + id);
if (tags) tags.innerHTML = data.content;
if (tooltip) tooltip.attr('label', data.content_full);
}
} catch (e) {
App.Error.report(e);
}
});
}
},
href: query
});
} else {
alert(__("No articles selected."));
}
},
setScore: function (id, pic) {
const row = pic.up("div[id*=RROW]");
const tmph = dojo.connect(dialog, 'onLoad', function () {
dojo.disconnect(tmph);
if (row) {
const score_old = row.getAttribute("data-score");
const score = prompt(__("Please enter new score for this article:"), score_old);
new Ajax.Autocompleter('tags_str', 'tags_choices',
"backend.php?op=article&method=completeTags",
{tokens: ',', paramName: "search"});
});
if (!isNaN(parseInt(score))) {
row.setAttribute("data-score", score);
dialog.show();
},
cdmMoveToId: function (id, params) {
params = params || {};
const pic = row.select(".icon-score")[0];
const force_to_top = params.force_to_top || false;
pic.innerHTML = Article.getScorePic(score);
pic.setAttribute("title", score);
const ctr = $("headlines-frame");
const row = $("RROW-" + id);
["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
.each(function(scl) {
if (row.hasClassName(scl))
row.removeClassName(scl);
});
if (!row || !ctr) return;
row.addClassName(Article.getScoreClass(score));
}
}
},
cdmUnsetActive: function (event) {
const row = $("RROW-" + Article.getActive());
if (force_to_top || !App.Scrollable.fitsInContainer(row, ctr)) {
ctr.scrollTop = row.offsetTop;
}
},
setActive: function (id) {
if (id != Article.getActive()) {
console.log("setActive", id, "was", Article.getActive());
if (row) {
$$("div[id*=RROW][class*=active]").each((row) => {
row.removeClassName("active");
if (event)
event.stopPropagation();
return false;
}
},
close: function () {
if (dijit.byId("content-insert"))
dijit.byId("headlines-wrap-inner").removeChild(
dijit.byId("content-insert"));
Article.setActive(0);
},
displayUrl: function (id) {
const query = {op: "rpc", method: "getlinktitlebyid", id: id};
xhrJson("backend.php", query, (reply) => {
if (reply && reply.link) {
prompt(__("Article URL:"), reply.link);
}
});
},
openInNewWindow: function (id) {
const w = window.open("");
if (w) {
w.opener = null;
w.location = "backend.php?op=article&method=redirect&id=" + id;
Headlines.toggleUnread(id, 0);
}
},
render: function (article) {
App.cleanupMemory("content-insert");
dijit.byId("headlines-wrap-inner").addChild(
dijit.byId("content-insert"));
const c = dijit.byId("content-insert");
try {
c.domNode.scrollTop = 0;
} catch (e) {
}
c.attr('content', article);
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
//Headlines.correctHeadlinesOffset(Article.getActive());
try {
c.focus();
} catch (e) {
}
},
formatComments: function(hl) {
let comments = "";
if (hl.comments || hl.num_comments > 0) {
let comments_msg = __("comments");
if (hl.num_comments > 0) {
comments_msg = hl.num_comments + " " + ngettext("comment", "comments", hl.num_comments)
}
comments = `<a href="${escapeHtml(hl.comments ? hl.comments : hl.link)}">(${comments_msg})</a>`;
}
return comments;
},
formatOriginallyFrom: function(hl) {
return hl.orig_feed ? `<span>
${__('Originally from:')} <a target="_blank" rel="noopener noreferrer" href="${escapeHtml(hl.orig_feed[1])}">${hl.orig_feed[0]}</a>
</span>` : "";
},
unpack: function(row) {
if (row.hasAttribute("data-content")) {
console.log("unpacking: " + row.id);
const container = row.querySelector(".content-inner");
container.innerHTML = row.getAttribute("data-content").trim();
// blank content element might screw up onclick selection and keyboard moving
if (container.textContent.length == 0)
container.innerHTML += "&nbsp;";
// in expandable mode, save content for later, so that we can pack unfocused rows back
if (App.isCombinedMode() && $("main").hasClassName("expandable"))
row.setAttribute("data-content-original", row.getAttribute("data-content"));
row.removeAttribute("data-content");
PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row);
}
},
pack: function(row) {
if (row.hasAttribute("data-content-original")) {
console.log("packing", row.id);
row.setAttribute("data-content", row.getAttribute("data-content-original"));
row.removeAttribute("data-content-original");
row.querySelector(".content-inner").innerHTML = "&nbsp;";
}
},
view: function (id, no_expand) {
this.setActive(id);
Headlines.scrollToArticleId(id);
if (!no_expand) {
const hl = Headlines.objectById(id);
if (hl) {
const comments = this.formatComments(hl);
const originally_from = this.formatOriginallyFrom(hl);
const article = `<div class="post post-${hl.id}" data-article-id="${hl.id}">
<div class="header">
<div class="row">
<div class="title"><a target="_blank" rel="noopener noreferrer"
title="${escapeHtml(hl.title)}"
href="${escapeHtml(hl.link)}">${hl.title}</a></div>
<div class="date">${hl.updated_long}</div>
</div>
<div class="row">
<div class="buttons left">${hl.buttons_left}</div>
<div class="comments">${comments}</div>
<div class="author">${hl.author}</div>
<i class="material-icons">label_outline</i>
<span id="ATSTR-${hl.id}">${hl.tags_str}</span>
&nbsp;<a title="${__("Edit tags for this article")}" href="#"
onclick="Article.editTags(${hl.id})">(+)</a>
<div class="buttons right">${hl.buttons}</div>
</div>
</div>
<div id="POSTNOTE-${hl.id}">${hl.note}</div>
<div class="content" lang="${hl.lang ? hl.lang : 'en'}">
${originally_from}
${hl.content}
${hl.enclosures}
</div>
</div>`;
Headlines.toggleUnread(id, 0);
this.render(article);
}
}
return false;
},
editTags: function (id) {
const query = "backend.php?op=article&method=editArticleTags&param=" + encodeURIComponent(id);
if (dijit.byId("editTagsDlg"))
dijit.byId("editTagsDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "editTagsDlg",
title: __("Edit article Tags"),
style: "width: 600px",
execute: function () {
if (this.validate()) {
Notify.progress("Saving article tags...", true);
xhrPost("backend.php", this.attr('value'), (transport) => {
try {
Notify.close();
dialog.hide();
const data = JSON.parse(transport.responseText);
if (data) {
const id = data.id;
const tags = $("ATSTR-" + id);
const tooltip = dijit.byId("ATSTRTIP-" + id);
if (tags) tags.innerHTML = data.content;
if (tooltip) tooltip.attr('label', data.content_full);
}
} catch (e) {
App.Error.report(e);
}
});
}
},
href: query
Article.pack(row);
});
const tmph = dojo.connect(dialog, 'onLoad', function () {
dojo.disconnect(tmph);
new Ajax.Autocompleter('tags_str', 'tags_choices',
"backend.php?op=article&method=completeTags",
{tokens: ',', paramName: "search"});
});
dialog.show();
},
cdmMoveToId: function (id, params) {
params = params || {};
const force_to_top = params.force_to_top || false;
const ctr = $("headlines-frame");
const row = $("RROW-" + id);
if (!row || !ctr) return;
if (row) {
Article.unpack(row);
if (force_to_top || !App.Scrollable.fitsInContainer(row, ctr)) {
ctr.scrollTop = row.offsetTop;
row.removeClassName("Unread");
row.addClassName("active");
PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id"));
}
},
setActive: function (id) {
if (id != Article.getActive()) {
console.log("setActive", id, "was", Article.getActive());
$$("div[id*=RROW][class*=active]").each((row) => {
row.removeClassName("active");
Article.pack(row);
});
const row = $("RROW-" + id);
if (row) {
Article.unpack(row);
row.removeClassName("Unread");
row.addClassName("active");
PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id"));
}
}
},
getActive: function () {
const row = document.querySelector("#headlines-frame > div[id*=RROW][class*=active]");
if (row)
return row.getAttribute("data-article-id");
else
return 0;
},
scrollByPages: function (page_offset) {
App.Scrollable.scrollByPages($("content-insert"), page_offset);
},
scroll: function (offset) {
App.Scrollable.scroll($("content-insert"), offset);
},
mouseIn: function (id) {
this.post_under_pointer = id;
},
mouseOut: function (id) {
this.post_under_pointer = false;
},
getUnderPointer: function () {
return this.post_under_pointer;
}
}
},
getActive: function () {
const row = document.querySelector("#headlines-frame > div[id*=RROW][class*=active]");
return Article;
});
if (row)
return row.getAttribute("data-article-id");
else
return 0;
},
scrollByPages: function (page_offset) {
App.Scrollable.scrollByPages($("content-insert"), page_offset);
},
scroll: function (offset) {
App.Scrollable.scroll($("content-insert"), offset);
},
mouseIn: function (id) {
this.post_under_pointer = id;
},
mouseOut: function (id) {
this.post_under_pointer = false;
},
getUnderPointer: function () {
return this.post_under_pointer;
}
}

View File

@ -1,8 +1,7 @@
'use strict'
/* global __, ngettext */
define(["dojo/_base/declare"], function (declare) {
// noinspection JSUnusedGlobalSymbols
CommonDialogs = {
// noinspection JSUnusedGlobalSymbols
const CommonDialogs = {
closeInfoBox: function() {
const dialog = dijit.byId("infoBox");
if (dialog) dialog.hide();
@ -478,6 +477,3 @@ define(["dojo/_base/declare"], function (declare) {
return false;
}
};
return CommonDialogs;
});

View File

@ -1,383 +1,380 @@
'use strict'
/* global __, ngettext */
define(["dojo/_base/declare"], function (declare) {
Filters = {
filterDlgCheckAction: function(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;
}
const action_param = $("filterDlg_paramBox");
// 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});
if (!action_param) {
console.log("filterDlgCheckAction: can't find action param box!");
return;
}
Element.hide(dijit.byId("filterDlg_actionParam").domNode);
Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
// 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});
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);
}
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.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) => {
try {
const li = dojo.create("li");
const cb = dojo.create("input", {type: "checkbox"}, li);
new dijit.form.CheckBox({
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) {
parentNode.replaceChild(li, replaceNode);
} else {
parentNode.appendChild(li);
}
} catch (e) {
App.Error.report(e);
}
});
},
createNewActionElement: function(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;
Element.show(dijit.byId("filterDlg_actionParam").domNode);
}
const query = {
op: "pref-filters", method: "printactionname",
action: dojo.formToJson(form)
};
} 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) => {
try {
const li = dojo.create("li");
xhrPost("backend.php", query, (transport) => {
try {
const li = dojo.create("li");
const cb = dojo.create("input", {type: "checkbox"}, li);
const cb = dojo.create("input", {type: "checkbox"}, li);
new dijit.form.CheckBox({
onChange: function () {
Lists.onRowChecked(this);
},
}, cb);
new dijit.form.CheckBox({
onChange: function () {
Lists.onRowChecked(this);
},
}, cb);
dojo.create("input", {
type: "hidden",
name: "action[]",
value: dojo.formToJson(form)
}, li);
dojo.create("input", {
type: "hidden",
name: "rule[]",
value: dojo.formToJson(form)
}, li);
dojo.create("span", {
onclick: function () {
dijit.byId('filterEditDlg').editAction(this);
},
innerHTML: transport.responseText
}, 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) {
App.Error.report(e);
if (replaceNode) {
parentNode.replaceChild(li, replaceNode);
} else {
parentNode.appendChild(li);
}
} catch (e) {
App.Error.report(e);
}
});
},
createNewActionElement: function(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 () {
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) {
parentNode.replaceChild(li, replaceNode);
} else {
parentNode.appendChild(li);
}
} catch (e) {
App.Error.report(e);
}
});
},
addFilterRule: function(replaceNode, ruleStr) {
if (dijit.byId("filterNewRuleDlg"))
dijit.byId("filterNewRuleDlg").destroyRecursive();
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();
}
},
content: __('Loading, please wait...'),
});
const tmph = dojo.connect(rule_dlg, "onShow", null, function (e) {
dojo.disconnect(tmph);
xhrPost("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (transport) => {
rule_dlg.attr('content', transport.responseText);
});
},
addFilterRule: function(replaceNode, ruleStr) {
if (dijit.byId("filterNewRuleDlg"))
dijit.byId("filterNewRuleDlg").destroyRecursive();
});
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();
}
},
content: __('Loading, please wait...'),
});
rule_dlg.show();
},
addFilterAction: function(replaceNode, actionStr) {
if (dijit.byId("filterNewActionDlg"))
dijit.byId("filterNewActionDlg").destroyRecursive();
const tmph = dojo.connect(rule_dlg, "onShow", null, function (e) {
dojo.disconnect(tmph);
const query = "backend.php?op=pref-filters&method=newaction&action=" +
encodeURIComponent(actionStr);
xhrPost("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (transport) => {
rule_dlg.attr('content', transport.responseText);
});
});
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
});
rule_dlg.show();
},
addFilterAction: function(replaceNode, actionStr) {
if (dijit.byId("filterNewActionDlg"))
dijit.byId("filterNewActionDlg").destroyRecursive();
rule_dlg.show();
},
editFilterTest: function(params) {
const query = "backend.php?op=pref-filters&method=newaction&action=" +
encodeURIComponent(actionStr);
if (dijit.byId("filterTestDlg"))
dijit.byId("filterTestDlg").destroyRecursive();
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 test_dlg = new dijit.Dialog({
id: "filterTestDlg",
title: "Test Filter",
style: "width: 600px",
results: 0,
limit: 100,
max_offset: 10000,
getTestResults: function (params, offset) {
params.method = 'testFilterDo';
params.offset = offset;
params.limit = test_dlg.limit;
rule_dlg.show();
},
editFilterTest: function(params) {
console.log("getTestResults:" + offset);
if (dijit.byId("filterTestDlg"))
dijit.byId("filterTestDlg").destroyRecursive();
xhrPost("backend.php", params, (transport) => {
try {
const result = JSON.parse(transport.responseText);
const test_dlg = new dijit.Dialog({
id: "filterTestDlg",
title: "Test Filter",
style: "width: 600px",
results: 0,
limit: 100,
max_offset: 10000,
getTestResults: function (params, offset) {
params.method = 'testFilterDo';
params.offset = offset;
params.limit = test_dlg.limit;
if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
test_dlg.results += result.length;
console.log("getTestResults:" + offset);
console.log("got results:" + result.length);
xhrPost("backend.php", params, (transport) => {
try {
const result = JSON.parse(transport.responseText);
$("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
.replace("%f", test_dlg.results)
.replace("%d", offset);
if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
test_dlg.results += result.length;
console.log(offset + " " + test_dlg.max_offset);
console.log("got results:" + result.length);
for (let i = 0; i < result.length; i++) {
const tmp = dojo.create("table", { innerHTML: result[i]});
$("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
.replace("%f", test_dlg.results)
.replace("%d", offset);
$("prefFilterTestResultList").innerHTML += tmp.innerHTML;
}
console.log(offset + " " + test_dlg.max_offset);
if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
for (let i = 0; i < result.length; i++) {
const tmp = dojo.create("table", { innerHTML: result[i]});
// get the next batch
window.setTimeout(function () {
test_dlg.getTestResults(params, offset + test_dlg.limit);
}, 0);
$("prefFilterTestResultList").innerHTML += tmp.innerHTML;
}
if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
// get the next batch
window.setTimeout(function () {
test_dlg.getTestResults(params, offset + test_dlg.limit);
}, 0);
} else {
// all done
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);
}
}
} else if (!result) {
console.log("getTestResults: can't parse results object");
} else {
// all done
Element.hide("prefFilterLoadingIndicator");
Notify.error("Error while trying to get filter test results.");
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);
}
} else {
console.log("getTestResults: dialog closed, bailing out.");
}
} catch (e) {
App.Error.report(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.");
} else {
console.log("getTestResults: dialog closed, bailing out.");
}
} catch (e) {
App.Error.report(e);
}
});
},
href: "backend.php?op=pref-filters&method=testFilterDlg"
});
dojo.connect(test_dlg, "onLoad", null, function (e) {
test_dlg.getTestResults(params, 0);
});
test_dlg.show();
},
quickAddFilter: function() {
let query;
if (!App.isPrefs()) {
query = {
op: "pref-filters", method: "newfilter",
feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()
};
} else {
query = {op: "pref-filters", method: "newfilter"};
}
console.log('quickAddFilter', query);
if (dijit.byId("feedEditDlg"))
dijit.byId("feedEditDlg").destroyRecursive();
if (dijit.byId("filterEditDlg"))
dijit.byId("filterEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "filterEditDlg",
title: __("Create Filter"),
style: "width: 600px",
test: function () {
Filters.editFilterTest(dojo.formToObject("filter_new_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);
},
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");
xhrPost("backend.php", query, () => {
if (App.isPrefs()) {
dijit.byId("filterTree").reload();
}
dialog.hide();
});
},
href: "backend.php?op=pref-filters&method=testFilterDlg"
});
}
},
href: "backend.php?" + dojo.objectToQuery(query)
});
dojo.connect(test_dlg, "onLoad", null, function (e) {
test_dlg.getTestResults(params, 0);
});
if (!App.isPrefs()) {
const selectedText = getSelectionText();
test_dlg.show();
},
quickAddFilter: function() {
let query;
const lh = dojo.connect(dialog, "onLoad", function () {
dojo.disconnect(lh);
if (!App.isPrefs()) {
query = {
op: "pref-filters", method: "newfilter",
feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()
};
} else {
query = {op: "pref-filters", method: "newfilter"};
}
if (selectedText != "") {
console.log('quickAddFilter', query);
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
Feeds.getActive();
if (dijit.byId("feedEditDlg"))
dijit.byId("feedEditDlg").destroyRecursive();
const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
if (dijit.byId("filterEditDlg"))
dijit.byId("filterEditDlg").destroyRecursive();
Filters.addFilterRule(null, dojo.toJson(rule));
const dialog = new dijit.Dialog({
id: "filterEditDlg",
title: __("Create Filter"),
style: "width: 600px",
test: function () {
Filters.editFilterTest(dojo.formToObject("filter_new_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);
},
addAction: function () {
Filters.addFilterAction();
},
addRule: function () {
Filters.addFilterRule();
},
deleteAction: function () {
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
e.parentNode.removeChild(e)
} 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));
}
});
},
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, () => {
if (App.isPrefs()) {
dijit.byId("filterTree").reload();
}
dialog.hide();
});
}
},
href: "backend.php?" + dojo.objectToQuery(query)
}
});
if (!App.isPrefs()) {
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();
},
};
return Filters;
});
}
dialog.show();
},
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
// based on http://www.velvetcache.org/2010/08/19/a-simple-javascript-hooks-system
PluginHost = {
const PluginHost = {
HOOK_ARTICLE_RENDERED: 1,
HOOK_ARTICLE_RENDERED_CDM: 2,
HOOK_ARTICLE_SET_ACTIVE: 3,

View File

@ -2,12 +2,6 @@
/* global dijit,__ */
let App;
let CommonDialogs;
let Filters;
let Feeds;
let Headlines;
let Article;
let PluginHost;
const Plugins = {};