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