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