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