3 var active_feed_cat = false;
4 var active_tab = false;
5 var feed_to_expand = false;
7 var xmlhttp = Ajax.getTransport();
9 var init_params = new Array();
11 var caller_subop = false;
12 var sanity_check_done = false;
13 var hotkey_prefix = false;
15 function infobox_callback() {
16 if (xmlhttp.readyState == 4) {
17 infobox_callback2(xmlhttp);
21 function infobox_submit_callback() {
22 if (xmlhttp.readyState == 4) {
23 infobox_submit_callback2(xmlhttp);
28 function replace_pubkey_callback() {
29 if (xmlhttp.readyState == 4) {
31 var link = document.getElementById("pubGenAddress");
33 if (xmlhttp.responseXML) {
35 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
38 link.href = new_link.firstChild.nodeValue;
39 //link.innerHTML = new_link.firstChild.nodeValue;
41 new Effect.Highlight(link);
43 notify_info("Published feed URL changed.");
45 notify_error("Could not change feed URL.");
49 notify_error("Could not change feed URL.");
52 exception_error("replace_pubkey_callback", e);
57 function expand_feed_callback() {
58 if (xmlhttp.readyState == 4) {
60 var container = document.getElementById("BRDET-" + feed_to_expand);
61 container.innerHTML=xmlhttp.responseText;
62 // container.style.display = "block";
63 Effect.Appear(container, {duration : 0.5});
66 exception_error("expand_feed_callback", e);
71 function feedlist_callback() {
72 if (xmlhttp.readyState == 4) {
74 var container = document.getElementById('prefContent');
75 container.innerHTML=xmlhttp.responseText;
76 selectTab("feedConfig", true);
79 var tuple = caller_subop.split(":");
80 if (tuple[0] == 'editFeed') {
81 window.setTimeout('editFeed('+tuple[1]+')', 100);
86 if (typeof correctPNG != 'undefined') {
93 exception_error("feedlist_callback", e);
98 /* stub for subscription dialog */
100 function dlg_frefresh_callback(transport) {
103 var container = document.getElementById('prefContent');
104 container.innerHTML=transport.responseText;
105 selectTab("feedConfig", true);
108 var tuple = caller_subop.split(":");
109 if (tuple[0] == 'editFeed') {
110 window.setTimeout('editFeed('+tuple[1]+')', 100);
113 caller_subop = false;
115 if (typeof correctPNG != 'undefined') {
120 exception_error("feedlist_callback", e);
125 function filterlist_callback() {
126 var container = document.getElementById('prefContent');
127 if (xmlhttp.readyState == 4) {
128 container.innerHTML=xmlhttp.responseText;
129 if (typeof correctPNG != 'undefined') {
137 function labellist_callback() {
141 var container = document.getElementById('prefContent');
142 if (xmlhttp.readyState == 4) {
144 container.innerHTML=xmlhttp.responseText;
146 if (document.getElementById("prefLabelList")) {
147 var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
149 for (var i = 0; i < elems.length; i++) {
150 if (elems[i].id && elems[i].id.match("LILT-")) {
152 var id = elems[i].id.replace("LILT-", "");
153 new Ajax.InPlaceEditor(elems[i],
154 'backend.php?op=pref-labels&subop=save&id=' + id,
155 {cols: 20, rows: 1});
160 if (typeof correctPNG != 'undefined') {
168 exception_error("labellist_callback", e);
172 function feed_browser_callback() {
173 var container = document.getElementById('prefContent');
174 if (xmlhttp.readyState == 4) {
175 container.innerHTML=xmlhttp.responseText;
181 function userlist_callback() {
182 var container = document.getElementById('prefContent');
183 if (xmlhttp.readyState == 4) {
184 container.innerHTML=xmlhttp.responseText;
190 function prefslist_callback() {
191 var container = document.getElementById('prefContent');
192 if (xmlhttp.readyState == 4) {
193 container.innerHTML=xmlhttp.responseText;
199 function gethelp_callback() {
200 var container = document.getElementById('prefHelpBox');
201 if (xmlhttp.readyState == 4) {
203 container.innerHTML = xmlhttp.responseText;
204 container.style.display = "block";
209 function notify_callback() {
210 if (xmlhttp.readyState == 4) {
211 notify_info(xmlhttp.responseText);
215 function prefs_reset_callback() {
216 if (xmlhttp.readyState == 4) {
217 notify_info(xmlhttp.responseText);
223 function changepass_callback() {
225 if (xmlhttp.readyState == 4) {
227 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
228 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
230 notify_info(xmlhttp.responseText);
231 var warn = document.getElementById("default_pass_warning");
232 if (warn) warn.style.display = "none";
235 document.forms['change_pass_form'].reset();
239 exception_error("changepass_callback", e);
243 function init_cat_inline_editor() {
246 if (document.getElementById("prefFeedCatList")) {
247 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
249 for (var i = 0; i < elems.length; i++) {
250 if (elems[i].id && elems[i].id.match("FCATT-")) {
251 var cat_id = elems[i].id.replace("FCATT-", "");
252 new Ajax.InPlaceEditor(elems[i],
253 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
259 exception_error("init_cat_inline_editor", e);
263 function infobox_feed_cat_callback() {
264 if (xmlhttp.readyState == 4) {
268 init_cat_inline_editor();
271 exception_error("infobox_feed_cat_callback", e);
276 function updateFeedList(sort_key) {
278 if (!xmlhttp_ready(xmlhttp)) {
283 var feed_search = document.getElementById("feed_search");
285 if (feed_search) { search = feed_search.value; }
287 var slat = document.getElementById("show_last_article_times");
289 var slat_checked = false;
291 slat_checked = slat.checked;
294 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
295 "&sort=" + param_escape(sort_key) +
296 "&slat=" + param_escape(slat_checked) +
297 "&search=" + param_escape(search), true);
298 xmlhttp.onreadystatechange=feedlist_callback;
303 function updateUsersList(sort_key) {
305 if (!xmlhttp_ready(xmlhttp)) {
310 var user_search = document.getElementById("user_search");
312 if (user_search) { search = user_search.value; }
314 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
315 + param_escape(sort_key) +
316 "&search=" + param_escape(search), true);
317 xmlhttp.onreadystatechange=userlist_callback;
322 function addLabel() {
326 if (!xmlhttp_ready(xmlhttp)) {
331 var caption = prompt(__("Please enter label caption:"), "");
333 if (caption == null) {
338 alert(__("Can't create label: missing caption."));
342 // we can be called from some other tab
343 active_tab = "labelConfig";
345 var query = "caption=" + param_escape(caption);
347 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
348 xmlhttp.onreadystatechange=infobox_submit_callback;
352 exception_error("addLabel", e);
358 if (!xmlhttp_ready(xmlhttp)) {
363 var link = document.getElementById("fadd_link");
365 if (link.value.length == 0) {
366 alert(__("Error: No feed URL given."));
367 } else if (!isValidURL(link.value)) {
368 alert(__("Error: Invalid feed URL."));
370 notify_progress("Adding feed...");
372 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
373 param_escape(link.value), true);
374 xmlhttp.onreadystatechange=feedlist_callback;
383 function addFeedCat() {
385 if (!xmlhttp_ready(xmlhttp)) {
390 var cat = document.getElementById("fadd_cat");
392 if (cat.value.length == 0) {
393 alert(__("Can't add category: no name specified."));
395 notify_progress("Adding feed category...");
397 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
398 param_escape(cat.value), true);
399 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
409 if (!xmlhttp_ready(xmlhttp)) {
414 var sqlexp = document.getElementById("uadd_box");
416 if (sqlexp.value.length == 0) {
417 alert(__("Can't add user: no login specified."));
419 notify_progress("Adding user...");
421 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
422 param_escape(sqlexp.value), true);
424 xmlhttp.onreadystatechange=userlist_callback;
432 function editUser(id) {
434 if (!xmlhttp_ready(xmlhttp)) {
441 notify_progress("Loading, please wait...");
443 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
444 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
446 disableContainerChildren("userOpToolbar", false);
448 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
449 param_escape(id), true);
450 xmlhttp.onreadystatechange=infobox_callback;
455 function editFilter(id) {
457 if (!xmlhttp_ready(xmlhttp)) {
464 notify_progress("Loading, please wait...");
466 // document.getElementById("create_filter_btn").disabled = true;
468 disableContainerChildren("filterOpToolbar", false);
470 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
471 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
473 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
474 xmlhttp.onreadystatechange=infobox_callback;
478 function editFeed(feed) {
480 // notify("Editing feed...");
482 if (!xmlhttp_ready(xmlhttp)) {
489 notify_progress("Loading, please wait...");
491 /* document.getElementById("subscribe_to_feed_btn").disabled = true;
494 document.getElementById("top25_feeds_btn").disabled = true;
496 // this button is not always available, no-op if not found
499 // clean selection from all rows & select row being edited
500 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
501 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
503 disableContainerChildren("feedOpToolbar", false);
505 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
506 param_escape(feed), true);
508 xmlhttp.onreadystatechange=infobox_callback;
513 function editFeedCat(cat) {
515 if (!xmlhttp_ready(xmlhttp)) {
522 notify_progress("Loading, please wait...");
524 active_feed_cat = cat;
526 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
527 param_escape(cat), true);
528 xmlhttp.onreadystatechange=infobox_callback;
533 function getSelectedLabels() {
534 return getSelectedTableRowIds("prefLabelList", "LILRR");
537 function getSelectedUsers() {
538 return getSelectedTableRowIds("prefUserList", "UMRR");
541 function getSelectedFeeds() {
542 return getSelectedTableRowIds("prefFeedList", "FEEDR");
545 function getSelectedFilters() {
546 return getSelectedTableRowIds("prefFilterList", "FILRR");
549 function getSelectedFeedCats() {
550 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
553 function getSelectedFeedsFromBrowser() {
555 var list = document.getElementById("browseFeedList");
556 if (!list) list = document.getElementById("browseBigFeedList");
558 var selected = new Array();
560 for (i = 0; i < list.childNodes.length; i++) {
561 var child = list.childNodes[i];
562 if (child.id && child.id.match("FBROW-")) {
563 var id = child.id.replace("FBROW-", "");
565 var cb = document.getElementById("FBCHK-" + id);
576 function removeSelectedLabels() {
578 if (!xmlhttp_ready(xmlhttp)) {
583 var sel_rows = getSelectedLabels();
585 if (sel_rows.length > 0) {
587 var ok = confirm(__("Remove selected labels?"));
590 notify_progress("Removing selected labels...");
592 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
593 param_escape(sel_rows.toString()), true);
594 xmlhttp.onreadystatechange=labellist_callback;
598 alert(__("No labels are selected."));
604 function removeSelectedUsers() {
606 if (!xmlhttp_ready(xmlhttp)) {
611 var sel_rows = getSelectedUsers();
613 if (sel_rows.length > 0) {
615 var ok = confirm(__("Remove selected users?"));
618 notify_progress("Removing selected users...");
620 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
621 param_escape(sel_rows.toString()), true);
622 xmlhttp.onreadystatechange=userlist_callback;
627 alert(__("No users are selected."));
633 function removeSelectedFilters() {
635 if (!xmlhttp_ready(xmlhttp)) {
640 var sel_rows = getSelectedFilters();
642 if (sel_rows.length > 0) {
644 var ok = confirm(__("Remove selected filters?"));
647 notify_progress("Removing selected filters...");
649 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
650 param_escape(sel_rows.toString()), true);
651 xmlhttp.onreadystatechange=filterlist_callback;
655 alert(__("No filters are selected."));
662 function removeSelectedFeeds() {
664 if (!xmlhttp_ready(xmlhttp)) {
669 var sel_rows = getSelectedFeeds();
671 if (sel_rows.length > 0) {
673 var ok = confirm(__("Unsubscribe from selected feeds?"));
677 notify_progress("Unsubscribing from selected feeds...");
679 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
680 param_escape(sel_rows.toString()), true);
681 xmlhttp.onreadystatechange=feedlist_callback;
687 alert(__("No feeds are selected."));
694 function clearSelectedFeeds() {
696 if (!xmlhttp_ready(xmlhttp)) {
701 var sel_rows = getSelectedFeeds();
703 if (sel_rows.length > 1) {
704 alert(__("Please select only one feed."));
708 if (sel_rows.length > 0) {
710 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
713 notify_progress("Clearing selected feed...");
714 clearFeedArticles(sel_rows[0]);
719 alert(__("No feeds are selected."));
726 function purgeSelectedFeeds() {
728 if (!xmlhttp_ready(xmlhttp)) {
733 var sel_rows = getSelectedFeeds();
735 if (sel_rows.length > 0) {
737 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
739 if (pr != undefined) {
740 notify_progress("Purging selected feed...");
742 var query = "backend.php?op=rpc&subop=purge&ids="+
743 param_escape(sel_rows.toString()) + "&days=" + pr;
747 new Ajax.Request(query, {
748 onComplete: function(transport) {
755 alert(__("No feeds are selected."));
762 function removeSelectedFeedCats() {
764 if (!xmlhttp_ready(xmlhttp)) {
769 var sel_rows = getSelectedFeedCats();
771 if (sel_rows.length > 0) {
773 var ok = confirm(__("Remove selected categories?"));
776 notify_progress("Removing selected categories...");
778 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
779 param_escape(sel_rows.toString()), true);
780 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
786 alert(__("No categories are selected."));
793 function feedEditCancel() {
795 if (!xmlhttp_ready(xmlhttp)) {
801 document.getElementById("subscribe_to_feed_btn").disabled = false;
802 document.getElementById("top25_feeds_btn").disabled = false;
804 // this button is not always available, no-op if not found
809 selectPrefRows('feed', false); // cleanup feed selection
814 function feedCatEditCancel() {
816 if (!xmlhttp_ready(xmlhttp)) {
821 active_feed_cat = false;
824 document.getElementById("subscribe_to_feed_btn").disabled = false;
825 document.getElementById("top25_feeds_btn").disabled = false;
827 // this button is not always available, no-op if not found
830 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
831 xmlhttp.onreadystatechange=infobox_callback;
837 function feedEditSave() {
841 if (!xmlhttp_ready(xmlhttp)) {
846 // FIXME: add parameter validation
848 var query = Form.serialize("edit_feed_form");
850 notify_progress("Saving feed...");
852 xmlhttp.open("POST", "backend.php", true);
853 xmlhttp.onreadystatechange=feedlist_callback;
854 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
862 exception_error("feedEditSave", e);
866 function userEditCancel() {
868 if (!xmlhttp_ready(xmlhttp)) {
873 selectPrefRows('user', false); // cleanup feed selection
879 function filterEditCancel() {
881 if (!xmlhttp_ready(xmlhttp)) {
887 document.getElementById("create_filter_btn").disabled = false;
888 selectPrefRows('filter', false); // cleanup feed selection
896 function userEditSave() {
898 if (!xmlhttp_ready(xmlhttp)) {
903 var login = document.forms["user_edit_form"].login.value;
905 if (login.length == 0) {
906 alert(__("Login field cannot be blank."));
910 notify_progress("Saving user...");
914 var query = Form.serialize("user_edit_form");
916 xmlhttp.open("GET", "backend.php?" + query, true);
917 xmlhttp.onreadystatechange=userlist_callback;
924 function filterEditSave() {
926 if (!xmlhttp_ready(xmlhttp)) {
931 /* if (!is_opera()) {
932 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
934 if (reg_exp.length == 0) {
935 alert("Filter expression field cannot be blank.");
940 notify_progress("Saving filter...");
942 var query = Form.serialize("filter_edit_form");
946 document.getElementById("create_filter_btn").disabled = false;
948 xmlhttp.open("GET", "backend.php?" + query, true);
949 xmlhttp.onreadystatechange=filterlist_callback;
956 function editSelectedUser() {
957 var rows = getSelectedUsers();
959 if (rows.length == 0) {
960 alert(__("No users are selected."));
964 if (rows.length > 1) {
965 alert(__("Please select only one user."));
974 function resetSelectedUserPass() {
975 var rows = getSelectedUsers();
977 if (rows.length == 0) {
978 alert(__("No users are selected."));
982 if (rows.length > 1) {
983 alert(__("Please select only one user."));
987 var ok = confirm(__("Reset password of selected user?"));
990 notify_progress("Resetting password for selected user...");
994 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
995 param_escape(id), true);
996 xmlhttp.onreadystatechange=userlist_callback;
1001 function selectedUserDetails() {
1003 if (!xmlhttp_ready(xmlhttp)) {
1004 printLockingError();
1008 var rows = getSelectedUsers();
1010 if (rows.length == 0) {
1011 alert(__("No users are selected."));
1015 if (rows.length > 1) {
1016 alert(__("Please select only one user."));
1020 notify_progress("Loading, please wait...");
1024 xmlhttp.open("GET", "backend.php?op=pref-users&subop=user-details&id=" + id, true);
1025 xmlhttp.onreadystatechange=infobox_callback;
1030 function selectedFeedDetails() {
1032 if (!xmlhttp_ready(xmlhttp)) {
1033 printLockingError();
1037 var rows = getSelectedFeeds();
1039 if (rows.length == 0) {
1040 alert(__("No feeds are selected."));
1044 if (rows.length > 1) {
1045 alert(__("Please select only one feed."));
1049 // var id = rows[0];
1053 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1054 param_escape(rows.toString()), true);
1055 xmlhttp.onreadystatechange=infobox_callback;
1060 function editSelectedFilter() {
1061 var rows = getSelectedFilters();
1063 if (rows.length == 0) {
1064 alert(__("No filters are selected."));
1068 if (rows.length > 1) {
1069 alert(__("Please select only one filter."));
1075 editFilter(rows[0]);
1080 function editSelectedFeed() {
1081 var rows = getSelectedFeeds();
1083 if (rows.length == 0) {
1084 alert(__("No feeds are selected."));
1088 if (rows.length > 1) {
1089 alert(__("Please select one feed."));
1099 function editSelectedFeeds() {
1101 if (!xmlhttp_ready(xmlhttp)) {
1102 printLockingError();
1106 var rows = getSelectedFeeds();
1108 if (rows.length == 0) {
1109 alert(__("No feeds are selected."));
1117 notify_progress("Loading, please wait...");
1119 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
1120 param_escape(rows.toString()), true);
1122 xmlhttp.onreadystatechange=infobox_callback;
1127 function editSelectedFeedCat() {
1128 var rows = getSelectedFeedCats();
1130 if (rows.length == 0) {
1131 alert(__("No categories are selected."));
1135 if (rows.length > 1) {
1136 alert(__("Please select only one category."));
1142 editFeedCat(rows[0]);
1146 function piggie(enable) {
1148 debug("I LOVEDED IT!");
1149 var piggie = document.getElementById("piggie");
1151 Element.show(piggie);
1152 Position.Center(piggie);
1153 Effect.Puff(piggie);
1158 function validateOpmlImport() {
1160 var opml_file = document.getElementById("opml_file");
1162 if (opml_file.value.length == 0) {
1163 alert(__("No OPML file to upload."));
1170 function updateFilterList(sort_key) {
1172 if (!xmlhttp_ready(xmlhttp)) {
1173 printLockingError();
1177 var filter_search = document.getElementById("filter_search");
1179 if (filter_search) { search = filter_search.value; }
1181 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1182 param_escape(sort_key) +
1183 "&search=" + param_escape(search), true);
1184 xmlhttp.onreadystatechange=filterlist_callback;
1189 function updateLabelList(sort_key) {
1191 if (!xmlhttp_ready(xmlhttp)) {
1192 printLockingError();
1196 var label_search = document.getElementById("label_search");
1198 if (label_search) { search = label_search.value; }
1200 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1201 param_escape(sort_key) +
1202 "&search=" + param_escape(search), true);
1203 xmlhttp.onreadystatechange=labellist_callback;
1207 function updatePrefsList() {
1209 if (!xmlhttp_ready(xmlhttp)) {
1210 printLockingError();
1214 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1215 xmlhttp.onreadystatechange=prefslist_callback;
1220 function selectTab(id, noupdate, subop) {
1224 if (!id) id = active_tab;
1228 if (!xmlhttp_ready(xmlhttp)) {
1229 printLockingError();
1234 var c = document.getElementById('prefContent');
1240 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1242 notify_progress("Loading, please wait...");
1244 // close active infobox if needed
1247 // clean up all current selections, just in case
1248 active_feed_cat = false;
1250 // Effect.Fade("prefContent", {duration: 1, to: 0.01,
1251 // queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1253 if (id == "feedConfig") {
1255 } else if (id == "filterConfig") {
1257 } else if (id == "labelConfig") {
1259 } else if (id == "genConfig") {
1261 } else if (id == "userConfig") {
1263 } else if (id == "feedBrowser") {
1264 updateBigFeedBrowser();
1268 /* clean selection from all tabs */
1270 var tabs_holder = document.getElementById("prefTabs");
1271 var tab = tabs_holder.firstChild;
1274 if (tab.className && tab.className.match("prefsTabSelected")) {
1275 tab.className = "prefsTab";
1277 tab = tab.nextSibling;
1280 /* mark new tab as selected */
1282 tab = document.getElementById(id + "Tab");
1285 if (!tab.className.match("Selected")) {
1286 tab.className = tab.className + "Selected";
1293 exception_error("selectTab", e);
1297 function backend_sanity_check_callback() {
1299 if (xmlhttp.readyState == 4) {
1303 if (sanity_check_done) {
1304 fatalError(11, "Sanity check request received twice. This can indicate "+
1305 "presence of Firebug or some other disrupting extension. "+
1306 "Please disable it and try again.");
1310 if (!xmlhttp.responseXML) {
1311 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1315 var reply = xmlhttp.responseXML.firstChild.firstChild;
1318 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1322 var error_code = reply.getAttribute("error-code");
1324 if (error_code && error_code != 0) {
1325 return fatalError(error_code, reply.getAttribute("error-msg"));
1328 debug("sanity check ok");
1330 var params = reply.nextSibling;
1333 debug('reading init-params...');
1334 var param = params.firstChild;
1337 var k = param.getAttribute("key");
1338 var v = param.getAttribute("value");
1339 debug(k + " => " + v);
1341 param = param.nextSibling;
1345 sanity_check_done = true;
1347 init_second_stage();
1350 exception_error("backend_sanity_check_callback", e);
1355 function init_second_stage() {
1358 active_tab = getInitParam("prefs_active_tab");
1359 if (!active_tab || active_tab == '0') active_tab = "genConfig";
1361 document.onkeydown = pref_hotkey_handler;
1363 var tab = getURLParam('tab');
1365 caller_subop = getURLParam('subop');
1371 if (navigator.userAgent.match("Opera")) {
1372 setTimeout("selectTab()", 500);
1374 selectTab(active_tab);
1378 loading_set_progress(60);
1381 exception_error("init_second_stage", e);
1389 if (arguments.callee.done) return;
1390 arguments.callee.done = true;
1392 if (getURLParam('debug')) {
1393 Element.show("debug_output");
1394 debug('debug mode activated');
1399 document.getElementById("prefContent").innerHTML =
1400 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1401 "to function properly. Your browser doesn't seem to support it.";
1405 loading_set_progress(30);
1407 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1408 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1412 exception_error("init", e);
1416 function categorizeSelectedFeeds() {
1418 if (!xmlhttp_ready(xmlhttp)) {
1419 printLockingError();
1423 var sel_rows = getSelectedFeeds();
1425 var cat_sel = document.getElementById("sfeed_set_fcat");
1426 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1428 if (sel_rows.length > 0) {
1430 notify_progress("Changing category of selected feeds...");
1432 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1433 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1434 xmlhttp.onreadystatechange=feedlist_callback;
1439 alert(__("No feeds are selected."));
1445 function validatePrefsReset() {
1447 var ok = confirm(__("Reset to defaults?"));
1451 var query = Form.serialize("pref_prefs_form");
1452 query = query + "&subop=reset-config";
1455 xmlhttp.open("POST", "backend.php", true);
1456 xmlhttp.onreadystatechange=prefs_reset_callback;
1457 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1458 xmlhttp.send(query);
1462 exception_error("validatePrefsSave", e);
1469 function browseFeeds(limit) {
1471 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1472 xmlhttp.onreadystatechange=infobox_callback;
1477 function feedBrowserSubscribe() {
1480 var selected = getSelectedFeedsFromBrowser();
1482 if (selected.length > 0) {
1484 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1485 param_escape(selected.toString()), true);
1486 xmlhttp.onreadystatechange=feedlist_callback;
1489 alert(__("No feeds are selected."));
1493 exception_error("feedBrowserSubscribe", e);
1497 function updateBigFeedBrowserBtn() {
1498 notify_progress("Loading, please wait...");
1499 return updateBigFeedBrowser();
1502 function updateBigFeedBrowser(limit, from_button) {
1504 if (!xmlhttp_ready(xmlhttp)) {
1505 printLockingError();
1509 var query = "backend.php?op=pref-feed-browser";
1511 var limit_sel = document.getElementById("feedBrowserLimit");
1514 var limit = limit_sel[limit_sel.selectedIndex].value;
1515 query = query + "&limit=" + param_escape(limit);
1518 var search = document.getElementById("feed_browser_search");
1521 query = query + "&search=" + param_escape(search.value);
1524 xmlhttp.open("GET", query, true);
1525 xmlhttp.onreadystatechange=feed_browser_callback;
1529 function browserToggleExpand(id) {
1531 /* if (feed_to_expand && feed_to_expand != id) {
1532 var d = document.getElementById("BRDET-" + feed_to_expand);
1533 d.style.display = "none";
1536 if (!xmlhttp_ready(xmlhttp)) {
1537 printLockingError();
1541 /* if (feed_to_expand && id != feed_to_expand) {
1542 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1545 var d = document.getElementById("BRDET-" + id);
1547 notify_progress("Loading, please wait...");
1549 if (Element.visible(d)) {
1550 Effect.Fade(d, {duration : 0.5});
1552 feed_to_expand = id;
1554 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1555 + param_escape(id), true);
1556 xmlhttp.onreadystatechange=expand_feed_callback;
1561 exception_error("browserToggleExpand", e);
1565 function selectPrefRows(kind, select) {
1568 var opbarid = false;
1573 if (kind == "feed") {
1574 opbarid = "feedOpToolbar";
1577 lname = "prefFeedList";
1578 } else if (kind == "fcat") {
1579 opbarid = "catOpToolbar";
1582 lname = "prefFeedCatList";
1583 } else if (kind == "filter") {
1584 opbarid = "filterOpToolbar";
1587 lname = "prefFilterList";
1588 } else if (kind == "label") {
1589 opbarid = "labelOpToolbar";
1592 lname = "prefLabelList";
1593 } else if (kind == "user") {
1594 opbarid = "userOpToolbar";
1597 lname = "prefUserList";
1601 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1602 disableContainerChildren(opbarid, !select);
1609 function toggleSelectPrefRow(sender, kind) {
1611 toggleSelectRow(sender);
1614 var opbarid = false;
1617 if (kind == "feed") {
1618 opbarid = "feedOpToolbar";
1619 nsel = getSelectedFeeds();
1620 } else if (kind == "fcat") {
1621 opbarid = "catOpToolbar";
1622 nsel = getSelectedFeedCats();
1623 } else if (kind == "filter") {
1624 opbarid = "filterOpToolbar";
1625 nsel = getSelectedFilters();
1626 } else if (kind == "label") {
1627 opbarid = "labelOpToolbar";
1628 nsel = getSelectedLabels();
1629 } else if (kind == "user") {
1630 opbarid = "userOpToolbar";
1631 nsel = getSelectedUsers();
1634 if (opbarid && nsel != -1) {
1635 disableContainerChildren(opbarid, nsel == false);
1641 function toggleSelectFBListRow(sender) {
1642 toggleSelectListRow(sender);
1643 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1648 function pref_hotkey_handler(e) {
1652 var shift_key = false;
1655 shift_key = e.shiftKey;
1661 keycode = window.event.keyCode;
1666 var keychar = String.fromCharCode(keycode);
1668 if (keycode == 27) { // escape
1669 if (Element.visible("hotkey_help_overlay")) {
1670 Element.hide("hotkey_help_overlay");
1672 hotkey_prefix = false;
1676 if (!hotkeys_enabled) {
1677 debug("hotkeys disabled");
1681 if (keycode == 16) return; // ignore lone shift
1683 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1684 hotkey_prefix = keycode;
1685 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
1689 if (Element.visible("hotkey_help_overlay")) {
1690 Element.hide("hotkey_help_overlay");
1693 if (keycode == 13 || keycode == 27) {
1696 seq = seq + "" + keycode;
1699 /* Global hotkeys */
1701 if (!hotkey_prefix) {
1703 if (keycode == 68 && shift_key) { // d
1704 if (!Element.visible("debug_output")) {
1705 Element.show("debug_output");
1706 debug('debug mode activated');
1708 Element.hide("debug_output");
1713 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1714 if (!Element.visible("hotkey_help_overlay")) {
1715 //Element.show("hotkey_help_overlay");
1716 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
1718 Element.hide("hotkey_help_overlay");
1723 if (keycode == 191 || keychar == '/') { // /
1724 var search_boxes = new Array("label_search",
1725 "feed_search", "filter_search", "user_search", "feed_browser_search");
1727 for (var i = 0; i < search_boxes.length; i++) {
1728 var elem = document.getElementById(search_boxes[i]);
1730 focus_element(search_boxes[i]);
1739 if (hotkey_prefix == 67) { // c
1740 hotkey_prefix = false;
1742 if (keycode == 70) { // f
1743 displayDlg("quickAddFilter");
1747 if (keycode == 83) { // s
1748 displayDlg("quickAddFeed");
1752 /* if (keycode == 76) { // l
1753 displayDlg("quickAddLabel");
1757 if (keycode == 85) { // u
1761 if (keycode == 67) { // c
1766 if (keycode == 84 && shift_key) { // T
1775 if (hotkey_prefix == 71) { // g
1777 hotkey_prefix = false;
1779 if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
1780 selectTab("genConfig");
1784 if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
1785 selectTab("feedConfig");
1789 if (keycode == 51 && document.getElementById("feedBrowserTab")) { // 3
1790 selectTab("feedBrowser");
1794 if (keycode == 52 && document.getElementById("filterConfigTab")) { // 4
1795 selectTab("filterConfig");
1799 if (keycode == 53 && document.getElementById("labelConfigTab")) { // 5
1800 selectTab("labelConfig");
1804 if (keycode == 54 && document.getElementById("userConfigTab")) { // 6
1805 selectTab("userConfig");
1809 if (keycode == 88) { // x
1815 if (document.getElementById("piggie")) {
1817 if (seq.match("807371717369")) {
1825 if (hotkey_prefix) {
1826 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1828 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
1832 exception_error("pref_hotkey_handler", e);
1836 function editFeedCats() {
1837 if (!xmlhttp_ready(xmlhttp)) {
1838 printLockingError();
1842 document.getElementById("subscribe_to_feed_btn").disabled = true;
1845 document.getElementById("top25_feeds_btn").disabled = true;
1847 // this button is not always available, no-op if not found
1850 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1851 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
1855 function showFeedsWithErrors() {
1856 displayDlg('feedUpdateErrors');
1859 function changeUserPassword() {
1863 if (!xmlhttp_ready(xmlhttp)) {
1864 printLockingError();
1868 var f = document.forms["change_pass_form"];
1871 if (f.OLD_PASSWORD.value == "") {
1872 new Effect.Highlight(f.OLD_PASSWORD);
1873 notify_error("Old password cannot be blank.");
1877 if (f.NEW_PASSWORD.value == "") {
1878 new Effect.Highlight(f.NEW_PASSWORD);
1879 notify_error("New password cannot be blank.");
1883 if (f.CONFIRM_PASSWORD.value == "") {
1884 new Effect.Highlight(f.CONFIRM_PASSWORD);
1885 notify_error("Entered passwords do not match.");
1889 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1890 new Effect.Highlight(f.CONFIRM_PASSWORD);
1891 new Effect.Highlight(f.NEW_PASSWORD);
1892 notify_error("Entered passwords do not match.");
1898 var query = Form.serialize("change_pass_form");
1900 notify_progress("Trying to change password...");
1902 xmlhttp.open("POST", "backend.php", true);
1903 xmlhttp.onreadystatechange=changepass_callback;
1904 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1905 xmlhttp.send(query);
1908 exception_error("changeUserPassword", e);
1914 function changeUserEmail() {
1918 if (!xmlhttp_ready(xmlhttp)) {
1919 printLockingError();
1923 var query = Form.serialize("change_email_form");
1925 notify_progress("Trying to change e-mail...");
1927 xmlhttp.open("POST", "backend.php", true);
1928 xmlhttp.onreadystatechange=notify_callback;
1929 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1930 xmlhttp.send(query);
1933 exception_error("changeUserPassword", e);
1940 function feedlistToggleSLAT() {
1941 notify_progress("Loading, please wait...");
1945 function pubRegenKey() {
1947 if (!xmlhttp_ready(xmlhttp)) {
1948 printLockingError();
1952 var ok = confirm(__("Replace current publishing address with a new one?"));
1956 notify_progress("Trying to change address...");
1958 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1959 xmlhttp.onreadystatechange=replace_pubkey_callback;
1966 function pubToClipboard() {
1970 if (!xmlhttp_ready(xmlhttp)) {
1971 printLockingError();
1975 var link = document.getElementById("pubGenAddress");
1979 exception_error("pubToClipboard", e);
1985 function validatePrefsSave() {
1988 var ok = confirm(__("Save current configuration?"));
1992 var query = Form.serialize("pref_prefs_form");
1993 query = query + "&subop=save-config";
1996 xmlhttp.open("POST", "backend.php", true);
1997 xmlhttp.onreadystatechange=notify_callback;
1998 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1999 xmlhttp.send(query);
2003 exception_error("validatePrefsSave", e);
2009 function feedActionChange() {
2011 var chooser = document.getElementById("feedActionChooser");
2012 var opid = chooser[chooser.selectedIndex].value;
2014 chooser.selectedIndex = 0;
2017 exception_error("feedActionChange", e);
2021 function feedActionGo(op) {
2023 if (op == "facEdit") {
2025 var rows = getSelectedFeeds();
2027 if (rows.length > 1) {
2028 editSelectedFeeds();
2034 if (op == "facClear") {
2035 clearSelectedFeeds();
2038 if (op == "facPurge") {
2039 purgeSelectedFeeds();
2042 if (op == "facEditCats") {
2046 if (op == "facRescore") {
2047 rescoreSelectedFeeds();
2050 if (op == "facUnsubscribe") {
2051 removeSelectedFeeds();
2055 exception_error("feedActionGo", e);
2060 function clearFeedArticles(feed_id) {
2062 notify_progress("Clearing feed...");
2064 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
2066 new Ajax.Request(query, {
2067 onComplete: function(transport) {
2074 function rescoreSelectedFeeds() {
2076 if (!xmlhttp_ready(xmlhttp)) {
2077 printLockingError();
2081 var sel_rows = getSelectedFeeds();
2083 if (sel_rows.length > 0) {
2085 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
2086 var ok = confirm(__("Rescore articles in selected feeds?"));
2089 notify_progress("Rescoring selected feeds...", true);
2091 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
2092 param_escape(sel_rows.toString()), true);
2093 xmlhttp.onreadystatechange=notify_callback;
2097 alert(__("No feeds are selected."));
2103 function rescore_all_feeds() {
2104 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
2107 notify_progress("Rescoring feeds...", true);
2109 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
2110 xmlhttp.onreadystatechange=notify_callback;
2115 function removeFilter(id, title) {
2117 if (!xmlhttp_ready(xmlhttp)) {
2118 printLockingError();
2122 var msg = __("Remove filter %s?").replace("%s", title);
2124 var ok = confirm(msg);
2129 notify_progress("Removing filter...");
2131 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
2132 param_escape(id), true);
2133 xmlhttp.onreadystatechange=filterlist_callback;
2140 function unsubscribeFeed(id, title) {
2142 if (!xmlhttp_ready(xmlhttp)) {
2143 printLockingError();
2147 var msg = __("Unsubscribe from %s?").replace("%s", title);
2149 var ok = confirm(msg);
2154 notify_progress("Removing feed...");
2156 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
2157 param_escape(id), true);
2158 xmlhttp.onreadystatechange=filterlist_callback;
2168 function feedsEditSave() {
2171 if (!xmlhttp_ready(xmlhttp)) {
2172 printLockingError();
2176 var ok = confirm(__("Save changes to selected feeds?"));
2180 var f = document.forms["batch_edit_feed_form"];
2182 var query = Form.serialize("batch_edit_feed_form");
2184 /* Form.serialize ignores unchecked checkboxes */
2186 if (!query.match("&hidden=") &&
2187 f.hidden.disabled == false) {
2188 query = query + "&hidden=false";
2191 if (!query.match("&rtl_content=") &&
2192 f.rtl_content.disabled == false) {
2193 query = query + "&rtl_content=false";
2196 if (!query.match("&private=") &&
2197 f.private.disabled == false) {
2198 query = query + "&private=false";
2201 if (!query.match("&cache_images=") &&
2202 f.cache_images.disabled == false) {
2203 query = query + "&cache_images=false";
2206 if (!query.match("&include_in_digest=") &&
2207 f.include_in_digest.disabled == false) {
2208 query = query + "&include_in_digest=false";
2213 notify_progress("Saving feeds...");
2215 xmlhttp.open("POST", "backend.php", true);
2216 xmlhttp.onreadystatechange=feedlist_callback;
2217 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2218 xmlhttp.send(query);
2223 exception_error("feedsEditSave", e);
2227 function batchFeedsToggleField(cb, elem, label) {
2229 var f = document.forms["batch_edit_feed_form"];
2230 var l = document.getElementById(label);
2233 f[elem].disabled = false;
2239 // new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
2240 // queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
2243 f[elem].disabled = true;
2246 l.className = "insensitive";
2251 exception_error("batchFeedsToggleField", e);