]> git.wh0rd.org - tt-rss.git/blame - prefs.js
add quick unsubscribe button to prefs/feedlist
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
1var xmlhttp = false;
2
91ff844a 3var active_feed_cat = false;
48f0adb0 4var active_label = false;
f5a50b25 5var active_tab = false;
c6232e43 6var feed_to_expand = false;
f5a50b25 7
a58069db 8var xmlhttp = Ajax.getTransport();
007bda35 9
a7565293
AD
10var init_params = new Array();
11
e513a74a 12var caller_subop = false;
7a09510c 13var sanity_check_done = false;
746dcf42 14var hotkey_prefix = false;
7a09510c 15
288487e4
AD
16function infobox_callback() {
17 if (xmlhttp.readyState == 4) {
18 infobox_callback2(xmlhttp);
19 }
20}
21
22function infobox_submit_callback() {
23 if (xmlhttp.readyState == 4) {
24 infobox_submit_callback2(xmlhttp);
25 }
26}
27
28
e4f4b46f 29function replace_pubkey_callback() {
c6232e43
AD
30 if (xmlhttp.readyState == 4) {
31 try {
e4f4b46f
AD
32 var link = document.getElementById("pubGenAddress");
33
34 if (xmlhttp.responseXML) {
35
945c243e
AD
36 var new_link = xmlhttp.responseXML.getElementsByTagName("link")[0];
37
38 if (new_link) {
39 link.href = new_link.firstChild.nodeValue;
e635d56a 40 //link.innerHTML = new_link.firstChild.nodeValue;
945c243e 41
3076c7b8
AD
42 new Effect.Highlight(link);
43
e635d56a 44 notify_info("Published feed URL changed.");
945c243e 45 } else {
e635d56a 46 notify_error("Could not change feed URL.");
945c243e 47 }
e4f4b46f
AD
48
49 } else {
e635d56a 50 notify_error("Could not change feed URL.");
e4f4b46f 51 }
c6232e43 52 } catch (e) {
e4f4b46f 53 exception_error("replace_pubkey_callback", e);
c6232e43
AD
54 }
55 }
945c243e 56}
c6232e43 57
e4f4b46f 58function expand_feed_callback() {
bc0ed820
AD
59 if (xmlhttp.readyState == 4) {
60 try {
e4f4b46f 61 var container = document.getElementById("BRDET-" + feed_to_expand);
bc0ed820 62 container.innerHTML=xmlhttp.responseText;
34a01a20 63// container.style.display = "block";
051c4d56 64 Effect.Appear(container, {duration : 0.5});
bc0ed820 65 } catch (e) {
e4f4b46f 66 exception_error("expand_feed_callback", e);
bc0ed820
AD
67 }
68 }
69}
70
007bda35 71function feedlist_callback() {
007bda35 72 if (xmlhttp.readyState == 4) {
47c6c988
AD
73 try {
74 var container = document.getElementById('prefContent');
75 container.innerHTML=xmlhttp.responseText;
a7f22b70 76 selectTab("feedConfig", true);
e513a74a
AD
77
78 if (caller_subop) {
79 var tuple = caller_subop.split(":");
80 if (tuple[0] == 'editFeed') {
81 window.setTimeout('editFeed('+tuple[1]+')', 100);
82 }
83
84 caller_subop = false;
85 }
23943c9b
AD
86 if (typeof correctPNG != 'undefined') {
87 correctPNG();
88 }
7f74a9da 89 notify("");
08827aaf
AD
90 remove_splash();
91
47c6c988
AD
92 } catch (e) {
93 exception_error("feedlist_callback", e);
961513a3 94 }
007bda35
AD
95 }
96}
97
442d77f1
AD
98/* stub for subscription dialog */
99
288487e4 100function dlg_frefresh_callback(transport) {
442d77f1 101
288487e4
AD
102 try {
103 var container = document.getElementById('prefContent');
104 container.innerHTML=transport.responseText;
105 selectTab("feedConfig", true);
442d77f1 106
288487e4
AD
107 if (caller_subop) {
108 var tuple = caller_subop.split(":");
109 if (tuple[0] == 'editFeed') {
110 window.setTimeout('editFeed('+tuple[1]+')', 100);
111 }
442d77f1 112
288487e4 113 caller_subop = false;
442d77f1 114 }
288487e4
AD
115 if (typeof correctPNG != 'undefined') {
116 correctPNG();
117 }
118 notify("");
119 } catch (e) {
120 exception_error("feedlist_callback", e);
442d77f1 121 }
288487e4 122
442d77f1
AD
123}
124
a0d53889 125function filterlist_callback() {
f5a50b25 126 var container = document.getElementById('prefContent');
a0d53889
AD
127 if (xmlhttp.readyState == 4) {
128 container.innerHTML=xmlhttp.responseText;
23943c9b
AD
129 if (typeof correctPNG != 'undefined') {
130 correctPNG();
131 }
7f74a9da 132 notify("");
08827aaf 133 remove_splash();
a0d53889
AD
134 }
135}
136
48f0adb0 137function labellist_callback() {
f5a50b25 138 var container = document.getElementById('prefContent');
48f0adb0 139 if (xmlhttp.readyState == 4) {
f156fd00 140 closeInfoBox();
48f0adb0 141 container.innerHTML=xmlhttp.responseText;
967955b7 142 if (active_label) {
48f0adb0
AD
143 var row = document.getElementById("LILRR-" + active_label);
144 if (row) {
145 if (!row.className.match("Selected")) {
146 row.className = row.className + "Selected";
147 }
148 }
149 var checkbox = document.getElementById("LICHK-" + active_label);
150
151 if (checkbox) {
152 checkbox.checked = true;
153 }
154 }
23943c9b
AD
155 if (typeof correctPNG != 'undefined') {
156 correctPNG();
157 }
7f74a9da 158 notify("");
08827aaf 159 remove_splash();
48f0adb0
AD
160 }
161}
4255b24c 162
c6232e43
AD
163function feed_browser_callback() {
164 var container = document.getElementById('prefContent');
165 if (xmlhttp.readyState == 4) {
166 container.innerHTML=xmlhttp.responseText;
7f74a9da 167 notify("");
08827aaf 168 remove_splash();
c6232e43
AD
169 }
170}
171
e6cb77a0
AD
172function userlist_callback() {
173 var container = document.getElementById('prefContent');
174 if (xmlhttp.readyState == 4) {
175 container.innerHTML=xmlhttp.responseText;
7f74a9da 176 notify("");
08827aaf 177 remove_splash();
e6cb77a0
AD
178 }
179}
180
4255b24c
AD
181function prefslist_callback() {
182 var container = document.getElementById('prefContent');
183 if (xmlhttp.readyState == 4) {
4255b24c 184 container.innerHTML=xmlhttp.responseText;
7f74a9da 185 notify("");
08827aaf 186 remove_splash();
4255b24c
AD
187 }
188}
189
b1895692
AD
190function gethelp_callback() {
191 var container = document.getElementById('prefHelpBox');
192 if (xmlhttp.readyState == 4) {
193
194 container.innerHTML = xmlhttp.responseText;
195 container.style.display = "block";
196
197 }
198}
4255b24c 199
0e091d38 200function notify_callback() {
0e091d38 201 if (xmlhttp.readyState == 4) {
42c32916
AD
202 notify_info(xmlhttp.responseText);
203 }
0e091d38
AD
204}
205
b652c1b7
AD
206function prefs_reset_callback() {
207 if (xmlhttp.readyState == 4) {
208 notify_info(xmlhttp.responseText);
209 selectTab();
210 }
211}
212
d95bd220
AD
213
214function changepass_callback() {
42395d28
AD
215 try {
216 if (xmlhttp.readyState == 4) {
217
218 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
219 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
220 } else {
221 notify_info(xmlhttp.responseText);
222 var warn = document.getElementById("default_pass_warning");
223 if (warn) warn.style.display = "none";
224 }
225
226 document.forms['change_pass_form'].reset();
d95bd220 227
42395d28
AD
228 }
229 } catch (e) {
230 exception_error("changepass_callback", e);
231 }
d95bd220
AD
232}
233
11f083e7
AD
234function infobox_feed_cat_callback() {
235 if (xmlhttp.readyState == 4) {
236 try {
237
238 infobox_callback();
239
240 if (document.getElementById("prefFeedCatList")) {
241 var elems = document.getElementById("prefFeedCatList").getElementsByTagName("SPAN");
242
243 for (var i = 0; i < elems.length; i++) {
244 if (elems[i].id && elems[i].id.match("FCATT-")) {
245 var cat_id = elems[i].id.replace("FCATT-", "");
246
247 new Ajax.InPlaceEditor(elems[i],
248 'backend.php?op=pref-feeds&subop=editCats&action=save&cid=' + cat_id);
249 }
250 }
251 }
252
253 } catch (e) {
254 exception_error("infobox_feed_cat_callback", e);
255 }
256 }
257}
258
b83c7545 259function updateFeedList(sort_key) {
007bda35 260
c0e5a40e 261 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
262 printLockingError();
263 return
264 }
265
f932bc9f
AD
266 var feed_search = document.getElementById("feed_search");
267 var search = "";
268 if (feed_search) { search = feed_search.value; }
269
400b60d8
AD
270 var slat = document.getElementById("show_last_article_times");
271
272 var slat_checked = false;
273 if (slat) {
274 slat_checked = slat.checked;
275 }
276
b83c7545 277 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f 278 "&sort=" + param_escape(sort_key) +
400b60d8 279 "&slat=" + param_escape(slat_checked) +
f932bc9f 280 "&search=" + param_escape(search), true);
007bda35
AD
281 xmlhttp.onreadystatechange=feedlist_callback;
282 xmlhttp.send(null);
283
284}
285
79ec0f2f 286function updateUsersList(sort_key) {
e6cb77a0
AD
287
288 if (!xmlhttp_ready(xmlhttp)) {
289 printLockingError();
290 return
291 }
292
a5bd7bf0
AD
293 var user_search = document.getElementById("user_search");
294 var search = "";
295 if (user_search) { search = user_search.value; }
296
79ec0f2f 297 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
a5bd7bf0
AD
298 + param_escape(sort_key) +
299 "&search=" + param_escape(search), true);
e6cb77a0
AD
300 xmlhttp.onreadystatechange=userlist_callback;
301 xmlhttp.send(null);
302
303}
304
48f0adb0
AD
305function addLabel() {
306
307 if (!xmlhttp_ready(xmlhttp)) {
308 printLockingError();
309 return
310 }
311
f156fd00 312 var form = document.forms['label_edit_form'];
48f0adb0 313
f156fd00
AD
314 var sql_exp = form.sql_exp.value;
315 var description = form.description.value;
48f0adb0 316
f156fd00 317 if (sql_exp == "") {
89cb787e 318 alert(__("Can't create label: missing SQL expression."));
f156fd00 319 return false;
48f0adb0
AD
320 }
321
f156fd00 322 if (description == "") {
89cb787e 323 alert(__("Can't create label: missing caption."));
f156fd00 324 return false;
de435974
AD
325 }
326
f156fd00 327 var query = Form.serialize("label_edit_form");
de435974 328
6068d33b
AD
329 // we can be called from some other tab
330 active_tab = "labelConfig";
331
f156fd00
AD
332 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
333 xmlhttp.onreadystatechange=infobox_submit_callback;
334 xmlhttp.send(null);
de435974 335}
48f0adb0 336
71ad3959
AD
337function addFeed() {
338
c0e5a40e 339 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
340 printLockingError();
341 return
342 }
343
331900c6
AD
344 var link = document.getElementById("fadd_link");
345
83fe4d6d 346 if (link.value.length == 0) {
f3977cf5 347 alert(__("Error: No feed URL given."));
605f7d46 348 } else if (!isValidURL(link.value)) {
f3977cf5 349 alert(__("Error: Invalid feed URL."));
331900c6 350 } else {
42c32916 351 notify_progress("Adding feed...");
331900c6 352
e513a74a 353 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
331900c6
AD
354 param_escape(link.value), true);
355 xmlhttp.onreadystatechange=feedlist_callback;
356 xmlhttp.send(null);
357
358 link.value = "";
359
360 }
361
362}
363
91ff844a
AD
364function addFeedCat() {
365
366 if (!xmlhttp_ready(xmlhttp)) {
367 printLockingError();
368 return
369 }
370
371 var cat = document.getElementById("fadd_cat");
372
373 if (cat.value.length == 0) {
f3977cf5 374 alert(__("Can't add category: no name specified."));
91ff844a 375 } else {
42c32916 376 notify_progress("Adding feed category...");
91ff844a 377
9c483746 378 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
91ff844a 379 param_escape(cat.value), true);
9c483746 380 xmlhttp.onreadystatechange=infobox_callback;
91ff844a
AD
381 xmlhttp.send(null);
382
383 link.value = "";
384
385 }
386
387}
e6cb77a0
AD
388function addUser() {
389
390 if (!xmlhttp_ready(xmlhttp)) {
391 printLockingError();
392 return
393 }
394
395 var sqlexp = document.getElementById("uadd_box");
396
397 if (sqlexp.value.length == 0) {
89cb787e 398 alert(__("Can't add user: no login specified."));
e6cb77a0 399 } else {
42c32916 400 notify_progress("Adding user...");
e6cb77a0
AD
401
402 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
403 param_escape(sqlexp.value), true);
404
405 xmlhttp.onreadystatechange=userlist_callback;
406 xmlhttp.send(null);
407
408 sqlexp.value = "";
409 }
410
411}
412
48f0adb0
AD
413function editLabel(id) {
414
415 if (!xmlhttp_ready(xmlhttp)) {
416 printLockingError();
417 return
418 }
419
6068d33b
AD
420 disableHotkeys();
421
9e31e1b9
AD
422 notify_progress("Loading, please wait...");
423
38bb1ceb 424// document.getElementById("label_create_btn").disabled = true;
f156fd00 425
48f0adb0
AD
426 active_label = id;
427
a4dbc524
AD
428 selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
429 selectTableRowById('LILRR-'+id, 'LICHK-'+id, true);
430
48f0adb0
AD
431 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
432 param_escape(id), true);
a4dbc524 433 xmlhttp.onreadystatechange=infobox_callback;
48f0adb0
AD
434 xmlhttp.send(null);
435
436}
437
e6cb77a0
AD
438function editUser(id) {
439
440 if (!xmlhttp_ready(xmlhttp)) {
441 printLockingError();
442 return
443 }
444
6068d33b
AD
445 disableHotkeys();
446
9e31e1b9
AD
447 notify_progress("Loading, please wait...");
448
3c5783b7
AD
449 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
450 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
e6cb77a0
AD
451
452 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
453 param_escape(id), true);
3c5783b7 454 xmlhttp.onreadystatechange=infobox_callback;
e6cb77a0
AD
455 xmlhttp.send(null);
456
457}
458
a0d53889
AD
459function editFilter(id) {
460
461 if (!xmlhttp_ready(xmlhttp)) {
462 printLockingError();
463 return
464 }
465
6068d33b
AD
466 disableHotkeys();
467
9e31e1b9
AD
468 notify_progress("Loading, please wait...");
469
38bb1ceb 470// document.getElementById("create_filter_btn").disabled = true;
4220b0bd 471
07164479
AD
472 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
473 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
a0d53889 474
07164479
AD
475 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
476 xmlhttp.onreadystatechange=infobox_callback;
a0d53889 477 xmlhttp.send(null);
a0d53889
AD
478}
479
331900c6
AD
480function editFeed(feed) {
481
508a81e1
AD
482// notify("Editing feed...");
483
c0e5a40e 484 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
485 printLockingError();
486 return
487 }
331900c6 488
6068d33b
AD
489 disableHotkeys();
490
9e31e1b9
AD
491 notify_progress("Loading, please wait...");
492
38bb1ceb 493/* document.getElementById("subscribe_to_feed_btn").disabled = true;
a349077c
AD
494
495 try {
496 document.getElementById("top25_feeds_btn").disabled = true;
497 } catch (e) {
498 // this button is not always available, no-op if not found
38bb1ceb 499 } */
a349077c 500
673d54ca 501 // clean selection from all rows & select row being edited
0ea4fb50 502 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 503 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
504
505 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
3c5783b7 506 param_escape(feed), true);
0ea4fb50
AD
507
508 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
509 xmlhttp.send(null);
510
7bce63e7 511 return false;
331900c6
AD
512}
513
91ff844a 514function editFeedCat(cat) {
48f0adb0 515
91ff844a
AD
516 if (!xmlhttp_ready(xmlhttp)) {
517 printLockingError();
518 return
48f0adb0
AD
519 }
520
6068d33b
AD
521 disableHotkeys();
522
9e31e1b9
AD
523 notify_progress("Loading, please wait...");
524
91ff844a 525 active_feed_cat = cat;
e6cb77a0 526
9c483746 527 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
91ff844a 528 param_escape(cat), true);
9c483746 529 xmlhttp.onreadystatechange=infobox_callback;
91ff844a 530 xmlhttp.send(null);
e6cb77a0 531
e6cb77a0
AD
532}
533
91ff844a
AD
534function getSelectedLabels() {
535 return getSelectedTableRowIds("prefLabelList", "LILRR");
536}
48f0adb0 537
91ff844a
AD
538function getSelectedUsers() {
539 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
540}
541
83fe4d6d 542function getSelectedFeeds() {
91ff844a
AD
543 return getSelectedTableRowIds("prefFeedList", "FEEDR");
544}
331900c6 545
91ff844a
AD
546function getSelectedFilters() {
547 return getSelectedTableRowIds("prefFilterList", "FILRR");
548}
331900c6 549
91ff844a
AD
550function getSelectedFeedCats() {
551 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
552}
553
c0ae0fdb
AD
554function getSelectedFeedsFromBrowser() {
555
556 var list = document.getElementById("browseFeedList");
557 if (!list) list = document.getElementById("browseBigFeedList");
558
559 var selected = new Array();
560
561 for (i = 0; i < list.childNodes.length; i++) {
562 var child = list.childNodes[i];
563 if (child.id && child.id.match("FBROW-")) {
564 var id = child.id.replace("FBROW-", "");
565
566 var cb = document.getElementById("FBCHK-" + id);
567
568 if (cb.checked) {
569 selected.push(id);
570 }
571 }
572 }
573
574 return selected;
575}
576
48f0adb0
AD
577function removeSelectedLabels() {
578
579 if (!xmlhttp_ready(xmlhttp)) {
580 printLockingError();
581 return
582 }
583
584 var sel_rows = getSelectedLabels();
585
586 if (sel_rows.length > 0) {
587
f56e3080 588 var ok = confirm(__("Remove selected labels?"));
48f0adb0 589
69668465 590 if (ok) {
42c32916 591 notify_progress("Removing selected labels...");
69668465
AD
592
593 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
594 param_escape(sel_rows.toString()), true);
595 xmlhttp.onreadystatechange=labellist_callback;
596 xmlhttp.send(null);
597 }
48f0adb0 598 } else {
89cb787e 599 alert(__("No labels are selected."));
48f0adb0 600 }
90ac84df
AD
601
602 return false;
48f0adb0
AD
603}
604
e6cb77a0
AD
605function removeSelectedUsers() {
606
607 if (!xmlhttp_ready(xmlhttp)) {
608 printLockingError();
609 return
610 }
611
612 var sel_rows = getSelectedUsers();
613
614 if (sel_rows.length > 0) {
615
f56e3080 616 var ok = confirm(__("Remove selected users?"));
e6cb77a0 617
69668465 618 if (ok) {
42c32916 619 notify_progress("Removing selected users...");
69668465
AD
620
621 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
622 param_escape(sel_rows.toString()), true);
623 xmlhttp.onreadystatechange=userlist_callback;
624 xmlhttp.send(null);
625 }
e6cb77a0
AD
626
627 } else {
89cb787e 628 alert(__("No users are selected."));
e6cb77a0 629 }
90ac84df
AD
630
631 return false;
e6cb77a0
AD
632}
633
48f0adb0
AD
634function removeSelectedFilters() {
635
636 if (!xmlhttp_ready(xmlhttp)) {
637 printLockingError();
638 return
639 }
640
641 var sel_rows = getSelectedFilters();
642
643 if (sel_rows.length > 0) {
644
f56e3080 645 var ok = confirm(__("Remove selected filters?"));
48f0adb0 646
69668465 647 if (ok) {
42c32916 648 notify_progress("Removing selected filters...");
69668465
AD
649
650 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
651 param_escape(sel_rows.toString()), true);
652 xmlhttp.onreadystatechange=filterlist_callback;
653 xmlhttp.send(null);
654 }
48f0adb0 655 } else {
89cb787e 656 alert(__("No filters are selected."));
48f0adb0 657 }
90ac84df
AD
658
659 return false;
48f0adb0
AD
660}
661
662
83fe4d6d
AD
663function removeSelectedFeeds() {
664
c0e5a40e 665 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
666 printLockingError();
667 return
668 }
669
83fe4d6d
AD
670 var sel_rows = getSelectedFeeds();
671
331900c6
AD
672 if (sel_rows.length > 0) {
673
f56e3080 674 var ok = confirm(__("Unsubscribe from selected feeds?"));
331900c6 675
69668465
AD
676 if (ok) {
677
42c32916 678 notify_progress("Unsubscribing from selected feeds...");
69668465
AD
679
680 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
681 param_escape(sel_rows.toString()), true);
682 xmlhttp.onreadystatechange=feedlist_callback;
683 xmlhttp.send(null);
684 }
71ad3959 685
71ad3959 686 } else {
331900c6 687
89cb787e 688 alert(__("No feeds are selected."));
331900c6 689
71ad3959 690 }
90ac84df
AD
691
692 return false;
71ad3959 693}
007bda35 694
7bce63e7
AD
695function removeFeed(id, title) {
696
697 if (!xmlhttp_ready(xmlhttp)) {
698 printLockingError();
699 return
700 }
701
702 if (id) {
703
704 var msg = __("Unsubscribe from %s?").replace("%s", title);
705
706 var ok = confirm(msg);
707
708 if (ok) {
709
710 notify_progress("Unsubscribing...");
711
712 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
713 param_escape(id), true);
714 xmlhttp.onreadystatechange=feedlist_callback;
715 xmlhttp.send(null);
716 }
717 }
718
719 return false;
720}
721
c4a36709
AD
722function clearSelectedFeeds() {
723
724 if (!xmlhttp_ready(xmlhttp)) {
725 printLockingError();
726 return
727 }
728
729 var sel_rows = getSelectedFeeds();
730
731 if (sel_rows.length > 1) {
732 alert(__("Please select only one feed."));
733 return;
734 }
735
736 if (sel_rows.length > 0) {
737
738 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
739
740 if (ok) {
741 notify_progress("Clearing selected feed...");
742 clearFeedArticles(sel_rows[0]);
743 }
744
745 } else {
746
747 alert(__("No feeds are selected."));
748
749 }
750
751 return false;
752}
753
e88a65f4
AD
754function purgeSelectedFeeds() {
755
756 if (!xmlhttp_ready(xmlhttp)) {
757 printLockingError();
758 return
759 }
760
761 var sel_rows = getSelectedFeeds();
762
763 if (sel_rows.length > 0) {
764
765 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
766
767 if (pr != undefined) {
768 notify_progress("Purging selected feed...");
769
770 var query = "backend.php?op=rpc&subop=purge&ids="+
771 param_escape(sel_rows.toString()) + "&days=" + pr;
772
773 debug(query);
774
775 new Ajax.Request(query, {
776 onComplete: function(transport) {
777 notify('');
778 } });
779 }
780
781 } else {
782
783 alert(__("No feeds are selected."));
784
785 }
786
787 return false;
788}
789
91ff844a
AD
790function removeSelectedFeedCats() {
791
792 if (!xmlhttp_ready(xmlhttp)) {
793 printLockingError();
794 return
795 }
796
797 var sel_rows = getSelectedFeedCats();
798
799 if (sel_rows.length > 0) {
800
f56e3080 801 var ok = confirm(__("Remove selected categories?"));
91ff844a 802
69668465 803 if (ok) {
42c32916 804 notify_progress("Removing selected categories...");
69668465 805
9c483746 806 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
69668465 807 param_escape(sel_rows.toString()), true);
9c483746 808 xmlhttp.onreadystatechange=infobox_callback;
69668465
AD
809 xmlhttp.send(null);
810 }
91ff844a
AD
811
812 } else {
813
89cb787e 814 alert(__("No categories are selected."));
91ff844a
AD
815
816 }
817
90ac84df 818 return false;
91ff844a
AD
819}
820
508a81e1
AD
821function feedEditCancel() {
822
c0e5a40e 823 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
824 printLockingError();
825 return
826 }
827
a349077c 828 try {
57f734c8 829 document.getElementById("subscribe_to_feed_btn").disabled = false;
a349077c
AD
830 document.getElementById("top25_feeds_btn").disabled = false;
831 } catch (e) {
832 // this button is not always available, no-op if not found
833 }
834
327a3bbe
AD
835 closeInfoBox();
836
673d54ca 837 selectPrefRows('feed', false); // cleanup feed selection
508a81e1 838
90ac84df 839 return false;
508a81e1
AD
840}
841
91ff844a
AD
842function feedCatEditCancel() {
843
844 if (!xmlhttp_ready(xmlhttp)) {
845 printLockingError();
846 return
847 }
848
849 active_feed_cat = false;
850
0ceded7a 851// notify("Operation cancelled.");
91ff844a 852
9c483746
AD
853 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
854 xmlhttp.onreadystatechange=infobox_callback;
91ff844a
AD
855 xmlhttp.send(null);
856
90ac84df 857 return false;
91ff844a
AD
858}
859
603c27f8
AD
860function feedEditSave() {
861
47c6c988 862 try {
47c6c988
AD
863
864 if (!xmlhttp_ready(xmlhttp)) {
865 printLockingError();
866 return
867 }
ad815c71 868
14f69488 869 // FIXME: add parameter validation
e3c99f3b 870
14f69488 871 var query = Form.serialize("edit_feed_form");
b0da3a7b 872
42c32916 873 notify_progress("Saving feed...");
673d54ca 874
47c6c988
AD
875 xmlhttp.open("POST", "backend.php", true);
876 xmlhttp.onreadystatechange=feedlist_callback;
877 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
878 xmlhttp.send(query);
879
59a543f0
AD
880 closeInfoBox();
881
c14b5566
AD
882 return false;
883
47c6c988
AD
884 } catch (e) {
885 exception_error("feedEditSave", e);
b0da3a7b 886 }
508a81e1
AD
887}
888
5ddadb4c
AD
889function feedCatEditSave() {
890
891 if (!xmlhttp_ready(xmlhttp)) {
892 printLockingError();
893 return
894 }
895
42c32916 896 notify_progress("Saving category...");
5ddadb4c 897
0666e120
AD
898 var query = Form.serialize("feed_cat_edit_form");
899
900 xmlhttp.open("GET", "backend.php?" + query, true);
9c483746 901 xmlhttp.onreadystatechange=infobox_callback;
5ddadb4c
AD
902 xmlhttp.send(null);
903
904 active_feed_cat = false;
905
90ac84df 906 return false;
5ddadb4c
AD
907}
908
48f0adb0
AD
909function labelEditCancel() {
910
911 if (!xmlhttp_ready(xmlhttp)) {
912 printLockingError();
913 return
914 }
915
57f734c8
AD
916 try {
917 document.getElementById("label_create_btn").disabled = false;
918 selectPrefRows('label', false); // cleanup feed selection
919 } catch (e) { }
f156fd00 920
48f0adb0
AD
921 active_label = false;
922
50bad812
AD
923 closeInfoBox();
924
90ac84df 925 return false;
48f0adb0
AD
926}
927
e6cb77a0
AD
928function userEditCancel() {
929
930 if (!xmlhttp_ready(xmlhttp)) {
931 printLockingError();
932 return
933 }
934
3c5783b7 935 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 936 closeInfoBox();
90ac84df
AD
937
938 return false;
e6cb77a0 939}
48f0adb0 940
a0d53889
AD
941function filterEditCancel() {
942
943 if (!xmlhttp_ready(xmlhttp)) {
944 printLockingError();
945 return
946 }
4220b0bd 947
57f734c8
AD
948 try {
949 document.getElementById("create_filter_btn").disabled = false;
950 selectPrefRows('filter', false); // cleanup feed selection
951 } catch (e) { }
952
07164479 953 closeInfoBox();
90ac84df
AD
954
955 return false;
a0d53889
AD
956}
957
48f0adb0
AD
958function labelEditSave() {
959
960 var label = active_label;
961
962 if (!xmlhttp_ready(xmlhttp)) {
963 printLockingError();
964 return
965 }
966
9ee3ac59 967/* if (!is_opera()) {
48f0adb0 968
7c620da8
AD
969 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
970 var description = document.forms["label_edit_form"].description.value;
971
972 if (sql_exp.length == 0) {
973 alert("SQL Expression cannot be blank.");
974 return false;
975 }
976
977 if (description.length == 0) {
978 alert("Caption field cannot be blank.");
979 return false;
980 }
9ee3ac59 981 } */
48f0adb0 982
50bad812
AD
983 closeInfoBox();
984
42c32916 985 notify_progress("Saving label...");
dbd9e2f1 986
48f0adb0
AD
987 active_label = false;
988
f3120e5a
AD
989 query = Form.serialize("label_edit_form");
990
50bad812 991 xmlhttp.open("GET", "backend.php?" + query, true);
48f0adb0
AD
992 xmlhttp.onreadystatechange=labellist_callback;
993 xmlhttp.send(null);
994
90ac84df 995 return false;
48f0adb0
AD
996}
997
e6cb77a0
AD
998function userEditSave() {
999
e6cb77a0
AD
1000 if (!xmlhttp_ready(xmlhttp)) {
1001 printLockingError();
1002 return
1003 }
1004
3c5783b7 1005 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
1006
1007 if (login.length == 0) {
89cb787e 1008 alert(__("Login field cannot be blank."));
e6cb77a0
AD
1009 return;
1010 }
3c5783b7 1011
42c32916 1012 notify_progress("Saving user...");
4220b0bd
AD
1013
1014 closeInfoBox();
1015
3c5783b7
AD
1016 var query = Form.serialize("user_edit_form");
1017
1018 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 1019 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 1020 xmlhttp.send(null);
90ac84df
AD
1021
1022 return false;
e6cb77a0
AD
1023}
1024
1025
a0d53889
AD
1026function filterEditSave() {
1027
a0d53889
AD
1028 if (!xmlhttp_ready(xmlhttp)) {
1029 printLockingError();
1030 return
1031 }
1032
9ee3ac59 1033/* if (!is_opera()) {
7c620da8
AD
1034 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
1035
1036 if (reg_exp.length == 0) {
1037 alert("Filter expression field cannot be blank.");
1038 return;
1039 }
9ee3ac59 1040 } */
a0d53889 1041
42c32916 1042 notify_progress("Saving filter...");
a0d53889 1043
7e939457 1044 var query = Form.serialize("filter_edit_form");
dbd9e2f1 1045
07164479
AD
1046 closeInfoBox();
1047
4220b0bd
AD
1048 document.getElementById("create_filter_btn").disabled = false;
1049
7e939457 1050 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 1051 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 1052 xmlhttp.send(null);
a0d53889 1053
90ac84df 1054 return false;
a0d53889
AD
1055}
1056
48f0adb0
AD
1057function editSelectedLabel() {
1058 var rows = getSelectedLabels();
a0d53889 1059
48f0adb0 1060 if (rows.length == 0) {
f3977cf5 1061 alert(__("No labels are selected."));
48f0adb0 1062 return;
a0d53889
AD
1063 }
1064
48f0adb0 1065 if (rows.length > 1) {
f3977cf5 1066 alert(__("Please select only one label."));
48f0adb0
AD
1067 return;
1068 }
a0d53889 1069
dbd9e2f1
AD
1070 notify("");
1071
48f0adb0 1072 editLabel(rows[0]);
a0d53889 1073
a0d53889
AD
1074}
1075
e6cb77a0
AD
1076function editSelectedUser() {
1077 var rows = getSelectedUsers();
1078
1079 if (rows.length == 0) {
f3977cf5 1080 alert(__("No users are selected."));
e6cb77a0
AD
1081 return;
1082 }
1083
1084 if (rows.length > 1) {
f3977cf5 1085 alert(__("Please select only one user."));
e6cb77a0
AD
1086 return;
1087 }
1088
dbd9e2f1
AD
1089 notify("");
1090
e6cb77a0
AD
1091 editUser(rows[0]);
1092}
1093
1094function resetSelectedUserPass() {
1095 var rows = getSelectedUsers();
1096
1097 if (rows.length == 0) {
f3977cf5 1098 alert(__("No users are selected."));
e6cb77a0
AD
1099 return;
1100 }
1101
1102 if (rows.length > 1) {
f3977cf5 1103 alert(__("Please select only one user."));
e6cb77a0
AD
1104 return;
1105 }
1106
f3977cf5 1107 var ok = confirm(__("Reset password of selected user?"));
e6cb77a0 1108
69668465 1109 if (ok) {
42c32916 1110 notify_progress("Resetting password for selected user...");
69668465
AD
1111
1112 var id = rows[0];
1113
1114 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
1115 param_escape(id), true);
1116 xmlhttp.onreadystatechange=userlist_callback;
1117 xmlhttp.send(null);
1118 }
e6cb77a0
AD
1119}
1120
717f5e64 1121function selectedUserDetails() {
e6cb77a0 1122
1a7572cb
AD
1123 if (!xmlhttp_ready(xmlhttp)) {
1124 printLockingError();
1125 return
1126 }
1127
717f5e64
AD
1128 var rows = getSelectedUsers();
1129
1130 if (rows.length == 0) {
f3977cf5 1131 alert(__("No users are selected."));
717f5e64
AD
1132 return;
1133 }
1134
1135 if (rows.length > 1) {
f3977cf5 1136 alert(__("Please select only one user."));
717f5e64
AD
1137 return;
1138 }
1139
0077a65c 1140 notify_progress("Loading, please wait...");
717f5e64 1141
0077a65c 1142 var id = rows[0];
dbd9e2f1 1143
1a7572cb 1144 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1145 xmlhttp.onreadystatechange=infobox_callback;
1146 xmlhttp.send(null);
1147
1148}
1149
1150function selectedFeedDetails() {
1151
1152 if (!xmlhttp_ready(xmlhttp)) {
1153 printLockingError();
1154 return
1155 }
1156
1157 var rows = getSelectedFeeds();
1158
1159 if (rows.length == 0) {
f3977cf5 1160 alert(__("No feeds are selected."));
c6c3a07f
AD
1161 return;
1162 }
1163
01b3e191 1164 if (rows.length > 1) {
f3977cf5 1165 alert(__("Please select only one feed."));
01b3e191
AD
1166 return;
1167 }
c6c3a07f 1168
df268d47 1169// var id = rows[0];
c6c3a07f 1170
dbd9e2f1
AD
1171 notify("");
1172
df268d47
AD
1173 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1174 param_escape(rows.toString()), true);
c6c3a07f 1175 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1176 xmlhttp.send(null);
717f5e64
AD
1177
1178}
a0d53889
AD
1179
1180function editSelectedFilter() {
1181 var rows = getSelectedFilters();
1182
1183 if (rows.length == 0) {
f3977cf5 1184 alert(__("No filters are selected."));
a0d53889
AD
1185 return;
1186 }
1187
1188 if (rows.length > 1) {
f3977cf5 1189 alert(__("Please select only one filter."));
a0d53889
AD
1190 return;
1191 }
1192
dbd9e2f1
AD
1193 notify("");
1194
a0d53889
AD
1195 editFilter(rows[0]);
1196
1197}
1198
1199
508a81e1
AD
1200function editSelectedFeed() {
1201 var rows = getSelectedFeeds();
1202
1203 if (rows.length == 0) {
f3977cf5 1204 alert(__("No feeds are selected."));
508a81e1
AD
1205 return;
1206 }
1207
1208 if (rows.length > 1) {
f3977cf5 1209 alert(__("Please select one feed."));
508a81e1
AD
1210 return;
1211 }
1212
dbd9e2f1
AD
1213 notify("");
1214
508a81e1 1215 editFeed(rows[0]);
91ff844a
AD
1216
1217}
1218
1219function editSelectedFeedCat() {
1220 var rows = getSelectedFeedCats();
1221
1222 if (rows.length == 0) {
f3977cf5 1223 alert(__("No categories are selected."));
91ff844a
AD
1224 return;
1225 }
1226
1227 if (rows.length > 1) {
f3977cf5 1228 alert(__("Please select only one category."));
91ff844a
AD
1229 return;
1230 }
1231
1232 notify("");
1233
1234 editFeedCat(rows[0]);
508a81e1
AD
1235
1236}
1237
eec498c3 1238function piggie(enable) {
13ad9102 1239 if (enable) {
d437c8cf 1240 debug("I LOVEDED IT!");
1cac3c31 1241 var piggie = document.getElementById("piggie");
33377ef3 1242
537625c6
AD
1243 Element.show(piggie);
1244 Position.Center(piggie);
1245 Effect.Puff(piggie);
1246
508a81e1 1247 }
508a81e1
AD
1248}
1249
9f311df6
AD
1250function validateOpmlImport() {
1251
1252 var opml_file = document.getElementById("opml_file");
1253
1254 if (opml_file.value.length == 0) {
f3977cf5 1255 alert(__("No OPML file to upload."));
9f311df6
AD
1256 return false;
1257 } else {
1258 return true;
1259 }
1260}
1261
0e317f9d 1262function updateFilterList(sort_key) {
a0d53889
AD
1263
1264 if (!xmlhttp_ready(xmlhttp)) {
1265 printLockingError();
1266 return
1267 }
1268
9c87d75c
AD
1269 var filter_search = document.getElementById("filter_search");
1270 var search = "";
1271 if (filter_search) { search = filter_search.value; }
1272
e161a2cc 1273 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
9c87d75c
AD
1274 param_escape(sort_key) +
1275 "&search=" + param_escape(search), true);
a0d53889
AD
1276 xmlhttp.onreadystatechange=filterlist_callback;
1277 xmlhttp.send(null);
1278
1279}
1280
e161a2cc 1281function updateLabelList(sort_key) {
48f0adb0
AD
1282
1283 if (!xmlhttp_ready(xmlhttp)) {
1284 printLockingError();
1285 return
1286 }
1287
112d2aec
AD
1288 var label_search = document.getElementById("label_search");
1289 var search = "";
1290 if (label_search) { search = label_search.value; }
1291
e161a2cc 1292 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
112d2aec
AD
1293 param_escape(sort_key) +
1294 "&search=" + param_escape(search), true);
48f0adb0
AD
1295 xmlhttp.onreadystatechange=labellist_callback;
1296 xmlhttp.send(null);
48f0adb0
AD
1297}
1298
4255b24c
AD
1299function updatePrefsList() {
1300
1301 if (!xmlhttp_ready(xmlhttp)) {
1302 printLockingError();
1303 return
1304 }
1305
4255b24c
AD
1306 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1307 xmlhttp.onreadystatechange=prefslist_callback;
1308 xmlhttp.send(null);
1309
1310}
1311
e513a74a 1312function selectTab(id, noupdate, subop) {
a7f22b70
AD
1313
1314// alert(id);
48f0adb0 1315
b2caf812 1316 if (!id) id = active_tab;
7f74a9da 1317
b2caf812 1318 try {
59a543f0 1319
b2caf812
AD
1320 if (!xmlhttp_ready(xmlhttp)) {
1321 printLockingError();
1322 return
a7f22b70 1323 }
f5a50b25 1324
a422968f
AD
1325 try {
1326 var c = document.getElementById('prefContent');
1327 c.scrollTop = 0;
1328 } catch (e) { };
1329
b2caf812 1330 if (!noupdate) {
f5a50b25 1331
b2caf812
AD
1332 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1333
9e31e1b9 1334 notify_progress("Loading, please wait...");
b2caf812
AD
1335
1336 // close active infobox if needed
1337 closeInfoBox();
1338
1339 // clean up all current selections, just in case
1340 active_feed_cat = false;
1341 active_label = false;
d15f8675
AD
1342
1343// Effect.Fade("prefContent", {duration: 1, to: 0.01,
1344// queue: { position:'end', scope: 'FEED_TAB', limit: 1 } } );
1345
b2caf812
AD
1346 if (id == "feedConfig") {
1347 updateFeedList();
1348 } else if (id == "filterConfig") {
1349 updateFilterList();
1350 } else if (id == "labelConfig") {
1351 updateLabelList();
1352 } else if (id == "genConfig") {
1353 updatePrefsList();
1354 } else if (id == "userConfig") {
1355 updateUsersList();
1356 } else if (id == "feedBrowser") {
1357 updateBigFeedBrowser();
1358 }
f5a50b25 1359 }
6068d33b
AD
1360
1361 /* clean selection from all tabs */
b2caf812 1362
6068d33b
AD
1363 var tabs_holder = document.getElementById("prefTabs");
1364 var tab = tabs_holder.firstChild;
1365
1366 while (tab) {
1367 if (tab.className && tab.className.match("prefsTabSelected")) {
b2caf812
AD
1368 tab.className = "prefsTab";
1369 }
6068d33b 1370 tab = tab.nextSibling;
f5a50b25 1371 }
6068d33b
AD
1372
1373 /* mark new tab as selected */
1374
b2caf812
AD
1375 tab = document.getElementById(id + "Tab");
1376
1377 if (tab) {
1378 if (!tab.className.match("Selected")) {
1379 tab.className = tab.className + "Selected";
1380 }
1381 }
1382
b2caf812 1383 active_tab = id;
f5a50b25 1384
b2caf812
AD
1385 } catch (e) {
1386 exception_error("selectTab", e);
a7565293 1387 }
a7565293
AD
1388}
1389
1390function backend_sanity_check_callback() {
f5a50b25 1391
a7565293
AD
1392 if (xmlhttp.readyState == 4) {
1393
1394 try {
7a09510c
AD
1395
1396 if (sanity_check_done) {
81352b54
AD
1397 fatalError(11, "Sanity check request received twice. This can indicate "+
1398 "presence of Firebug or some other disrupting extension. "+
1399 "Please disable it and try again.");
7a09510c
AD
1400 return;
1401 }
1402
a7565293
AD
1403 if (!xmlhttp.responseXML) {
1404 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1405 return;
1406 }
1407
1408 var reply = xmlhttp.responseXML.firstChild.firstChild;
1409
1410 if (!reply) {
1411 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1412 return;
1413 }
1414
1415 var error_code = reply.getAttribute("error-code");
1416
1417 if (error_code && error_code != 0) {
1418 return fatalError(error_code, reply.getAttribute("error-msg"));
1419 }
1420
1421 debug("sanity check ok");
1422
1423 var params = reply.nextSibling;
1424
1425 if (params) {
1426 debug('reading init-params...');
1427 var param = params.firstChild;
1428
1429 while (param) {
1430 var k = param.getAttribute("key");
1431 var v = param.getAttribute("value");
1432 debug(k + " => " + v);
1433 init_params[k] = v;
1434 param = param.nextSibling;
1435 }
1436 }
1437
7a09510c
AD
1438 sanity_check_done = true;
1439
a7565293
AD
1440 init_second_stage();
1441
1442 } catch (e) {
1443 exception_error("backend_sanity_check_callback", e);
1444 }
1445 }
1446}
1447
1448function init_second_stage() {
1449
b2caf812
AD
1450 try {
1451 active_tab = getInitParam("prefs_active_tab");
fe8d2059 1452 if (!active_tab || active_tab == '0') active_tab = "genConfig";
4da47970 1453
d437c8cf
AD
1454 document.onkeydown = pref_hotkey_handler;
1455
e513a74a
AD
1456 var tab = getURLParam('tab');
1457
1458 caller_subop = getURLParam('subop');
1459
1460 if (tab) {
1461 active_tab = tab;
1462 }
1463
b2caf812
AD
1464 if (navigator.userAgent.match("Opera")) {
1465 setTimeout("selectTab()", 500);
1466 } else {
1467 selectTab(active_tab);
1468 }
1469 notify("");
08827aaf
AD
1470
1471 loading_set_progress(60);
1472
b2caf812
AD
1473 } catch (e) {
1474 exception_error("init_second_stage", e);
1475 }
a0d53889
AD
1476}
1477
007bda35 1478function init() {
e2ec66a8 1479
7719618b
AD
1480 try {
1481
97dcd654
AD
1482 if (arguments.callee.done) return;
1483 arguments.callee.done = true;
1484
a7565293 1485 if (getURLParam('debug')) {
8836613c 1486 Element.show("debug_output");
a7565293
AD
1487 debug('debug mode activated');
1488 }
1489
7719618b
AD
1490 // IE kludge
1491 if (!xmlhttp) {
1492 document.getElementById("prefContent").innerHTML =
1493 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1494 "to function properly. Your browser doesn't seem to support it.";
1495 return;
1496 }
4da47970 1497
08827aaf
AD
1498 loading_set_progress(30);
1499
a7565293
AD
1500 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1501 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1502 xmlhttp.send(null);
1503
7719618b
AD
1504 } catch (e) {
1505 exception_error("init", e);
e2ec66a8 1506 }
007bda35 1507}
b1895692 1508
f932bc9f
AD
1509function categorizeSelectedFeeds() {
1510
1511 if (!xmlhttp_ready(xmlhttp)) {
1512 printLockingError();
1513 return
1514 }
1515
1516 var sel_rows = getSelectedFeeds();
1517
1518 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1519 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1520
1521 if (sel_rows.length > 0) {
1522
42c32916 1523 notify_progress("Changing category of selected feeds...");
f932bc9f
AD
1524
1525 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1526 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1527 xmlhttp.onreadystatechange=feedlist_callback;
1528 xmlhttp.send(null);
1529
1530 } else {
1531
f3977cf5 1532 alert(__("No feeds are selected."));
f932bc9f
AD
1533
1534 }
1535
1536}
69668465
AD
1537
1538function validatePrefsReset() {
b652c1b7
AD
1539 try {
1540 var ok = confirm(__("Reset to defaults?"));
1541
1542 if (ok) {
1543
1544 var query = Form.serialize("pref_prefs_form");
1545 query = query + "&subop=reset-config";
1546 debug(query);
1547
1548 xmlhttp.open("POST", "backend.php", true);
1549 xmlhttp.onreadystatechange=prefs_reset_callback;
1550 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1551 xmlhttp.send(query);
1552 }
1553
1554 } catch (e) {
1555 exception_error("validatePrefsSave", e);
1556 }
1557
1558 return false;
1559
69668465 1560}
f9cb39ac 1561
6311acbe 1562function browseFeeds(limit) {
f9cb39ac
AD
1563
1564 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1565 xmlhttp.onreadystatechange=infobox_callback;
1566 xmlhttp.send(null);
1567
1568}
a0476535
AD
1569
1570function feedBrowserSubscribe() {
1571 try {
a0476535 1572
c0ae0fdb 1573 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1574
1575 if (selected.length > 0) {
1576 closeInfoBox();
1577 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1578 param_escape(selected.toString()), true);
1579 xmlhttp.onreadystatechange=feedlist_callback;
1580 xmlhttp.send(null);
1581 } else {
89cb787e 1582 alert(__("No feeds are selected."));
a0476535
AD
1583 }
1584
1585 } catch (e) {
1586 exception_error("feedBrowserSubscribe", e);
1587 }
1588}
c6232e43 1589
6311acbe 1590function updateBigFeedBrowser(limit) {
c6232e43
AD
1591
1592 if (!xmlhttp_ready(xmlhttp)) {
1593 printLockingError();
1594 return
1595 }
1596
6311acbe
AD
1597 var query = "backend.php?op=pref-feed-browser";
1598
1599 var limit_sel = document.getElementById("feedBrowserLimit");
1600
1601 if (limit_sel) {
1602 var limit = limit_sel[limit_sel.selectedIndex].value;
1603 query = query + "&limit=" + param_escape(limit);
1604 }
1605
1606 xmlhttp.open("GET", query, true);
c6232e43
AD
1607 xmlhttp.onreadystatechange=feed_browser_callback;
1608 xmlhttp.send(null);
c6232e43
AD
1609}
1610
c2b2aee0 1611function browserToggleExpand(id) {
c6232e43
AD
1612 try {
1613/* if (feed_to_expand && feed_to_expand != id) {
1614 var d = document.getElementById("BRDET-" + feed_to_expand);
1615 d.style.display = "none";
1616 } */
c2b2aee0 1617
ff725e9b
AD
1618 if (!xmlhttp_ready(xmlhttp)) {
1619 printLockingError();
1620 return
1621 }
1622
051c4d56
AD
1623/* if (feed_to_expand && id != feed_to_expand) {
1624 Effect.Fade('BRDET-' + feed_to_expand, {duration : 0.5});
1625 } */
c2b2aee0 1626
051c4d56 1627 var d = document.getElementById("BRDET-" + id);
c6232e43 1628
34a01a20 1629 if (Element.visible(d)) {
051c4d56 1630 Effect.Fade(d, {duration : 0.5});
34a01a20 1631 } else {
c2b2aee0 1632 feed_to_expand = id;
c6232e43 1633
c2b2aee0
AD
1634 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1635 + param_escape(id), true);
1636 xmlhttp.onreadystatechange=expand_feed_callback;
1637 xmlhttp.send(null);
1638 }
c6232e43
AD
1639
1640 } catch (e) {
34a01a20 1641 exception_error("browserToggleExpand", e);
c6232e43
AD
1642 }
1643}
64dc5976 1644
ce3bf408
AD
1645function selectPrefRows(kind, select) {
1646
1647 if (kind) {
1648 var opbarid = false;
1649 var nchk = false;
1650 var nrow = false;
1651 var lname = false;
1652
1653 if (kind == "feed") {
1654 opbarid = "feedOpToolbar";
1655 nrow = "FEEDR-";
1656 nchk = "FRCHK-";
1657 lname = "prefFeedList";
1658 } else if (kind == "fcat") {
1659 opbarid = "catOpToolbar";
1660 nrow = "FCATR-";
9c483746 1661 nchk = "FCCHK-";
ce3bf408
AD
1662 lname = "prefFeedCatList";
1663 } else if (kind == "filter") {
1664 opbarid = "filterOpToolbar";
1665 nrow = "FILRR-";
1666 nchk = "FICHK-";
1667 lname = "prefFilterList";
1668 } else if (kind == "label") {
1669 opbarid = "labelOpToolbar";
1670 nrow = "LILRR-";
a4dbc524 1671 nchk = "LICHK-";
ce3bf408
AD
1672 lname = "prefLabelList";
1673 } else if (kind == "user") {
1674 opbarid = "userOpToolbar";
1675 nrow = "UMRR-";
1676 nchk = "UMCHK-";
1677 lname = "prefUserList";
1678 }
1679
1680 if (opbarid) {
1681 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1682 disableContainerChildren(opbarid, !select);
1683 }
1684
1685 }
1686}
1687
1688
1689function toggleSelectPrefRow(sender, kind) {
1690
1691 toggleSelectRow(sender);
1692
1693 if (kind) {
1694 var opbarid = false;
1695 var nsel = -1;
1696
1697 if (kind == "feed") {
1698 opbarid = "feedOpToolbar";
1699 nsel = getSelectedFeeds();
1700 } else if (kind == "fcat") {
1701 opbarid = "catOpToolbar";
1702 nsel = getSelectedFeedCats();
1703 } else if (kind == "filter") {
1704 opbarid = "filterOpToolbar";
1705 nsel = getSelectedFilters();
1706 } else if (kind == "label") {
1707 opbarid = "labelOpToolbar";
1708 nsel = getSelectedLabels();
1709 } else if (kind == "user") {
1710 opbarid = "userOpToolbar";
1711 nsel = getSelectedUsers();
1712 }
1713
1714 if (opbarid && nsel != -1) {
1715 disableContainerChildren(opbarid, nsel == false);
1716 }
1717
1718 }
1719}
1720
c0ae0fdb
AD
1721function toggleSelectFBListRow(sender) {
1722 toggleSelectListRow(sender);
1723 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1724}
d437c8cf
AD
1725
1726var seq = "";
1727
1728function pref_hotkey_handler(e) {
1729 try {
1730
1731 var keycode;
746dcf42
AD
1732 var shift_key = false;
1733
1734 try {
1735 shift_key = e.shiftKey;
1736 } catch (e) {
1737
1738 }
1739
d437c8cf
AD
1740 if (window.event) {
1741 keycode = window.event.keyCode;
1742 } else if (e) {
1743 keycode = e.which;
1744 }
746dcf42 1745
eec498c3
AD
1746 var keychar = String.fromCharCode(keycode);
1747
746dcf42
AD
1748 if (keycode == 27) { // escape
1749 if (Element.visible("hotkey_help_overlay")) {
1750 Element.hide("hotkey_help_overlay");
1751 }
1752 hotkey_prefix = false;
1753 closeInfoBox();
1754 }
1755
1756 if (!hotkeys_enabled) {
1757 debug("hotkeys disabled");
1758 return;
1759 }
1760
1761 if (keycode == 16) return; // ignore lone shift
1762
6068d33b
AD
1763 if ((keycode == 67 || keycode == 71) && !hotkey_prefix) {
1764 hotkey_prefix = keycode;
eec498c3 1765 debug("KP: PREFIX=" + keycode + " CHAR=" + keychar);
6068d33b
AD
1766 return;
1767 }
1768
746dcf42
AD
1769 if (Element.visible("hotkey_help_overlay")) {
1770 Element.hide("hotkey_help_overlay");
1771 }
1772
d437c8cf
AD
1773 if (keycode == 13 || keycode == 27) {
1774 seq = "";
1775 } else {
1776 seq = seq + "" + keycode;
1777 }
1778
746dcf42 1779 /* Global hotkeys */
d437c8cf 1780
746dcf42
AD
1781 if (!hotkey_prefix) {
1782
1783 if (keycode == 68 && shift_key) { // d
8836613c
AD
1784 if (!Element.visible("debug_output")) {
1785 Element.show("debug_output");
746dcf42
AD
1786 debug('debug mode activated');
1787 } else {
8836613c 1788 Element.hide("debug_output");
746dcf42 1789 }
746dcf42
AD
1790 return;
1791 }
1792
eec498c3 1793 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
746dcf42 1794 if (!Element.visible("hotkey_help_overlay")) {
86deaa0e
AD
1795 //Element.show("hotkey_help_overlay");
1796 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
746dcf42
AD
1797 } else {
1798 Element.hide("hotkey_help_overlay");
1799 }
eec498c3 1800 return false;
746dcf42
AD
1801 }
1802
eec498c3 1803 if (keycode == 191 || keychar == '/') { // /
477402d8
AD
1804 var search_boxes = new Array("label_search",
1805 "feed_search", "filter_search", "user_search");
1806
1807 for (var i = 0; i < search_boxes.length; i++) {
1808 var elem = document.getElementById(search_boxes[i]);
1809 if (elem) {
eec498c3
AD
1810 focus_element(search_boxes[i]);
1811 return false;
477402d8
AD
1812 }
1813 }
477402d8 1814 }
6068d33b
AD
1815 }
1816
1817 /* Prefix c */
1818
1819 if (hotkey_prefix == 67) { // c
1820 hotkey_prefix = false;
1821
1822 if (keycode == 70) { // f
eec498c3
AD
1823 displayDlg("quickAddFilter");
1824 return false;
6068d33b
AD
1825 }
1826
1827 if (keycode == 83) { // s
eec498c3
AD
1828 displayDlg("quickAddFeed");
1829 return false;
6068d33b
AD
1830 }
1831
1832 if (keycode == 76) { // l
eec498c3
AD
1833 displayDlg("quickAddLabel");
1834 return false;
6068d33b
AD
1835 }
1836
1837 if (keycode == 85) { // u
1838 // no-op
1839 }
1840
57f734c8 1841 if (keycode == 67) { // c
eec498c3
AD
1842 editFeedCats();
1843 return false;
57f734c8
AD
1844 }
1845
a80b05ea 1846 if (keycode == 84 && shift_key) { // T
eec498c3
AD
1847 browseFeeds();
1848 return false;
a80b05ea
AD
1849 }
1850
6068d33b
AD
1851 }
1852
1853 /* Prefix g */
1854
1855 if (hotkey_prefix == 71) { // g
1856
1857 hotkey_prefix = false;
1858
1859 if (keycode == 49 && document.getElementById("genConfigTab")) { // 1
746dcf42 1860 selectTab("genConfig");
eec498c3 1861 return false;
746dcf42
AD
1862 }
1863
1864 if (keycode == 50 && document.getElementById("feedConfigTab")) { // 2
eec498c3
AD
1865 selectTab("feedConfig");
1866 return false;
746dcf42
AD
1867 }
1868
1869 if (keycode == 51 && document.getElementById("feedBrowserTab")) { // 3
eec498c3
AD
1870 selectTab("feedBrowser");
1871 return false;
746dcf42
AD
1872 }
1873
1874 if (keycode == 52 && document.getElementById("filterConfigTab")) { // 4
eec498c3
AD
1875 selectTab("filterConfig");
1876 return false;
746dcf42
AD
1877 }
1878
1879 if (keycode == 53 && document.getElementById("labelConfigTab")) { // 5
eec498c3
AD
1880 selectTab("labelConfig");
1881 return false;
746dcf42
AD
1882 }
1883
1884 if (keycode == 54 && document.getElementById("userConfigTab")) { // 6
eec498c3
AD
1885 selectTab("userConfig");
1886 return false;
746dcf42
AD
1887 }
1888
8d727bfc
AD
1889 if (keycode == 88) { // x
1890 return gotoMain();
1891 }
1892
746dcf42
AD
1893 }
1894
1895 if (document.getElementById("piggie")) {
1896
1897 if (seq.match("807371717369")) {
1898 seq = "";
eec498c3 1899 piggie(true);
746dcf42 1900 } else {
eec498c3 1901 piggie(false);
746dcf42
AD
1902 }
1903 }
1904
1905 if (hotkey_prefix) {
eec498c3 1906 debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
d437c8cf 1907 } else {
eec498c3 1908 debug("KP: CODE=" + keycode + " CHAR=" + keychar);
d437c8cf 1909 }
d437c8cf
AD
1910
1911 } catch (e) {
1912 exception_error("pref_hotkey_handler", e);
1913 }
1914}
1915
9c483746
AD
1916function editFeedCats() {
1917 if (!xmlhttp_ready(xmlhttp)) {
1918 printLockingError();
1919 return
1920 }
1921
a349077c
AD
1922 document.getElementById("subscribe_to_feed_btn").disabled = true;
1923
1924 try {
1925 document.getElementById("top25_feeds_btn").disabled = true;
1926 } catch (e) {
1927 // this button is not always available, no-op if not found
1928 }
1929
9c483746 1930 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
11f083e7 1931 xmlhttp.onreadystatechange=infobox_feed_cat_callback;
9c483746
AD
1932 xmlhttp.send(null);
1933}
a3656a41
AD
1934
1935function showFeedsWithErrors() {
1936 displayDlg('feedUpdateErrors');
1937}
073ca0e6 1938
d95bd220
AD
1939function changeUserPassword() {
1940
1941 try {
1942
1943 if (!xmlhttp_ready(xmlhttp)) {
1944 printLockingError();
1945 return false;
1946 }
1947
ae661a8c
AD
1948 var f = document.forms["change_pass_form"];
1949
1950 if (f) {
1951 if (f.OLD_PASSWORD.value == "") {
1952 new Effect.Highlight(f.OLD_PASSWORD);
1953 notify_error("Old password cannot be blank.");
1954 return false;
1955 }
1956
1957 if (f.NEW_PASSWORD.value == "") {
1958 new Effect.Highlight(f.NEW_PASSWORD);
1959 notify_error("New password cannot be blank.");
1960 return false;
1961 }
1962
1963 if (f.CONFIRM_PASSWORD.value == "") {
1964 new Effect.Highlight(f.CONFIRM_PASSWORD);
1965 notify_error("Entered passwords do not match.");
1966 return false;
1967 }
1968
1969 if (f.CONFIRM_PASSWORD.value != f.NEW_PASSWORD.value) {
1970 new Effect.Highlight(f.CONFIRM_PASSWORD);
1971 new Effect.Highlight(f.NEW_PASSWORD);
1972 notify_error("Entered passwords do not match.");
1973 return false;
1974 }
1975
1976 }
1977
d95bd220
AD
1978 var query = Form.serialize("change_pass_form");
1979
1980 notify_progress("Trying to change password...");
1981
1982 xmlhttp.open("POST", "backend.php", true);
1983 xmlhttp.onreadystatechange=changepass_callback;
1984 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1985 xmlhttp.send(query);
1986
1987 } catch (e) {
1988 exception_error("changeUserPassword", e);
1989 }
1990
1991 return false;
1992}
073ca0e6 1993
42395d28
AD
1994function changeUserEmail() {
1995
1996 try {
1997
1998 if (!xmlhttp_ready(xmlhttp)) {
1999 printLockingError();
2000 return false;
2001 }
2002
2003 var query = Form.serialize("change_email_form");
2004
2005 notify_progress("Trying to change e-mail...");
2006
2007 xmlhttp.open("POST", "backend.php", true);
2008 xmlhttp.onreadystatechange=notify_callback;
2009 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2010 xmlhttp.send(query);
2011
2012 } catch (e) {
2013 exception_error("changeUserPassword", e);
2014 }
2015
2016 return false;
2017
2018}
400b60d8
AD
2019
2020function feedlistToggleSLAT() {
2021 notify_progress("Loading, please wait...");
2022 updateFeedList()
2023}
bc0ed820 2024
e4f4b46f
AD
2025function pubRegenKey() {
2026
bc0ed820
AD
2027 if (!xmlhttp_ready(xmlhttp)) {
2028 printLockingError();
e4f4b46f 2029 return false;
bc0ed820
AD
2030 }
2031
f56e3080 2032 var ok = confirm(__("Replace current publishing address with a new one?"));
bc0ed820 2033
e4f4b46f
AD
2034 if (ok) {
2035
2036 notify_progress("Trying to change address...");
2037
945c243e 2038 xmlhttp.open("GET", "backend.php?op=rpc&subop=regenPubKey");
e4f4b46f
AD
2039 xmlhttp.onreadystatechange=replace_pubkey_callback;
2040 xmlhttp.send(null);
2041 }
2042
2043 return false;
945c243e 2044}
b652c1b7 2045
e635d56a
AD
2046function pubToClipboard() {
2047
2048 try {
2049
2050 if (!xmlhttp_ready(xmlhttp)) {
2051 printLockingError();
2052 return false;
2053 }
2054
2055 var link = document.getElementById("pubGenAddress");
2056 alert(link.href);
2057
2058 } catch (e) {
2059 exception_error("pubToClipboard", e);
2060 }
2061
2062 return false;
2063}
2064
b652c1b7
AD
2065function validatePrefsSave() {
2066 try {
2067
2068 var ok = confirm(__("Save current configuration?"));
2069
2070 if (ok) {
2071
2072 var query = Form.serialize("pref_prefs_form");
2073 query = query + "&subop=save-config";
2074 debug(query);
2075
2076 xmlhttp.open("POST", "backend.php", true);
2077 xmlhttp.onreadystatechange=notify_callback;
2078 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2079 xmlhttp.send(query);
2080 }
2081
2082 } catch (e) {
2083 exception_error("validatePrefsSave", e);
2084 }
2085
2086 return false;
2087}
c4a36709
AD
2088
2089function feedActionChange() {
2090 try {
2091 var chooser = document.getElementById("feedActionChooser");
2092 var opid = chooser[chooser.selectedIndex].value;
2093
2094 chooser.selectedIndex = 0;
2095 feedActionGo(opid);
2096 } catch (e) {
2097 exception_error("feedActionChange", e);
2098 }
2099}
2100
2101function feedActionGo(op) {
2102 try {
2103 if (op == "facEdit") {
2104 editSelectedFeed();
2105 }
2106
2107 if (op == "facClear") {
2108 clearSelectedFeeds();
2109 }
2110
2111 if (op == "facPurge") {
2112 purgeSelectedFeeds();
2113 }
2114
e88a65f4
AD
2115 if (op == "facEditCats") {
2116 editFeedCats();
2117 }
2118
fee840fb
AD
2119 if (op == "facRescore") {
2120 rescoreSelectedFeeds();
2121 }
2122
c4a36709
AD
2123 if (op == "facUnsubscribe") {
2124 removeSelectedFeeds();
2125 }
2126
2127 } catch (e) {
2128 exception_error("feedActionGo", e);
2129
2130 }
2131}
2132
2133function clearFeedArticles(feed_id) {
2134
2135 notify_progress("Clearing feed...");
2136
2137 var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id;
2138
2139 new Ajax.Request(query, {
2140 onComplete: function(transport) {
2141 notify('');
2142 } });
2143
2144 return false;
2145}
2146
fee840fb
AD
2147function rescoreSelectedFeeds() {
2148
2149 if (!xmlhttp_ready(xmlhttp)) {
2150 printLockingError();
2151 return
2152 }
2153
2154 var sel_rows = getSelectedFeeds();
2155
2156 if (sel_rows.length > 0) {
2157
ef1b0366
AD
2158 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
2159 var ok = confirm(__("Rescore articles in selected feeds?"));
fee840fb
AD
2160
2161 if (ok) {
95a948a5 2162 notify_progress("Rescoring selected feeds...");
fee840fb
AD
2163
2164 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids="+
2165 param_escape(sel_rows.toString()), true);
2166 xmlhttp.onreadystatechange=notify_callback;
2167 xmlhttp.send(null);
2168 }
2169 } else {
2170 alert(__("No feeds are selected."));
2171 }
2172
2173 return false;
2174}
c4a36709 2175
95a948a5
AD
2176function rescore_all_feeds() {
2177 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
2178
2179 if (ok) {
2180 notify_progress("Rescoring feeds...");
2181
2182 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=rescoreAll&quiet=1", true);
2183 xmlhttp.onreadystatechange=notify_callback;
2184 xmlhttp.send(null);
2185 }
a80b05ea 2186}