fix feed icon upload not working, rework form to use FormData/ajax

master
Andrew Dolgov 6 years ago
parent 08183fcd27
commit 019f4578bc

@ -473,6 +473,7 @@ class Pref_Feeds extends Handler_Protected {
$icon_file = $tmp_file; $icon_file = $tmp_file;
$feed_id = clean($_REQUEST["feed_id"]); $feed_id = clean($_REQUEST["feed_id"]);
$rc = 2; // failed
if (is_file($icon_file) && $feed_id) { if (is_file($icon_file) && $feed_id) {
if (filesize($icon_file) < 65535) { if (filesize($icon_file) < 65535) {
@ -492,21 +493,15 @@ class Pref_Feeds extends Handler_Protected {
$rc = 0; $rc = 0;
} }
} else {
$rc = 2;
} }
} else { } else {
$rc = 1; $rc = 1;
} }
} else {
$rc = 2;
} }
if (is_file($icon_file)) @unlink($icon_file); if (is_file($icon_file)) @unlink($icon_file);
print "<script type=\"text/javascript\">"; print $rc;
print "parent.CommonDialogs.uploadIconHandler($rc);";
print "</script>";
return; return;
} }
@ -766,20 +761,16 @@ class Pref_Feeds extends Handler_Protected {
/* Icon */ /* Icon */
print "<img class='feedIcon' src=\"".Feeds::getFeedIcon($feed_id)."\">"; print "<img class='feedIcon feed-editor-icon' src=\"".Feeds::getFeedIcon($feed_id)."\">";
print "<iframe name='icon_upload_iframe'
style='width: 400px; height: 100px; display: none;'></iframe>";
print "<form style='display : block' target='icon_upload_iframe' print "<form onsubmit='return false;' id='feed_icon_upload_form'
enctype='multipart/form-data' method='POST' enctype='multipart/form-data' method='POST'>
action='backend.php'>
<label class='dijitButton'>".__("Choose file...")." <label class='dijitButton'>".__("Choose file...")."
<input style='display: none' id='icon_file' size='10' name='icon_file' type='file'> <input style='display: none' id='icon_file' size='10' name='icon_file' type='file'>
</label> </label>
<input type='hidden' name='op' value='pref-feeds'> <input type='hidden' name='op' value='pref-feeds'>
<input type='hidden' name='feed_id' value=\"$feed_id\"> <input type='hidden' name='feed_id' value='$feed_id'>
<input type='hidden' name='method' value=\"uploadicon\"> <input type='hidden' name='method' value='uploadicon'>
<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.uploadFeedIcon();\" <button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.uploadFeedIcon();\"
type='submit'>".__('Replace')."</button> type='submit'>".__('Replace')."</button>
<button class='alt-danger' dojoType='dijit.form.Button' onclick=\"return CommonDialogs.removeFeedIcon($feed_id);\" <button class='alt-danger' dojoType='dijit.form.Button' onclick=\"return CommonDialogs.removeFeedIcon($feed_id);\"

@ -7,25 +7,6 @@ define(["dojo/_base/declare"], function (declare) {
const dialog = dijit.byId("infoBox"); const dialog = dijit.byId("infoBox");
if (dialog) dialog.hide(); if (dialog) dialog.hide();
}, },
uploadIconHandler: function(rc) {
switch (rc) {
case 0:
Notify.info("Upload complete.");
if (App.isPrefs())
dijit.byId("feedTree").reload();
else
Feeds.reload();
break;
case 1:
Notify.error("Upload failed: icon is too big.");
break;
case 2:
Notify.error("Upload failed.");
break;
}
},
removeFeedIcon: function(id) { removeFeedIcon: function(id) {
if (confirm(__("Remove stored feed icon?"))) { if (confirm(__("Remove stored feed icon?"))) {
Notify.progress("Removing feed icon...", true); Notify.progress("Removing feed icon...", true);
@ -40,6 +21,11 @@ define(["dojo/_base/declare"], function (declare) {
else else
Feeds.reload(); Feeds.reload();
const icon = $$(".feed-editor-icon")[0];
if (icon)
icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime());
}); });
} }
@ -52,7 +38,35 @@ define(["dojo/_base/declare"], function (declare) {
alert(__("Please select an image file to upload.")); alert(__("Please select an image file to upload."));
} else if (confirm(__("Upload new icon for this feed?"))) { } else if (confirm(__("Upload new icon for this feed?"))) {
Notify.progress("Uploading, please wait...", true); Notify.progress("Uploading, please wait...", true);
return true;
const xhr = new XMLHttpRequest();
xhr.open( 'POST', 'backend.php', true );
xhr.onload = function () {
switch (parseInt(this.responseText)) {
case 0:
Notify.info("Upload complete.");
if (App.isPrefs())
dijit.byId("feedTree").reload();
else
Feeds.reload();
const icon = $$(".feed-editor-icon")[0];
if (icon)
icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime());
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")));
} }
return false; return false;
@ -466,4 +480,4 @@ define(["dojo/_base/declare"], function (declare) {
}; };
return CommonDialogs; return CommonDialogs;
}); });

Loading…
Cancel
Save