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