]> git.wh0rd.org - tt-rss.git/blame - prefs.js
password change form is functional now (closes #27)
[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
AD
701
702 var private = document.getElementById("iedit_private").checked;
47c6c988 703
48fa05ad
AD
704 var fcat_id = 0;
705
706 if (fcat) {
707 fcat_id = fcat[fcat.selectedIndex].id;
708 }
1da7e457
AD
709
710 var pfeed = document.getElementById("iedit_parent_feed");
711 var parent_feed_id = pfeed[pfeed.selectedIndex].id;
47c6c988
AD
712
713 if (link.length == 0) {
714 notify("Feed link cannot be blank.");
715 return;
716 }
717
718 if (title.length == 0) {
719 notify("Feed title cannot be blank.");
720 return;
721 }
722
723 var auth_login = document.getElementById("iedit_login").value;
724 var auth_pass = document.getElementById("iedit_pass").value;
725
726 active_feed = false;
727
728 notify("Saving feed...");
d148926e 729
47c6c988
AD
730 var query = "op=pref-feeds&subop=editSave&id=" +
731 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) +
732 "&ui=" + param_escape(upd_intl) + "&pi=" + param_escape(purge_intl) +
e3c99f3b
AD
733 "&catid=" + param_escape(fcat_id) + "&login=" + param_escape(auth_login) +
734 "&pfeed=" + param_escape(parent_feed_id) + "&pass=" + param_escape(auth_pass) +
735 "&private=" + param_escape(private);
508a81e1 736
47c6c988
AD
737 xmlhttp.open("POST", "backend.php", true);
738 xmlhttp.onreadystatechange=feedlist_callback;
739 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
740 xmlhttp.send(query);
741
742 } catch (e) {
743 exception_error("feedEditSave", e);
508a81e1 744 }
508a81e1
AD
745}
746
5ddadb4c
AD
747function feedCatEditSave() {
748
749 if (!xmlhttp_ready(xmlhttp)) {
750 printLockingError();
751 return
752 }
753
f0e81ffe 754 notify("Saving category...");
5ddadb4c
AD
755
756 var cat_title = document.getElementById("iedit_title").value;
757
758 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=saveCat&id=" +
759 param_escape(active_feed_cat) + "&title=" + param_escape(cat_title),
760 true);
761 xmlhttp.onreadystatechange=feedlist_callback;
762 xmlhttp.send(null);
763
764 active_feed_cat = false;
765
766}
767
768
d9dde1d6
AD
769function labelTest() {
770
771 var sqlexp = document.getElementById("iedit_expr").value;
772 var descr = document.getElementById("iedit_descr").value;
773
774 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
775 param_escape(sqlexp) + "&descr=" + param_escape(descr), true);
776
777 xmlhttp.onreadystatechange=infobox_callback;
778 xmlhttp.send(null);
779
780}
781
01c9c74a
AD
782function displayHelpInfobox(topic_id) {
783
784 xmlhttp.open("GET", "backend.php?op=help&tid=" +
785 param_escape(topic_id) + "&noheaders=1", true);
786
787 xmlhttp.onreadystatechange=infobox_callback;
788 xmlhttp.send(null);
789
790}
791
48f0adb0
AD
792function labelEditCancel() {
793
794 if (!xmlhttp_ready(xmlhttp)) {
795 printLockingError();
796 return
797 }
798
799 active_label = false;
800
801 notify("Operation cancelled.");
802
803 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
804 xmlhttp.onreadystatechange=labellist_callback;
805 xmlhttp.send(null);
806
807}
808
e6cb77a0
AD
809function userEditCancel() {
810
811 if (!xmlhttp_ready(xmlhttp)) {
812 printLockingError();
813 return
814 }
815
816 active_user = false;
817
818 notify("Operation cancelled.");
819
820 xmlhttp.open("GET", "backend.php?op=pref-users", true);
821 xmlhttp.onreadystatechange=userlist_callback;
822 xmlhttp.send(null);
823
824}
48f0adb0 825
a0d53889
AD
826function filterEditCancel() {
827
828 if (!xmlhttp_ready(xmlhttp)) {
829 printLockingError();
830 return
831 }
832
833 active_filter = false;
834
835 notify("Operation cancelled.");
836
837 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
838 xmlhttp.onreadystatechange=filterlist_callback;
839 xmlhttp.send(null);
840
841}
842
48f0adb0
AD
843function labelEditSave() {
844
845 var label = active_label;
846
847 if (!xmlhttp_ready(xmlhttp)) {
848 printLockingError();
849 return
850 }
851
852 var sqlexp = document.getElementById("iedit_expr").value;
853 var descr = document.getElementById("iedit_descr").value;
854
855// notify("Saving label " + sqlexp + ": " + descr);
856
857 if (sqlexp.length == 0) {
858 notify("SQL expression cannot be blank.");
859 return;
860 }
861
862 if (descr.length == 0) {
863 notify("Caption cannot be blank.");
864 return;
865 }
866
f0e81ffe 867 notify("Saving label...");
dbd9e2f1 868
48f0adb0
AD
869 active_label = false;
870
871 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
872 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
873 true);
874
875 xmlhttp.onreadystatechange=labellist_callback;
876 xmlhttp.send(null);
877
878}
879
e6cb77a0
AD
880function userEditSave() {
881
882 var user = active_user;
883
884 if (!xmlhttp_ready(xmlhttp)) {
885 printLockingError();
886 return
887 }
888
889 var login = document.getElementById("iedit_ulogin").value;
890 var level = document.getElementById("iedit_ulevel").value;
72932a75 891 var email = document.getElementById("iedit_email").value;
e6cb77a0
AD
892
893 if (login.length == 0) {
894 notify("Login cannot be blank.");
895 return;
896 }
897
898 if (level.length == 0) {
899 notify("User level cannot be blank.");
900 return;
901 }
902
903 active_user = false;
904
f0e81ffe 905 notify("Saving user...");
dbd9e2f1 906
e6cb77a0 907 xmlhttp.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
72932a75
AD
908 user + "&l=" + param_escape(login) + "&al=" + param_escape(level) +
909 "&e=" + param_escape(email), true);
e6cb77a0 910
dbd9e2f1 911 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0
AD
912 xmlhttp.send(null);
913
914}
915
916
a0d53889
AD
917function filterEditSave() {
918
919 var filter = active_filter;
920
921 if (!xmlhttp_ready(xmlhttp)) {
922 printLockingError();
923 return
924 }
925
926 var regexp = document.getElementById("iedit_regexp").value;
927 var descr = document.getElementById("iedit_descr").value;
25cb5736 928 var match = document.getElementById("iedit_match");
19c9cb11 929
25cb5736 930 var v_match = match[match.selectedIndex].text;
a0d53889 931
ead60402
AD
932 var feed = document.getElementById("iedit_feed");
933 var feed_id = feed[feed.selectedIndex].id;
934
19c9cb11
AD
935 var action = document.getElementById("iedit_filter_action");
936 var action_id = action[action.selectedIndex].id;
937
a0d53889
AD
938// notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
939
940 if (regexp.length == 0) {
941 notify("Filter expression cannot be blank.");
942 return;
943 }
944
945 active_filter = false;
946
947 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
948 filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
19c9cb11
AD
949 "&m=" + param_escape(v_match) + "&fid=" + param_escape(feed_id) +
950 "&aid=" + param_escape(action_id), true);
dbd9e2f1 951
f0e81ffe 952 notify("Saving filter...");
dbd9e2f1 953
a0d53889
AD
954 xmlhttp.onreadystatechange=filterlist_callback;
955 xmlhttp.send(null);
956
957}
958
48f0adb0
AD
959function editSelectedLabel() {
960 var rows = getSelectedLabels();
a0d53889 961
48f0adb0
AD
962 if (rows.length == 0) {
963 notify("No labels are selected.");
964 return;
a0d53889
AD
965 }
966
48f0adb0
AD
967 if (rows.length > 1) {
968 notify("Please select one label.");
969 return;
970 }
a0d53889 971
dbd9e2f1
AD
972 notify("");
973
48f0adb0 974 editLabel(rows[0]);
a0d53889 975
a0d53889
AD
976}
977
e6cb77a0
AD
978function editSelectedUser() {
979 var rows = getSelectedUsers();
980
981 if (rows.length == 0) {
982 notify("No users are selected.");
983 return;
984 }
985
986 if (rows.length > 1) {
987 notify("Please select one user.");
988 return;
989 }
990
dbd9e2f1
AD
991 notify("");
992
e6cb77a0
AD
993 editUser(rows[0]);
994}
995
996function resetSelectedUserPass() {
997 var rows = getSelectedUsers();
998
999 if (rows.length == 0) {
1000 notify("No users are selected.");
1001 return;
1002 }
1003
1004 if (rows.length > 1) {
1005 notify("Please select one user.");
1006 return;
1007 }
1008
69668465 1009 var ok = confirm("Reset password of selected user?");
e6cb77a0 1010
69668465
AD
1011 if (ok) {
1012 notify("Resetting password for selected user...");
1013
1014 var id = rows[0];
1015
1016 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
1017 param_escape(id), true);
1018 xmlhttp.onreadystatechange=userlist_callback;
1019 xmlhttp.send(null);
1020 }
e6cb77a0
AD
1021}
1022
717f5e64 1023function selectedUserDetails() {
e6cb77a0 1024
1a7572cb
AD
1025 if (!xmlhttp_ready(xmlhttp)) {
1026 printLockingError();
1027 return
1028 }
1029
717f5e64
AD
1030 var rows = getSelectedUsers();
1031
1032 if (rows.length == 0) {
1033 notify("No users are selected.");
1034 return;
1035 }
1036
1037 if (rows.length > 1) {
1038 notify("Please select one user.");
1039 return;
1040 }
1041
1042 var id = rows[0];
1043
dbd9e2f1
AD
1044 notify("");
1045
1a7572cb 1046 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1047 xmlhttp.onreadystatechange=infobox_callback;
1048 xmlhttp.send(null);
1049
1050}
1051
1052function selectedFeedDetails() {
1053
1054 if (!xmlhttp_ready(xmlhttp)) {
1055 printLockingError();
1056 return
1057 }
1058
1059 var rows = getSelectedFeeds();
1060
1061 if (rows.length == 0) {
1062 notify("No feeds are selected.");
1063 return;
1064 }
1065
df268d47
AD
1066// if (rows.length > 1) {
1067// notify("Please select one feed.");
1068// return;
1069// }
c6c3a07f 1070
df268d47 1071// var id = rows[0];
c6c3a07f 1072
dbd9e2f1
AD
1073 notify("");
1074
df268d47
AD
1075 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1076 param_escape(rows.toString()), true);
c6c3a07f 1077 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1078 xmlhttp.send(null);
717f5e64
AD
1079
1080}
a0d53889
AD
1081
1082function editSelectedFilter() {
1083 var rows = getSelectedFilters();
1084
1085 if (rows.length == 0) {
1086 notify("No filters are selected.");
1087 return;
1088 }
1089
1090 if (rows.length > 1) {
1091 notify("Please select one filter.");
1092 return;
1093 }
1094
dbd9e2f1
AD
1095 notify("");
1096
a0d53889
AD
1097 editFilter(rows[0]);
1098
1099}
1100
1101
508a81e1
AD
1102function editSelectedFeed() {
1103 var rows = getSelectedFeeds();
1104
1105 if (rows.length == 0) {
1106 notify("No feeds are selected.");
1107 return;
1108 }
1109
1110 if (rows.length > 1) {
1111 notify("Please select one feed.");
1112 return;
1113 }
1114
dbd9e2f1
AD
1115 notify("");
1116
508a81e1 1117 editFeed(rows[0]);
91ff844a
AD
1118
1119}
1120
1121function editSelectedFeedCat() {
1122 var rows = getSelectedFeedCats();
1123
1124 if (rows.length == 0) {
1125 notify("No categories are selected.");
1126 return;
1127 }
1128
1129 if (rows.length > 1) {
1130 notify("Please select one category.");
1131 return;
1132 }
1133
1134 notify("");
1135
1136 editFeedCat(rows[0]);
508a81e1
AD
1137
1138}
1139
13ad9102
AD
1140function localPiggieFunction(enable) {
1141 if (enable) {
508a81e1
AD
1142 piggie.style.display = "block";
1143 seq = "";
1144 notify("I loveded it!!!");
1145 } else {
1146 piggie.style.display = "none";
1147 notify("");
1148 }
508a81e1
AD
1149}
1150
9f311df6
AD
1151function validateOpmlImport() {
1152
1153 var opml_file = document.getElementById("opml_file");
1154
1155 if (opml_file.value.length == 0) {
1156 notify("Please select OPML file to upload.");
1157 return false;
1158 } else {
1159 return true;
1160 }
1161}
1162
a0d53889
AD
1163function updateFilterList() {
1164
1165 if (!xmlhttp_ready(xmlhttp)) {
1166 printLockingError();
1167 return
1168 }
1169
f5a50b25
AD
1170// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1171
1172 p_notify("Loading, please wait...");
a0d53889
AD
1173
1174 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1175 xmlhttp.onreadystatechange=filterlist_callback;
1176 xmlhttp.send(null);
1177
1178}
1179
48f0adb0
AD
1180function updateLabelList() {
1181
1182 if (!xmlhttp_ready(xmlhttp)) {
1183 printLockingError();
1184 return
1185 }
1186
f5a50b25
AD
1187 p_notify("Loading, please wait...");
1188
1189// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1190
1191 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1192 xmlhttp.onreadystatechange=labellist_callback;
1193 xmlhttp.send(null);
48f0adb0
AD
1194}
1195
4255b24c
AD
1196function updatePrefsList() {
1197
1198 if (!xmlhttp_ready(xmlhttp)) {
1199 printLockingError();
1200 return
1201 }
1202
1203 p_notify("Loading, please wait...");
1204
1205 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1206 xmlhttp.onreadystatechange=prefslist_callback;
1207 xmlhttp.send(null);
1208
1209}
1210
a7f22b70
AD
1211function selectTab(id, noupdate) {
1212
1213// alert(id);
48f0adb0 1214
c6c3a07f
AD
1215 if (!xmlhttp_ready(xmlhttp)) {
1216 printLockingError();
1217 return
1218 }
1219
a7f22b70
AD
1220 if (!noupdate) {
1221
1222 if (id == "feedConfig") {
1223 updateFeedList();
1224 } else if (id == "filterConfig") {
1225 updateFilterList();
1226 } else if (id == "labelConfig") {
1227 updateLabelList();
1228 } else if (id == "genConfig") {
1229 updatePrefsList();
1230 } else if (id == "userConfig") {
1231 updateUsersList();
1232 } else if (id == "feedBrowser") {
1233 updateBigFeedBrowser();
1234 }
a0d53889 1235 }
f5a50b25
AD
1236
1237 var tab = document.getElementById(active_tab + "Tab");
1238
1239 if (tab) {
1240 if (tab.className.match("Selected")) {
1241 tab.className = "prefsTab";
1242 }
1243 }
1244
1245 tab = document.getElementById(id + "Tab");
1246
1247 if (tab) {
1248 if (!tab.className.match("Selected")) {
1249 tab.className = tab.className + "Selected";
1250 }
1251 }
1252
1253 active_tab = id;
1254
4da47970
AD
1255 setCookie('ttrss_pref_acttab', active_tab);
1256
a0d53889
AD
1257}
1258
007bda35 1259function init() {
e2ec66a8 1260
7719618b
AD
1261 try {
1262
1263 // IE kludge
1264 if (!xmlhttp) {
1265 document.getElementById("prefContent").innerHTML =
1266 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1267 "to function properly. Your browser doesn't seem to support it.";
1268 return;
1269 }
4da47970
AD
1270
1271 active_tab = getCookie("ttrss_pref_acttab");
1272 if (!active_tab) active_tab = "genConfig";
1273 selectTab(active_tab);
7719618b
AD
1274
1275 document.onkeydown = hotkey_handler;
1276 notify("");
1277 } catch (e) {
1278 exception_error("init", e);
e2ec66a8 1279 }
007bda35 1280}
b1895692 1281
c6c3a07f 1282function closeInfoBox() {
2317ffaa
AD
1283 var box = document.getElementById('infoBox');
1284 var shadow = document.getElementById('infoBoxShadow');
1285
1286 if (shadow) {
1287 shadow.style.display = "none";
1288 } else if (box) {
1289 box.style.display = "none";
1290 }
1a7572cb 1291}
f932bc9f
AD
1292
1293function categorizeSelectedFeeds() {
1294
1295 if (!xmlhttp_ready(xmlhttp)) {
1296 printLockingError();
1297 return
1298 }
1299
1300 var sel_rows = getSelectedFeeds();
1301
1302 var cat_sel = document.getElementById("sfeed_set_fcat");
1303 var cat_id = cat_sel[cat_sel.selectedIndex].id;
1304
1305 if (sel_rows.length > 0) {
1306
1307 notify("Changing category of selected feeds...");
1308
1309 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1310 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1311 xmlhttp.onreadystatechange=feedlist_callback;
1312 xmlhttp.send(null);
1313
1314 } else {
1315
1316 notify("Please select some feeds first.");
1317
1318 }
1319
1320}
69668465
AD
1321
1322function validatePrefsReset() {
1323 return confirm("Reset to defaults?");
1324}
f9cb39ac
AD
1325
1326function browseFeeds() {
1327
1328 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1329 xmlhttp.onreadystatechange=infobox_callback;
1330 xmlhttp.send(null);
1331
1332}
a0476535
AD
1333
1334function feedBrowserSubscribe() {
1335 try {
1336 var list = document.getElementById("browseFeedList");
1337
072f1ee2
AD
1338 if (!list) list = document.getElementById("browseBigFeedList");
1339
a0476535
AD
1340 var selected = new Array();
1341
1342 for (i = 0; i < list.childNodes.length; i++) {
1343 var child = list.childNodes[i];
1344 if (child.id && child.id.match("FBROW-")) {
1345 var id = child.id.replace("FBROW-", "");
1346
1347 var cb = document.getElementById("FBCHK-" + id);
1348
1349 if (cb.checked) {
1350 selected.push(id);
1351 }
1352 }
1353 }
1354
1355 if (selected.length > 0) {
1356 closeInfoBox();
1357 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1358 param_escape(selected.toString()), true);
1359 xmlhttp.onreadystatechange=feedlist_callback;
1360 xmlhttp.send(null);
1361 } else {
1362 alert("No feeds are selected.");
1363 }
1364
1365 } catch (e) {
1366 exception_error("feedBrowserSubscribe", e);
1367 }
1368}
c6232e43
AD
1369
1370function updateBigFeedBrowser() {
1371
1372 if (!xmlhttp_ready(xmlhttp)) {
1373 printLockingError();
1374 return
1375 }
1376
1377 p_notify("Loading, please wait...");
1378
1379 xmlhttp.open("GET", "backend.php?op=pref-feed-browser", true);
1380 xmlhttp.onreadystatechange=feed_browser_callback;
1381 xmlhttp.send(null);
1382
1383}
1384
c2b2aee0 1385function browserToggleExpand(id) {
c6232e43
AD
1386 try {
1387/* if (feed_to_expand && feed_to_expand != id) {
1388 var d = document.getElementById("BRDET-" + feed_to_expand);
1389 d.style.display = "none";
1390 } */
c2b2aee0
AD
1391
1392 var d = document.getElementById("BRDET-" + id);
1393
1394 if (d.style.display == "block") {
1395 d.style.display = "none";
1396
1397 } else {
c6232e43 1398
c2b2aee0 1399 feed_to_expand = id;
c6232e43 1400
c2b2aee0
AD
1401 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1402 + param_escape(id), true);
1403 xmlhttp.onreadystatechange=expand_feed_callback;
1404 xmlhttp.send(null);
1405 }
c6232e43
AD
1406
1407 } catch (e) {
1408 exception_error("browserExpand", e);
1409 }
1410}