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