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