2018-12-02 15:38:27 +00:00
|
|
|
'use strict'
|
2020-06-04 20:27:22 +00:00
|
|
|
|
2021-02-12 16:55:05 +00:00
|
|
|
/* eslint-disable new-cap */
|
|
|
|
/* eslint-disable no-new */
|
|
|
|
|
2021-02-12 12:50:06 +00:00
|
|
|
/* global __, dojo, dijit, Notify, App, Feeds, $$, xhrPost, xhrJson, Tables, Effect, fox */
|
2020-06-04 20:27:22 +00:00
|
|
|
|
|
|
|
/* exported CommonDialogs */
|
2020-06-04 16:50:13 +00:00
|
|
|
const CommonDialogs = {
|
2018-12-02 17:07:57 +00:00
|
|
|
closeInfoBox: function() {
|
|
|
|
const dialog = dijit.byId("infoBox");
|
|
|
|
if (dialog) dialog.hide();
|
|
|
|
},
|
|
|
|
removeFeedIcon: function(id) {
|
|
|
|
if (confirm(__("Remove stored feed icon?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing feed icon...", true);
|
2018-12-02 17:07:57 +00:00
|
|
|
|
|
|
|
const query = {op: "pref-feeds", method: "removeicon", feed_id: id};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.info("Feed icon removed.");
|
2018-12-03 17:16:07 +00:00
|
|
|
|
|
|
|
if (App.isPrefs())
|
|
|
|
dijit.byId("feedTree").reload();
|
|
|
|
else
|
2018-12-02 17:07:57 +00:00
|
|
|
Feeds.reload();
|
2018-12-03 17:16:07 +00:00
|
|
|
|
2019-03-14 06:08:44 +00:00
|
|
|
const icon = $$(".feed-editor-icon")[0];
|
|
|
|
|
|
|
|
if (icon)
|
|
|
|
icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime());
|
|
|
|
|
2018-12-02 17:07:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
uploadFeedIcon: function() {
|
|
|
|
const file = $("icon_file");
|
|
|
|
|
|
|
|
if (file.value.length == 0) {
|
|
|
|
alert(__("Please select an image file to upload."));
|
|
|
|
} else if (confirm(__("Upload new icon for this feed?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Uploading, please wait...", true);
|
2019-03-14 06:08:44 +00:00
|
|
|
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.open( 'POST', 'backend.php', true );
|
|
|
|
xhr.onload = function () {
|
|
|
|
switch (parseInt(this.responseText)) {
|
|
|
|
case 0:
|
2020-06-05 04:44:57 +00:00
|
|
|
{
|
|
|
|
Notify.info("Upload complete.");
|
2019-03-14 06:08:44 +00:00
|
|
|
|
2020-06-05 04:44:57 +00:00
|
|
|
if (App.isPrefs())
|
|
|
|
dijit.byId("feedTree").reload();
|
|
|
|
else
|
|
|
|
Feeds.reload();
|
2019-03-14 06:08:44 +00:00
|
|
|
|
2020-06-05 04:44:57 +00:00
|
|
|
const icon = $$(".feed-editor-icon")[0];
|
2019-03-14 06:08:44 +00:00
|
|
|
|
2020-06-05 04:44:57 +00:00
|
|
|
if (icon)
|
|
|
|
icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime());
|
2019-03-14 06:08:44 +00:00
|
|
|
|
2020-06-05 04:44:57 +00:00
|
|
|
}
|
2019-03-14 06:08:44 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Notify.error("Upload failed: icon is too big.");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Notify.error("Upload failed.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhr.send(new FormData($("feed_icon_upload_form")));
|
2018-12-02 17:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-12-02 14:00:58 +00:00
|
|
|
quickAddFeed: function() {
|
2020-09-15 13:28:09 +00:00
|
|
|
xhrPost("backend.php",
|
|
|
|
{op: "feeds", method: "quickAddFeed"},
|
|
|
|
(transport) => {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2020-09-15 13:28:09 +00:00
|
|
|
id: "feedAddDlg",
|
|
|
|
title: __("Subscribe to Feed"),
|
|
|
|
content: transport.responseText,
|
|
|
|
show_error: function (msg) {
|
|
|
|
const elem = $("fadd_error_message");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
elem.innerHTML = msg;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
if (!Element.visible(elem))
|
|
|
|
new Effect.Appear(elem);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
},
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
console.log(dojo.objectToQuery(this.attr('value')));
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
const feed_url = this.attr('value').feed;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
Element.show("feed_add_spinner");
|
|
|
|
Element.hide("fadd_error_message");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
xhrPost("backend.php", this.attr('value'), (transport) => {
|
|
|
|
try {
|
2020-06-04 20:27:22 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
let reply;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
try {
|
|
|
|
reply = JSON.parse(transport.responseText);
|
|
|
|
} catch (e) {
|
|
|
|
Element.hide("feed_add_spinner");
|
|
|
|
alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
|
|
|
|
console.log('quickAddFeed, backend returned:' + transport.responseText);
|
|
|
|
return;
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
const rc = reply['result'];
|
|
|
|
|
|
|
|
Notify.close();
|
|
|
|
Element.hide("feed_add_spinner");
|
|
|
|
|
|
|
|
console.log(rc);
|
|
|
|
|
|
|
|
switch (parseInt(rc['code'])) {
|
|
|
|
case 1:
|
|
|
|
dialog.hide();
|
|
|
|
Notify.info(__("Subscribed to %s").replace("%s", feed_url));
|
|
|
|
|
|
|
|
if (App.isPrefs())
|
|
|
|
dijit.byId("feedTree").reload();
|
|
|
|
else
|
|
|
|
Feeds.reload();
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dialog.show_error(__("Specified URL seems to be invalid."));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
dialog.show_error(__("Specified URL doesn't seem to contain any feeds."));
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
const feeds = rc['feeds'];
|
|
|
|
|
|
|
|
Element.show("fadd_multiple_notify");
|
|
|
|
|
|
|
|
const select = dijit.byId("feedDlg_feedContainerSelect");
|
|
|
|
|
|
|
|
while (select.getOptions().length > 0)
|
|
|
|
select.removeOption(0);
|
|
|
|
|
|
|
|
select.addOption({value: '', label: __("Expand to select feed")});
|
|
|
|
|
|
|
|
for (const feedUrl in feeds) {
|
|
|
|
if (feeds.hasOwnProperty(feedUrl)) {
|
|
|
|
select.addOption({value: feedUrl, label: feeds[feedUrl]});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Effect.Appear('feedDlg_feedsContainer', {duration: 0.5});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
dialog.show_error(__("Couldn't download the specified URL: %s").replace("%s", rc['message']));
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
dialog.show_error(__("XML validation failed: %s").replace("%s", rc['message']));
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
dialog.show_error(__("You are already subscribed to this feed."));
|
|
|
|
break;
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error(transport.responseText);
|
|
|
|
App.Error.report(e);
|
2020-06-04 20:27:22 +00:00
|
|
|
}
|
2020-09-15 13:28:09 +00:00
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
2020-09-15 13:28:09 +00:00
|
|
|
},
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
|
2020-09-15 13:28:09 +00:00
|
|
|
dialog.show();
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
},
|
|
|
|
showFeedsWithErrors: function() {
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2018-12-02 14:00:58 +00:00
|
|
|
id: "errorFeedsDlg",
|
|
|
|
title: __("Feeds with update errors"),
|
|
|
|
getSelectedFeeds: function () {
|
2018-12-07 11:03:33 +00:00
|
|
|
return Tables.getSelected("error-feeds-list");
|
2018-12-02 14:00:58 +00:00
|
|
|
},
|
|
|
|
removeSelected: function () {
|
|
|
|
const sel_rows = this.getSelectedFeeds();
|
|
|
|
|
|
|
|
if (sel_rows.length > 0) {
|
|
|
|
if (confirm(__("Remove selected feeds?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing selected feeds...", true);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-feeds", method: "remove",
|
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 14:00:58 +00:00
|
|
|
dialog.hide();
|
2018-12-03 17:16:07 +00:00
|
|
|
|
|
|
|
if (App.isPrefs())
|
|
|
|
dijit.byId("feedTree").reload();
|
|
|
|
else
|
|
|
|
Feeds.reload();
|
|
|
|
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
alert(__("No feeds selected."));
|
|
|
|
}
|
|
|
|
},
|
2021-02-12 15:38:26 +00:00
|
|
|
content: __("Loading, please wait...")
|
|
|
|
});
|
|
|
|
|
|
|
|
const tmph = dojo.connect(dialog, 'onShow', function () {
|
|
|
|
dojo.disconnect(tmph);
|
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (transport) => {
|
|
|
|
dialog.attr('content', transport.responseText);
|
|
|
|
})
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
},
|
|
|
|
addLabel: function(select, callback) {
|
|
|
|
const caption = prompt(__("Please enter label caption:"), "");
|
|
|
|
|
|
|
|
if (caption != undefined && caption.trim().length > 0) {
|
|
|
|
|
|
|
|
const query = {op: "pref-labels", method: "add", caption: caption.trim()};
|
|
|
|
|
|
|
|
if (select)
|
|
|
|
Object.extend(query, {output: "select"});
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Loading, please wait...", true);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", query, (transport) => {
|
|
|
|
if (callback) {
|
|
|
|
callback(transport);
|
|
|
|
} else if (App.isPrefs()) {
|
|
|
|
dijit.byId("labelTree").reload();
|
|
|
|
} else {
|
|
|
|
Feeds.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unsubscribeFeed: function(feed_id, title) {
|
|
|
|
|
|
|
|
const msg = __("Unsubscribe from %s?").replace("%s", title);
|
|
|
|
|
2019-12-10 06:10:45 +00:00
|
|
|
if (typeof title == "undefined" || confirm(msg)) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing feed...");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
const query = {op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
|
|
|
if (App.isPrefs()) {
|
2018-12-03 17:16:07 +00:00
|
|
|
dijit.byId("feedTree").reload();
|
2018-12-02 14:00:58 +00:00
|
|
|
} else {
|
|
|
|
if (feed_id == Feeds.getActive())
|
|
|
|
setTimeout(() => {
|
|
|
|
Feeds.open({feed: -5})
|
|
|
|
},
|
|
|
|
100);
|
|
|
|
|
|
|
|
if (feed_id < 0) Feeds.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2020-02-28 09:17:49 +00:00
|
|
|
editFeed: function (feed) {
|
2018-12-02 14:00:58 +00:00
|
|
|
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);
|
|
|
|
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2018-12-02 14:00:58 +00:00
|
|
|
id: "feedEditDlg",
|
|
|
|
title: __("Edit Feed"),
|
2021-02-12 12:50:06 +00:00
|
|
|
unsubscribeFeed: function(feed_id, title) {
|
|
|
|
if (confirm(__("Unsubscribe from %s?").replace("%s", title))) {
|
|
|
|
dialog.hide();
|
|
|
|
CommonDialogs.unsubscribeFeed(feed_id);
|
|
|
|
}
|
|
|
|
},
|
2018-12-02 14:00:58 +00:00
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Saving data...", true);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", dialog.attr('value'), () => {
|
|
|
|
dialog.hide();
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-03 17:16:07 +00:00
|
|
|
|
|
|
|
if (App.isPrefs())
|
2020-09-15 15:55:34 +00:00
|
|
|
dijit.byId("feedTree") && dijit.byId("feedTree").reload();
|
2018-12-03 17:16:07 +00:00
|
|
|
else
|
|
|
|
Feeds.reload();
|
|
|
|
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2021-02-12 15:38:26 +00:00
|
|
|
content: __("Loading, please wait...")
|
|
|
|
});
|
|
|
|
|
|
|
|
const tmph = dojo.connect(dialog, 'onShow', function () {
|
|
|
|
dojo.disconnect(tmph);
|
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "editfeed", id: feed}, (transport) => {
|
|
|
|
dialog.attr('content', transport.responseText);
|
|
|
|
})
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
},
|
|
|
|
genUrlChangeKey: function(feed, is_cat) {
|
|
|
|
if (confirm(__("Generate new syndication address for this feed?"))) {
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Trying to change address...", true);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
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(/&key=.*$/,
|
|
|
|
"&key=" + new_link);
|
|
|
|
|
|
|
|
e.href = e.href.replace(/&key=.*$/,
|
|
|
|
"&key=" + new_link);
|
|
|
|
|
|
|
|
new Effect.Highlight(e);
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
} else {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.error("Could not change feed URL.");
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
2021-02-11 18:42:38 +00:00
|
|
|
},
|
|
|
|
publishedOPML: function() {
|
|
|
|
|
|
|
|
Notify.progress("Loading, please wait...", true);
|
|
|
|
|
|
|
|
xhrJson("backend.php", {op: "pref-feeds", method: "getOPMLKey"}, (reply) => {
|
|
|
|
try {
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2021-02-11 19:04:39 +00:00
|
|
|
title: __("Public OPML URL"),
|
2021-02-11 18:42:38 +00:00
|
|
|
content: `
|
|
|
|
<header>${__("Your Public OPML URL is:")}</header>
|
|
|
|
<section>
|
|
|
|
<div class='panel text-center'>
|
2021-02-11 19:04:39 +00:00
|
|
|
<a id='pub_opml_url' href="${App.escapeHtml(reply.link)}" target='_blank'>${reply.link}</a>
|
2021-02-11 18:42:38 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<footer class='text-center'>
|
|
|
|
<button dojoType='dijit.form.Button' onclick="return Helpers.OPML.changeKey()">
|
|
|
|
${__('Generate new URL')}
|
|
|
|
</button>
|
|
|
|
<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>
|
|
|
|
${__('Close this window')}
|
|
|
|
</button>
|
2021-02-11 19:04:39 +00:00
|
|
|
</footer>
|
|
|
|
`
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
Notify.close();
|
|
|
|
|
|
|
|
} catch (e) {
|
2021-02-12 16:17:50 +00:00
|
|
|
App.Error.report(e);
|
2021-02-11 19:04:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2021-02-12 16:17:50 +00:00
|
|
|
generatedFeed: function(feed, is_cat, rss_url, feed_title) {
|
2021-02-11 19:04:39 +00:00
|
|
|
|
|
|
|
Notify.progress("Loading, please wait...", true);
|
|
|
|
|
|
|
|
xhrJson("backend.php", {op: "pref-feeds", method: "getFeedKey", id: feed, is_cat: is_cat}, (reply) => {
|
|
|
|
try {
|
2021-02-12 16:17:50 +00:00
|
|
|
if (!feed_title && typeof Feeds != "undefined")
|
|
|
|
feed_title = Feeds.getName(feed, is_cat);
|
|
|
|
|
2021-02-11 19:04:39 +00:00
|
|
|
const secret_url = rss_url + "&key=" + encodeURIComponent(reply.link);
|
|
|
|
|
2021-02-12 12:22:10 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
2021-02-11 19:04:39 +00:00
|
|
|
title: __("Show as feed"),
|
|
|
|
content: `
|
|
|
|
<header>${__("%s can be accessed via the following secret URL:").replace("%s", feed_title)}</header>
|
|
|
|
<section>
|
|
|
|
<div class='panel text-center'>
|
|
|
|
<a id='gen_feed_url' href="${App.escapeHtml(secret_url)}" target='_blank'>${secret_url}</a>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<footer>
|
|
|
|
<button dojoType='dijit.form.Button' style='float : left' class='alt-info'
|
|
|
|
onclick='window.open("https://tt-rss.org/wiki/GeneratedFeeds")'>
|
|
|
|
<i class='material-icons'>help</i> ${__("More info...")}</button>
|
|
|
|
<button dojoType='dijit.form.Button' onclick="return CommonDialogs.genUrlChangeKey('${feed}', '${is_cat}')">
|
|
|
|
${__('Generate new URL')}
|
|
|
|
</button>
|
|
|
|
<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>
|
|
|
|
${__('Close this window')}
|
|
|
|
</button>
|
|
|
|
</footer>
|
2021-02-11 18:42:38 +00:00
|
|
|
`
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
Notify.close();
|
|
|
|
|
|
|
|
} catch (e) {
|
2021-02-12 16:17:50 +00:00
|
|
|
App.Error.report(e);
|
2021-02-11 18:42:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2018-12-03 06:33:44 +00:00
|
|
|
};
|