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