'use strict' /* eslint-disable new-cap */ /* eslint-disable no-new */ /* global __, dojo, dijit, Notify, App, Feeds, xhr, Tables, fox */ /* exported CommonDialogs */ const CommonDialogs = { closeInfoBox: function() { const dialog = dijit.byId("infoBox"); if (dialog) dialog.hide(); }, subscribeToFeed: function() { xhr.json("backend.php", {op: "feeds", method: "subscribeToFeed"}, (reply) => { const dialog = new fox.SingleUseDialog({ title: __("Subscribe to feed"), content: `
`, show_error: function (msg) { const elem = App.byId("fadd_error_message"); elem.innerHTML = msg; Element.show(elem); }, execute: function () { if (this.validate()) { console.log(dojo.objectToQuery(this.attr('value'))); const feed_url = this.attr('value').feed; Element.show("feed_add_spinner"); Element.hide("fadd_error_message"); xhr.json("backend.php", this.attr('value'), (reply) => { try { if (!reply) { 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.")); return; } const rc = reply['result']; Notify.close(); Element.hide("feed_add_spinner"); console.log(rc); switch (parseInt(rc['code'])) { case 0: dialog.show_error(__("You are already subscribed to this feed.")); break; 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]}); } } Element.show('feedDlg_feedsContainer'); } 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 7: dialog.show_error(__("Error while creating feed database entry.")); break; case 8: dialog.show_error(__("You are not allowed to perform this operation.")); break; } } catch (e) { console.error(reply); App.Error.report(e); } }); } }, }); dialog.show(); }); }, showFeedsWithErrors: function() { xhr.json("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (reply) => { const dialog = new fox.SingleUseDialog({ id: "errorFeedsDlg", title: __("Feeds with update errors"), getSelectedFeeds: function () { return Tables.getSelected("error-feeds-list"); }, removeSelected: function () { const sel_rows = this.getSelectedFeeds(); if (sel_rows.length > 0) { if (confirm(__("Remove selected feeds?"))) { Notify.progress("Removing selected feeds...", true); const query = { op: "pref-feeds", method: "remove", ids: sel_rows.toString() }; xhr.post("backend.php", query, () => { Notify.close(); dialog.hide(); if (App.isPrefs()) dijit.byId("feedTree").reload(); else Feeds.reload(); }); } } else { alert(__("No feeds selected.")); } }, content: `${App.escapeHtml(row.title)} | ${App.escapeHtml(row.last_error)} |