opml import: no more iframe, use client dialog

This commit is contained in:
Andrew Dolgov 2021-02-12 08:22:00 +03:00
parent 3134d71b8f
commit 83b0738b04
3 changed files with 42 additions and 32 deletions

View File

@ -13,28 +13,6 @@ class Dlg extends Handler_Protected {
return false; return false;
} }
function importOpml() {
print_notice("If you have imported labels and/or filters, you might need to reload preferences to see your new data.");
print "<div class='panel panel-scrollable'>";
$opml = new OPML($_REQUEST);
$opml->opml_import($_SESSION["uid"]);
print "</div>";
print "<footer class='text-center'>";
print "<button dojoType='dijit.form.Button'
onclick=\"dijit.byId('opmlImportDlg').execute()\">".
__('Close this window')."</button>";
print "</footer>";
print "</div>";
//return;
}
function printTagCloud() { function printTagCloud() {
print "<div class='panel text-center'>"; print "<div class='panel text-center'>";

View File

@ -1194,6 +1194,11 @@ class Pref_Feeds extends Handler_Protected {
Feeds::add_feed_category($feed_cat); Feeds::add_feed_category($feed_cat);
} }
function importOpml() {
$opml = new OPML($_REQUEST);
$opml->opml_import($_SESSION["uid"]);
}
function index() { function index() {
print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; print "<div dojoType='dijit.layout.AccordionContainer' region='center'>";
@ -1340,17 +1345,11 @@ class Pref_Feeds extends Handler_Protected {
print_notice("Only main settings profile can be migrated using OPML."); print_notice("Only main settings profile can be migrated using OPML.");
print "<iframe id=\"upload_iframe\" print "<form id='opml_import_form' method='post' enctype='multipart/form-data' >
name=\"upload_iframe\" onload=\"Helpers.OPML.onImportComplete(this)\"
style=\"width: 400px; height: 100px; display: none;\"></iframe>";
print "<form name='opml_form' style='display : inline-block' target='upload_iframe'
enctype='multipart/form-data' method='POST'
action='backend.php'>
<label class='dijitButton'>".__("Choose file...")." <label class='dijitButton'>".__("Choose file...")."
<input style='display : none' id='opml_file' name='opml_file' type='file'>&nbsp; <input style='display : none' id='opml_file' name='opml_file' type='file'>&nbsp;
</label> </label>
<input type='hidden' name='op' value='dlg'> <input type='hidden' name='op' value='pref-feeds'>
<input type='hidden' name='csrf_token' value='".$_SESSION['csrf_token']."'> <input type='hidden' name='csrf_token' value='".$_SESSION['csrf_token']."'>
<input type='hidden' name='method' value='importOpml'> <input type='hidden' name='method' value='importOpml'>
<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return Helpers.OPML.import();\" type=\"submit\">" . <button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return Helpers.OPML.import();\" type=\"submit\">" .

View File

@ -220,9 +220,42 @@ const Helpers = {
} else { } else {
Notify.progress("Importing, please wait...", true); Notify.progress("Importing, please wait...", true);
Element.show("upload_iframe"); const xhr = new XMLHttpRequest();
return true; xhr.open( 'POST', 'backend.php', true );
xhr.onload = function () {
Notify.close();
const dialog = new dijit.Dialog({
title: __("OPML Import"),
style: "width: 600px",
onCancel: function () {
window.location.reload();
},
execute: function () {
window.location.reload();
},
content: `
<div class='alert alert-info'>
${__("If you have imported labels and/or filters, you might need to reload preferences to see your new data.")}
</div>
<div class='panel panel-scrollable'>
${xhr.responseText}
</div>
<footer class='text-center'>
<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>
${__('Close this window')}
</button>
</footer>
`
});
dialog.show();
};
xhr.send(new FormData($("opml_import_form")));
return false;
} }
}, },
onImportComplete: function(iframe) { onImportComplete: function(iframe) {