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