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