]> git.wh0rd.org - tt-rss.git/blame - prefs.js
fix: enable toolbar form before viewing feed for the first time
[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
1cac3c31
AD
8var piggie_top = -400;
9var piggie_fwd = true;
10
a58069db 11var xmlhttp = Ajax.getTransport();
007bda35 12
a7565293
AD
13var init_params = new Array();
14
e513a74a
AD
15var caller_subop = false;
16
7a09510c
AD
17var sanity_check_done = false;
18
c6232e43
AD
19function expand_feed_callback() {
20 if (xmlhttp.readyState == 4) {
21 try {
22 var container = document.getElementById("BRDET-" + feed_to_expand);
23 container.innerHTML=xmlhttp.responseText;
24 container.style.display = "block";
4d4200a8 25// p_notify("");
c6232e43
AD
26 } catch (e) {
27 exception_error("expand_feed_callback", e);
28 }
29 }
30}
31
007bda35 32function feedlist_callback() {
007bda35 33 if (xmlhttp.readyState == 4) {
47c6c988
AD
34 try {
35 var container = document.getElementById('prefContent');
36 container.innerHTML=xmlhttp.responseText;
a7f22b70 37 selectTab("feedConfig", true);
e513a74a
AD
38
39 if (caller_subop) {
40 var tuple = caller_subop.split(":");
41 if (tuple[0] == 'editFeed') {
42 window.setTimeout('editFeed('+tuple[1]+')', 100);
43 }
44
45 caller_subop = false;
46 }
23943c9b
AD
47 if (typeof correctPNG != 'undefined') {
48 correctPNG();
49 }
7f74a9da 50 notify("");
47c6c988
AD
51 } catch (e) {
52 exception_error("feedlist_callback", e);
961513a3 53 }
007bda35
AD
54 }
55}
56
442d77f1
AD
57/* stub for subscription dialog */
58
59function dlg_frefresh_callback() {
60 if (xmlhttp.readyState == 4) {
61 // setTimeout("updateFeedList()", 500);
62
63 try {
64 var container = document.getElementById('prefContent');
65 container.innerHTML=xmlhttp.responseText;
66 selectTab("feedConfig", true);
67
68 if (caller_subop) {
69 var tuple = caller_subop.split(":");
70 if (tuple[0] == 'editFeed') {
71 window.setTimeout('editFeed('+tuple[1]+')', 100);
72 }
73
74 caller_subop = false;
75 }
76 if (typeof correctPNG != 'undefined') {
77 correctPNG();
78 }
79 notify("");
80 } catch (e) {
81 exception_error("feedlist_callback", e);
82 }
83 }
84}
85
a0d53889 86function filterlist_callback() {
f5a50b25 87 var container = document.getElementById('prefContent');
a0d53889
AD
88 if (xmlhttp.readyState == 4) {
89 container.innerHTML=xmlhttp.responseText;
23943c9b
AD
90 if (typeof correctPNG != 'undefined') {
91 correctPNG();
92 }
7f74a9da 93 notify("");
a0d53889
AD
94 }
95}
96
48f0adb0 97function labellist_callback() {
f5a50b25 98 var container = document.getElementById('prefContent');
48f0adb0 99 if (xmlhttp.readyState == 4) {
f156fd00 100 closeInfoBox();
48f0adb0 101 container.innerHTML=xmlhttp.responseText;
967955b7 102 if (active_label) {
48f0adb0
AD
103 var row = document.getElementById("LILRR-" + active_label);
104 if (row) {
105 if (!row.className.match("Selected")) {
106 row.className = row.className + "Selected";
107 }
108 }
109 var checkbox = document.getElementById("LICHK-" + active_label);
110
111 if (checkbox) {
112 checkbox.checked = true;
113 }
114 }
23943c9b
AD
115 if (typeof correctPNG != 'undefined') {
116 correctPNG();
117 }
7f74a9da 118 notify("");
48f0adb0
AD
119 }
120}
4255b24c 121
a4dbc524
AD
122function labeltest_callback() {
123 var container = document.getElementById('label_test_result');
124 if (xmlhttp.readyState == 4) {
125 container.innerHTML=xmlhttp.responseText;
126 notify("");
127 }
128}
129
c6232e43
AD
130function feed_browser_callback() {
131 var container = document.getElementById('prefContent');
132 if (xmlhttp.readyState == 4) {
133 container.innerHTML=xmlhttp.responseText;
7f74a9da 134 notify("");
c6232e43
AD
135 }
136}
137
e6cb77a0
AD
138function userlist_callback() {
139 var container = document.getElementById('prefContent');
140 if (xmlhttp.readyState == 4) {
141 container.innerHTML=xmlhttp.responseText;
7f74a9da 142 notify("");
e6cb77a0
AD
143 }
144}
145
4255b24c
AD
146function prefslist_callback() {
147 var container = document.getElementById('prefContent');
148 if (xmlhttp.readyState == 4) {
149
150 container.innerHTML=xmlhttp.responseText;
7f74a9da
AD
151
152 notify("");
4255b24c
AD
153 }
154}
155
b1895692
AD
156function gethelp_callback() {
157 var container = document.getElementById('prefHelpBox');
158 if (xmlhttp.readyState == 4) {
159
160 container.innerHTML = xmlhttp.responseText;
161 container.style.display = "block";
162
163 }
164}
4255b24c 165
0e091d38 166function notify_callback() {
0e091d38 167 if (xmlhttp.readyState == 4) {
42c32916
AD
168 notify_info(xmlhttp.responseText);
169 }
0e091d38
AD
170}
171
d95bd220
AD
172
173function changepass_callback() {
42395d28
AD
174 try {
175 if (xmlhttp.readyState == 4) {
176
177 if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
178 notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
179 } else {
180 notify_info(xmlhttp.responseText);
181 var warn = document.getElementById("default_pass_warning");
182 if (warn) warn.style.display = "none";
183 }
184
185 document.forms['change_pass_form'].reset();
d95bd220 186
42395d28
AD
187 }
188 } catch (e) {
189 exception_error("changepass_callback", e);
190 }
d95bd220
AD
191}
192
b83c7545 193function updateFeedList(sort_key) {
007bda35 194
c0e5a40e 195 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
196 printLockingError();
197 return
198 }
199
f5a50b25
AD
200// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
201
ce3bf408 202// p_notify("Loading, please wait...");
007bda35 203
f932bc9f
AD
204 var feed_search = document.getElementById("feed_search");
205 var search = "";
206 if (feed_search) { search = feed_search.value; }
207
400b60d8
AD
208 var slat = document.getElementById("show_last_article_times");
209
210 var slat_checked = false;
211 if (slat) {
212 slat_checked = slat.checked;
213 }
214
b83c7545 215 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f 216 "&sort=" + param_escape(sort_key) +
400b60d8 217 "&slat=" + param_escape(slat_checked) +
f932bc9f 218 "&search=" + param_escape(search), true);
007bda35
AD
219 xmlhttp.onreadystatechange=feedlist_callback;
220 xmlhttp.send(null);
221
222}
223
79ec0f2f 224function updateUsersList(sort_key) {
e6cb77a0
AD
225
226 if (!xmlhttp_ready(xmlhttp)) {
227 printLockingError();
228 return
229 }
230
231// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
232
ce3bf408 233// p_notify("Loading, please wait...");
e6cb77a0 234
79ec0f2f
AD
235 xmlhttp.open("GET", "backend.php?op=pref-users&sort="
236 + param_escape(sort_key), true);
e6cb77a0
AD
237 xmlhttp.onreadystatechange=userlist_callback;
238 xmlhttp.send(null);
239
240}
241
48f0adb0
AD
242function addLabel() {
243
244 if (!xmlhttp_ready(xmlhttp)) {
245 printLockingError();
246 return
247 }
248
f156fd00 249 var form = document.forms['label_edit_form'];
48f0adb0 250
f156fd00
AD
251 var sql_exp = form.sql_exp.value;
252 var description = form.description.value;
48f0adb0 253
f156fd00
AD
254 if (sql_exp == "") {
255 alert("Can't create label: missing SQL expression.");
256 return false;
48f0adb0
AD
257 }
258
f156fd00
AD
259 if (description == "") {
260 alert("Can't create label: missing caption.");
261 return false;
de435974
AD
262 }
263
f156fd00 264 var query = Form.serialize("label_edit_form");
de435974 265
f156fd00
AD
266 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
267 xmlhttp.onreadystatechange=infobox_submit_callback;
268 xmlhttp.send(null);
de435974 269}
48f0adb0 270
71ad3959
AD
271function addFeed() {
272
c0e5a40e 273 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
274 printLockingError();
275 return
276 }
277
331900c6
AD
278 var link = document.getElementById("fadd_link");
279
83fe4d6d 280 if (link.value.length == 0) {
f3977cf5 281 alert(__("Error: No feed URL given."));
605f7d46 282 } else if (!isValidURL(link.value)) {
f3977cf5 283 alert(__("Error: Invalid feed URL."));
331900c6 284 } else {
42c32916 285 notify_progress("Adding feed...");
331900c6 286
e513a74a 287 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
331900c6
AD
288 param_escape(link.value), true);
289 xmlhttp.onreadystatechange=feedlist_callback;
290 xmlhttp.send(null);
291
292 link.value = "";
293
294 }
295
296}
297
91ff844a
AD
298function addFeedCat() {
299
300 if (!xmlhttp_ready(xmlhttp)) {
301 printLockingError();
302 return
303 }
304
305 var cat = document.getElementById("fadd_cat");
306
307 if (cat.value.length == 0) {
f3977cf5 308 alert(__("Can't add category: no name specified."));
91ff844a 309 } else {
42c32916 310 notify_progress("Adding feed category...");
91ff844a 311
9c483746 312 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
91ff844a 313 param_escape(cat.value), true);
9c483746 314 xmlhttp.onreadystatechange=infobox_callback;
91ff844a
AD
315 xmlhttp.send(null);
316
317 link.value = "";
318
319 }
320
321}
e6cb77a0
AD
322function addUser() {
323
324 if (!xmlhttp_ready(xmlhttp)) {
325 printLockingError();
326 return
327 }
328
329 var sqlexp = document.getElementById("uadd_box");
330
331 if (sqlexp.value.length == 0) {
01b3e191 332 alert("Can't add user: no login specified.");
e6cb77a0 333 } else {
42c32916 334 notify_progress("Adding user...");
e6cb77a0
AD
335
336 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
337 param_escape(sqlexp.value), true);
338
339 xmlhttp.onreadystatechange=userlist_callback;
340 xmlhttp.send(null);
341
342 sqlexp.value = "";
343 }
344
345}
346
48f0adb0
AD
347function editLabel(id) {
348
349 if (!xmlhttp_ready(xmlhttp)) {
350 printLockingError();
351 return
352 }
353
9e31e1b9
AD
354 notify_progress("Loading, please wait...");
355
f156fd00
AD
356 document.getElementById("label_create_btn").disabled = true;
357
48f0adb0
AD
358 active_label = id;
359
a4dbc524
AD
360 selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
361 selectTableRowById('LILRR-'+id, 'LICHK-'+id, true);
362
48f0adb0
AD
363 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
364 param_escape(id), true);
a4dbc524 365 xmlhttp.onreadystatechange=infobox_callback;
48f0adb0
AD
366 xmlhttp.send(null);
367
368}
369
e6cb77a0
AD
370function editUser(id) {
371
372 if (!xmlhttp_ready(xmlhttp)) {
373 printLockingError();
374 return
375 }
376
9e31e1b9
AD
377 notify_progress("Loading, please wait...");
378
3c5783b7
AD
379 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
380 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
e6cb77a0
AD
381
382 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
383 param_escape(id), true);
3c5783b7 384 xmlhttp.onreadystatechange=infobox_callback;
e6cb77a0
AD
385 xmlhttp.send(null);
386
387}
388
a0d53889
AD
389function editFilter(id) {
390
391 if (!xmlhttp_ready(xmlhttp)) {
392 printLockingError();
393 return
394 }
395
9e31e1b9
AD
396 notify_progress("Loading, please wait...");
397
4220b0bd
AD
398 document.getElementById("create_filter_btn").disabled = true;
399
07164479
AD
400 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
401 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
a0d53889 402
07164479
AD
403 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
404 xmlhttp.onreadystatechange=infobox_callback;
a0d53889 405 xmlhttp.send(null);
a0d53889
AD
406}
407
331900c6
AD
408function editFeed(feed) {
409
508a81e1
AD
410// notify("Editing feed...");
411
c0e5a40e 412 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
413 printLockingError();
414 return
415 }
331900c6 416
9e31e1b9
AD
417 notify_progress("Loading, please wait...");
418
a349077c
AD
419 document.getElementById("subscribe_to_feed_btn").disabled = true;
420
421 try {
422 document.getElementById("top25_feeds_btn").disabled = true;
423 } catch (e) {
424 // this button is not always available, no-op if not found
425 }
426
673d54ca 427 // clean selection from all rows & select row being edited
0ea4fb50 428 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 429 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
430
431 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
3c5783b7 432 param_escape(feed), true);
0ea4fb50
AD
433
434 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
435 xmlhttp.send(null);
436
437}
438
91ff844a 439function editFeedCat(cat) {
48f0adb0 440
91ff844a
AD
441 if (!xmlhttp_ready(xmlhttp)) {
442 printLockingError();
443 return
48f0adb0
AD
444 }
445
9e31e1b9
AD
446 notify_progress("Loading, please wait...");
447
91ff844a 448 active_feed_cat = cat;
e6cb77a0 449
9c483746 450 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
91ff844a 451 param_escape(cat), true);
9c483746 452 xmlhttp.onreadystatechange=infobox_callback;
91ff844a 453 xmlhttp.send(null);
e6cb77a0 454
e6cb77a0
AD
455}
456
91ff844a
AD
457function getSelectedLabels() {
458 return getSelectedTableRowIds("prefLabelList", "LILRR");
459}
48f0adb0 460
91ff844a
AD
461function getSelectedUsers() {
462 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
463}
464
83fe4d6d 465function getSelectedFeeds() {
91ff844a
AD
466 return getSelectedTableRowIds("prefFeedList", "FEEDR");
467}
331900c6 468
91ff844a
AD
469function getSelectedFilters() {
470 return getSelectedTableRowIds("prefFilterList", "FILRR");
471}
331900c6 472
91ff844a
AD
473function getSelectedFeedCats() {
474 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
475}
476
c0ae0fdb
AD
477function getSelectedFeedsFromBrowser() {
478
479 var list = document.getElementById("browseFeedList");
480 if (!list) list = document.getElementById("browseBigFeedList");
481
482 var selected = new Array();
483
484 for (i = 0; i < list.childNodes.length; i++) {
485 var child = list.childNodes[i];
486 if (child.id && child.id.match("FBROW-")) {
487 var id = child.id.replace("FBROW-", "");
488
489 var cb = document.getElementById("FBCHK-" + id);
490
491 if (cb.checked) {
492 selected.push(id);
493 }
494 }
495 }
496
497 return selected;
498}
499
48f0adb0
AD
500function removeSelectedLabels() {
501
502 if (!xmlhttp_ready(xmlhttp)) {
503 printLockingError();
504 return
505 }
506
507 var sel_rows = getSelectedLabels();
508
509 if (sel_rows.length > 0) {
510
69668465 511 var ok = confirm("Remove selected labels?");
48f0adb0 512
69668465 513 if (ok) {
42c32916 514 notify_progress("Removing selected labels...");
69668465
AD
515
516 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
517 param_escape(sel_rows.toString()), true);
518 xmlhttp.onreadystatechange=labellist_callback;
519 xmlhttp.send(null);
520 }
48f0adb0 521 } else {
01b3e191 522 alert("No labels are selected.");
48f0adb0 523 }
90ac84df
AD
524
525 return false;
48f0adb0
AD
526}
527
e6cb77a0
AD
528function removeSelectedUsers() {
529
530 if (!xmlhttp_ready(xmlhttp)) {
531 printLockingError();
532 return
533 }
534
535 var sel_rows = getSelectedUsers();
536
537 if (sel_rows.length > 0) {
538
69668465 539 var ok = confirm("Remove selected users?");
e6cb77a0 540
69668465 541 if (ok) {
42c32916 542 notify_progress("Removing selected users...");
69668465
AD
543
544 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
545 param_escape(sel_rows.toString()), true);
546 xmlhttp.onreadystatechange=userlist_callback;
547 xmlhttp.send(null);
548 }
e6cb77a0
AD
549
550 } else {
01b3e191 551 alert("No users are selected.");
e6cb77a0 552 }
90ac84df
AD
553
554 return false;
e6cb77a0
AD
555}
556
48f0adb0
AD
557function removeSelectedFilters() {
558
559 if (!xmlhttp_ready(xmlhttp)) {
560 printLockingError();
561 return
562 }
563
564 var sel_rows = getSelectedFilters();
565
566 if (sel_rows.length > 0) {
567
69668465 568 var ok = confirm("Remove selected filters?");
48f0adb0 569
69668465 570 if (ok) {
42c32916 571 notify_progress("Removing selected filters...");
69668465
AD
572
573 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
574 param_escape(sel_rows.toString()), true);
575 xmlhttp.onreadystatechange=filterlist_callback;
576 xmlhttp.send(null);
577 }
48f0adb0 578 } else {
01b3e191 579 alert("No filters are selected.");
48f0adb0 580 }
90ac84df
AD
581
582 return false;
48f0adb0
AD
583}
584
585
83fe4d6d
AD
586function removeSelectedFeeds() {
587
c0e5a40e 588 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
589 printLockingError();
590 return
591 }
592
83fe4d6d
AD
593 var sel_rows = getSelectedFeeds();
594
331900c6
AD
595 if (sel_rows.length > 0) {
596
1d7bf5a0 597 var ok = confirm("Unsubscribe from selected feeds?");
331900c6 598
69668465
AD
599 if (ok) {
600
42c32916 601 notify_progress("Unsubscribing from selected feeds...");
69668465
AD
602
603 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
604 param_escape(sel_rows.toString()), true);
605 xmlhttp.onreadystatechange=feedlist_callback;
606 xmlhttp.send(null);
607 }
71ad3959 608
71ad3959 609 } else {
331900c6 610
01b3e191 611 alert("No feeds are selected.");
331900c6 612
71ad3959 613 }
90ac84df
AD
614
615 return false;
71ad3959 616}
007bda35 617
91ff844a
AD
618function removeSelectedFeedCats() {
619
620 if (!xmlhttp_ready(xmlhttp)) {
621 printLockingError();
622 return
623 }
624
625 var sel_rows = getSelectedFeedCats();
626
627 if (sel_rows.length > 0) {
628
69668465 629 var ok = confirm("Remove selected categories?");
91ff844a 630
69668465 631 if (ok) {
42c32916 632 notify_progress("Removing selected categories...");
69668465 633
9c483746 634 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
69668465 635 param_escape(sel_rows.toString()), true);
9c483746 636 xmlhttp.onreadystatechange=infobox_callback;
69668465
AD
637 xmlhttp.send(null);
638 }
91ff844a
AD
639
640 } else {
641
01b3e191 642 alert("No categories are selected.");
91ff844a
AD
643
644 }
645
90ac84df 646 return false;
91ff844a
AD
647}
648
508a81e1
AD
649function feedEditCancel() {
650
c0e5a40e 651 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
652 printLockingError();
653 return
654 }
655
a349077c
AD
656 document.getElementById("subscribe_to_feed_btn").disabled = false;
657
658 try {
659 document.getElementById("top25_feeds_btn").disabled = false;
660 } catch (e) {
661 // this button is not always available, no-op if not found
662 }
663
327a3bbe
AD
664 closeInfoBox();
665
673d54ca 666 selectPrefRows('feed', false); // cleanup feed selection
508a81e1 667
90ac84df 668 return false;
508a81e1
AD
669}
670
91ff844a
AD
671function feedCatEditCancel() {
672
673 if (!xmlhttp_ready(xmlhttp)) {
674 printLockingError();
675 return
676 }
677
678 active_feed_cat = false;
679
0ceded7a 680// notify("Operation cancelled.");
91ff844a 681
9c483746
AD
682 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
683 xmlhttp.onreadystatechange=infobox_callback;
91ff844a
AD
684 xmlhttp.send(null);
685
90ac84df 686 return false;
91ff844a
AD
687}
688
603c27f8
AD
689function feedEditSave() {
690
47c6c988 691 try {
47c6c988
AD
692
693 if (!xmlhttp_ready(xmlhttp)) {
694 printLockingError();
695 return
696 }
ad815c71 697
14f69488 698 // FIXME: add parameter validation
e3c99f3b 699
14f69488 700 var query = Form.serialize("edit_feed_form");
b0da3a7b 701
42c32916 702 notify_progress("Saving feed...");
673d54ca 703
47c6c988
AD
704 xmlhttp.open("POST", "backend.php", true);
705 xmlhttp.onreadystatechange=feedlist_callback;
706 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
707 xmlhttp.send(query);
708
59a543f0
AD
709 closeInfoBox();
710
c14b5566
AD
711 return false;
712
47c6c988
AD
713 } catch (e) {
714 exception_error("feedEditSave", e);
b0da3a7b 715 }
508a81e1
AD
716}
717
5ddadb4c
AD
718function feedCatEditSave() {
719
720 if (!xmlhttp_ready(xmlhttp)) {
721 printLockingError();
722 return
723 }
724
42c32916 725 notify_progress("Saving category...");
5ddadb4c 726
0666e120
AD
727 var query = Form.serialize("feed_cat_edit_form");
728
729 xmlhttp.open("GET", "backend.php?" + query, true);
9c483746 730 xmlhttp.onreadystatechange=infobox_callback;
5ddadb4c
AD
731 xmlhttp.send(null);
732
733 active_feed_cat = false;
734
90ac84df 735 return false;
5ddadb4c
AD
736}
737
738
d9dde1d6
AD
739function labelTest() {
740
a4dbc524
AD
741 var container = document.getElementById('label_test_result');
742 container.style.display = "block";
743 container.innerHTML = "<p>Loading, please wait...</p>";
744
f3120e5a
AD
745 var form = document.forms['label_edit_form'];
746
747 var sql_exp = form.sql_exp.value;
748 var description = form.description.value;
d9dde1d6
AD
749
750 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
f3120e5a 751 param_escape(sql_exp) + "&descr=" + param_escape(description), true);
d9dde1d6 752
a4dbc524 753 xmlhttp.onreadystatechange=labeltest_callback;
d9dde1d6
AD
754 xmlhttp.send(null);
755
90ac84df 756 return false;
d9dde1d6
AD
757}
758
01c9c74a
AD
759function displayHelpInfobox(topic_id) {
760
442d77f1 761/* if (!xmlhttp_ready(xmlhttp)) {
9e31e1b9
AD
762 printLockingError();
763 return
764 }
765
766 notify_progress("Loading help...");
767
01c9c74a 768 xmlhttp.open("GET", "backend.php?op=help&tid=" +
442d77f1 769 param_escape(topic_id), true);
01c9c74a 770
442d77f1
AD
771 xmlhttp.onreadystatechange=helpbox_callback;
772 xmlhttp.send(null); */
773
774 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
775
776 var w = window.open(url, "ttrss_help",
777 "status=0,toolbar=0,location=0,width=400,height=450,menubar=0");
01c9c74a
AD
778
779}
780
48f0adb0
AD
781function labelEditCancel() {
782
783 if (!xmlhttp_ready(xmlhttp)) {
784 printLockingError();
785 return
786 }
787
f156fd00
AD
788 document.getElementById("label_create_btn").disabled = false;
789
48f0adb0
AD
790 active_label = false;
791
a4dbc524 792 selectPrefRows('label', false); // cleanup feed selection
50bad812
AD
793 closeInfoBox();
794
90ac84df 795 return false;
48f0adb0
AD
796}
797
e6cb77a0
AD
798function userEditCancel() {
799
800 if (!xmlhttp_ready(xmlhttp)) {
801 printLockingError();
802 return
803 }
804
3c5783b7 805 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 806 closeInfoBox();
90ac84df
AD
807
808 return false;
e6cb77a0 809}
48f0adb0 810
a0d53889
AD
811function filterEditCancel() {
812
813 if (!xmlhttp_ready(xmlhttp)) {
814 printLockingError();
815 return
816 }
4220b0bd
AD
817
818 document.getElementById("create_filter_btn").disabled = false;
07164479
AD
819
820 selectPrefRows('filter', false); // cleanup feed selection
821 closeInfoBox();
90ac84df
AD
822
823 return false;
a0d53889
AD
824}
825
48f0adb0
AD
826function labelEditSave() {
827
828 var label = active_label;
829
830 if (!xmlhttp_ready(xmlhttp)) {
831 printLockingError();
832 return
833 }
834
9ee3ac59 835/* if (!is_opera()) {
48f0adb0 836
7c620da8
AD
837 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
838 var description = document.forms["label_edit_form"].description.value;
839
840 if (sql_exp.length == 0) {
841 alert("SQL Expression cannot be blank.");
842 return false;
843 }
844
845 if (description.length == 0) {
846 alert("Caption field cannot be blank.");
847 return false;
848 }
9ee3ac59 849 } */
48f0adb0 850
50bad812
AD
851 closeInfoBox();
852
42c32916 853 notify_progress("Saving label...");
dbd9e2f1 854
48f0adb0
AD
855 active_label = false;
856
f3120e5a
AD
857 query = Form.serialize("label_edit_form");
858
50bad812 859 xmlhttp.open("GET", "backend.php?" + query, true);
48f0adb0
AD
860 xmlhttp.onreadystatechange=labellist_callback;
861 xmlhttp.send(null);
862
90ac84df 863 return false;
48f0adb0
AD
864}
865
e6cb77a0
AD
866function userEditSave() {
867
e6cb77a0
AD
868 if (!xmlhttp_ready(xmlhttp)) {
869 printLockingError();
870 return
871 }
872
3c5783b7 873 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
874
875 if (login.length == 0) {
3c5783b7 876 alert("Login field cannot be blank.");
e6cb77a0
AD
877 return;
878 }
3c5783b7 879
42c32916 880 notify_progress("Saving user...");
4220b0bd
AD
881
882 closeInfoBox();
883
3c5783b7
AD
884 var query = Form.serialize("user_edit_form");
885
886 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 887 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 888 xmlhttp.send(null);
90ac84df
AD
889
890 return false;
e6cb77a0
AD
891}
892
893
a0d53889
AD
894function filterEditSave() {
895
a0d53889
AD
896 if (!xmlhttp_ready(xmlhttp)) {
897 printLockingError();
898 return
899 }
900
9ee3ac59 901/* if (!is_opera()) {
7c620da8
AD
902 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
903
904 if (reg_exp.length == 0) {
905 alert("Filter expression field cannot be blank.");
906 return;
907 }
9ee3ac59 908 } */
a0d53889 909
42c32916 910 notify_progress("Saving filter...");
a0d53889 911
7e939457 912 var query = Form.serialize("filter_edit_form");
dbd9e2f1 913
07164479
AD
914 closeInfoBox();
915
4220b0bd
AD
916 document.getElementById("create_filter_btn").disabled = false;
917
7e939457 918 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 919 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 920 xmlhttp.send(null);
a0d53889 921
90ac84df 922 return false;
a0d53889
AD
923}
924
48f0adb0
AD
925function editSelectedLabel() {
926 var rows = getSelectedLabels();
a0d53889 927
48f0adb0 928 if (rows.length == 0) {
f3977cf5 929 alert(__("No labels are selected."));
48f0adb0 930 return;
a0d53889
AD
931 }
932
48f0adb0 933 if (rows.length > 1) {
f3977cf5 934 alert(__("Please select only one label."));
48f0adb0
AD
935 return;
936 }
a0d53889 937
dbd9e2f1
AD
938 notify("");
939
48f0adb0 940 editLabel(rows[0]);
a0d53889 941
a0d53889
AD
942}
943
e6cb77a0
AD
944function editSelectedUser() {
945 var rows = getSelectedUsers();
946
947 if (rows.length == 0) {
f3977cf5 948 alert(__("No users are selected."));
e6cb77a0
AD
949 return;
950 }
951
952 if (rows.length > 1) {
f3977cf5 953 alert(__("Please select only one user."));
e6cb77a0
AD
954 return;
955 }
956
dbd9e2f1
AD
957 notify("");
958
e6cb77a0
AD
959 editUser(rows[0]);
960}
961
962function resetSelectedUserPass() {
963 var rows = getSelectedUsers();
964
965 if (rows.length == 0) {
f3977cf5 966 alert(__("No users are selected."));
e6cb77a0
AD
967 return;
968 }
969
970 if (rows.length > 1) {
f3977cf5 971 alert(__("Please select only one user."));
e6cb77a0
AD
972 return;
973 }
974
f3977cf5 975 var ok = confirm(__("Reset password of selected user?"));
e6cb77a0 976
69668465 977 if (ok) {
42c32916 978 notify_progress("Resetting password for selected user...");
69668465
AD
979
980 var id = rows[0];
981
982 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
983 param_escape(id), true);
984 xmlhttp.onreadystatechange=userlist_callback;
985 xmlhttp.send(null);
986 }
e6cb77a0
AD
987}
988
717f5e64 989function selectedUserDetails() {
e6cb77a0 990
1a7572cb
AD
991 if (!xmlhttp_ready(xmlhttp)) {
992 printLockingError();
993 return
994 }
995
717f5e64
AD
996 var rows = getSelectedUsers();
997
998 if (rows.length == 0) {
f3977cf5 999 alert(__("No users are selected."));
717f5e64
AD
1000 return;
1001 }
1002
1003 if (rows.length > 1) {
f3977cf5 1004 alert(__("Please select only one user."));
717f5e64
AD
1005 return;
1006 }
1007
0077a65c 1008 notify_progress("Loading, please wait...");
717f5e64 1009
0077a65c 1010 var id = rows[0];
dbd9e2f1 1011
1a7572cb 1012 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1013 xmlhttp.onreadystatechange=infobox_callback;
1014 xmlhttp.send(null);
1015
1016}
1017
1018function selectedFeedDetails() {
1019
1020 if (!xmlhttp_ready(xmlhttp)) {
1021 printLockingError();
1022 return
1023 }
1024
1025 var rows = getSelectedFeeds();
1026
1027 if (rows.length == 0) {
f3977cf5 1028 alert(__("No feeds are selected."));
c6c3a07f
AD
1029 return;
1030 }
1031
01b3e191 1032 if (rows.length > 1) {
f3977cf5 1033 alert(__("Please select only one feed."));
01b3e191
AD
1034 return;
1035 }
c6c3a07f 1036
df268d47 1037// var id = rows[0];
c6c3a07f 1038
dbd9e2f1
AD
1039 notify("");
1040
df268d47
AD
1041 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1042 param_escape(rows.toString()), true);
c6c3a07f 1043 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1044 xmlhttp.send(null);
717f5e64
AD
1045
1046}
a0d53889
AD
1047
1048function editSelectedFilter() {
1049 var rows = getSelectedFilters();
1050
1051 if (rows.length == 0) {
f3977cf5 1052 alert(__("No filters are selected."));
a0d53889
AD
1053 return;
1054 }
1055
1056 if (rows.length > 1) {
f3977cf5 1057 alert(__("Please select only one filter."));
a0d53889
AD
1058 return;
1059 }
1060
dbd9e2f1
AD
1061 notify("");
1062
a0d53889
AD
1063 editFilter(rows[0]);
1064
1065}
1066
1067
508a81e1
AD
1068function editSelectedFeed() {
1069 var rows = getSelectedFeeds();
1070
1071 if (rows.length == 0) {
f3977cf5 1072 alert(__("No feeds are selected."));
508a81e1
AD
1073 return;
1074 }
1075
1076 if (rows.length > 1) {
f3977cf5 1077 alert(__("Please select one feed."));
508a81e1
AD
1078 return;
1079 }
1080
dbd9e2f1
AD
1081 notify("");
1082
508a81e1 1083 editFeed(rows[0]);
91ff844a
AD
1084
1085}
1086
1087function editSelectedFeedCat() {
1088 var rows = getSelectedFeedCats();
1089
1090 if (rows.length == 0) {
f3977cf5 1091 alert(__("No categories are selected."));
91ff844a
AD
1092 return;
1093 }
1094
1095 if (rows.length > 1) {
f3977cf5 1096 alert(__("Please select only one category."));
91ff844a
AD
1097 return;
1098 }
1099
1100 notify("");
1101
1102 editFeedCat(rows[0]);
508a81e1
AD
1103
1104}
1105
1cac3c31
AD
1106function piggie_callback() {
1107 var piggie = document.getElementById("piggie");
1108
1109 piggie.style.top = piggie_top;
e0b6a737
AD
1110 piggie.style.backgroundColor = "white";
1111 piggie.style.borderWidth = "1px";
1cac3c31
AD
1112
1113 if (piggie_fwd && piggie_top < 0) {
1114 setTimeout("piggie_callback()", 50);
1115 piggie_top = piggie_top + 10;
1116 } else if (piggie_fwd && piggie_top >= 0) {
1117 piggie_fwd = false;
1118 setTimeout("piggie_callback()", 50);
1119 } else if (!piggie_fwd && piggie_top > -400) {
1120 setTimeout("piggie_callback()", 50);
1121 piggie_top = piggie_top - 10;
1122 } else if (!piggie_fwd && piggie_top <= -400) {
1123 piggie.style.display = "none";
1124 piggie_fwd = true;
1125 }
1126}
1127
33377ef3
AD
1128var piggie_opacity = 0;
1129
1130function piggie2_callback() {
1131 var piggie = document.getElementById("piggie");
1132 piggie.style.top = 0;
1133 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1134 piggie.style.backgroundColor = "transparent";
1135 piggie.style.borderWidth = "0px";
33377ef3
AD
1136
1137 if (piggie_fwd && piggie_opacity < 1) {
1138 setTimeout("piggie2_callback()", 50);
1139 piggie_opacity = piggie_opacity + 0.03;
1140 } else if (piggie_fwd && piggie_opacity >= 1) {
1141 piggie_fwd = false;
1142 setTimeout("piggie2_callback()", 50);
1143 } else if (!piggie_fwd && piggie_opacity > 0) {
1144 setTimeout("piggie2_callback()", 50);
1145 piggie_opacity = piggie_opacity - 0.03;
1146 } else if (!piggie_fwd && piggie_opacity <= 0) {
1147 piggie.style.display = "none";
1148 piggie_fwd = true;
1149 }
1150}
1151
13ad9102
AD
1152function localPiggieFunction(enable) {
1153 if (enable) {
d437c8cf 1154 debug("I LOVEDED IT!");
1cac3c31 1155 var piggie = document.getElementById("piggie");
508a81e1 1156 piggie.style.display = "block";
33377ef3 1157
292a8a12 1158 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
33377ef3
AD
1159 piggie2_callback();
1160 } else {
1161 piggie_callback();
1162 }
508a81e1 1163 }
508a81e1
AD
1164}
1165
9f311df6
AD
1166function validateOpmlImport() {
1167
1168 var opml_file = document.getElementById("opml_file");
1169
1170 if (opml_file.value.length == 0) {
f3977cf5 1171 alert(__("No OPML file to upload."));
9f311df6
AD
1172 return false;
1173 } else {
1174 return true;
1175 }
1176}
1177
0e317f9d 1178function updateFilterList(sort_key) {
a0d53889
AD
1179
1180 if (!xmlhttp_ready(xmlhttp)) {
1181 printLockingError();
1182 return
1183 }
1184
f5a50b25
AD
1185// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1186
ce3bf408 1187// p_notify("Loading, please wait...");
a0d53889 1188
e161a2cc
AD
1189 xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
1190 param_escape(sort_key), true);
a0d53889
AD
1191 xmlhttp.onreadystatechange=filterlist_callback;
1192 xmlhttp.send(null);
1193
1194}
1195
e161a2cc 1196function updateLabelList(sort_key) {
48f0adb0
AD
1197
1198 if (!xmlhttp_ready(xmlhttp)) {
1199 printLockingError();
1200 return
1201 }
1202
ce3bf408 1203// p_notify("Loading, please wait...");
f5a50b25
AD
1204
1205// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0 1206
e161a2cc
AD
1207 xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
1208 param_escape(sort_key), true);
48f0adb0
AD
1209 xmlhttp.onreadystatechange=labellist_callback;
1210 xmlhttp.send(null);
48f0adb0
AD
1211}
1212
4255b24c
AD
1213function updatePrefsList() {
1214
1215 if (!xmlhttp_ready(xmlhttp)) {
1216 printLockingError();
1217 return
1218 }
1219
ce3bf408 1220// p_notify("Loading, please wait...");
4255b24c
AD
1221
1222 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1223 xmlhttp.onreadystatechange=prefslist_callback;
1224 xmlhttp.send(null);
1225
1226}
1227
e513a74a 1228function selectTab(id, noupdate, subop) {
a7f22b70
AD
1229
1230// alert(id);
48f0adb0 1231
b2caf812 1232 if (!id) id = active_tab;
7f74a9da 1233
b2caf812 1234 try {
59a543f0 1235
b2caf812
AD
1236 if (!xmlhttp_ready(xmlhttp)) {
1237 printLockingError();
1238 return
a7f22b70 1239 }
f5a50b25 1240
a422968f
AD
1241 try {
1242 var c = document.getElementById('prefContent');
1243 c.scrollTop = 0;
1244 } catch (e) { };
1245
b2caf812 1246 if (!noupdate) {
f5a50b25 1247
b2caf812
AD
1248 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1249
9e31e1b9 1250 notify_progress("Loading, please wait...");
b2caf812
AD
1251
1252 // close active infobox if needed
1253 closeInfoBox();
1254
1255 // clean up all current selections, just in case
1256 active_feed_cat = false;
1257 active_label = false;
1258
1259 if (id == "feedConfig") {
1260 updateFeedList();
1261 } else if (id == "filterConfig") {
1262 updateFilterList();
1263 } else if (id == "labelConfig") {
1264 updateLabelList();
1265 } else if (id == "genConfig") {
1266 updatePrefsList();
1267 } else if (id == "userConfig") {
1268 updateUsersList();
1269 } else if (id == "feedBrowser") {
1270 updateBigFeedBrowser();
1271 }
f5a50b25 1272 }
b2caf812
AD
1273
1274 var tab = document.getElementById(active_tab + "Tab");
1275
1276 if (tab) {
1277 if (tab.className.match("Selected")) {
1278 tab.className = "prefsTab";
1279 }
f5a50b25 1280 }
b2caf812
AD
1281
1282 tab = document.getElementById(id + "Tab");
1283
1284 if (tab) {
1285 if (!tab.className.match("Selected")) {
1286 tab.className = tab.className + "Selected";
1287 }
1288 }
1289
b2caf812 1290 active_tab = id;
f5a50b25 1291
b2caf812
AD
1292 } catch (e) {
1293 exception_error("selectTab", e);
a7565293 1294 }
a7565293
AD
1295}
1296
1297function backend_sanity_check_callback() {
f5a50b25 1298
a7565293
AD
1299 if (xmlhttp.readyState == 4) {
1300
1301 try {
7a09510c
AD
1302
1303 if (sanity_check_done) {
81352b54
AD
1304 fatalError(11, "Sanity check request received twice. This can indicate "+
1305 "presence of Firebug or some other disrupting extension. "+
1306 "Please disable it and try again.");
7a09510c
AD
1307 return;
1308 }
1309
a7565293
AD
1310 if (!xmlhttp.responseXML) {
1311 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1312 return;
1313 }
1314
1315 var reply = xmlhttp.responseXML.firstChild.firstChild;
1316
1317 if (!reply) {
1318 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1319 return;
1320 }
1321
1322 var error_code = reply.getAttribute("error-code");
1323
1324 if (error_code && error_code != 0) {
1325 return fatalError(error_code, reply.getAttribute("error-msg"));
1326 }
1327
1328 debug("sanity check ok");
1329
1330 var params = reply.nextSibling;
1331
1332 if (params) {
1333 debug('reading init-params...');
1334 var param = params.firstChild;
1335
1336 while (param) {
1337 var k = param.getAttribute("key");
1338 var v = param.getAttribute("value");
1339 debug(k + " => " + v);
1340 init_params[k] = v;
1341 param = param.nextSibling;
1342 }
1343 }
1344
7a09510c
AD
1345 sanity_check_done = true;
1346
a7565293
AD
1347 init_second_stage();
1348
1349 } catch (e) {
1350 exception_error("backend_sanity_check_callback", e);
1351 }
1352 }
1353}
1354
1355function init_second_stage() {
1356
b2caf812
AD
1357 try {
1358 active_tab = getInitParam("prefs_active_tab");
fe8d2059 1359 if (!active_tab || active_tab == '0') active_tab = "genConfig";
4da47970 1360
d437c8cf
AD
1361 document.onkeydown = pref_hotkey_handler;
1362
e513a74a
AD
1363 var tab = getURLParam('tab');
1364
1365 caller_subop = getURLParam('subop');
1366
1367 if (tab) {
1368 active_tab = tab;
1369 }
1370
b2caf812
AD
1371 if (navigator.userAgent.match("Opera")) {
1372 setTimeout("selectTab()", 500);
1373 } else {
1374 selectTab(active_tab);
1375 }
1376 notify("");
1377 } catch (e) {
1378 exception_error("init_second_stage", e);
1379 }
a0d53889
AD
1380}
1381
007bda35 1382function init() {
e2ec66a8 1383
7719618b
AD
1384 try {
1385
97dcd654
AD
1386 if (arguments.callee.done) return;
1387 arguments.callee.done = true;
1388
a7565293
AD
1389 if (getURLParam('debug')) {
1390 document.getElementById('debug_output').style.display = 'block';
1391 debug('debug mode activated');
1392 }
1393
7719618b
AD
1394 // IE kludge
1395 if (!xmlhttp) {
1396 document.getElementById("prefContent").innerHTML =
1397 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1398 "to function properly. Your browser doesn't seem to support it.";
1399 return;
1400 }
4da47970 1401
a7565293
AD
1402 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1403 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1404 xmlhttp.send(null);
1405
7719618b
AD
1406 } catch (e) {
1407 exception_error("init", e);
e2ec66a8 1408 }
007bda35 1409}
b1895692 1410
f932bc9f
AD
1411function categorizeSelectedFeeds() {
1412
1413 if (!xmlhttp_ready(xmlhttp)) {
1414 printLockingError();
1415 return
1416 }
1417
1418 var sel_rows = getSelectedFeeds();
1419
1420 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1421 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1422
1423 if (sel_rows.length > 0) {
1424
42c32916 1425 notify_progress("Changing category of selected feeds...");
f932bc9f
AD
1426
1427 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1428 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1429 xmlhttp.onreadystatechange=feedlist_callback;
1430 xmlhttp.send(null);
1431
1432 } else {
1433
f3977cf5 1434 alert(__("No feeds are selected."));
f932bc9f
AD
1435
1436 }
1437
1438}
69668465
AD
1439
1440function validatePrefsReset() {
f3977cf5 1441 return confirm(__("Reset to defaults?"));
69668465 1442}
f9cb39ac 1443
6311acbe 1444function browseFeeds(limit) {
f9cb39ac
AD
1445
1446 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1447 xmlhttp.onreadystatechange=infobox_callback;
1448 xmlhttp.send(null);
1449
1450}
a0476535
AD
1451
1452function feedBrowserSubscribe() {
1453 try {
a0476535 1454
c0ae0fdb 1455 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1456
1457 if (selected.length > 0) {
1458 closeInfoBox();
1459 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1460 param_escape(selected.toString()), true);
1461 xmlhttp.onreadystatechange=feedlist_callback;
1462 xmlhttp.send(null);
1463 } else {
1464 alert("No feeds are selected.");
1465 }
1466
1467 } catch (e) {
1468 exception_error("feedBrowserSubscribe", e);
1469 }
1470}
c6232e43 1471
6311acbe 1472function updateBigFeedBrowser(limit) {
c6232e43
AD
1473
1474 if (!xmlhttp_ready(xmlhttp)) {
1475 printLockingError();
1476 return
1477 }
1478
ce3bf408 1479// p_notify("Loading, please wait...");
c6232e43 1480
6311acbe
AD
1481 var query = "backend.php?op=pref-feed-browser";
1482
1483 var limit_sel = document.getElementById("feedBrowserLimit");
1484
1485 if (limit_sel) {
1486 var limit = limit_sel[limit_sel.selectedIndex].value;
1487 query = query + "&limit=" + param_escape(limit);
1488 }
1489
1490 xmlhttp.open("GET", query, true);
c6232e43
AD
1491 xmlhttp.onreadystatechange=feed_browser_callback;
1492 xmlhttp.send(null);
c6232e43
AD
1493}
1494
c2b2aee0 1495function browserToggleExpand(id) {
c6232e43
AD
1496 try {
1497/* if (feed_to_expand && feed_to_expand != id) {
1498 var d = document.getElementById("BRDET-" + feed_to_expand);
1499 d.style.display = "none";
1500 } */
c2b2aee0 1501
ff725e9b
AD
1502 if (!xmlhttp_ready(xmlhttp)) {
1503 printLockingError();
1504 return
1505 }
1506
c2b2aee0
AD
1507 var d = document.getElementById("BRDET-" + id);
1508
1509 if (d.style.display == "block") {
1510 d.style.display = "none";
1511
1512 } else {
c6232e43 1513
c2b2aee0 1514 feed_to_expand = id;
c6232e43 1515
ff725e9b
AD
1516 d.style.display = "block";
1517 d.innerHTML = "Loading, please wait...";
1518
c2b2aee0
AD
1519 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1520 + param_escape(id), true);
1521 xmlhttp.onreadystatechange=expand_feed_callback;
1522 xmlhttp.send(null);
1523 }
c6232e43
AD
1524
1525 } catch (e) {
1526 exception_error("browserExpand", e);
1527 }
1528}
64dc5976 1529
ce3bf408
AD
1530function selectPrefRows(kind, select) {
1531
1532 if (kind) {
1533 var opbarid = false;
1534 var nchk = false;
1535 var nrow = false;
1536 var lname = false;
1537
1538 if (kind == "feed") {
1539 opbarid = "feedOpToolbar";
1540 nrow = "FEEDR-";
1541 nchk = "FRCHK-";
1542 lname = "prefFeedList";
1543 } else if (kind == "fcat") {
1544 opbarid = "catOpToolbar";
1545 nrow = "FCATR-";
9c483746 1546 nchk = "FCCHK-";
ce3bf408
AD
1547 lname = "prefFeedCatList";
1548 } else if (kind == "filter") {
1549 opbarid = "filterOpToolbar";
1550 nrow = "FILRR-";
1551 nchk = "FICHK-";
1552 lname = "prefFilterList";
1553 } else if (kind == "label") {
1554 opbarid = "labelOpToolbar";
1555 nrow = "LILRR-";
a4dbc524 1556 nchk = "LICHK-";
ce3bf408
AD
1557 lname = "prefLabelList";
1558 } else if (kind == "user") {
1559 opbarid = "userOpToolbar";
1560 nrow = "UMRR-";
1561 nchk = "UMCHK-";
1562 lname = "prefUserList";
1563 }
1564
1565 if (opbarid) {
1566 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1567 disableContainerChildren(opbarid, !select);
1568 }
1569
1570 }
1571}
1572
1573
1574function toggleSelectPrefRow(sender, kind) {
1575
1576 toggleSelectRow(sender);
1577
1578 if (kind) {
1579 var opbarid = false;
1580 var nsel = -1;
1581
1582 if (kind == "feed") {
1583 opbarid = "feedOpToolbar";
1584 nsel = getSelectedFeeds();
1585 } else if (kind == "fcat") {
1586 opbarid = "catOpToolbar";
1587 nsel = getSelectedFeedCats();
1588 } else if (kind == "filter") {
1589 opbarid = "filterOpToolbar";
1590 nsel = getSelectedFilters();
1591 } else if (kind == "label") {
1592 opbarid = "labelOpToolbar";
1593 nsel = getSelectedLabels();
1594 } else if (kind == "user") {
1595 opbarid = "userOpToolbar";
1596 nsel = getSelectedUsers();
1597 }
1598
1599 if (opbarid && nsel != -1) {
1600 disableContainerChildren(opbarid, nsel == false);
1601 }
1602
1603 }
1604}
1605
c0ae0fdb
AD
1606function toggleSelectFBListRow(sender) {
1607 toggleSelectListRow(sender);
1608 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1609}
d437c8cf
AD
1610
1611var seq = "";
1612
1613function pref_hotkey_handler(e) {
1614 try {
1615
1616 var keycode;
1617
1618 if (!hotkeys_enabled) return;
1619
1620 if (window.event) {
1621 keycode = window.event.keyCode;
1622 } else if (e) {
1623 keycode = e.which;
1624 }
1625
1626 if (keycode == 13 || keycode == 27) {
1627 seq = "";
1628 } else {
1629 seq = seq + "" + keycode;
1630 }
1631
1632
1633 if (document.getElementById("piggie")) {
1634
1635 if (seq.match("807371717369")) {
1636 seq = "";
1637 localPiggieFunction(true);
1638 } else {
1639 localPiggieFunction(false);
1640 }
1641 }
1642
1643 } catch (e) {
1644 exception_error("pref_hotkey_handler", e);
1645 }
1646}
1647
23c2a4e7
AD
1648function userSwitch() {
1649 var chooser = document.getElementById("userSwitch");
1650 var user = chooser[chooser.selectedIndex].value;
1651 window.location = "prefs.php?swu=" + user;
1652}
9c483746
AD
1653
1654function editFeedCats() {
1655 if (!xmlhttp_ready(xmlhttp)) {
1656 printLockingError();
1657 return
1658 }
1659
a349077c
AD
1660 document.getElementById("subscribe_to_feed_btn").disabled = true;
1661
1662 try {
1663 document.getElementById("top25_feeds_btn").disabled = true;
1664 } catch (e) {
1665 // this button is not always available, no-op if not found
1666 }
1667
9c483746
AD
1668 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
1669 xmlhttp.onreadystatechange=infobox_callback;
1670 xmlhttp.send(null);
1671}
a3656a41
AD
1672
1673function showFeedsWithErrors() {
1674 displayDlg('feedUpdateErrors');
1675}
073ca0e6 1676
d95bd220
AD
1677function changeUserPassword() {
1678
1679 try {
1680
1681 if (!xmlhttp_ready(xmlhttp)) {
1682 printLockingError();
1683 return false;
1684 }
1685
1686 var query = Form.serialize("change_pass_form");
1687
1688 notify_progress("Trying to change password...");
1689
1690 xmlhttp.open("POST", "backend.php", true);
1691 xmlhttp.onreadystatechange=changepass_callback;
1692 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1693 xmlhttp.send(query);
1694
1695 } catch (e) {
1696 exception_error("changeUserPassword", e);
1697 }
1698
1699 return false;
1700}
073ca0e6 1701
42395d28
AD
1702function changeUserEmail() {
1703
1704 try {
1705
1706 if (!xmlhttp_ready(xmlhttp)) {
1707 printLockingError();
1708 return false;
1709 }
1710
1711 var query = Form.serialize("change_email_form");
1712
1713 notify_progress("Trying to change e-mail...");
1714
1715 xmlhttp.open("POST", "backend.php", true);
1716 xmlhttp.onreadystatechange=notify_callback;
1717 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1718 xmlhttp.send(query);
1719
1720 } catch (e) {
1721 exception_error("changeUserPassword", e);
1722 }
1723
1724 return false;
1725
1726}
400b60d8
AD
1727
1728function feedlistToggleSLAT() {
1729 notify_progress("Loading, please wait...");
1730 updateFeedList()
1731}