]> git.wh0rd.org - tt-rss.git/blame - prefs.js
release 1.1.5
[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) {
01b3e191 242 alert("Can't add label: missing SQL expression.");
48f0adb0
AD
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) {
01b3e191 270 alert("Can't add filter: missing filter expression.");
de435974
AD
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) {
01b3e191 300 alert("Can't add feed: 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) {
01b3e191 325 alert("Can't add category: no name specified.");
91ff844a
AD
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) {
01b3e191 349 alert("Can't add user: no login specified.");
e6cb77a0
AD
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
01b3e191 479/*function 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
01b3e191 505 alert("No feeds are selected.");
83fe4d6d
AD
506
507 }
01b3e191 508} */
83fe4d6d 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 531 } else {
01b3e191 532 alert("No labels are selected.");
48f0adb0
AD
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 {
01b3e191 559 alert("No users are selected.");
e6cb77a0
AD
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 584 } else {
01b3e191 585 alert("No filters are selected.");
48f0adb0
AD
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
01b3e191 615 alert("No feeds are selected.");
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
01b3e191 645 alert("No categories are selected.");
91ff844a
AD
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;
25cb5736 947 var match = document.getElementById("iedit_match");
19c9cb11 948
25cb5736 949 var v_match = match[match.selectedIndex].text;
a0d53889 950
ead60402
AD
951 var feed = document.getElementById("iedit_feed");
952 var feed_id = feed[feed.selectedIndex].id;
953
19c9cb11
AD
954 var action = document.getElementById("iedit_filter_action");
955 var action_id = action[action.selectedIndex].id;
956
a0d53889 957 if (regexp.length == 0) {
01b3e191 958 alert("Can't save filter: match expression is blank.");
a0d53889
AD
959 return;
960 }
961
962 active_filter = false;
963
964 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
01b3e191
AD
965 filter + "&r=" + param_escape(regexp) + "&m=" + param_escape(v_match) +
966 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
dbd9e2f1 967
f0e81ffe 968 notify("Saving filter...");
dbd9e2f1 969
a0d53889
AD
970 xmlhttp.onreadystatechange=filterlist_callback;
971 xmlhttp.send(null);
972
973}
974
48f0adb0
AD
975function editSelectedLabel() {
976 var rows = getSelectedLabels();
a0d53889 977
48f0adb0 978 if (rows.length == 0) {
01b3e191 979 alert("No labels are selected.");
48f0adb0 980 return;
a0d53889
AD
981 }
982
48f0adb0 983 if (rows.length > 1) {
01b3e191 984 alert("Please select only one label.");
48f0adb0
AD
985 return;
986 }
a0d53889 987
dbd9e2f1
AD
988 notify("");
989
48f0adb0 990 editLabel(rows[0]);
a0d53889 991
a0d53889
AD
992}
993
e6cb77a0
AD
994function editSelectedUser() {
995 var rows = getSelectedUsers();
996
997 if (rows.length == 0) {
01b3e191 998 alert("No users are selected.");
e6cb77a0
AD
999 return;
1000 }
1001
1002 if (rows.length > 1) {
01b3e191 1003 alert("Please select only one user.");
e6cb77a0
AD
1004 return;
1005 }
1006
dbd9e2f1
AD
1007 notify("");
1008
e6cb77a0
AD
1009 editUser(rows[0]);
1010}
1011
1012function resetSelectedUserPass() {
1013 var rows = getSelectedUsers();
1014
1015 if (rows.length == 0) {
01b3e191 1016 alert("No users are selected.");
e6cb77a0
AD
1017 return;
1018 }
1019
1020 if (rows.length > 1) {
01b3e191 1021 alert("Please select only one user.");
e6cb77a0
AD
1022 return;
1023 }
1024
69668465 1025 var ok = confirm("Reset password of selected user?");
e6cb77a0 1026
69668465
AD
1027 if (ok) {
1028 notify("Resetting password for selected user...");
1029
1030 var id = rows[0];
1031
1032 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
1033 param_escape(id), true);
1034 xmlhttp.onreadystatechange=userlist_callback;
1035 xmlhttp.send(null);
1036 }
e6cb77a0
AD
1037}
1038
717f5e64 1039function selectedUserDetails() {
e6cb77a0 1040
1a7572cb
AD
1041 if (!xmlhttp_ready(xmlhttp)) {
1042 printLockingError();
1043 return
1044 }
1045
717f5e64
AD
1046 var rows = getSelectedUsers();
1047
1048 if (rows.length == 0) {
01b3e191 1049 alert("No users are selected.");
717f5e64
AD
1050 return;
1051 }
1052
1053 if (rows.length > 1) {
01b3e191 1054 alert("Please select only one user.");
717f5e64
AD
1055 return;
1056 }
1057
1058 var id = rows[0];
1059
dbd9e2f1
AD
1060 notify("");
1061
1a7572cb 1062 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1063 xmlhttp.onreadystatechange=infobox_callback;
1064 xmlhttp.send(null);
1065
1066}
1067
1068function selectedFeedDetails() {
1069
1070 if (!xmlhttp_ready(xmlhttp)) {
1071 printLockingError();
1072 return
1073 }
1074
1075 var rows = getSelectedFeeds();
1076
1077 if (rows.length == 0) {
01b3e191 1078 alert("No feeds are selected.");
c6c3a07f
AD
1079 return;
1080 }
1081
01b3e191
AD
1082 if (rows.length > 1) {
1083 notify("Please select only one feed.");
1084 return;
1085 }
c6c3a07f 1086
df268d47 1087// var id = rows[0];
c6c3a07f 1088
dbd9e2f1
AD
1089 notify("");
1090
df268d47
AD
1091 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1092 param_escape(rows.toString()), true);
c6c3a07f 1093 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1094 xmlhttp.send(null);
717f5e64
AD
1095
1096}
a0d53889
AD
1097
1098function editSelectedFilter() {
1099 var rows = getSelectedFilters();
1100
1101 if (rows.length == 0) {
01b3e191 1102 alert("No filters are selected.");
a0d53889
AD
1103 return;
1104 }
1105
1106 if (rows.length > 1) {
01b3e191 1107 alert("Please select only one filter.");
a0d53889
AD
1108 return;
1109 }
1110
dbd9e2f1
AD
1111 notify("");
1112
a0d53889
AD
1113 editFilter(rows[0]);
1114
1115}
1116
1117
508a81e1
AD
1118function editSelectedFeed() {
1119 var rows = getSelectedFeeds();
1120
1121 if (rows.length == 0) {
1122 notify("No feeds are selected.");
1123 return;
1124 }
1125
1126 if (rows.length > 1) {
1127 notify("Please select one feed.");
1128 return;
1129 }
1130
dbd9e2f1
AD
1131 notify("");
1132
508a81e1 1133 editFeed(rows[0]);
91ff844a
AD
1134
1135}
1136
1137function editSelectedFeedCat() {
1138 var rows = getSelectedFeedCats();
1139
1140 if (rows.length == 0) {
01b3e191 1141 alert("No categories are selected.");
91ff844a
AD
1142 return;
1143 }
1144
1145 if (rows.length > 1) {
01b3e191 1146 alert("Please select only one category.");
91ff844a
AD
1147 return;
1148 }
1149
1150 notify("");
1151
1152 editFeedCat(rows[0]);
508a81e1
AD
1153
1154}
1155
1cac3c31
AD
1156function piggie_callback() {
1157 var piggie = document.getElementById("piggie");
1158
1159 piggie.style.top = piggie_top;
e0b6a737
AD
1160 piggie.style.backgroundColor = "white";
1161 piggie.style.borderWidth = "1px";
1cac3c31
AD
1162
1163 if (piggie_fwd && piggie_top < 0) {
1164 setTimeout("piggie_callback()", 50);
1165 piggie_top = piggie_top + 10;
1166 } else if (piggie_fwd && piggie_top >= 0) {
1167 piggie_fwd = false;
1168 setTimeout("piggie_callback()", 50);
1169 } else if (!piggie_fwd && piggie_top > -400) {
1170 setTimeout("piggie_callback()", 50);
1171 piggie_top = piggie_top - 10;
1172 } else if (!piggie_fwd && piggie_top <= -400) {
1173 piggie.style.display = "none";
1174 piggie_fwd = true;
1175 }
1176}
1177
33377ef3
AD
1178var piggie_opacity = 0;
1179
1180function piggie2_callback() {
1181 var piggie = document.getElementById("piggie");
1182 piggie.style.top = 0;
1183 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1184 piggie.style.backgroundColor = "transparent";
1185 piggie.style.borderWidth = "0px";
33377ef3
AD
1186
1187 if (piggie_fwd && piggie_opacity < 1) {
1188 setTimeout("piggie2_callback()", 50);
1189 piggie_opacity = piggie_opacity + 0.03;
1190 } else if (piggie_fwd && piggie_opacity >= 1) {
1191 piggie_fwd = false;
1192 setTimeout("piggie2_callback()", 50);
1193 } else if (!piggie_fwd && piggie_opacity > 0) {
1194 setTimeout("piggie2_callback()", 50);
1195 piggie_opacity = piggie_opacity - 0.03;
1196 } else if (!piggie_fwd && piggie_opacity <= 0) {
1197 piggie.style.display = "none";
1198 piggie_fwd = true;
1199 }
1200}
1201
13ad9102
AD
1202function localPiggieFunction(enable) {
1203 if (enable) {
1cac3c31 1204 var piggie = document.getElementById("piggie");
508a81e1 1205 piggie.style.display = "block";
33377ef3
AD
1206
1207 if (navigator.userAgent.match("Firefox") && Math.random(1) > 0.5) {
1208 piggie2_callback();
1209 } else {
1210 piggie_callback();
1211 }
508a81e1 1212 }
508a81e1
AD
1213}
1214
9f311df6
AD
1215function validateOpmlImport() {
1216
1217 var opml_file = document.getElementById("opml_file");
1218
1219 if (opml_file.value.length == 0) {
01b3e191 1220 alert("No OPML file to upload.");
9f311df6
AD
1221 return false;
1222 } else {
1223 return true;
1224 }
1225}
1226
a0d53889
AD
1227function updateFilterList() {
1228
1229 if (!xmlhttp_ready(xmlhttp)) {
1230 printLockingError();
1231 return
1232 }
1233
f5a50b25
AD
1234// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1235
1236 p_notify("Loading, please wait...");
a0d53889
AD
1237
1238 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1239 xmlhttp.onreadystatechange=filterlist_callback;
1240 xmlhttp.send(null);
1241
1242}
1243
48f0adb0
AD
1244function updateLabelList() {
1245
1246 if (!xmlhttp_ready(xmlhttp)) {
1247 printLockingError();
1248 return
1249 }
1250
f5a50b25
AD
1251 p_notify("Loading, please wait...");
1252
1253// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1254
1255 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1256 xmlhttp.onreadystatechange=labellist_callback;
1257 xmlhttp.send(null);
48f0adb0
AD
1258}
1259
4255b24c
AD
1260function updatePrefsList() {
1261
1262 if (!xmlhttp_ready(xmlhttp)) {
1263 printLockingError();
1264 return
1265 }
1266
1267 p_notify("Loading, please wait...");
1268
1269 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1270 xmlhttp.onreadystatechange=prefslist_callback;
1271 xmlhttp.send(null);
1272
1273}
1274
a7f22b70
AD
1275function selectTab(id, noupdate) {
1276
1277// alert(id);
48f0adb0 1278
c6c3a07f
AD
1279 if (!xmlhttp_ready(xmlhttp)) {
1280 printLockingError();
1281 return
1282 }
1283
a7f22b70
AD
1284 if (!noupdate) {
1285
1286 if (id == "feedConfig") {
1287 updateFeedList();
1288 } else if (id == "filterConfig") {
1289 updateFilterList();
1290 } else if (id == "labelConfig") {
1291 updateLabelList();
1292 } else if (id == "genConfig") {
1293 updatePrefsList();
1294 } else if (id == "userConfig") {
1295 updateUsersList();
1296 } else if (id == "feedBrowser") {
1297 updateBigFeedBrowser();
1298 }
a0d53889 1299 }
f5a50b25
AD
1300
1301 var tab = document.getElementById(active_tab + "Tab");
1302
1303 if (tab) {
1304 if (tab.className.match("Selected")) {
1305 tab.className = "prefsTab";
1306 }
1307 }
1308
1309 tab = document.getElementById(id + "Tab");
1310
1311 if (tab) {
1312 if (!tab.className.match("Selected")) {
1313 tab.className = tab.className + "Selected";
1314 }
1315 }
1316
1317 active_tab = id;
1318
4da47970
AD
1319 setCookie('ttrss_pref_acttab', active_tab);
1320
a0d53889
AD
1321}
1322
007bda35 1323function init() {
e2ec66a8 1324
7719618b
AD
1325 try {
1326
97dcd654
AD
1327 if (arguments.callee.done) return;
1328 arguments.callee.done = true;
1329
7719618b
AD
1330 // IE kludge
1331 if (!xmlhttp) {
1332 document.getElementById("prefContent").innerHTML =
1333 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1334 "to function properly. Your browser doesn't seem to support it.";
1335 return;
1336 }
4da47970
AD
1337
1338 active_tab = getCookie("ttrss_pref_acttab");
1339 if (!active_tab) active_tab = "genConfig";
1340 selectTab(active_tab);
7719618b
AD
1341
1342 document.onkeydown = hotkey_handler;
1343 notify("");
1344 } catch (e) {
1345 exception_error("init", e);
e2ec66a8 1346 }
007bda35 1347}
b1895692 1348
c6c3a07f 1349function closeInfoBox() {
2317ffaa
AD
1350 var box = document.getElementById('infoBox');
1351 var shadow = document.getElementById('infoBoxShadow');
1352
1353 if (shadow) {
1354 shadow.style.display = "none";
1355 } else if (box) {
1356 box.style.display = "none";
1357 }
1a7572cb 1358}
f932bc9f
AD
1359
1360function categorizeSelectedFeeds() {
1361
1362 if (!xmlhttp_ready(xmlhttp)) {
1363 printLockingError();
1364 return
1365 }
1366
1367 var sel_rows = getSelectedFeeds();
1368
1369 var cat_sel = document.getElementById("sfeed_set_fcat");
1370 var cat_id = cat_sel[cat_sel.selectedIndex].id;
1371
1372 if (sel_rows.length > 0) {
1373
1374 notify("Changing category of selected feeds...");
1375
1376 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1377 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1378 xmlhttp.onreadystatechange=feedlist_callback;
1379 xmlhttp.send(null);
1380
1381 } else {
1382
01b3e191 1383 alert("No feeds are selected.");
f932bc9f
AD
1384
1385 }
1386
1387}
69668465
AD
1388
1389function validatePrefsReset() {
1390 return confirm("Reset to defaults?");
1391}
f9cb39ac
AD
1392
1393function browseFeeds() {
1394
1395 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1396 xmlhttp.onreadystatechange=infobox_callback;
1397 xmlhttp.send(null);
1398
1399}
a0476535
AD
1400
1401function feedBrowserSubscribe() {
1402 try {
1403 var list = document.getElementById("browseFeedList");
1404
072f1ee2
AD
1405 if (!list) list = document.getElementById("browseBigFeedList");
1406
a0476535
AD
1407 var selected = new Array();
1408
1409 for (i = 0; i < list.childNodes.length; i++) {
1410 var child = list.childNodes[i];
1411 if (child.id && child.id.match("FBROW-")) {
1412 var id = child.id.replace("FBROW-", "");
1413
1414 var cb = document.getElementById("FBCHK-" + id);
1415
1416 if (cb.checked) {
1417 selected.push(id);
1418 }
1419 }
1420 }
1421
1422 if (selected.length > 0) {
1423 closeInfoBox();
1424 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1425 param_escape(selected.toString()), true);
1426 xmlhttp.onreadystatechange=feedlist_callback;
1427 xmlhttp.send(null);
1428 } else {
1429 alert("No feeds are selected.");
1430 }
1431
1432 } catch (e) {
1433 exception_error("feedBrowserSubscribe", e);
1434 }
1435}
c6232e43
AD
1436
1437function updateBigFeedBrowser() {
1438
1439 if (!xmlhttp_ready(xmlhttp)) {
1440 printLockingError();
1441 return
1442 }
1443
1444 p_notify("Loading, please wait...");
1445
1446 xmlhttp.open("GET", "backend.php?op=pref-feed-browser", true);
1447 xmlhttp.onreadystatechange=feed_browser_callback;
1448 xmlhttp.send(null);
1449
1450}
1451
c2b2aee0 1452function browserToggleExpand(id) {
c6232e43
AD
1453 try {
1454/* if (feed_to_expand && feed_to_expand != id) {
1455 var d = document.getElementById("BRDET-" + feed_to_expand);
1456 d.style.display = "none";
1457 } */
c2b2aee0
AD
1458
1459 var d = document.getElementById("BRDET-" + id);
1460
1461 if (d.style.display == "block") {
1462 d.style.display = "none";
1463
1464 } else {
c6232e43 1465
c2b2aee0 1466 feed_to_expand = id;
c6232e43 1467
c2b2aee0
AD
1468 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1469 + param_escape(id), true);
1470 xmlhttp.onreadystatechange=expand_feed_callback;
1471 xmlhttp.send(null);
1472 }
c6232e43
AD
1473
1474 } catch (e) {
1475 exception_error("browserExpand", e);
1476 }
1477}