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