3 var active_feed_cat = false;
4 var active_tab = false;
6 var xmlhttp = Ajax.getTransport();
8 var init_params = new Array();
10 var caller_subop = false;
11 var sanity_check_done = false;
12 var hotkey_prefix = false;
14 function infobox_callback() {
15 if (xmlhttp.readyState == 4) {
16 infobox_callback2(xmlhttp);
20 function infobox_submit_callback() {
21 if (xmlhttp.readyState == 4) {
22 infobox_submit_callback2(xmlhttp);
27 function replace_pubkey_callback() {
28 if (xmlhttp.readyState == 4) {
30 var link = document.getElementById("pubGenAddress");
32 if (xmlhttp.responseXML) {
34 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
37 link.href = new_link.firstChild.nodeValue;
38 //link.innerHTML = new_link.firstChild.nodeValue;
40 new Effect.Highlight(link);
42 notify_info("Published feed URL changed.");
44 notify_error("Could not change feed URL.");
48 notify_error("Could not change feed URL.");
51 exception_error("replace_pubkey_callback", e);
56 function feedlist_callback() {
57 if (xmlhttp.readyState == 4) {
59 var container = document.getElementById('prefContent');
60 container.innerHTML=xmlhttp.responseText;
61 selectTab("feedConfig", true);
64 var tuple = caller_subop.split(":");
65 if (tuple[0] == 'editFeed') {
66 window.setTimeout('editFeed('+tuple[1]+')', 100);
71 if (typeof correctPNG != 'undefined') {
78 exception_error("feedlist_callback", e);
83 /* stub for subscription dialog */
85 function dlg_frefresh_callback(transport) {
88 var container = document.getElementById('prefContent');
89 container.innerHTML=transport.responseText;
90 selectTab("feedConfig", true);
93 var tuple = caller_subop.split(":");
94 if (tuple[0] == 'editFeed') {
95 window.setTimeout('editFeed('+tuple[1]+')', 100);
100 if (typeof correctPNG != 'undefined') {
105 exception_error("feedlist_callback", e);
110 function filterlist_callback() {
111 var container = document.getElementById('prefContent');
112 if (xmlhttp.readyState == 4) {
113 container.innerHTML=xmlhttp.responseText;
114 if (typeof correctPNG != 'undefined') {
122 function labellist_callback() {
126 var container = document.getElementById('prefContent');
127 if (xmlhttp.readyState == 4) {
129 container.innerHTML=xmlhttp.responseText;
131 if (document.getElementById("prefLabelList")) {
132 var elems = document.getElementById("prefLabelList").getElementsByTagName("SPAN");
134 for (var i = 0; i < elems.length; i++) {
135 if (elems[i].id && elems[i].id.match("LILT-")) {
137 var id = elems[i].id.replace("LILT-", "");
138 new Ajax.InPlaceEditor(elems[i],
139 'backend.php?op=pref-labels&subop=save&id=' + id,
140 {cols: 20, rows: 1});
145 if (typeof correctPNG != 'undefined') {
153 exception_error("labellist_callback", e);
157 function feed_browser_callback() {
158 var container = document.getElementById('prefContent');
159 if (xmlhttp.readyState == 4) {
160 container.innerHTML=xmlhttp.responseText;
166 function userlist_callback() {
167 var container = document.getElementById('prefContent');
168 if (xmlhttp.readyState == 4) {
169 container.innerHTML=xmlhttp.responseText;
175 function prefslist_callback() {
176 var container = document.getElementById('prefContent');
177 if (xmlhttp.readyState == 4) {
178 container.innerHTML=xmlhttp.responseText;
184 function gethelp_callback() {
185 var container = document.getElementById('prefHelpBox');
186 if (xmlhttp.readyState == 4) {
188 container.innerHTML = xmlhttp.responseText;
189 container.style.display = "block";
194 function notify_callback() {
195 if (xmlhttp.readyState == 4) {
196 notify_info(xmlhttp.responseText);
200 function prefs_reset_callback() {
201 if (xmlhttp.readyState == 4) {
202 notify_info(xmlhttp.responseText);
208 function changepass_callback() {
210 if (xmlhttp.readyState == 4) {
212 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
213 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
215 notify_info(xmlhttp.responseText);
216 var warn = document.getElementById("default_pass_warning");
217 if (warn) warn.style.display = "none";
220 document.forms['change_pass_form'].reset();
224 exception_error("changepass_callback", e);
228 function init_cat_inline_editor() {
231 if (document.getElementById("prefFeedCatList")) {
232 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
234 for (var i = 0; i < elems.length; i++) {
235 if (elems[i].id && elems[i].id.match("FCATT-")) {
236 var cat_id = elems[i].id.replace("FCATT-", "");
237 new Ajax.InPlaceEditor(elems[i],
238 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
244 exception_error("init_cat_inline_editor", e);
248 function infobox_feed_cat_callback() {
249 if (xmlhttp.readyState == 4) {
253 init_cat_inline_editor();
256 exception_error("infobox_feed_cat_callback", e);
261 function updateFeedList(sort_key) {
263 if (!xmlhttp_ready(xmlhttp)) {
268 var feed_search = document.getElementById("feed_search");
270 if (feed_search) { search = feed_search.value; }
272 var slat = document.getElementById("show_last_article_times");
274 var slat_checked = false;
276 slat_checked = slat.checked;
279 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
280 "&sort=" + param_escape(sort_key) +
281 "&slat=" + param_escape(slat_checked) +
282 "&search=" + param_escape(search), true);
283 xmlhttp.onreadystatechange=feedlist_callback;
288 function updateUsersList(sort_key) {
290 if (!xmlhttp_ready(xmlhttp)) {
295 var user_search = document.getElementById("user_search");
297 if (user_search) { search = user_search.value; }
299 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
300 + param_escape(sort_key) +
301 "&search=" + param_escape(search), true);
302 xmlhttp.onreadystatechange=userlist_callback;
307 function addLabel() {
311 if (!xmlhttp_ready(xmlhttp)) {
316 var caption = prompt(__("Please enter label caption:"), "");
318 if (caption == null) {
323 alert(__("Can't create label: missing caption."));
327 // we can be called from some other tab
328 active_tab = "labelConfig";
330 var query = "caption=" + param_escape(caption);
332 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
333 xmlhttp.onreadystatechange=infobox_submit_callback;
337 exception_error("addLabel", e);
343 if (!xmlhttp_ready(xmlhttp)) {
348 var link = document.getElementById("fadd_link");
350 if (link.value.length == 0) {
351 alert(__("Error: No feed URL given."));
352 } else if (!isValidURL(link.value)) {
353 alert(__("Error: Invalid feed URL."));
355 notify_progress("Adding feed...");
357 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
358 param_escape(link.value), true);
359 xmlhttp.onreadystatechange=feedlist_callback;
368 function addFeedCat() {
370 if (!xmlhttp_ready(xmlhttp)) {
375 var cat = document.getElementById("fadd_cat");
377 if (cat.value.length == 0) {
378 alert(__("Can't add category: no name specified."));
380 notify_progress("Adding feed category...");
382 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
383 param_escape(cat.value), true);
384 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
394 if (!xmlhttp_ready(xmlhttp)) {
399 var sqlexp = document.getElementById("uadd_box");
401 if (sqlexp.value.length == 0) {
402 alert(__("Can't add user: no login specified."));
404 notify_progress("Adding user...");
406 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
407 param_escape(sqlexp.value), true);
409 xmlhttp.onreadystatechange=userlist_callback;
417 function editUser(id) {
419 if (!xmlhttp_ready(xmlhttp)) {
426 notify_progress("Loading, please wait...");
428 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
429 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
431 disableContainerChildren("userOpToolbar", false);
433 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
434 param_escape(id), true);
435 xmlhttp.onreadystatechange=infobox_callback;
440 function editFilter(id) {
442 if (!xmlhttp_ready(xmlhttp)) {
449 notify_progress("Loading, please wait...");
451 // document.getElementById("create_filter_btn").disabled = true;
453 disableContainerChildren("filterOpToolbar", false);
455 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
456 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
458 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
459 xmlhttp.onreadystatechange=infobox_callback;
463 function editFeed(feed) {
465 // notify("Editing feed...");
467 if (!xmlhttp_ready(xmlhttp)) {
474 notify_progress("Loading, please wait...");
476 /* document.getElementById("subscribe_to_feed_btn").disabled = true;
479 document.getElementById("top25_feeds_btn").disabled = true;
481 // this button is not always available, no-op if not found
484 // clean selection from all rows & select row being edited
485 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
486 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
488 disableContainerChildren("feedOpToolbar", false);
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");
539 function removeSelectedLabels() {
541 if (!xmlhttp_ready(xmlhttp)) {
546 var sel_rows = getSelectedLabels();
548 if (sel_rows.length > 0) {
550 var ok = confirm(__("Remove selected labels?"));
553 notify_progress("Removing selected labels...");
555 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
556 param_escape(sel_rows.toString()), true);
557 xmlhttp.onreadystatechange=labellist_callback;
561 alert(__("No labels are selected."));
567 function removeSelectedUsers() {
569 if (!xmlhttp_ready(xmlhttp)) {
574 var sel_rows = getSelectedUsers();
576 if (sel_rows.length > 0) {
578 var ok = confirm(__("Remove selected users?"));
581 notify_progress("Removing selected users...");
583 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
584 param_escape(sel_rows.toString()), true);
585 xmlhttp.onreadystatechange=userlist_callback;
590 alert(__("No users are selected."));
596 function removeSelectedFilters() {
598 if (!xmlhttp_ready(xmlhttp)) {
603 var sel_rows = getSelectedFilters();
605 if (sel_rows.length > 0) {
607 var ok = confirm(__("Remove selected filters?"));
610 notify_progress("Removing selected filters...");
612 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
613 param_escape(sel_rows.toString()), true);
614 xmlhttp.onreadystatechange=filterlist_callback;
618 alert(__("No filters are selected."));
625 function removeSelectedFeeds() {
627 if (!xmlhttp_ready(xmlhttp)) {
632 var sel_rows = getSelectedFeeds();
634 if (sel_rows.length > 0) {
636 var ok = confirm(__("Unsubscribe from selected feeds?"));
640 notify_progress("Unsubscribing from selected feeds...");
642 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
643 param_escape(sel_rows.toString()), true);
644 xmlhttp.onreadystatechange=feedlist_callback;
650 alert(__("No feeds are selected."));
657 function clearSelectedFeeds() {
659 if (!xmlhttp_ready(xmlhttp)) {
664 var sel_rows = getSelectedFeeds();
666 if (sel_rows.length > 1) {
667 alert(__("Please select only one feed."));
671 if (sel_rows.length > 0) {
673 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
676 notify_progress("Clearing selected feed...");
677 clearFeedArticles(sel_rows[0]);
682 alert(__("No feeds are selected."));
689 function purgeSelectedFeeds() {
691 if (!xmlhttp_ready(xmlhttp)) {
696 var sel_rows = getSelectedFeeds();
698 if (sel_rows.length > 0) {
700 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
702 if (pr != undefined) {
703 notify_progress("Purging selected feed...");
705 var query = "backend.php?op=rpc&subop=purge&ids="+
706 param_escape(sel_rows.toString()) + "&days=" + pr;
710 new Ajax.Request(query, {
711 onComplete: function(transport) {
718 alert(__("No feeds are selected."));
725 function removeSelectedFeedCats() {
727 if (!xmlhttp_ready(xmlhttp)) {
732 var sel_rows = getSelectedFeedCats();
734 if (sel_rows.length > 0) {
736 var ok = confirm(__("Remove selected categories?"));
739 notify_progress("Removing selected categories...");
741 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
742 param_escape(sel_rows.toString()), true);
743 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
749 alert(__("No categories are selected."));
756 function feedEditCancel() {
758 if (!xmlhttp_ready(xmlhttp)) {
764 document.getElementById("subscribe_to_feed_btn").disabled = false;
765 document.getElementById("top25_feeds_btn").disabled = false;
767 // this button is not always available, no-op if not found
772 selectPrefRows('feed', false); // cleanup feed selection
777 function feedCatEditCancel() {
779 if (!xmlhttp_ready(xmlhttp)) {
784 active_feed_cat = false;
787 document.getElementById("subscribe_to_feed_btn").disabled = false;
788 document.getElementById("top25_feeds_btn").disabled = false;
790 // this button is not always available, no-op if not found
793 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
794 xmlhttp.onreadystatechange=infobox_callback;
800 function feedEditSave() {
804 if (!xmlhttp_ready(xmlhttp)) {
809 // FIXME: add parameter validation
811 var query = Form.serialize("edit_feed_form");
813 notify_progress("Saving feed...");
815 xmlhttp.open("POST", "backend.php", true);
816 xmlhttp.onreadystatechange=feedlist_callback;
817 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
825 exception_error("feedEditSave", e);
829 function userEditCancel() {
831 if (!xmlhttp_ready(xmlhttp)) {
836 selectPrefRows('user', false); // cleanup feed selection
842 function filterEditCancel() {
844 if (!xmlhttp_ready(xmlhttp)) {
850 document.getElementById("create_filter_btn").disabled = false;
851 selectPrefRows('filter', false); // cleanup feed selection
859 function userEditSave() {
861 if (!xmlhttp_ready(xmlhttp)) {
866 var login = document.forms["user_edit_form"].login.value;
868 if (login.length == 0) {
869 alert(__("Login field cannot be blank."));
873 notify_progress("Saving user...");
877 var query = Form.serialize("user_edit_form");
879 xmlhttp.open("GET", "backend.php?" + query, true);
880 xmlhttp.onreadystatechange=userlist_callback;
887 function filterEditSave() {
889 if (!xmlhttp_ready(xmlhttp)) {
894 /* if (!is_opera()) {
895 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
897 if (reg_exp.length == 0) {
898 alert("Filter expression field cannot be blank.");
903 notify_progress("Saving filter...");
905 var query = Form.serialize("filter_edit_form");
909 document.getElementById("create_filter_btn").disabled = false;
911 xmlhttp.open("GET", "backend.php?" + query, true);
912 xmlhttp.onreadystatechange=filterlist_callback;
919 function editSelectedUser() {
920 var rows = getSelectedUsers();
922 if (rows.length == 0) {
923 alert(__("No users are selected."));
927 if (rows.length > 1) {
928 alert(__("Please select only one user."));
937 function resetSelectedUserPass() {
938 var rows = getSelectedUsers();
940 if (rows.length == 0) {
941 alert(__("No users are selected."));
945 if (rows.length > 1) {
946 alert(__("Please select only one user."));
950 var ok = confirm(__("Reset password of selected user?"));
953 notify_progress("Resetting password for selected user...");
957 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
958 param_escape(id), true);
959 xmlhttp.onreadystatechange=userlist_callback;
964 function selectedUserDetails() {
966 if (!xmlhttp_ready(xmlhttp)) {
971 var rows = getSelectedUsers();
973 if (rows.length == 0) {
974 alert(__("No users are selected."));
978 if (rows.length > 1) {
979 alert(__("Please select only one user."));
983 notify_progress("Loading, please wait...");
987 xmlhttp.open("GET", "backend.php?op=pref-users&subop=user-details&id=" + id, true);
988 xmlhttp.onreadystatechange=infobox_callback;
993 function selectedFeedDetails() {
995 if (!xmlhttp_ready(xmlhttp)) {
1000 var rows = getSelectedFeeds();
1002 if (rows.length == 0) {
1003 alert(__("No feeds are selected."));
1007 if (rows.length > 1) {
1008 alert(__("Please select only one feed."));
1012 // var id = rows[0];
1016 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1017 param_escape(rows.toString()), true);
1018 xmlhttp.onreadystatechange=infobox_callback;
1023 function editSelectedFilter() {
1024 var rows = getSelectedFilters();
1026 if (rows.length == 0) {
1027 alert(__("No filters are selected."));
1031 if (rows.length > 1) {
1032 alert(__("Please select only one filter."));
1038 editFilter(rows[0]);
1043 function editSelectedFeed() {
1044 var rows = getSelectedFeeds();
1046 if (rows.length == 0) {
1047 alert(__("No feeds are selected."));
1051 if (rows.length > 1) {
1052 alert(__("Please select one feed."));
1062 function editSelectedFeeds() {
1064 if (!xmlhttp_ready(xmlhttp)) {
1065 printLockingError();
1069 var rows = getSelectedFeeds();
1071 if (rows.length == 0) {
1072 alert(__("No feeds are selected."));
1080 notify_progress("Loading, please wait...");
1082 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeeds&ids=" +
1083 param_escape(rows.toString()), true);
1085 xmlhttp.onreadystatechange=infobox_callback;
1090 function editSelectedFeedCat() {
1091 var rows = getSelectedFeedCats();
1093 if (rows.length == 0) {
1094 alert(__("No categories are selected."));
1098 if (rows.length > 1) {
1099 alert(__("Please select only one category."));
1105 editFeedCat(rows[0]);
1109 function piggie(enable) {
1111 debug("I LOVEDED IT!");
1112 var piggie = document.getElementById("piggie");
1114 Element.show(piggie);
1115 Position.Center(piggie);
1116 Effect.Puff(piggie);
1121 function validateOpmlImport() {
1123 var opml_file = document.getElementById("opml_file");
1125 if (opml_file.value.length == 0) {
1126 alert(__("No OPML file to upload."));
1133 function updateFilterList(sort_key) {
1135 if (!xmlhttp_ready(xmlhttp)) {
1136 printLockingError();
1140 var filter_search = document.getElementById("filter_search");
1142 if (filter_search) { search = filter_search.value; }
1144 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1145 param_escape(sort_key) +
1146 "&search=" + param_escape(search), true);
1147 xmlhttp.onreadystatechange=filterlist_callback;
1152 function updateLabelList(sort_key) {
1154 if (!xmlhttp_ready(xmlhttp)) {
1155 printLockingError();
1159 var label_search = document.getElementById("label_search");
1161 if (label_search) { search = label_search.value; }
1163 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1164 param_escape(sort_key) +
1165 "&search=" + param_escape(search), true);
1166 xmlhttp.onreadystatechange=labellist_callback;
1170 function updatePrefsList() {
1172 if (!xmlhttp_ready(xmlhttp)) {
1173 printLockingError();
1177 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1178 xmlhttp.onreadystatechange=prefslist_callback;
1183 function selectTab(id, noupdate, subop) {
1187 if (!id) id = active_tab;
1191 if (!xmlhttp_ready(xmlhttp)) {
1192 printLockingError();
1197 var c = document.getElementById('prefContent');
1203 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1205 notify_progress("Loading, please wait...");
1207 // close active infobox if needed
1210 // clean up all current selections, just in case
1211 active_feed_cat = false;
1213 // Effect.Fade("prefContent", {duration: 1, to: 0.01,
1214 // queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1216 if (id == "feedConfig") {
1218 } else if (id == "filterConfig") {
1220 } else if (id == "labelConfig") {
1222 } else if (id == "genConfig") {
1224 } else if (id == "userConfig") {
1229 /* clean selection from all tabs */
1231 var tabs_holder = document.getElementById("prefTabs");
1232 var tab = tabs_holder.firstChild;
1235 if (tab.className && tab.className.match("prefsTabSelected")) {
1236 tab.className = "prefsTab";
1238 tab = tab.nextSibling;
1241 /* mark new tab as selected */
1243 tab = document.getElementById(id + "Tab");
1246 if (!tab.className.match("Selected")) {
1247 tab.className = tab.className + "Selected";
1254 exception_error("selectTab", e);
1258 function backend_sanity_check_callback() {
1260 if (xmlhttp.readyState == 4) {
1264 if (sanity_check_done) {
1265 fatalError(11, "Sanity check request received twice. This can indicate "+
1266 "presence of Firebug or some other disrupting extension. "+
1267 "Please disable it and try again.");
1271 if (!xmlhttp.responseXML) {
1272 fatalError(3, "Sanity Check: Received reply is not XML",
1273 xmlhttp.responseText);
1277 var reply = xmlhttp.responseXML.firstChild.firstChild;
1280 fatalError(3, "Sanity Check: Invalid RPC reply", xmlhttp.responseText);
1284 var error_code = reply.getAttribute("error-code");
1286 if (error_code && error_code != 0) {
1287 return fatalError(error_code, reply.getAttribute("error-msg"));
1290 debug("sanity check ok");
1292 var params = reply.nextSibling;
1295 debug('reading init-params...');
1296 var param = params.firstChild;
1299 var k = param.getAttribute("key");
1300 var v = param.getAttribute("value");
1301 debug(k + " => " + v);
1303 param = param.nextSibling;
1307 sanity_check_done = true;
1309 init_second_stage();
1312 exception_error("backend_sanity_check_callback", e);
1317 function init_second_stage() {
1320 active_tab = getInitParam("prefs_active_tab");
1321 if (!document.getElementById(active_tab+"Tab")) active_tab = "genConfig";
1322 if (!active_tab || active_tab == '0') active_tab = "genConfig";
1324 document.onkeydown = pref_hotkey_handler;
1326 var tab = getURLParam('tab');
1328 caller_subop = getURLParam('subop');
1330 if (getURLParam("subopparam")) {
1331 caller_subop = caller_subop + ":" + getURLParam("subopparam");
1338 if (navigator.userAgent.match("Opera")) {
1339 setTimeout("selectTab()", 500);
1341 selectTab(active_tab);
1345 loading_set_progress(60);
1348 exception_error("init_second_stage", e);
1356 if (arguments.callee.done) return;
1357 arguments.callee.done = true;
1359 if (getURLParam('debug')) {
1360 Element.show("debug_output");
1361 debug('debug mode activated');
1366 document.getElementById("prefContent").innerHTML =
1367 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1368 "to function properly. Your browser doesn't seem to support it.";
1372 loading_set_progress(30);
1374 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1375 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1379 exception_error("init", e);
1383 function categorizeSelectedFeeds() {
1385 if (!xmlhttp_ready(xmlhttp)) {
1386 printLockingError();
1390 var sel_rows = getSelectedFeeds();
1392 var cat_sel = document.getElementById("sfeed_set_fcat");
1393 var cat_id = cat_sel[cat_sel.selectedIndex].value;
1395 if (sel_rows.length > 0) {
1397 notify_progress("Changing category of selected feeds...");
1399 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1400 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1401 xmlhttp.onreadystatechange=feedlist_callback;
1406 alert(__("No feeds are selected."));
1412 function validatePrefsReset() {
1414 var ok = confirm(__("Reset to defaults?"));
1418 var query = Form.serialize("pref_prefs_form");
1419 query = query + "&subop=reset-config";
1422 xmlhttp.open("POST", "backend.php", true);
1423 xmlhttp.onreadystatechange=prefs_reset_callback;
1424 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1425 xmlhttp.send(query);
1429 exception_error("validatePrefsSave", e);
1436 function browseFeeds(limit) {
1438 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1439 xmlhttp.onreadystatechange=infobox_callback;
1444 function feedBrowserSubscribe() {
1447 var selected = getSelectedFeedsFromBrowser();
1449 if (selected.length > 0) {
1451 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1452 param_escape(selected.toString()), true);
1453 xmlhttp.onreadystatechange=feedlist_callback;
1456 alert(__("No feeds are selected."));
1460 exception_error("feedBrowserSubscribe", e);
1464 function updateBigFeedBrowserBtn() {
1465 notify_progress("Loading, please wait...");
1466 return updateBigFeedBrowser();
1469 function selectPrefRows(kind, select) {
1472 var opbarid = false;
1477 if (kind == "feed") {
1478 opbarid = "feedOpToolbar";
1481 lname = "prefFeedList";
1482 } else if (kind == "fcat") {
1483 opbarid = "catOpToolbar";
1486 lname = "prefFeedCatList";
1487 } else if (kind == "filter") {
1488 opbarid = "filterOpToolbar";
1491 lname = "prefFilterList";
1492 } else if (kind == "label") {
1493 opbarid = "labelOpToolbar";
1496 lname = "prefLabelList";
1497 } else if (kind == "user") {
1498 opbarid = "userOpToolbar";
1501 lname = "prefUserList";
1505 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1506 disableContainerChildren(opbarid, !select);
1513 function toggleSelectPrefRow(sender, kind) {
1515 toggleSelectRow(sender);
1518 var opbarid = false;
1521 if (kind == "feed") {
1522 opbarid = "feedOpToolbar";
1523 nsel = getSelectedFeeds();
1524 } else if (kind == "fcat") {
1525 opbarid = "catOpToolbar";
1526 nsel = getSelectedFeedCats();
1527 } else if (kind == "filter") {
1528 opbarid = "filterOpToolbar";
1529 nsel = getSelectedFilters();
1530 } else if (kind == "label") {
1531 opbarid = "labelOpToolbar";
1532 nsel = getSelectedLabels();
1533 } else if (kind == "user") {
1534 opbarid = "userOpToolbar";
1535 nsel = getSelectedUsers();
1538 if (opbarid && nsel != -1) {
1539 disableContainerChildren(opbarid, nsel == false);
1545 function toggleSelectFBListRow(sender) {
1546 toggleSelectListRow(sender);
1547 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1552 function pref_hotkey_handler(e) {
1556 var shift_key = false;
1559 shift_key = e.shiftKey;
1565 keycode = window.event.keyCode;
1570 var keychar = String.fromCharCode(keycode);
1572 if (keycode == 27) { // escape
1573 if (Element.visible("hotkey_help_overlay")) {
1574 Element.hide("hotkey_help_overlay");
1576 hotkey_prefix = false;
1580 if (!hotkeys_enabled) {
1581 debug("hotkeys disabled");
1585 if (keycode == 16) return; // ignore lone shift
1587 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1588 hotkey_prefix = keycode;
1589 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
1593 if (Element.visible("hotkey_help_overlay")) {
1594 Element.hide("hotkey_help_overlay");
1597 if (keycode == 13 || keycode == 27) {
1600 seq = seq + "" + keycode;
1603 /* Global hotkeys */
1605 if (!hotkey_prefix) {
1607 if (keycode == 68 && shift_key) { // d
1608 if (!Element.visible("debug_output")) {
1609 Element.show("debug_output");
1610 debug('debug mode activated');
1612 Element.hide("debug_output");
1617 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
1618 if (!Element.visible("hotkey_help_overlay")) {
1619 //Element.show("hotkey_help_overlay");
1620 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
1622 Element.hide("hotkey_help_overlay");
1627 if (keycode == 191 || keychar == '/') { // /
1628 var search_boxes = new Array("label_search",
1629 "feed_search", "filter_search", "user_search", "feed_browser_search");
1631 for (var i = 0; i < search_boxes.length; i++) {
1632 var elem = document.getElementById(search_boxes[i]);
1634 focus_element(search_boxes[i]);
1643 if (hotkey_prefix == 67) { // c
1644 hotkey_prefix = false;
1646 if (keycode == 70) { // f
1647 displayDlg("quickAddFilter");
1651 if (keycode == 83) { // s
1652 displayDlg("quickAddFeed");
1656 /* if (keycode == 76) { // l
1657 displayDlg("quickAddLabel");
1661 if (keycode == 85) { // u
1665 if (keycode == 67) { // c
1670 if (keycode == 84 && shift_key) { // T
1679 if (hotkey_prefix == 71) { // g
1681 hotkey_prefix = false;
1683 if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
1684 selectTab("genConfig");
1688 if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
1689 selectTab("feedConfig");
1693 if (keycode == 51 && document.getElementById("filterConfigTab")) { // 4
1694 selectTab("filterConfig");
1698 if (keycode == 52 && document.getElementById("labelConfigTab")) { // 5
1699 selectTab("labelConfig");
1703 if (keycode == 53 && document.getElementById("userConfigTab")) { // 6
1704 selectTab("userConfig");
1708 if (keycode == 88) { // x
1714 if (document.getElementById("piggie")) {
1716 if (seq.match("807371717369")) {
1724 if (hotkey_prefix) {
1725 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1727 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
1731 exception_error("pref_hotkey_handler", e);
1735 function editFeedCats() {
1736 if (!xmlhttp_ready(xmlhttp)) {
1737 printLockingError();
1741 document.getElementById("subscribe_to_feed_btn").disabled = true;
1744 document.getElementById("top25_feeds_btn").disabled = true;
1746 // this button is not always available, no-op if not found
1749 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1750 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
1754 function showFeedsWithErrors() {
1755 displayDlg('feedUpdateErrors');
1758 function changeUserPassword() {
1762 if (!xmlhttp_ready(xmlhttp)) {
1763 printLockingError();
1767 var f = document.forms["change_pass_form"];
1770 if (f.OLD_PASSWORD.value == "") {
1771 new Effect.Highlight(f.OLD_PASSWORD);
1772 notify_error("Old password cannot be blank.");
1776 if (f.NEW_PASSWORD.value == "") {
1777 new Effect.Highlight(f.NEW_PASSWORD);
1778 notify_error("New password cannot be blank.");
1782 if (f.CONFIRM_PASSWORD.value == "") {
1783 new Effect.Highlight(f.CONFIRM_PASSWORD);
1784 notify_error("Entered passwords do not match.");
1788 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1789 new Effect.Highlight(f.CONFIRM_PASSWORD);
1790 new Effect.Highlight(f.NEW_PASSWORD);
1791 notify_error("Entered passwords do not match.");
1797 var query = Form.serialize("change_pass_form");
1799 notify_progress("Trying to change password...");
1801 xmlhttp.open("POST", "backend.php", true);
1802 xmlhttp.onreadystatechange=changepass_callback;
1803 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1804 xmlhttp.send(query);
1807 exception_error("changeUserPassword", e);
1813 function changeUserEmail() {
1817 if (!xmlhttp_ready(xmlhttp)) {
1818 printLockingError();
1822 var query = Form.serialize("change_email_form");
1824 notify_progress("Trying to change e-mail...");
1826 xmlhttp.open("POST", "backend.php", true);
1827 xmlhttp.onreadystatechange=notify_callback;
1828 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1829 xmlhttp.send(query);
1832 exception_error("changeUserPassword", e);
1839 function feedlistToggleSLAT() {
1840 notify_progress("Loading, please wait...");
1844 function pubRegenKey() {
1846 if (!xmlhttp_ready(xmlhttp)) {
1847 printLockingError();
1851 var ok = confirm(__("Replace current publishing address with a new one?"));
1855 notify_progress("Trying to change address...");
1857 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
1858 xmlhttp.onreadystatechange=replace_pubkey_callback;
1865 function pubToClipboard() {
1869 if (!xmlhttp_ready(xmlhttp)) {
1870 printLockingError();
1874 var link = document.getElementById("pubGenAddress");
1878 exception_error("pubToClipboard", e);
1884 function validatePrefsSave() {
1887 var ok = confirm(__("Save current configuration?"));
1891 var query = Form.serialize("pref_prefs_form");
1892 query = query + "&subop=save-config";
1895 xmlhttp.open("POST", "backend.php", true);
1896 xmlhttp.onreadystatechange=notify_callback;
1897 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1898 xmlhttp.send(query);
1902 exception_error("validatePrefsSave", e);
1908 function feedActionChange() {
1910 var chooser = document.getElementById("feedActionChooser");
1911 var opid = chooser[chooser.selectedIndex].value;
1913 chooser.selectedIndex = 0;
1916 exception_error("feedActionChange", e);
1920 function feedActionGo(op) {
1922 if (op == "facEdit") {
1924 var rows = getSelectedFeeds();
1926 if (rows.length > 1) {
1927 editSelectedFeeds();
1933 if (op == "facClear") {
1934 clearSelectedFeeds();
1937 if (op == "facPurge") {
1938 purgeSelectedFeeds();
1941 if (op == "facEditCats") {
1945 if (op == "facRescore") {
1946 rescoreSelectedFeeds();
1949 if (op == "facUnsubscribe") {
1950 removeSelectedFeeds();
1954 exception_error("feedActionGo", e);
1959 function clearFeedArticles(feed_id) {
1961 notify_progress("Clearing feed...");
1963 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
1965 new Ajax.Request(query, {
1966 onComplete: function(transport) {
1973 function rescoreSelectedFeeds() {
1975 if (!xmlhttp_ready(xmlhttp)) {
1976 printLockingError();
1980 var sel_rows = getSelectedFeeds();
1982 if (sel_rows.length > 0) {
1984 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
1985 var ok = confirm(__("Rescore articles in selected feeds?"));
1988 notify_progress("Rescoring selected feeds...", true);
1990 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
1991 param_escape(sel_rows.toString()), true);
1992 xmlhttp.onreadystatechange=notify_callback;
1996 alert(__("No feeds are selected."));
2002 function rescore_all_feeds() {
2003 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
2006 notify_progress("Rescoring feeds...", true);
2008 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
2009 xmlhttp.onreadystatechange=notify_callback;
2014 function removeFilter(id, title) {
2016 if (!xmlhttp_ready(xmlhttp)) {
2017 printLockingError();
2021 var msg = __("Remove filter %s?").replace("%s", title);
2023 var ok = confirm(msg);
2028 notify_progress("Removing filter...");
2030 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
2031 param_escape(id), true);
2032 xmlhttp.onreadystatechange=filterlist_callback;
2039 function unsubscribeFeed(id, title) {
2041 if (!xmlhttp_ready(xmlhttp)) {
2042 printLockingError();
2046 var msg = __("Unsubscribe from %s?").replace("%s", title);
2048 var ok = confirm(msg);
2053 notify_progress("Removing feed...");
2055 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
2056 param_escape(id), true);
2057 xmlhttp.onreadystatechange=filterlist_callback;
2067 function feedsEditSave() {
2070 if (!xmlhttp_ready(xmlhttp)) {
2071 printLockingError();
2075 var ok = confirm(__("Save changes to selected feeds?"));
2079 var f = document.forms["batch_edit_feed_form"];
2081 var query = Form.serialize("batch_edit_feed_form");
2083 /* Form.serialize ignores unchecked checkboxes */
2085 if (!query.match("&hidden=") &&
2086 f.hidden.disabled == false) {
2087 query = query + "&hidden=false";
2090 if (!query.match("&rtl_content=") &&
2091 f.rtl_content.disabled == false) {
2092 query = query + "&rtl_content=false";
2095 if (!query.match("&private=") &&
2096 f.private.disabled == false) {
2097 query = query + "&private=false";
2100 if (!query.match("&cache_images=") &&
2101 f.cache_images.disabled == false) {
2102 query = query + "&cache_images=false";
2105 if (!query.match("&include_in_digest=") &&
2106 f.include_in_digest.disabled == false) {
2107 query = query + "&include_in_digest=false";
2112 notify_progress("Saving feeds...");
2114 xmlhttp.open("POST", "backend.php", true);
2115 xmlhttp.onreadystatechange=feedlist_callback;
2116 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2117 xmlhttp.send(query);
2122 exception_error("feedsEditSave", e);
2126 function batchFeedsToggleField(cb, elem, label) {
2128 var f = document.forms["batch_edit_feed_form"];
2129 var l = document.getElementById(label);
2132 f[elem].disabled = false;
2138 // new Effect.Highlight(f[elem], {duration: 1, startcolor: "#fff7d5",
2139 // queue: { position:'end', scope: 'BPEFQ', limit: 1 } } );
2142 f[elem].disabled = true;
2145 l.className = "insensitive";
2150 exception_error("batchFeedsToggleField", e);