]> git.wh0rd.org - tt-rss.git/blame - prefs.js
add BackReqBox to prefs.php
[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
b2caf812 1115 if (!id) id = active_tab;
7f74a9da 1116
b2caf812 1117 try {
59a543f0 1118
b2caf812
AD
1119 if (!xmlhttp_ready(xmlhttp)) {
1120 printLockingError();
1121 return
a7f22b70 1122 }
f5a50b25 1123
b2caf812 1124 if (!noupdate) {
f5a50b25 1125
b2caf812
AD
1126 debug("selectTab: " + id + "(NU: " + noupdate + ")");
1127
1128 notify("Loading, please wait...", true);
1129
1130 // close active infobox if needed
1131 closeInfoBox();
1132
1133 // clean up all current selections, just in case
1134 active_feed_cat = false;
1135 active_label = false;
1136
1137 if (id == "feedConfig") {
1138 updateFeedList();
1139 } else if (id == "filterConfig") {
1140 updateFilterList();
1141 } else if (id == "labelConfig") {
1142 updateLabelList();
1143 } else if (id == "genConfig") {
1144 updatePrefsList();
1145 } else if (id == "userConfig") {
1146 updateUsersList();
1147 } else if (id == "feedBrowser") {
1148 updateBigFeedBrowser();
1149 }
f5a50b25 1150 }
b2caf812
AD
1151
1152 var tab = document.getElementById(active_tab + "Tab");
1153
1154 if (tab) {
1155 if (tab.className.match("Selected")) {
1156 tab.className = "prefsTab";
1157 }
f5a50b25 1158 }
b2caf812
AD
1159
1160 tab = document.getElementById(id + "Tab");
1161
1162 if (tab) {
1163 if (!tab.className.match("Selected")) {
1164 tab.className = tab.className + "Selected";
1165 }
1166 }
1167
1168 if (active_tab != id) {
1169 storeInitParam("prefs_active_tab", id);
1170 }
1171
1172 active_tab = id;
f5a50b25 1173
b2caf812
AD
1174 } catch (e) {
1175 exception_error("selectTab", e);
a7565293 1176 }
a7565293
AD
1177}
1178
1179function backend_sanity_check_callback() {
f5a50b25 1180
a7565293
AD
1181 if (xmlhttp.readyState == 4) {
1182
1183 try {
1184
1185 if (!xmlhttp.responseXML) {
1186 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
1187 return;
1188 }
1189
1190 var reply = xmlhttp.responseXML.firstChild.firstChild;
1191
1192 if (!reply) {
1193 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
1194 return;
1195 }
1196
1197 var error_code = reply.getAttribute("error-code");
1198
1199 if (error_code && error_code != 0) {
1200 return fatalError(error_code, reply.getAttribute("error-msg"));
1201 }
1202
1203 debug("sanity check ok");
1204
1205 var params = reply.nextSibling;
1206
1207 if (params) {
1208 debug('reading init-params...');
1209 var param = params.firstChild;
1210
1211 while (param) {
1212 var k = param.getAttribute("key");
1213 var v = param.getAttribute("value");
1214 debug(k + " => " + v);
1215 init_params[k] = v;
1216 param = param.nextSibling;
1217 }
1218 }
1219
1220 init_second_stage();
1221
1222 } catch (e) {
1223 exception_error("backend_sanity_check_callback", e);
1224 }
1225 }
1226}
1227
1228function init_second_stage() {
1229
b2caf812
AD
1230 try {
1231 active_tab = getInitParam("prefs_active_tab");
1232 if (!active_tab) active_tab = "genConfig";
4da47970 1233
b2caf812
AD
1234 if (navigator.userAgent.match("Opera")) {
1235 setTimeout("selectTab()", 500);
1236 } else {
1237 selectTab(active_tab);
1238 }
1239 notify("");
1240 } catch (e) {
1241 exception_error("init_second_stage", e);
1242 }
a0d53889
AD
1243}
1244
007bda35 1245function init() {
e2ec66a8 1246
7719618b
AD
1247 try {
1248
97dcd654
AD
1249 if (arguments.callee.done) return;
1250 arguments.callee.done = true;
1251
a7565293
AD
1252 if (getURLParam('debug')) {
1253 document.getElementById('debug_output').style.display = 'block';
1254 debug('debug mode activated');
1255 }
1256
7719618b
AD
1257 // IE kludge
1258 if (!xmlhttp) {
1259 document.getElementById("prefContent").innerHTML =
1260 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1261 "to function properly. Your browser doesn't seem to support it.";
1262 return;
1263 }
4da47970 1264
a7565293
AD
1265 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
1266 xmlhttp.onreadystatechange=backend_sanity_check_callback;
1267 xmlhttp.send(null);
1268
7719618b
AD
1269 } catch (e) {
1270 exception_error("init", e);
e2ec66a8 1271 }
007bda35 1272}
b1895692 1273
f932bc9f
AD
1274function categorizeSelectedFeeds() {
1275
1276 if (!xmlhttp_ready(xmlhttp)) {
1277 printLockingError();
1278 return
1279 }
1280
1281 var sel_rows = getSelectedFeeds();
1282
1283 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1284 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1285
1286 if (sel_rows.length > 0) {
1287
1288 notify("Changing category of selected feeds...");
1289
1290 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1291 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1292 xmlhttp.onreadystatechange=feedlist_callback;
1293 xmlhttp.send(null);
1294
1295 } else {
1296
01b3e191 1297 alert("No feeds are selected.");
f932bc9f
AD
1298
1299 }
1300
1301}
69668465
AD
1302
1303function validatePrefsReset() {
1304 return confirm("Reset to defaults?");
1305}
f9cb39ac 1306
6311acbe 1307function browseFeeds(limit) {
f9cb39ac
AD
1308
1309 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1310 xmlhttp.onreadystatechange=infobox_callback;
1311 xmlhttp.send(null);
1312
1313}
a0476535
AD
1314
1315function feedBrowserSubscribe() {
1316 try {
a0476535 1317
c0ae0fdb 1318 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1319
1320 if (selected.length > 0) {
1321 closeInfoBox();
1322 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1323 param_escape(selected.toString()), true);
1324 xmlhttp.onreadystatechange=feedlist_callback;
1325 xmlhttp.send(null);
1326 } else {
1327 alert("No feeds are selected.");
1328 }
1329
1330 } catch (e) {
1331 exception_error("feedBrowserSubscribe", e);
1332 }
1333}
c6232e43 1334
6311acbe 1335function updateBigFeedBrowser(limit) {
c6232e43
AD
1336
1337 if (!xmlhttp_ready(xmlhttp)) {
1338 printLockingError();
1339 return
1340 }
1341
ce3bf408 1342// p_notify("Loading, please wait...");
c6232e43 1343
6311acbe
AD
1344 var query = "backend.php?op=pref-feed-browser";
1345
1346 var limit_sel = document.getElementById("feedBrowserLimit");
1347
1348 if (limit_sel) {
1349 var limit = limit_sel[limit_sel.selectedIndex].value;
1350 query = query + "&limit=" + param_escape(limit);
1351 }
1352
1353 xmlhttp.open("GET", query, true);
c6232e43
AD
1354 xmlhttp.onreadystatechange=feed_browser_callback;
1355 xmlhttp.send(null);
c6232e43
AD
1356}
1357
c2b2aee0 1358function browserToggleExpand(id) {
c6232e43
AD
1359 try {
1360/* if (feed_to_expand && feed_to_expand != id) {
1361 var d = document.getElementById("BRDET-" + feed_to_expand);
1362 d.style.display = "none";
1363 } */
c2b2aee0 1364
ff725e9b
AD
1365 if (!xmlhttp_ready(xmlhttp)) {
1366 printLockingError();
1367 return
1368 }
1369
c2b2aee0
AD
1370 var d = document.getElementById("BRDET-" + id);
1371
1372 if (d.style.display == "block") {
1373 d.style.display = "none";
1374
1375 } else {
c6232e43 1376
c2b2aee0 1377 feed_to_expand = id;
c6232e43 1378
ff725e9b
AD
1379 d.style.display = "block";
1380 d.innerHTML = "Loading, please wait...";
1381
c2b2aee0
AD
1382 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1383 + param_escape(id), true);
1384 xmlhttp.onreadystatechange=expand_feed_callback;
1385 xmlhttp.send(null);
1386 }
c6232e43
AD
1387
1388 } catch (e) {
1389 exception_error("browserExpand", e);
1390 }
1391}
64dc5976
AD
1392
1393function validateNewPassword(form) {
1394 if (form.OLD_PASSWORD.value == "") {
88103301 1395 alert("Old password cannot be blank");
64dc5976
AD
1396 return false;
1397 }
1398 if (form.NEW_PASSWORD.value == "") {
1399 alert("New password cannot be blank");
1400 return false;
1401 }
1402 return true;
1403}
ce3bf408
AD
1404
1405function selectPrefRows(kind, select) {
1406
1407 if (kind) {
1408 var opbarid = false;
1409 var nchk = false;
1410 var nrow = false;
1411 var lname = false;
1412
1413 if (kind == "feed") {
1414 opbarid = "feedOpToolbar";
1415 nrow = "FEEDR-";
1416 nchk = "FRCHK-";
1417 lname = "prefFeedList";
1418 } else if (kind == "fcat") {
1419 opbarid = "catOpToolbar";
1420 nrow = "FCATR-";
1421 nchk = "FCHK-";
1422 lname = "prefFeedCatList";
1423 } else if (kind == "filter") {
1424 opbarid = "filterOpToolbar";
1425 nrow = "FILRR-";
1426 nchk = "FICHK-";
1427 lname = "prefFilterList";
1428 } else if (kind == "label") {
1429 opbarid = "labelOpToolbar";
1430 nrow = "LILRR-";
1431 nchk = "LCHK-";
1432 lname = "prefLabelList";
1433 } else if (kind == "user") {
1434 opbarid = "userOpToolbar";
1435 nrow = "UMRR-";
1436 nchk = "UMCHK-";
1437 lname = "prefUserList";
1438 }
1439
1440 if (opbarid) {
1441 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1442 disableContainerChildren(opbarid, !select);
1443 }
1444
1445 }
1446}
1447
1448
1449function toggleSelectPrefRow(sender, kind) {
1450
1451 toggleSelectRow(sender);
1452
1453 if (kind) {
1454 var opbarid = false;
1455 var nsel = -1;
1456
1457 if (kind == "feed") {
1458 opbarid = "feedOpToolbar";
1459 nsel = getSelectedFeeds();
1460 } else if (kind == "fcat") {
1461 opbarid = "catOpToolbar";
1462 nsel = getSelectedFeedCats();
1463 } else if (kind == "filter") {
1464 opbarid = "filterOpToolbar";
1465 nsel = getSelectedFilters();
1466 } else if (kind == "label") {
1467 opbarid = "labelOpToolbar";
1468 nsel = getSelectedLabels();
1469 } else if (kind == "user") {
1470 opbarid = "userOpToolbar";
1471 nsel = getSelectedUsers();
1472 }
1473
1474 if (opbarid && nsel != -1) {
1475 disableContainerChildren(opbarid, nsel == false);
1476 }
1477
1478 }
1479}
1480
c0ae0fdb
AD
1481function toggleSelectFBListRow(sender) {
1482 toggleSelectListRow(sender);
1483 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1484}