rework batch feed editor

This commit is contained in:
Andrew Dolgov 2010-11-21 11:55:28 +03:00
parent 29f118253d
commit 05acc0d653
3 changed files with 154 additions and 248 deletions

View file

@ -1476,7 +1476,7 @@ function editFeed(feed, event) {
style: "width: 600px", style: "width: 600px",
execute: function() { execute: function() {
if (this.validate()) { if (this.validate()) {
console.log(dojo.objectToQuery(this.attr('value'))); // console.log(dojo.objectToQuery(this.attr('value')));
notify_progress("Saving data...", true); notify_progress("Saving data...", true);

View file

@ -2,7 +2,7 @@
function batch_edit_cbox($elem, $label = false) { function batch_edit_cbox($elem, $label = false) {
print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
onchange=\"batchFeedsToggleField(this, '$elem', '$label')\">"; onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">";
} }
function module_pref_feeds($link) { function module_pref_feeds($link) {
@ -472,25 +472,19 @@
if ($subop == "editfeeds") { if ($subop == "editfeeds") {
$feed_ids = db_escape_string($_REQUEST["ids"]); $feed_ids = db_escape_string($_REQUEST["ids"]);
header("Content-Type: text/xml");
print "<dlg id=\"$subop\">";
print "<title>".__('Multiple Feed Editor')."</title>";
print "<content><![CDATA[";
print "<form id=\"batch_edit_feed_form\" onsubmit=\"return false\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">";
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">";
print "<input type=\"hidden\" name=\"ids\" value=\"$feed_ids\">"; print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"batchEditSave\">";
print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
print "<input type=\"hidden\" name=\"subop\" value=\"batchEditSave\">";
print "<div class=\"dlgSec\">".__("Feed")."</div>"; print "<div class=\"dlgSec\">".__("Feed")."</div>";
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
/* Title */ /* Title */
print "<input disabled style=\"font-size : 16px\" size=\"35\" onkeypress=\"return filterCR(event, feedEditSave)\" print "<input dojoType=\"dijit.form.ValidationTextBox\"
name=\"title\" value=\"$title\">"; disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\"
name=\"title\" value=\"$title\">";
batch_edit_cbox("title"); batch_edit_cbox("title");
@ -499,7 +493,8 @@
print "<br/>"; print "<br/>";
print __('URL:') . " "; print __('URL:') . " ";
print "<input disabled size=\"40\" onkeypress=\"return filterCR(event, feedEditSave)\" print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\"
required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\"
name=\"feed_url\" value=\"$feed_url\">"; name=\"feed_url\" value=\"$feed_url\">";
batch_edit_cbox("feed_url"); batch_edit_cbox("feed_url");
@ -512,7 +507,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,
'disabled="1" dojoType="dijit.form.Select"');
batch_edit_cbox("cat_id"); batch_edit_cbox("cat_id");
@ -526,7 +522,7 @@
/* Update Interval */ /* Update Interval */
print_select_hash("update_interval", $update_interval, $update_intervals, print_select_hash("update_interval", $update_interval, $update_intervals,
"disabled"); 'disabled="1" dojoType="dijit.form.Select"');
batch_edit_cbox("update_interval"); batch_edit_cbox("update_interval");
@ -534,19 +530,19 @@
print " " . __('using') . " "; print " " . __('using') . " ";
print_select_hash("update_method", $update_method, $update_methods, print_select_hash("update_method", $update_method, $update_methods,
"disabled"); 'disabled="1" dojoType="dijit.form.Select"');
batch_edit_cbox("update_method"); batch_edit_cbox("update_method");
/* Purge intl */ /* Purge intl */
if (FORCE_ARTICLE_PURGE != 0) { if (FORCE_ARTICLE_PURGE == 0) {
print "<br/>"; print "<br/>";
print __('Article purging:') . " "; print __('Article purging:') . " ";
print_select_hash("purge_interval", $purge_interval, $purge_intervals, print_select_hash("purge_interval", $purge_interval, $purge_intervals,
"disabled"); 'disabled="1" dojoType="dijit.form.Select"');
batch_edit_cbox("purge_interval"); batch_edit_cbox("purge_interval");
} }
@ -555,16 +551,14 @@
print "<div class=\"dlgSec\">".__("Authentication")."</div>"; print "<div class=\"dlgSec\">".__("Authentication")."</div>";
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
print __('Login:') . " "; print "<input dojoType=\"dijit.form.TextBox\"
print "<input disabled size=\"15\" onkeypress=\"return filterCR(event, feedEditSave)\" placeHolder=\"".__("Login")."\" disabled=\"1\"
name=\"auth_login\" value=\"$auth_login\">"; name=\"auth_login\" value=\"$auth_login\">";
batch_edit_cbox("auth_login"); batch_edit_cbox("auth_login");
print " " . __("Password:") . " "; print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\"
placeHolder=\"".__("Password")."\" disabled=\"1\"
print "<input disabled size=\"15\" type=\"password\" name=\"auth_pass\"
onkeypress=\"return filterCR(event, feedEditSave)\"
value=\"$auth_pass\">"; value=\"$auth_pass\">";
batch_edit_cbox("auth_pass"); batch_edit_cbox("auth_pass");
@ -573,55 +567,48 @@
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 "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\"
dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
print "<input disabled type=\"checkbox\" name=\"private\" id=\"private\"
$checked>&nbsp;<label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>";
print "&nbsp;"; batch_edit_cbox("private", "private_l"); print "&nbsp;"; batch_edit_cbox("private", "private_l");
print "<br/><input disabled type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\" print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
$checked>&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>"; dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>";
print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l"); print "&nbsp;"; batch_edit_cbox("rtl_content", "rtl_content_l");
print "<br/><input disabled type=\"checkbox\" id=\"include_in_digest\" print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\"
name=\"include_in_digest\" name=\"include_in_digest\"
$checked>&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>";
print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l"); print "&nbsp;"; batch_edit_cbox("include_in_digest", "include_in_digest_l");
print "<br/><input disabled type=\"checkbox\" id=\"always_display_enclosures\" print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\"
name=\"always_display_enclosures\" name=\"always_display_enclosures\"
$checked>&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; dojoType=\"dijit.form.CheckBox\">&nbsp;<label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>";
print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); print "&nbsp;"; batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
print "<br/><input disabled type=\"checkbox\" id=\"cache_images\" print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\"
name=\"cache_images\" name=\"cache_images\"
$checked>&nbsp;<label class='insensitive' id=\"cache_images_l\" dojoType=\"dijit.form.CheckBox\">&nbsp;<label class='insensitive' id=\"cache_images_l\"
for=\"cache_images\">". for=\"cache_images\">".
__('Cache images locally')."</label>"; __('Cache images locally')."</label>";
if (SIMPLEPIE_CACHE_IMAGES) { print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
print "&nbsp;"; batch_edit_cbox("cache_images", "cache_images_l");
}
print "</div>"; print "</div>";
print "</div>";
print "</form>";
print "<div class='dlgButtons'> print "<div class='dlgButtons'>
<input type=\"submit\" class=\"button\" <input type=\"submit\" class=\"button\"
onclick=\"return feedsEditSave()\" value=\"".__('Save')."\"> onclick=\"return dijit.byId('feedEditDlg').execute()\"
value=\"".__('Save')."\">
<input type='submit' class='button' <input type='submit' class='button'
onclick=\"return closeInfoBox()\" value=\"".__('Cancel')."\"> onclick=\"return dijit.byId('feedEditDlg').hide()\"
value=\"".__('Cancel')."\">
</div>"; </div>";
print "]]></content></dlg>";
return; return;
} }
@ -763,7 +750,7 @@
db_query($link, "COMMIT"); db_query($link, "COMMIT");
} }
return;
} }
if ($subop == "remove") { if ($subop == "remove") {

315
prefs.js
View file

@ -1,5 +1,3 @@
var active_feed_cat = false;
var init_params = new Array(); var init_params = new Array();
var caller_subop = false; var caller_subop = false;
@ -759,16 +757,78 @@ function editSelectedFeeds() {
notify(""); notify("");
notify_progress("Loading, please wait...", true); var query = "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
var query = "?op=pref-feeds&subop=editfeeds&ids=" +
param_escape(rows.toString()); param_escape(rows.toString());
new Ajax.Request("backend.php", { if (dijit.byId("feedEditDlg"))
parameters: query, dijit.byId("feedEditDlg").destroyRecursive();
onComplete: function(transport) {
infobox_callback2(transport); dialog = new dijit.Dialog({
} }); id: "feedEditDlg",
title: __("Edit Multiple Feeds"),
style: "width: 600px",
getChildByName: function (name) {
var rv = null
this.getChildren().each(
function(child) {
if (child.name == name) {
rv = child;
return;
}
});
return rv;
},
toggleField: function (checkbox, elem, label) {
this.getChildByName(elem).attr('disabled', !checkbox.checked);
if ($(label))
if (checkbox.checked)
$(label).removeClassName('insensitive');
else
$(label).addClassName('insensitive');
},
execute: function() {
if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
var query = dojo.objectToQuery(this.attr('value'));
/* Form.serialize ignores unchecked checkboxes */
if (!query.match("&rtl_content=") &&
this.getChildByName('rtl_content').attr('disabled') == false) {
query = query + "&rtl_content=false";
}
if (!query.match("&private=") &&
this.getChildByName('private').attr('disabled') == false) {
query = query + "&private=false";
}
if (!query.match("&cache_images=") &&
this.getChildByName('cache_images').attr('disabled') == false) {
query = query + "&cache_images=false";
}
if (!query.match("&include_in_digest=") &&
this.getChildByName('include_in_digest').attr('disabled') == false) {
query = query + "&include_in_digest=false";
}
console.log(query);
notify_progress("Saving data...", true);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
dialog.hide();
updateFeedList();
}})
}
},
href: query});
dialog.show();
} catch (e) { } catch (e) {
exception_error("editSelectedFeeds", e); exception_error("editSelectedFeeds", e);
@ -800,81 +860,35 @@ function opmlImport() {
} }
} }
function updateFilterList(sort_key) { function updateFilterList() {
try { new Ajax.Request("backend.php", {
parameters: "?op=pref-filters",
var filter_search = $("filter_search"); onComplete: function(transport) {
var search = ""; filterlist_callback2(transport);
if (filter_search) { search = filter_search.value; } } });
var query = "?op=pref-filters&sort=" +
param_escape(sort_key) +
"&search=" + param_escape(search);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
filterlist_callback2(transport);
} });
} catch (e) {
exception_error("updateFilterList", e);
}
} }
function updateLabelList(sort_key) { function updateLabelList() {
new Ajax.Request("backend.php", {
try { parameters: "?op=pref-labels",
onComplete: function(transport) {
var label_search = $("label_search"); labellist_callback2(transport);
var search = ""; } });
if (label_search) { search = label_search.value; }
var query = "?op=pref-labels&sort=" +
param_escape(sort_key) +
"&search=" + param_escape(search);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
labellist_callback2(transport);
} });
} catch (e) {
exception_error("updateLabelList", e);
}
} }
function updatePrefsList() { function updatePrefsList() {
var query = "?op=pref-prefs";
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: "?op=pref-prefs",
onComplete: function(transport) { onComplete: function(transport) {
prefslist_callback2(transport); prefslist_callback2(transport);
} }); } });
} }
function selectTab(id, noupdate, subop) { function selectTab(id, noupdate, subop) {
try { try {
if (!noupdate) { if (!noupdate) {
console.log("selectTab: " + id + "(NU: " + noupdate + ")");
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
// close active infobox if needed
closeInfoBox(); closeInfoBox();
// clean up all current selections, just in case
active_feed_cat = false;
// Effect.Fade("prefContent", {duration: 1, to: 0.01,
// queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
if (id == "feedConfig") { if (id == "feedConfig") {
updateFeedList(); updateFeedList();
@ -892,14 +906,6 @@ function selectTab(id, noupdate, subop) {
dijit.byId("pref-tabs").selectChild(tab); dijit.byId("pref-tabs").selectChild(tab);
} }
/* clean selection from all tabs */
$$("#prefTabs div").invoke('removeClassName', 'Selected');
/* mark new tab as selected */
$(id + "Tab").addClassName("Selected");
} catch (e) { } catch (e) {
exception_error("selectTab", e); exception_error("selectTab", e);
@ -907,7 +913,6 @@ function selectTab(id, noupdate, subop) {
} }
function init_second_stage() { function init_second_stage() {
try { try {
document.onkeydown = pref_hotkey_handler; document.onkeydown = pref_hotkey_handler;
@ -923,15 +928,13 @@ function init_second_stage() {
notify(""); notify("");
dojo.addOnLoad(function() { dojo.addOnLoad(function() {
var tab = getURLParam('tab'); var tab = getURLParam('tab');
if (tab) { if (tab) {
tab = dijit.byId(tab + "Tab"); tab = dijit.byId(tab + "Tab");
if (tab) dijit.byId("pref-tabs").selectChild(tab); if (tab) dijit.byId("pref-tabs").selectChild(tab);
} }
});
});
setTimeout("hotkey_prefix_timeout()", 5*1000); setTimeout("hotkey_prefix_timeout()", 5*1000);
@ -1467,85 +1470,6 @@ function removeFilter(id, title) {
return false; return false;
} }
function feedsEditSave() {
try {
var ok = confirm(__("Save changes to selected feeds?"));
if (ok) {
var f = document.forms["batch_edit_feed_form"];
var query = Form.serialize("batch_edit_feed_form");
/* Form.serialize ignores unchecked checkboxes */
if (!query.match("&rtl_content=") &&
f.rtl_content.disabled == false) {
query = query + "&rtl_content=false";
}
if (!query.match("&private=") &&
f.private.disabled == false) {
query = query + "&private=false";
}
if (!query.match("&cache_images=") &&
f.cache_images.disabled == false) {
query = query + "&cache_images=false";
}
if (!query.match("&include_in_digest=") &&
f.include_in_digest.disabled == false) {
query = query + "&include_in_digest=false";
}
closeInfoBox();
notify_progress("Saving feeds...");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
feedlist_callback2(transport);
} });
}
return false;
} catch (e) {
exception_error("feedsEditSave", e);
}
}
function batchFeedsToggleField(cb, elem, label) {
try {
var f = document.forms["batch_edit_feed_form"];
var l = $(label);
if (cb.checked) {
f[elem].disabled = false;
if (l) {
l.className = "";
};
// new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
// queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
} else {
f[elem].disabled = true;
if (l) {
l.className = "insensitive";
};
}
} catch (e) {
exception_error("batchFeedsToggleField", e);
}
}
function labelColorReset() { function labelColorReset() {
try { try {
var labels = getSelectedLabels(); var labels = getSelectedLabels();
@ -1569,43 +1493,6 @@ function labelColorReset() {
} }
} }
function setLabelColor(id, fg, bg) {
try {
var kind = '';
var color = '';
if (fg && bg) {
kind = 'both';
} else if (fg) {
kind = 'fg';
color = fg;
} else if (bg) {
kind = 'bg';
color = bg;
}
var query = "?op=pref-labels&subop=color-set&kind="+kind+
"&ids=" + param_escape(id) + "&fg=" + param_escape(fg) +
"&bg=" + param_escape(bg) + "&color=" + param_escape(color);
// console.log(query);
var e = $("LICID-" + id);
if (e) {
if (fg) e.style.color = fg;
if (bg) e.style.backgroundColor = bg;
}
new Ajax.Request("backend.php", { parameters: query });
updateFilterList();
} catch (e) {
exception_error("colorPickerDo", e);
}
}
function inPreferences() { function inPreferences() {
return true; return true;
@ -1766,6 +1653,38 @@ function editLabel(id, event) {
id: "labelEditDlg", id: "labelEditDlg",
title: __("Label Editor"), title: __("Label Editor"),
style: "width: 600px", style: "width: 600px",
setLabelColor: function(id, fg, bg) {
var kind = '';
var color = '';
if (fg && bg) {
kind = 'both';
} else if (fg) {
kind = 'fg';
color = fg;
} else if (bg) {
kind = 'bg';
color = bg;
}
var query = "?op=pref-labels&subop=color-set&kind="+kind+
"&ids=" + param_escape(id) + "&fg=" + param_escape(fg) +
"&bg=" + param_escape(bg) + "&color=" + param_escape(color);
// console.log(query);
var e = $("LICID-" + id);
if (e) {
if (fg) e.style.color = fg;
if (bg) e.style.backgroundColor = bg;
}
new Ajax.Request("backend.php", { parameters: query });
updateFilterList();
},
execute: function() { execute: function() {
if (this.validate()) { if (this.validate()) {
var caption = this.attr('value').id; var caption = this.attr('value').id;
@ -1775,7 +1694,7 @@ function editLabel(id, event) {
var query = dojo.objectToQuery(this.attr('value')); var query = dojo.objectToQuery(this.attr('value'));
dijit.byId('labelTree').setNameById(id, caption); dijit.byId('labelTree').setNameById(id, caption);
setLabelColor(id, fg_color, bg_color); this.setLabelColor(id, fg_color, bg_color);
this.hide(); this.hide();
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {