refactor feed edit dialog

This commit is contained in:
Andrew Dolgov 2010-11-20 15:29:50 +03:00
parent 141fb6e3a6
commit f9c388f509
6 changed files with 88 additions and 191 deletions

View File

@ -107,7 +107,7 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
menu.addChild(new dijit.MenuItem({ menu.addChild(new dijit.MenuItem({
label: __("Edit feed"), label: __("Edit feed"),
onClick: function() { onClick: function() {
editFeedDlg(this.getParent().row_id); editFeed(this.getParent().row_id);
}})); }}));
menu.addChild(new dijit.MenuItem({ menu.addChild(new dijit.MenuItem({

View File

@ -1330,7 +1330,7 @@ function has_local_storage() {
function catSelectOnChange(elem) { function catSelectOnChange(elem) {
try { try {
var value = elem[elem.selectedIndex].value; /* var value = elem[elem.selectedIndex].value;
var def = elem.getAttribute('default'); var def = elem.getAttribute('default');
if (value == "ADD_CAT") { if (value == "ADD_CAT") {
@ -1341,7 +1341,7 @@ function catSelectOnChange(elem) {
elem.selectedIndex = 0; elem.selectedIndex = 0;
quickAddCat(elem); quickAddCat(elem);
} } */
} catch (e) { } catch (e) {
exception_error("catSelectOnChange", e); exception_error("catSelectOnChange", e);
@ -1563,3 +1563,47 @@ function getSelectedTableRowIds(id) {
return rows; return rows;
} }
function editFeed(feed, event) {
try {
var query = "backend.php?op=pref-feeds&subop=editfeed&id=" +
param_escape(feed);
console.log(query);
if (dijit.byId("feedEditDlg"))
dijit.byId("feedEditDlg").destroyRecursive();
dialog = new dijit.Dialog({
id: "feedEditDlg",
title: __("Edit Feed"),
style: "width: 600px",
execute: function() {
if (this.validate()) {
console.log(dojo.objectToQuery(this.attr('value')));
notify_progress("Saving data...", true);
new Ajax.Request("backend.php", {
parameters: dojo.objectToQuery(dialog.attr('value')),
onComplete: function(transport) {
dialog.hide();
if (inPreferences()) {
updateFeedList();
} else {
notify('');
dlg_frefresh_callback(transport);
}
}})
}
},
href: query});
dialog.show();
} catch (e) {
exception_error("editFeed", e);
}
}

View File

@ -2998,7 +2998,7 @@
$line["id"], htmlspecialchars($line["title"])); $line["id"], htmlspecialchars($line["title"]));
} }
print "<option value=\"ADD_CAT\">" .__("Add category...") . "</option>"; # print "<option value=\"ADD_CAT\">" .__("Add category...") . "</option>";
print "</select>"; print "</select>";
} }

View File

@ -245,11 +245,6 @@
} }
if ($subop == "editfeed") { if ($subop == "editfeed") {
header("Content-Type: text/xml");
print "<dlg id=\"$subop\">";
print "<title>".__('Feed Editor')."</title>";
print "<content><![CDATA[";
$feed_id = db_escape_string($_REQUEST["id"]); $feed_id = db_escape_string($_REQUEST["id"]);
@ -260,28 +255,17 @@
$title = htmlspecialchars(db_fetch_result($result, $title = htmlspecialchars(db_fetch_result($result,
0, "title")); 0, "title"));
$icon_file = ICONS_DIR . "/$feed_id.ico"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$feed_id\">";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
if (file_exists($icon_file) && filesize($icon_file) > 0) { print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"editSave\">";
$feed_icon = "<img width=\"16\" height=\"16\"
src=\"" . ICONS_URL . "/$feed_id.ico\">";
} else {
$feed_icon = "";
}
print "<form id=\"edit_feed_form\" onsubmit=\"return false\">";
print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
print "<div class=\"dlgSec\">".__("Feed")."</div>"; print "<div class=\"dlgSec\">".__("Feed")."</div>";
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
/* Title */ /* Title */
print "<input style=\"font-size : 16px\" size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\" print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
name=\"title\" value=\"$title\">"; style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">";
/* Feed URL */ /* Feed URL */
@ -292,7 +276,8 @@
print "<br/>"; print "<br/>";
print __('URL:') . " "; print __('URL:') . " ";
print "<input size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\" print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
regExp='^(http|https)://.*' style=\"width : 20em\"
name=\"feed_url\" value=\"$feed_url\">"; name=\"feed_url\" value=\"$feed_url\">";
/* Category */ /* Category */
@ -305,7 +290,8 @@
print __('Place in category:') . " "; print __('Place in category:') . " ";
print_feed_cat_select($link, "cat_id", $cat_id, $disabled); print_feed_cat_select($link, "cat_id", $cat_id,
'dojoType="dijit.form.Select"');
} }
print "</div>"; print "</div>";
@ -317,14 +303,17 @@
$update_interval = db_fetch_result($result, 0, "update_interval"); $update_interval = db_fetch_result($result, 0, "update_interval");
print_select_hash("update_interval", $update_interval, $update_intervals); print_select_hash("update_interval", $update_interval, $update_intervals,
'dojoType="dijit.form.Select"');
/* Update method */ /* Update method */
$update_method = db_fetch_result($result, 0, "update_method"); $update_method = db_fetch_result($result, 0, "update_method",
'dojoType="dijit.form.Select"');
print " " . __('using') . " "; print " " . __('using') . " ";
print_select_hash("update_method", $update_method, $update_methods); print_select_hash("update_method", $update_method, $update_methods,
'dojoType="dijit.form.Select"');
$purge_interval = db_fetch_result($result, 0, "purge_interval"); $purge_interval = db_fetch_result($result, 0, "purge_interval");
@ -336,7 +325,8 @@
print __('Article purging:') . " "; print __('Article purging:') . " ";
print_select_hash("purge_interval", $purge_interval, $purge_intervals); print_select_hash("purge_interval", $purge_interval, $purge_intervals,
'dojoType="dijit.form.Select"');
} else { } else {
print "<input type='hidden' name='purge_interval' value='$purge_interval'>"; print "<input type='hidden' name='purge_interval' value='$purge_interval'>";
@ -353,15 +343,14 @@
print "<tr><td>" . __('Login:') . "</td><td>"; print "<tr><td>" . __('Login:') . "</td><td>";
print "<input size=\"20\" onkeypress=\"return filterCR(event, feedEditSave)\" print "<input dojoType=\"dijit.form.TextBox\"
name=\"auth_login\" value=\"$auth_login\">"; name=\"auth_login\" value=\"$auth_login\">";
print "</tr><tr><td>" . __("Password:") . "</td><td>"; print "</tr><tr><td>" . __("Password:") . "</td><td>";
$auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass")); $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass"));
print "<input size=\"20\" type=\"password\" name=\"auth_pass\" print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
onkeypress=\"return filterCR(event, feedEditSave)\"
value=\"$auth_pass\">"; value=\"$auth_pass\">";
print "</td></tr></table>"; print "</td></tr></table>";
@ -370,39 +359,39 @@
print "<div class=\"dlgSec\">".__("Options")."</div>"; print "<div class=\"dlgSec\">".__("Options")."</div>";
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
print "<div style=\"line-height : 100%\">"; # print "<div style=\"line-height : 100%\">";
$private = sql_bool_to_bool(db_fetch_result($result, 0, "private")); $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
if ($private) { if ($private) {
$checked = "checked"; $checked = "checked=\"1\"";
} else { } else {
$checked = ""; $checked = "";
} }
print "<input type=\"checkbox\" name=\"private\" id=\"private\" print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\"
$checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>"; $checked>&nbsp;<label for=\"private\">".__('Hide from Popular feeds')."</label>";
$rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
if ($rtl_content) { if ($rtl_content) {
$checked = "checked"; $checked = "checked=\"1\"";
} else { } else {
$checked = ""; $checked = "";
} }
print "<br/><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\" print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
$checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>"; $checked>&nbsp;<label for=\"rtl_content\">".__('Right-to-left content')."</label>";
$include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest")); $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
if ($include_in_digest) { if ($include_in_digest) {
$checked = "checked"; $checked = "checked=\"1\"";
} else { } else {
$checked = ""; $checked = "";
} }
print "<br/><input type=\"checkbox\" id=\"include_in_digest\" print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"
name=\"include_in_digest\" name=\"include_in_digest\"
$checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; $checked>&nbsp;<label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
@ -415,7 +404,7 @@
$checked = ""; $checked = "";
} }
print "<br/><input type=\"checkbox\" id=\"always_display_enclosures\" print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"
name=\"always_display_enclosures\" name=\"always_display_enclosures\"
$checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; $checked>&nbsp;<label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
@ -423,21 +412,19 @@
$cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
if ($cache_images) { if ($cache_images) {
$checked = "checked"; $checked = "checked=\"1\"";
} else { } else {
$checked = ""; $checked = "";
} }
print "<br/><input type=\"checkbox\" id=\"cache_images\" print "<br/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\"
name=\"cache_images\" name=\"cache_images\"
$checked>&nbsp;<label for=\"cache_images\">". $checked>&nbsp;<label for=\"cache_images\">".
__('Cache images locally (SimplePie only)')."</label>"; __('Cache images locally (SimplePie only)')."</label>";
# print "</div>";
print "</div>"; print "</div>";
print "</div>";
print "</form>";
/* Icon */ /* Icon */
@ -456,9 +443,9 @@
<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=\"subop\" value=\"uploadicon\"> <input type=\"hidden\" name=\"subop\" value=\"uploadicon\">
<button onclick=\"return uploadFeedIcon();\" <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\"
type=\"submit\">".__('Replace')."</button> type=\"submit\">".__('Replace')."</button>
<button onclick=\"return removeFeedIcon($feed_id);\" <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\"
type=\"submit\">".__('Remove')."</button> type=\"submit\">".__('Remove')."</button>
</form>"; </form>";
@ -468,14 +455,12 @@
print "<div class='dlgButtons'> print "<div class='dlgButtons'>
<div style=\"float : left\"> <div style=\"float : left\">
<button onclick='return unsubscribeFeed($feed_id, \"$title\")'>". <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>".
__('Unsubscribe')."</button> __('Unsubscribe')."</button>
</div> </div>
<button onclick=\"return feedEditSave()\">".__('Save')."</button> <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button>
<button onclick=\"return feedEditCancel()\">".__('Cancel')."</button> <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button>
</div>"; </div>";
print "]]></content></dlg>";
return; return;
} }

View File

@ -347,39 +347,6 @@ function editFilter(id, event) {
} }
} }
function editFeed(feed, event) {
try {
if (event && !event.ctrlKey) {
notify_progress("Loading, please wait...");
// selectTableRows('prefFeedList', 'none');
// selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
var query = "?op=pref-feeds&subop=editfeed&id=" +
param_escape(feed);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
infobox_callback2(transport);
document.forms["edit_feed_form"].title.focus();
} });
} else if (event.ctrlKey) {
// var cb = $('FRCHK-' + feed);
// cb.checked = !cb.checked;
// toggleSelectRow(cb);
}
} catch (e) {
exception_error("editFeed", e);
}
}
function getSelectedLabels() { function getSelectedLabels() {
var tree = dijit.byId("labelTree"); var tree = dijit.byId("labelTree");
var items = tree.model.getCheckedItems(); var items = tree.model.getCheckedItems();
@ -679,36 +646,6 @@ function removeSelectedFeedCats() {
return false; return false;
} }
function feedEditCancel() {
closeInfoBox();
return false;
}
function feedEditSave() {
try {
// FIXME: add parameter validation
var query = Form.serialize("edit_feed_form");
notify_progress("Saving feed...");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
feedlist_callback2(transport);
} });
closeInfoBox();
return false;
} catch (e) {
exception_error("feedEditSave", e);
}
}
function userEditCancel() { function userEditCancel() {
closeInfoBox(); closeInfoBox();
return false; return false;
@ -1080,6 +1017,7 @@ function init() {
dojo.require("dijit.form.Select"); dojo.require("dijit.form.Select");
dojo.require("dijit.form.FilteringSelect"); dojo.require("dijit.form.FilteringSelect");
dojo.require("dijit.form.TextBox"); dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.CheckBox");
dojo.require("dijit.form.ValidationTextBox"); dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.RadioButton"); dojo.require("dijit.form.RadioButton");
dojo.require("dijit.form.Select"); dojo.require("dijit.form.Select");

View File

@ -279,6 +279,7 @@ function init() {
dojo.require("dijit.form.TextBox"); dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.ValidationTextBox"); dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.FilteringSelect"); dojo.require("dijit.form.FilteringSelect");
dojo.require("dijit.form.CheckBox");
dojo.require("dijit.Toolbar"); dojo.require("dijit.Toolbar");
dojo.require("dijit.ProgressBar"); dojo.require("dijit.ProgressBar");
dojo.require("dijit.Menu"); dojo.require("dijit.Menu");
@ -375,7 +376,7 @@ function quickMenuGo(opid) {
} }
if (opid == "qmcEditFeed") { if (opid == "qmcEditFeed") {
editFeedDlg(getActiveFeedId()); editFeed(getActiveFeedId());
} }
if (opid == "qmcRemoveFeed") { if (opid == "qmcRemoveFeed") {
@ -530,77 +531,6 @@ function catchupFeedInGroup(id) {
} }
} }
function editFeedDlg(feed) {
try {
if (!feed) {
alert(__("Please select some feed first."));
return;
}
if ((feed <= 0) || activeFeedIsCat()) {
alert(__("You can't edit this kind of feed."));
return;
}
var query = "";
if (feed > 0) {
query = "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed);
} else {
query = "?op=pref-labels&subop=edit&id=" + param_escape(-feed-11);
}
disableHotkeys();
notify_progress("Loading, please wait...", true);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
infobox_callback2(transport);
document.forms["edit_feed_form"].title.focus();
} });
} catch (e) {
exception_error("editFeedDlg", e);
}
}
/* this functions duplicate those of prefs.js feed editor, with
some differences because there is no feedlist */
function feedEditCancel() {
closeInfoBox();
return false;
}
function feedEditSave() {
try {
// FIXME: add parameter validation
var query = Form.serialize("edit_feed_form");
notify_progress("Saving feed...");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
dlg_frefresh_callback(transport);
} });
cache_flush();
closeInfoBox();
return false;
} catch (e) {
exception_error("feedEditSave (main)", e);
}
}
function collapse_feedlist() { function collapse_feedlist() {
try { try {
@ -913,7 +843,7 @@ function hotkey_handler(e) {
} }
if (keycode == 69) { // e if (keycode == 69) { // e
editFeedDlg(getActiveFeedId()); editFeed(getActiveFeedId());
return false; return false;
} }