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