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