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});
65 exception_error("expand_feed_callback", e);
70 function feedlist_callback() {
71 if (xmlhttp.readyState == 4) {
73 var container = document.getElementById('prefContent');
74 container.innerHTML=xmlhttp.responseText;
75 selectTab("feedConfig", true);
78 var tuple = caller_subop.split(":");
79 if (tuple[0] == 'editFeed') {
80 window.setTimeout('editFeed('+tuple[1]+')', 100);
85 if (typeof correctPNG != 'undefined') {
92 exception_error("feedlist_callback", e);
97 /* stub for subscription dialog */
99 function dlg_frefresh_callback(transport) {
102 var container = document.getElementById('prefContent');
103 container.innerHTML=transport.responseText;
104 selectTab("feedConfig", true);
107 var tuple = caller_subop.split(":");
108 if (tuple[0] == 'editFeed') {
109 window.setTimeout('editFeed('+tuple[1]+')', 100);
112 caller_subop = false;
114 if (typeof correctPNG != 'undefined') {
119 exception_error("feedlist_callback", e);
124 function filterlist_callback() {
125 var container = document.getElementById('prefContent');
126 if (xmlhttp.readyState == 4) {
127 container.innerHTML=xmlhttp.responseText;
128 if (typeof correctPNG != 'undefined') {
136 function labellist_callback() {
140 var container = document.getElementById('prefContent');
141 if (xmlhttp.readyState == 4) {
143 container.innerHTML=xmlhttp.responseText;
145 if (document.getElementById("prefLabelList")) {
146 var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
148 for (var i = 0; i < elems.length; i++) {
149 if (elems[i].id && elems[i].id.match("LILT-")) {
151 var id = elems[i].id.replace("LILT-", "");
152 new Ajax.InPlaceEditor(elems[i],
153 'backend.php?op=pref-labels&subop=save&id=' + id,
154 {cols: 20, rows: 1});
159 if (typeof correctPNG != 'undefined') {
167 exception_error("labellist_callback", e);
171 function feed_browser_callback() {
172 var container = document.getElementById('prefContent');
173 if (xmlhttp.readyState == 4) {
174 container.innerHTML=xmlhttp.responseText;
180 function userlist_callback() {
181 var container = document.getElementById('prefContent');
182 if (xmlhttp.readyState == 4) {
183 container.innerHTML=xmlhttp.responseText;
189 function prefslist_callback() {
190 var container = document.getElementById('prefContent');
191 if (xmlhttp.readyState == 4) {
192 container.innerHTML=xmlhttp.responseText;
198 function gethelp_callback() {
199 var container = document.getElementById('prefHelpBox');
200 if (xmlhttp.readyState == 4) {
202 container.innerHTML = xmlhttp.responseText;
203 container.style.display = "block";
208 function notify_callback() {
209 if (xmlhttp.readyState == 4) {
210 notify_info(xmlhttp.responseText);
214 function prefs_reset_callback() {
215 if (xmlhttp.readyState == 4) {
216 notify_info(xmlhttp.responseText);
222 function changepass_callback() {
224 if (xmlhttp.readyState == 4) {
226 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
227 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
229 notify_info(xmlhttp.responseText);
230 var warn = document.getElementById("default_pass_warning");
231 if (warn) warn.style.display = "none";
234 document.forms['change_pass_form'].reset();
238 exception_error("changepass_callback", e);
242 function infobox_feed_cat_callback() {
243 if (xmlhttp.readyState == 4) {
248 if (document.getElementById("prefFeedCatList")) {
249 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
251 for (var i = 0; i < elems.length; i++) {
252 if (elems[i].id && elems[i].id.match("FCATT-")) {
253 var cat_id = elems[i].id.replace("FCATT-", "");
255 new Ajax.InPlaceEditor(elems[i],
256 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
262 exception_error("infobox_feed_cat_callback", e);
267 function updateFeedList(sort_key) {
269 if (!xmlhttp_ready(xmlhttp)) {
274 var feed_search = document.getElementById("feed_search");
276 if (feed_search) { search = feed_search.value; }
278 var slat = document.getElementById("show_last_article_times");
280 var slat_checked = false;
282 slat_checked = slat.checked;
285 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
286 "&sort=" + param_escape(sort_key) +
287 "&slat=" + param_escape(slat_checked) +
288 "&search=" + param_escape(search), true);
289 xmlhttp.onreadystatechange=feedlist_callback;
294 function updateUsersList(sort_key) {
296 if (!xmlhttp_ready(xmlhttp)) {
301 var user_search = document.getElementById("user_search");
303 if (user_search) { search = user_search.value; }
305 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
306 + param_escape(sort_key) +
307 "&search=" + param_escape(search), true);
308 xmlhttp.onreadystatechange=userlist_callback;
313 function addLabel() {
317 if (!xmlhttp_ready(xmlhttp)) {
322 var caption = prompt(__("Please enter label caption:"), "");
324 if (caption == null) {
329 alert(__("Can't create label: missing caption."));
333 // we can be called from some other tab
334 active_tab = "labelConfig";
336 var query = "caption=" + param_escape(caption);
338 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
339 xmlhttp.onreadystatechange=infobox_submit_callback;
343 exception_error("addLabel", e);
349 if (!xmlhttp_ready(xmlhttp)) {
354 var link = document.getElementById("fadd_link");
356 if (link.value.length == 0) {
357 alert(__("Error: No feed URL given."));
358 } else if (!isValidURL(link.value)) {
359 alert(__("Error: Invalid feed URL."));
361 notify_progress("Adding feed...");
363 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
364 param_escape(link.value), true);
365 xmlhttp.onreadystatechange=feedlist_callback;
374 function addFeedCat() {
376 if (!xmlhttp_ready(xmlhttp)) {
381 var cat = document.getElementById("fadd_cat");
383 if (cat.value.length == 0) {
384 alert(__("Can't add category: no name specified."));
386 notify_progress("Adding feed category...");
388 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
389 param_escape(cat.value), true);
390 xmlhttp.onreadystatechange=infobox_callback;
400 if (!xmlhttp_ready(xmlhttp)) {
405 var sqlexp = document.getElementById("uadd_box");
407 if (sqlexp.value.length == 0) {
408 alert(__("Can't add user: no login specified."));
410 notify_progress("Adding user...");
412 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
413 param_escape(sqlexp.value), true);
415 xmlhttp.onreadystatechange=userlist_callback;
423 function editUser(id) {
425 if (!xmlhttp_ready(xmlhttp)) {
432 notify_progress("Loading, please wait...");
434 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
435 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
437 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
438 param_escape(id), true);
439 xmlhttp.onreadystatechange=infobox_callback;
444 function editFilter(id) {
446 if (!xmlhttp_ready(xmlhttp)) {
453 notify_progress("Loading, please wait...");
455 // document.getElementById("create_filter_btn").disabled = true;
457 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
458 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
460 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
461 xmlhttp.onreadystatechange=infobox_callback;
465 function editFeed(feed) {
467 // notify("Editing feed...");
469 if (!xmlhttp_ready(xmlhttp)) {
476 notify_progress("Loading, please wait...");
478 /* document.getElementById("subscribe_to_feed_btn").disabled = true;
481 document.getElementById("top25_feeds_btn").disabled = true;
483 // this button is not always available, no-op if not found
486 // clean selection from all rows & select row being edited
487 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
488 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
490 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
491 param_escape(feed), true);
493 xmlhttp.onreadystatechange=infobox_callback;
498 function editFeedCat(cat) {
500 if (!xmlhttp_ready(xmlhttp)) {
507 notify_progress("Loading, please wait...");
509 active_feed_cat = cat;
511 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
512 param_escape(cat), true);
513 xmlhttp.onreadystatechange=infobox_callback;
518 function getSelectedLabels() {
519 return getSelectedTableRowIds("prefLabelList", "LILRR");
522 function getSelectedUsers() {
523 return getSelectedTableRowIds("prefUserList", "UMRR");
526 function getSelectedFeeds() {
527 return getSelectedTableRowIds("prefFeedList", "FEEDR");
530 function getSelectedFilters() {
531 return getSelectedTableRowIds("prefFilterList", "FILRR");
534 function getSelectedFeedCats() {
535 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
538 function getSelectedFeedsFromBrowser() {
540 var list = document.getElementById("browseFeedList");
541 if (!list) list = document.getElementById("browseBigFeedList");
543 var selected = new Array();
545 for (i = 0; i < list.childNodes.length; i++) {
546 var child = list.childNodes[i];
547 if (child.id && child.id.match("FBROW-")) {
548 var id = child.id.replace("FBROW-", "");
550 var cb = document.getElementById("FBCHK-" + id);
561 function removeSelectedLabels() {
563 if (!xmlhttp_ready(xmlhttp)) {
568 var sel_rows = getSelectedLabels();
570 if (sel_rows.length > 0) {
572 var ok = confirm(__("Remove selected labels?"));
575 notify_progress("Removing selected labels...");
577 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
578 param_escape(sel_rows.toString()), true);
579 xmlhttp.onreadystatechange=labellist_callback;
583 alert(__("No labels are selected."));
589 function removeSelectedUsers() {
591 if (!xmlhttp_ready(xmlhttp)) {
596 var sel_rows = getSelectedUsers();
598 if (sel_rows.length > 0) {
600 var ok = confirm(__("Remove selected users?"));
603 notify_progress("Removing selected users...");
605 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
606 param_escape(sel_rows.toString()), true);
607 xmlhttp.onreadystatechange=userlist_callback;
612 alert(__("No users are selected."));
618 function removeSelectedFilters() {
620 if (!xmlhttp_ready(xmlhttp)) {
625 var sel_rows = getSelectedFilters();
627 if (sel_rows.length > 0) {
629 var ok = confirm(__("Remove selected filters?"));
632 notify_progress("Removing selected filters...");
634 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
635 param_escape(sel_rows.toString()), true);
636 xmlhttp.onreadystatechange=filterlist_callback;
640 alert(__("No filters are selected."));
647 function removeSelectedFeeds() {
649 if (!xmlhttp_ready(xmlhttp)) {
654 var sel_rows = getSelectedFeeds();
656 if (sel_rows.length > 0) {
658 var ok = confirm(__("Unsubscribe from selected feeds?"));
662 notify_progress("Unsubscribing from selected feeds...");
664 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
665 param_escape(sel_rows.toString()), true);
666 xmlhttp.onreadystatechange=feedlist_callback;
672 alert(__("No feeds are selected."));
679 function clearSelectedFeeds() {
681 if (!xmlhttp_ready(xmlhttp)) {
686 var sel_rows = getSelectedFeeds();
688 if (sel_rows.length > 1) {
689 alert(__("Please select only one feed."));
693 if (sel_rows.length > 0) {
695 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
698 notify_progress("Clearing selected feed...");
699 clearFeedArticles(sel_rows[0]);
704 alert(__("No feeds are selected."));
711 function purgeSelectedFeeds() {
713 if (!xmlhttp_ready(xmlhttp)) {
718 var sel_rows = getSelectedFeeds();
720 if (sel_rows.length > 0) {
722 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
724 if (pr != undefined) {
725 notify_progress("Purging selected feed...");
727 var query = "backend.php?op=rpc&subop=purge&ids="+
728 param_escape(sel_rows.toString()) + "&days=" + pr;
732 new Ajax.Request(query, {
733 onComplete: function(transport) {
740 alert(__("No feeds are selected."));
747 function removeSelectedFeedCats() {
749 if (!xmlhttp_ready(xmlhttp)) {
754 var sel_rows = getSelectedFeedCats();
756 if (sel_rows.length > 0) {
758 var ok = confirm(__("Remove selected categories?"));
761 notify_progress("Removing selected categories...");
763 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
764 param_escape(sel_rows.toString()), true);
765 xmlhttp.onreadystatechange=infobox_callback;
771 alert(__("No categories are selected."));
778 function feedEditCancel() {
780 if (!xmlhttp_ready(xmlhttp)) {
786 document.getElementById("subscribe_to_feed_btn").disabled = false;
787 document.getElementById("top25_feeds_btn").disabled = false;
789 // this button is not always available, no-op if not found
794 selectPrefRows('feed', false); // cleanup feed selection
799 function feedCatEditCancel() {
801 if (!xmlhttp_ready(xmlhttp)) {
806 active_feed_cat = false;
808 // notify("Operation cancelled.");
810 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
811 xmlhttp.onreadystatechange=infobox_callback;
817 function feedEditSave() {
821 if (!xmlhttp_ready(xmlhttp)) {
826 // FIXME: add parameter validation
828 var query = Form.serialize("edit_feed_form");
830 notify_progress("Saving feed...");
832 xmlhttp.open("POST", "backend.php", true);
833 xmlhttp.onreadystatechange=feedlist_callback;
834 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
842 exception_error("feedEditSave", e);
846 function feedCatEditSave() {
848 if (!xmlhttp_ready(xmlhttp)) {
853 notify_progress("Saving category...");
855 var query = Form.serialize("feed_cat_edit_form");
857 xmlhttp.open("GET", "backend.php?" + query, true);
858 xmlhttp.onreadystatechange=infobox_callback;
861 active_feed_cat = false;
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 xmlhttp.open("GET", query, true);
1519 xmlhttp.onreadystatechange=feed_browser_callback;
1523 function browserToggleExpand(id) {
1525 /* if (feed_to_expand && feed_to_expand != id) {
1526 var d = document.getElementById("BRDET-" + feed_to_expand);
1527 d.style.display = "none";
1530 if (!xmlhttp_ready(xmlhttp)) {
1531 printLockingError();
1535 /* if (feed_to_expand && id != feed_to_expand) {
1536 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1539 var d = document.getElementById("BRDET-" + id);
1541 if (Element.visible(d)) {
1542 Effect.Fade(d, {duration : 0.5});
1544 feed_to_expand = id;
1546 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1547 + param_escape(id), true);
1548 xmlhttp.onreadystatechange=expand_feed_callback;
1553 exception_error("browserToggleExpand", e);
1557 function selectPrefRows(kind, select) {
1560 var opbarid = false;
1565 if (kind == "feed") {
1566 opbarid = "feedOpToolbar";
1569 lname = "prefFeedList";
1570 } else if (kind == "fcat") {
1571 opbarid = "catOpToolbar";
1574 lname = "prefFeedCatList";
1575 } else if (kind == "filter") {
1576 opbarid = "filterOpToolbar";
1579 lname = "prefFilterList";
1580 } else if (kind == "label") {
1581 opbarid = "labelOpToolbar";
1584 lname = "prefLabelList";
1585 } else if (kind == "user") {
1586 opbarid = "userOpToolbar";
1589 lname = "prefUserList";
1593 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1594 disableContainerChildren(opbarid, !select);
1601 function toggleSelectPrefRow(sender, kind) {
1603 toggleSelectRow(sender);
1606 var opbarid = false;
1609 if (kind == "feed") {
1610 opbarid = "feedOpToolbar";
1611 nsel = getSelectedFeeds();
1612 } else if (kind == "fcat") {
1613 opbarid = "catOpToolbar";
1614 nsel = getSelectedFeedCats();
1615 } else if (kind == "filter") {
1616 opbarid = "filterOpToolbar";
1617 nsel = getSelectedFilters();
1618 } else if (kind == "label") {
1619 opbarid = "labelOpToolbar";
1620 nsel = getSelectedLabels();
1621 } else if (kind == "user") {
1622 opbarid = "userOpToolbar";
1623 nsel = getSelectedUsers();
1626 if (opbarid && nsel != -1) {
1627 disableContainerChildren(opbarid, nsel == false);
1633 function toggleSelectFBListRow(sender) {
1634 toggleSelectListRow(sender);
1635 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1640 function pref_hotkey_handler(e) {
1644 var shift_key = false;
1647 shift_key = e.shiftKey;
1653 keycode = window.event.keyCode;
1658 var keychar = String.fromCharCode(keycode);
1660 if (keycode == 27) { // escape
1661 if (Element.visible("hotkey_help_overlay")) {
1662 Element.hide("hotkey_help_overlay");
1664 hotkey_prefix = false;
1668 if (!hotkeys_enabled) {
1669 debug("hotkeys disabled");
1673 if (keycode == 16) return; // ignore lone shift
1675 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1676 hotkey_prefix = keycode;
1677 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
1681 if (Element.visible("hotkey_help_overlay")) {
1682 Element.hide("hotkey_help_overlay");
1685 if (keycode == 13 || keycode == 27) {
1688 seq = seq + "" + keycode;
1691 /* Global hotkeys */
1693 if (!hotkey_prefix) {
1695 if (keycode == 68 && shift_key) { // d
1696 if (!Element.visible("debug_output")) {
1697 Element.show("debug_output");
1698 debug('debug mode activated');
1700 Element.hide("debug_output");
1705 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1706 if (!Element.visible("hotkey_help_overlay")) {
1707 //Element.show("hotkey_help_overlay");
1708 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
1710 Element.hide("hotkey_help_overlay");
1715 if (keycode == 191 || keychar == '/') { // /
1716 var search_boxes = new Array("label_search",
1717 "feed_search", "filter_search", "user_search");
1719 for (var i = 0; i < search_boxes.length; i++) {
1720 var elem = document.getElementById(search_boxes[i]);
1722 focus_element(search_boxes[i]);
1731 if (hotkey_prefix == 67) { // c
1732 hotkey_prefix = false;
1734 if (keycode == 70) { // f
1735 displayDlg("quickAddFilter");
1739 if (keycode == 83) { // s
1740 displayDlg("quickAddFeed");
1744 /* if (keycode == 76) { // l
1745 displayDlg("quickAddLabel");
1749 if (keycode == 85) { // u
1753 if (keycode == 67) { // c
1758 if (keycode == 84 && shift_key) { // T
1767 if (hotkey_prefix == 71) { // g
1769 hotkey_prefix = false;
1771 if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
1772 selectTab("genConfig");
1776 if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
1777 selectTab("feedConfig");
1781 if (keycode == 51 && document.getElementById("feedBrowserTab")) { // 3
1782 selectTab("feedBrowser");
1786 if (keycode == 52 && document.getElementById("filterConfigTab")) { // 4
1787 selectTab("filterConfig");
1791 if (keycode == 53 && document.getElementById("labelConfigTab")) { // 5
1792 selectTab("labelConfig");
1796 if (keycode == 54 && document.getElementById("userConfigTab")) { // 6
1797 selectTab("userConfig");
1801 if (keycode == 88) { // x
1807 if (document.getElementById("piggie")) {
1809 if (seq.match("807371717369")) {
1817 if (hotkey_prefix) {
1818 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1820 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
1824 exception_error("pref_hotkey_handler", e);
1828 function editFeedCats() {
1829 if (!xmlhttp_ready(xmlhttp)) {
1830 printLockingError();
1834 document.getElementById("subscribe_to_feed_btn").disabled = true;
1837 document.getElementById("top25_feeds_btn").disabled = true;
1839 // this button is not always available, no-op if not found
1842 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1843 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
1847 function showFeedsWithErrors() {
1848 displayDlg('feedUpdateErrors');
1851 function changeUserPassword() {
1855 if (!xmlhttp_ready(xmlhttp)) {
1856 printLockingError();
1860 var f = document.forms["change_pass_form"];
1863 if (f.OLD_PASSWORD.value == "") {
1864 new Effect.Highlight(f.OLD_PASSWORD);
1865 notify_error("Old password cannot be blank.");
1869 if (f.NEW_PASSWORD.value == "") {
1870 new Effect.Highlight(f.NEW_PASSWORD);
1871 notify_error("New password cannot be blank.");
1875 if (f.CONFIRM_PASSWORD.value == "") {
1876 new Effect.Highlight(f.CONFIRM_PASSWORD);
1877 notify_error("Entered passwords do not match.");
1881 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1882 new Effect.Highlight(f.CONFIRM_PASSWORD);
1883 new Effect.Highlight(f.NEW_PASSWORD);
1884 notify_error("Entered passwords do not match.");
1890 var query = Form.serialize("change_pass_form");
1892 notify_progress("Trying to change password...");
1894 xmlhttp.open("POST", "backend.php", true);
1895 xmlhttp.onreadystatechange=changepass_callback;
1896 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1897 xmlhttp.send(query);
1900 exception_error("changeUserPassword", e);
1906 function changeUserEmail() {
1910 if (!xmlhttp_ready(xmlhttp)) {
1911 printLockingError();
1915 var query = Form.serialize("change_email_form");
1917 notify_progress("Trying to change e-mail...");
1919 xmlhttp.open("POST", "backend.php", true);
1920 xmlhttp.onreadystatechange=notify_callback;
1921 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1922 xmlhttp.send(query);
1925 exception_error("changeUserPassword", e);
1932 function feedlistToggleSLAT() {
1933 notify_progress("Loading, please wait...");
1937 function pubRegenKey() {
1939 if (!xmlhttp_ready(xmlhttp)) {
1940 printLockingError();
1944 var ok = confirm(__("Replace current publishing address with a new one?"));
1948 notify_progress("Trying to change address...");
1950 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1951 xmlhttp.onreadystatechange=replace_pubkey_callback;
1958 function pubToClipboard() {
1962 if (!xmlhttp_ready(xmlhttp)) {
1963 printLockingError();
1967 var link = document.getElementById("pubGenAddress");
1971 exception_error("pubToClipboard", e);
1977 function validatePrefsSave() {
1980 var ok = confirm(__("Save current configuration?"));
1984 var query = Form.serialize("pref_prefs_form");
1985 query = query + "&subop=save-config";
1988 xmlhttp.open("POST", "backend.php", true);
1989 xmlhttp.onreadystatechange=notify_callback;
1990 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1991 xmlhttp.send(query);
1995 exception_error("validatePrefsSave", e);
2001 function feedActionChange() {
2003 var chooser = document.getElementById("feedActionChooser");
2004 var opid = chooser[chooser.selectedIndex].value;
2006 chooser.selectedIndex = 0;
2009 exception_error("feedActionChange", e);
2013 function feedActionGo(op) {
2015 if (op == "facEdit") {
2017 var rows = getSelectedFeeds();
2019 if (rows.length > 1) {
2020 editSelectedFeeds();
2026 if (op == "facClear") {
2027 clearSelectedFeeds();
2030 if (op == "facPurge") {
2031 purgeSelectedFeeds();
2034 if (op == "facEditCats") {
2038 if (op == "facRescore") {
2039 rescoreSelectedFeeds();
2042 if (op == "facUnsubscribe") {
2043 removeSelectedFeeds();
2047 exception_error("feedActionGo", e);
2052 function clearFeedArticles(feed_id) {
2054 notify_progress("Clearing feed...");
2056 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
2058 new Ajax.Request(query, {
2059 onComplete: function(transport) {
2066 function rescoreSelectedFeeds() {
2068 if (!xmlhttp_ready(xmlhttp)) {
2069 printLockingError();
2073 var sel_rows = getSelectedFeeds();
2075 if (sel_rows.length > 0) {
2077 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
2078 var ok = confirm(__("Rescore articles in selected feeds?"));
2081 notify_progress("Rescoring selected feeds...", true);
2083 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
2084 param_escape(sel_rows.toString()), true);
2085 xmlhttp.onreadystatechange=notify_callback;
2089 alert(__("No feeds are selected."));
2095 function rescore_all_feeds() {
2096 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
2099 notify_progress("Rescoring feeds...", true);
2101 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
2102 xmlhttp.onreadystatechange=notify_callback;
2107 function removeFilter(id, title) {
2109 if (!xmlhttp_ready(xmlhttp)) {
2110 printLockingError();
2114 var msg = __("Remove filter %s?").replace("%s", title);
2116 var ok = confirm(msg);
2121 notify_progress("Removing filter...");
2123 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
2124 param_escape(id), true);
2125 xmlhttp.onreadystatechange=filterlist_callback;
2132 function unsubscribeFeed(id, title) {
2134 if (!xmlhttp_ready(xmlhttp)) {
2135 printLockingError();
2139 var msg = __("Unsubscribe from %s?").replace("%s", title);
2141 var ok = confirm(msg);
2146 notify_progress("Removing feed...");
2148 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
2149 param_escape(id), true);
2150 xmlhttp.onreadystatechange=filterlist_callback;
2160 function feedsEditSave() {
2163 if (!xmlhttp_ready(xmlhttp)) {
2164 printLockingError();
2168 var ok = confirm(__("Save changes to selected feeds?"));
2172 var f = document.forms["batch_edit_feed_form"];
2174 var query = Form.serialize("batch_edit_feed_form");
2176 /* Form.serialize ignores unchecked checkboxes */
2178 if (!query.match("&hidden=") &&
2179 f.hidden.disabled == false) {
2180 query = query + "&hidden=false";
2183 if (!query.match("&rtl_content=") &&
2184 f.rtl_content.disabled == false) {
2185 query = query + "&rtl_content=false";
2188 if (!query.match("&private=") &&
2189 f.private.disabled == false) {
2190 query = query + "&private=false";
2193 if (!query.match("&cache_images=") &&
2194 f.cache_images.disabled == false) {
2195 query = query + "&cache_images=false";
2198 if (!query.match("&include_in_digest=") &&
2199 f.include_in_digest.disabled == false) {
2200 query = query + "&include_in_digest=false";
2205 notify_progress("Saving feeds...");
2207 xmlhttp.open("POST", "backend.php", true);
2208 xmlhttp.onreadystatechange=feedlist_callback;
2209 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2210 xmlhttp.send(query);
2215 exception_error("feedsEditSave", e);
2219 function batchFeedsToggleField(cb, elem, label) {
2221 var f = document.forms["batch_edit_feed_form"];
2222 var l = document.getElementById(label);
2225 f[elem].disabled = false;
2231 // new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
2232 // queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
2235 f[elem].disabled = true;
2238 l.className = "insensitive";
2243 exception_error("batchFeedsToggleField", e);