subscribe to feed: use client dialog

master
Andrew Dolgov 4 years ago
parent ecb36b6354
commit 6b006a18e7

@ -581,85 +581,10 @@ class Feeds extends Handler_Protected {
return $reply; return $reply;
} }
function quickAddFeed() { function subscribeToFeed() {
print "<form onsubmit='return false'>"; print json_encode([
"cat_select" => format_feed_cat_select("cat", false, 'dojoType="fox.form.Select"')
print_hidden("op", "rpc"); ]);
print_hidden("method", "addfeed");
print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>";
print "<div id='fadd_multiple_notify' style='display : none'>";
print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.");
print "<p></div>";
print "<section>";
print "<fieldset>";
print "<div style='float : right'><img style='display : none' id='feed_add_spinner' src='images/indicator_white.gif'></div>";
print "<input style='font-size : 16px; width : 500px;'
placeHolder=\"".__("Feed or site URL")."\"
dojoType='dijit.form.ValidationTextBox' required='1' name='feed' id='feedDlg_feedUrl'>";
print "</fieldset>";
print "<fieldset>";
if (get_pref('ENABLE_FEED_CATS')) {
print "<label class='inline'>" . __('Place in category:') . "</label> ";
print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"');
}
print "</fieldset>";
print "</section>";
print '<div id="feedDlg_feedsContainer" style="display : none">
<header>' . __('Available feeds') . '</header>
<section>
<fieldset>
<select id="feedDlg_feedContainerSelect"
dojoType="fox.form.Select" size="3">
<script type="dojo/method" event="onChange" args="value">
dijit.byId("feedDlg_feedUrl").attr("value", value);
</script>
</select>
</fieldset>
</section>
</div>';
print "<div id='feedDlg_loginContainer' style='display : none'>
<section>
<fieldset>
<input dojoType=\"dijit.form.TextBox\" name='login'\"
placeHolder=\"".__("Login")."\"
autocomplete=\"new-password\"
style=\"width : 10em;\">
<input
placeHolder=\"".__("Password")."\"
dojoType=\"dijit.form.TextBox\" type='password'
autocomplete=\"new-password\"
style=\"width : 10em;\" name='pass'\">
</fieldset>
</section>
</div>";
print "<section>";
print "<label>
<label class='checkbox'><input type='checkbox' name='need_auth' dojoType='dijit.form.CheckBox' id='feedDlg_loginCheck'
onclick='App.displayIfChecked(this, \"feedDlg_loginContainer\")'>
".__('This feed requires authentication.')."</label>";
print "</section>";
print "<footer>";
print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'
onclick='App.dialogOf(this).execute()'>".__('Subscribe')."</button>";
print "<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
__('Cancel')."</button>";
print "</footer>";
print "</form>";
} }
function search() { function search() {
@ -1077,6 +1002,18 @@ class Feeds extends Handler_Protected {
} }
} }
function add() {
$feed = clean($_REQUEST['feed']);
$cat = clean($_REQUEST['cat']);
$need_auth = isset($_REQUEST['need_auth']);
$login = $need_auth ? clean($_REQUEST['login']) : '';
$pass = $need_auth ? clean($_REQUEST['pass']) : '';
$rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
print json_encode(array("result" => $rc));
}
/** /**
* @return array (code => Status code, message => error message if available) * @return array (code => Status code, message => error message if available)
* *

@ -1241,7 +1241,7 @@ class Pref_Feeds extends Handler_Protected {
<div dojoType="fox.form.DropDownButton"> <div dojoType="fox.form.DropDownButton">
<span><?= __('Feeds') ?></span> <span><?= __('Feeds') ?></span>
<div dojoType="dijit.Menu" style="display: none"> <div dojoType="dijit.Menu" style="display: none">
<div onclick="CommonDialogs.quickAddFeed()" <div onclick="CommonDialogs.subscribeToFeed()"
dojoType="dijit.MenuItem"><?= __('Subscribe to feed') ?></div> dojoType="dijit.MenuItem"><?= __('Subscribe to feed') ?></div>
<div onclick="dijit.byId('feedTree').editSelectedFeed()" <div onclick="dijit.byId('feedTree').editSelectedFeed()"
dojoType="dijit.MenuItem"><?= __('Edit selected feeds') ?></div> dojoType="dijit.MenuItem"><?= __('Edit selected feeds') ?></div>

@ -80,18 +80,6 @@ class RPC extends Handler_Protected {
} }
} }
function addfeed() {
$feed = clean($_REQUEST['feed']);
$cat = clean($_REQUEST['cat']);
$need_auth = isset($_REQUEST['need_auth']);
$login = $need_auth ? clean($_REQUEST['login']) : '';
$pass = $need_auth ? clean($_REQUEST['pass']) : '';
$rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass);
print json_encode(array("result" => $rc));
}
function togglepref() { function togglepref() {
$key = clean($_REQUEST["key"]); $key = clean($_REQUEST["key"]);
set_pref($key, !get_pref($key)); set_pref($key, !get_pref($key));

@ -838,7 +838,7 @@ const App = {
if (this.is_prefs) { if (this.is_prefs) {
this.hotkey_actions["feed_subscribe"] = () => { this.hotkey_actions["feed_subscribe"] = () => {
CommonDialogs.quickAddFeed(); CommonDialogs.subscribeToFeed();
}; };
this.hotkey_actions["create_label"] = () => { this.hotkey_actions["create_label"] = () => {
@ -994,7 +994,7 @@ const App = {
Feeds.toggleUnread(); Feeds.toggleUnread();
}; };
this.hotkey_actions["feed_subscribe"] = () => { this.hotkey_actions["feed_subscribe"] = () => {
CommonDialogs.quickAddFeed(); CommonDialogs.subscribeToFeed();
}; };
this.hotkey_actions["feed_debug_update"] = () => { this.hotkey_actions["feed_debug_update"] = () => {
if (!Feeds.activeIsCat() && parseInt(Feeds.getActive()) > 0) { if (!Feeds.activeIsCat() && parseInt(Feeds.getActive()) > 0) {
@ -1139,7 +1139,7 @@ const App = {
Feeds.search(); Feeds.search();
break; break;
case "qmcAddFeed": case "qmcAddFeed":
CommonDialogs.quickAddFeed(); CommonDialogs.subscribeToFeed();
break; break;
case "qmcDigest": case "qmcDigest":
window.location.href = "backend.php?op=digest"; window.location.href = "backend.php?op=digest";

@ -77,15 +77,93 @@ const CommonDialogs = {
return false; return false;
}, },
quickAddFeed: function() { subscribeToFeed: function() {
xhrPost("backend.php", xhrJson("backend.php",
{op: "feeds", method: "quickAddFeed"}, {op: "feeds", method: "subscribeToFeed"},
(transport) => { (reply) => {
const dialog = new fox.SingleUseDialog({ const dialog = new fox.SingleUseDialog({
id: "feedAddDlg",
title: __("Subscribe to Feed"), title: __("Subscribe to Feed"),
content: transport.responseText, content: `
<form onsubmit='return false'>
${App.FormFields.hidden("op", "feeds")}
${App.FormFields.hidden("method", "add")}
<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>
<div id='fadd_multiple_notify' style='display : none'>
<div class='alert alert-info'>
${__("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below.")}
</div>
</div>
<section>
<fieldset>
<div style='float : right'><img style='display : none' id='feed_add_spinner' src='images/indicator_white.gif'></div>
<input style='font-size : 16px; width : 500px;'
placeHolder="${__("Feed or site URL")}"
dojoType='dijit.form.ValidationTextBox'
required='1' name='feed' id='feedDlg_feedUrl'>
</fieldset>
${App.getInitParam('enable_feed_cats') ?
`
<fieldset>
<label class='inline'>${__('Place in category:')}</label>
${reply.cat_select}
</fieldset>
` : ''}
</section>
<div id="feedDlg_feedsContainer" style="display : none">
<header>${__('Available feeds')}</header>
<section>
<fieldset>
<select id="feedDlg_feedContainerSelect"
dojoType="fox.form.Select" size="3">
<script type="dojo/method" event="onChange" args="value">
dijit.byId("feedDlg_feedUrl").attr("value", value);
</script>
</select>
</fieldset>
</section>
</div>
<div id='feedDlg_loginContainer' style='display : none'>
<section>
<fieldset>
<input dojoType="dijit.form.TextBox" name='login'"
placeHolder="${__("Login")}"
autocomplete="new-password"
style="width : 10em;">
<input
placeHolder="${__("Password")}"
dojoType="dijit.form.TextBox" type='password'
autocomplete="new-password"
style="width : 10em;" name='pass'">
</fieldset>
</section>
</div>
<section>
<label class='checkbox'>
<input type='checkbox' name='need_auth' dojoType='dijit.form.CheckBox' id='feedDlg_loginCheck'
onclick='App.displayIfChecked(this, "feedDlg_loginContainer")'>
${__('This feed requires authentication.')}
</label>
</section>
<footer>
<button dojoType='dijit.form.Button' class='alt-primary' type='submit'
onclick='App.dialogOf(this).execute()'>
${__('Subscribe')}
</button>
<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>
${__('Cancel')}
</button>
</footer>
</form>
`,
show_error: function (msg) { show_error: function (msg) {
const elem = $("fadd_error_message"); const elem = $("fadd_error_message");
@ -114,7 +192,7 @@ const CommonDialogs = {
} catch (e) { } catch (e) {
Element.hide("feed_add_spinner"); 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.")); 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); console.log('subscribeToFeed, backend returned:' + transport.responseText);
return; return;
} }

Loading…
Cancel
Save