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