]> git.wh0rd.org Git - tt-rss.git/blob - prefs.js
df49f85be1dacd2e103c2a4d752c215c04dd7935
[tt-rss.git] / prefs.js
1 /*
2         This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>              
3         Licensed under GPL v.2 or (at your preference) any later version.
4 */
5
6 var xmlhttp = false;
7
8 var active_feed = false;
9 var active_filter = false;
10 var active_label = false;
11
12 var active_tab = false;
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 feedlist_callback() {
34         var container = document.getElementById('prefContent');
35         if (xmlhttp.readyState == 4) {
36                 container.innerHTML=xmlhttp.responseText;
37                 if (active_feed) {
38                         var row = document.getElementById("FEEDR-" + active_feed);
39                         if (row) {
40                                 if (!row.className.match("Selected")) {
41                                         row.className = row.className + "Selected";
42                                 }               
43                         }
44                         var checkbox = document.getElementById("FRCHK-" + active_feed);
45                         if (checkbox) {
46                                 checkbox.checked = true;
47                         }
48                 }
49                 p_notify("");
50         }
51 }
52
53 function filterlist_callback() {
54         var container = document.getElementById('prefContent');
55         if (xmlhttp.readyState == 4) {
56
57                 container.innerHTML=xmlhttp.responseText;
58
59                 if (active_filter) {
60                         var row = document.getElementById("FILRR-" + active_filter);
61                         if (row) {
62                                 if (!row.className.match("Selected")) {
63                                         row.className = row.className + "Selected";
64                                 }               
65                         }
66                         var checkbox = document.getElementById("FICHK-" + active_filter);
67                         
68                         if (checkbox) {
69                                 checkbox.checked = true;
70                         }
71                 }
72                 p_notify("");
73         }
74 }
75
76 function labellist_callback() {
77         var container = document.getElementById('prefContent');
78         if (xmlhttp.readyState == 4) {
79                 container.innerHTML=xmlhttp.responseText;
80
81                 if (active_filter) {
82                         var row = document.getElementById("LILRR-" + active_label);
83                         if (row) {
84                                 if (!row.className.match("Selected")) {
85                                         row.className = row.className + "Selected";
86                                 }               
87                         }
88                         var checkbox = document.getElementById("LICHK-" + active_label);
89                         
90                         if (checkbox) {
91                                 checkbox.checked = true;
92                         }
93                 }
94                 p_notify("");
95         }
96 }
97
98 function prefslist_callback() {
99         var container = document.getElementById('prefContent');
100         if (xmlhttp.readyState == 4) {
101
102                 container.innerHTML=xmlhttp.responseText;
103
104                 p_notify("");
105         }
106 }
107
108 function gethelp_callback() {
109         var container = document.getElementById('prefHelpBox');
110         if (xmlhttp.readyState == 4) {
111
112                 container.innerHTML = xmlhttp.responseText;
113                 container.style.display = "block";
114
115         }
116 }
117
118
119 function notify_callback() {
120         var container = document.getElementById('notify');
121         if (xmlhttp.readyState == 4) {
122                 container.innerHTML=xmlhttp.responseText;
123         }
124 }
125
126
127 function updateFeedList() {
128
129         if (!xmlhttp_ready(xmlhttp)) {
130                 printLockingError();
131                 return
132         }
133
134 //      document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
135
136         p_notify("Loading, please wait...");
137
138         xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
139         xmlhttp.onreadystatechange=feedlist_callback;
140         xmlhttp.send(null);
141
142 }
143
144 function toggleSelectRow(sender) {
145         var parent_row = sender.parentNode.parentNode;
146
147         if (sender.checked) {
148                 if (!parent_row.className.match("Selected")) {
149                         parent_row.className = parent_row.className + "Selected";
150                 }
151         } else {
152                 if (parent_row.className.match("Selected")) {
153                         parent_row.className = parent_row.className.replace("Selected", "");
154                 }
155         }
156 }
157
158 function addLabel() {
159
160         if (!xmlhttp_ready(xmlhttp)) {
161                 printLockingError();
162                 return
163         }
164
165         var sqlexp = document.getElementById("ladd_expr");
166
167         if (sqlexp.value.length == 0) {
168                 notify("Missing SQL expression.");
169         } else {
170                 notify("Adding label...");
171
172                 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
173                         param_escape(sqlexp.value), true);                      
174                         
175                 xmlhttp.onreadystatechange=labellist_callback;
176                 xmlhttp.send(null);
177
178                 sqlexp.value = "";
179         }
180
181 }
182
183 function addFilter() {
184
185         if (!xmlhttp_ready(xmlhttp)) {
186                 printLockingError();
187                 return
188         }
189
190         var regexp = document.getElementById("fadd_regexp");
191         var match = document.getElementById("fadd_match");
192
193         if (regexp.value.length == 0) {
194                 notify("Missing filter expression.");
195         } else {
196                 notify("Adding filter...");
197
198                 var v_match = match[match.selectedIndex].text;
199
200                 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
201                         param_escape(regexp.value) + "&match=" + v_match, true);                        
202                         
203                 xmlhttp.onreadystatechange=filterlist_callback;
204                 xmlhttp.send(null);
205
206                 regexp.value = "";
207         }
208
209 }
210
211 function addFeed() {
212
213         if (!xmlhttp_ready(xmlhttp)) {
214                 printLockingError();
215                 return
216         }
217
218         var link = document.getElementById("fadd_link");
219
220         if (link.value.length == 0) {
221                 notify("Missing feed URL.");
222         } else {
223                 notify("Adding feed...");
224
225                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
226                         param_escape(link.value), true);
227                 xmlhttp.onreadystatechange=feedlist_callback;
228                 xmlhttp.send(null);
229
230                 link.value = "";
231
232         }
233
234 }
235
236 function editLabel(id) {
237
238         if (!xmlhttp_ready(xmlhttp)) {
239                 printLockingError();
240                 return
241         }
242
243         active_label = id;
244
245         xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
246                 param_escape(id), true);
247         xmlhttp.onreadystatechange=labellist_callback;
248         xmlhttp.send(null);
249
250 }
251
252 function editFilter(id) {
253
254         if (!xmlhttp_ready(xmlhttp)) {
255                 printLockingError();
256                 return
257         }
258
259         active_filter = id;
260
261         xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
262                 param_escape(id), true);
263         xmlhttp.onreadystatechange=filterlist_callback;
264         xmlhttp.send(null);
265
266 }
267
268 function editFeed(feed) {
269
270 //      notify("Editing feed...");
271
272         if (!xmlhttp_ready(xmlhttp)) {
273                 printLockingError();
274                 return
275         }
276
277         active_feed = feed;
278
279         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
280                 param_escape(feed), true);
281         xmlhttp.onreadystatechange=feedlist_callback;
282         xmlhttp.send(null);
283
284 }
285
286 function getSelectedLabels() {
287
288         var content = document.getElementById("prefLabelList");
289
290         var sel_rows = new Array();
291
292         for (i = 0; i < content.rows.length; i++) {
293                 if (content.rows[i].className.match("Selected")) {
294                         var row_id = content.rows[i].id.replace("LILRR-", "");
295                         sel_rows.push(row_id);  
296                 }
297         }
298
299         return sel_rows;
300 }
301
302
303 function getSelectedFilters() {
304
305         var content = document.getElementById("prefFilterList");
306
307         var sel_rows = new Array();
308
309         for (i = 0; i < content.rows.length; i++) {
310                 if (content.rows[i].className.match("Selected")) {
311                         var row_id = content.rows[i].id.replace("FILRR-", "");
312                         sel_rows.push(row_id);  
313                 }
314         }
315
316         return sel_rows;
317 }
318
319 function getSelectedFeeds() {
320
321         var content = document.getElementById("prefFeedList");
322
323         var sel_rows = new Array();
324
325         for (i = 0; i < content.rows.length; i++) {
326                 if (content.rows[i].className.match("Selected")) {
327                         var row_id = content.rows[i].id.replace("FEEDR-", "");
328                         sel_rows.push(row_id);  
329                 }
330         }
331
332         return sel_rows;
333 }
334
335 function readSelectedFeeds() {
336
337         if (!xmlhttp_ready(xmlhttp)) {
338                 printLockingError();
339                 return
340         }
341
342         var sel_rows = getSelectedFeeds();
343
344         if (sel_rows.length > 0) {
345
346                 notify("Marking selected feeds as read...");
347
348                 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
349                         param_escape(sel_rows.toString()), true);
350                 xmlhttp.onreadystatechange=notify_callback;
351                 xmlhttp.send(null);
352
353         } else {
354
355                 notify("Please select some feeds first.");
356
357         }
358 }
359
360 function unreadSelectedFeeds() {
361
362         if (!xmlhttp_ready(xmlhttp)) {
363                 printLockingError();
364                 return
365         }
366
367         var sel_rows = getSelectedFeeds();
368
369         if (sel_rows.length > 0) {
370
371                 notify("Marking selected feeds as unread...");
372
373                 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
374                         param_escape(sel_rows.toString()), true);
375                 xmlhttp.onreadystatechange=notify_callback;
376                 xmlhttp.send(null);
377
378         } else {
379
380                 notify("Please select some feeds first.");
381
382         }
383 }
384
385 function removeSelectedLabels() {
386
387         if (!xmlhttp_ready(xmlhttp)) {
388                 printLockingError();
389                 return
390         }
391
392         var sel_rows = getSelectedLabels();
393
394         if (sel_rows.length > 0) {
395
396                 notify("Removing selected labels...");
397
398                 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
399                         param_escape(sel_rows.toString()), true);
400                 xmlhttp.onreadystatechange=labellist_callback;
401                 xmlhttp.send(null);
402
403         } else {
404                 notify("Please select some labels first.");
405         }
406 }
407
408 function removeSelectedFilters() {
409
410         if (!xmlhttp_ready(xmlhttp)) {
411                 printLockingError();
412                 return
413         }
414
415         var sel_rows = getSelectedFilters();
416
417         if (sel_rows.length > 0) {
418
419                 notify("Removing selected filters...");
420
421                 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
422                         param_escape(sel_rows.toString()), true);
423                 xmlhttp.onreadystatechange=filterlist_callback;
424                 xmlhttp.send(null);
425
426         } else {
427                 notify("Please select some filters first.");
428         }
429 }
430
431
432 function removeSelectedFeeds() {
433
434         if (!xmlhttp_ready(xmlhttp)) {
435                 printLockingError();
436                 return
437         }
438
439         var sel_rows = getSelectedFeeds();
440
441         if (sel_rows.length > 0) {
442
443                 notify("Removing selected feeds...");
444
445                 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
446                         param_escape(sel_rows.toString()), true);
447                 xmlhttp.onreadystatechange=feedlist_callback;
448                 xmlhttp.send(null);
449
450         } else {
451
452                 notify("Please select some feeds first.");
453
454         }
455
456 }
457
458 function feedEditCancel() {
459
460         if (!xmlhttp_ready(xmlhttp)) {
461                 printLockingError();
462                 return
463         }
464
465         active_feed = false;
466
467         notify("Operation cancelled.");
468
469         xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
470         xmlhttp.onreadystatechange=feedlist_callback;
471         xmlhttp.send(null);
472
473 }
474
475 function feedEditSave() {
476
477         var feed = active_feed;
478
479         if (!xmlhttp_ready(xmlhttp)) {
480                 printLockingError();
481                 return
482         }
483
484         var link = document.getElementById("iedit_link").value;
485         var title = document.getElementById("iedit_title").value;
486         var upd_intl = document.getElementById("iedit_updintl").value;
487         var purge_intl = document.getElementById("iedit_purgintl").value;
488
489 //      notify("Saving feed.");
490
491 /*      if (upd_intl < 0) {
492                 notify("Update interval must be &gt;= 0 (0 = default)");
493                 return;
494         }
495
496         if (purge_intl < 0) {
497                 notify("Purge days must be &gt;= 0 (0 = default)");
498                 return;
499         } */
500
501         if (link.length == 0) {
502                 notify("Feed link cannot be blank.");
503                 return;
504         }
505
506         if (title.length == 0) {
507                 notify("Feed title cannot be blank.");
508                 return;
509         }
510
511         active_feed = false;
512
513         xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
514                 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) +
515                 "&ui=" + param_escape(upd_intl) + "&pi=" + param_escape(purge_intl), true);
516         xmlhttp.onreadystatechange=feedlist_callback;
517         xmlhttp.send(null);
518
519 }
520
521 function labelEditCancel() {
522
523         if (!xmlhttp_ready(xmlhttp)) {
524                 printLockingError();
525                 return
526         }
527
528         active_label = false;
529
530         notify("Operation cancelled.");
531
532         xmlhttp.open("GET", "backend.php?op=pref-labels", true);
533         xmlhttp.onreadystatechange=labellist_callback;
534         xmlhttp.send(null);
535
536 }
537
538
539 function filterEditCancel() {
540
541         if (!xmlhttp_ready(xmlhttp)) {
542                 printLockingError();
543                 return
544         }
545
546         active_filter = false;
547
548         notify("Operation cancelled.");
549
550         xmlhttp.open("GET", "backend.php?op=pref-filters", true);
551         xmlhttp.onreadystatechange=filterlist_callback;
552         xmlhttp.send(null);
553
554 }
555
556 function labelEditSave() {
557
558         var label = active_label;
559
560         if (!xmlhttp_ready(xmlhttp)) {
561                 printLockingError();
562                 return
563         }
564
565         var sqlexp = document.getElementById("iedit_expr").value;
566         var descr = document.getElementById("iedit_descr").value;
567
568 //      notify("Saving label " + sqlexp + ": " + descr);
569
570         if (sqlexp.length == 0) {
571                 notify("SQL expression cannot be blank.");
572                 return;
573         }
574
575         if (descr.length == 0) {
576                 notify("Caption cannot be blank.");
577                 return;
578         }
579
580         active_label = false;
581
582         xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
583                 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
584                 true);
585                 
586         xmlhttp.onreadystatechange=labellist_callback;
587         xmlhttp.send(null);
588
589 }
590
591 function filterEditSave() {
592
593         var filter = active_filter;
594
595         if (!xmlhttp_ready(xmlhttp)) {
596                 printLockingError();
597                 return
598         }
599
600         var regexp = document.getElementById("iedit_regexp").value;
601         var descr = document.getElementById("iedit_descr").value;
602         var match = document.getElementById("iedit_match");
603
604         var v_match = match[match.selectedIndex].text;
605
606 //      notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
607
608         if (regexp.length == 0) {
609                 notify("Filter expression cannot be blank.");
610                 return;
611         }
612
613         active_filter = false;
614
615         xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
616                 filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
617                 "&m=" + param_escape(v_match), true);
618                 
619         xmlhttp.onreadystatechange=filterlist_callback;
620         xmlhttp.send(null); 
621
622 }
623
624 function editSelectedLabel() {
625         var rows = getSelectedLabels();
626
627         if (rows.length == 0) {
628                 notify("No labels are selected.");
629                 return;
630         }
631
632         if (rows.length > 1) {
633                 notify("Please select one label.");
634                 return;
635         }
636
637         editLabel(rows[0]);
638
639 }
640
641
642 function editSelectedFilter() {
643         var rows = getSelectedFilters();
644
645         if (rows.length == 0) {
646                 notify("No filters are selected.");
647                 return;
648         }
649
650         if (rows.length > 1) {
651                 notify("Please select one filter.");
652                 return;
653         }
654
655         editFilter(rows[0]);
656
657 }
658
659
660 function editSelectedFeed() {
661         var rows = getSelectedFeeds();
662
663         if (rows.length == 0) {
664                 notify("No feeds are selected.");
665                 return;
666         }
667
668         if (rows.length > 1) {
669                 notify("Please select one feed.");
670                 return;
671         }
672
673         editFeed(rows[0]);
674
675 }
676
677 function localPiggieFunction(enable) {
678         if (enable) {
679                 piggie.style.display = "block";
680                 seq = "";
681                 notify("I loveded it!!!");
682         } else {
683                 piggie.style.display = "none";
684                 notify("");
685         }
686 }
687
688 function validateOpmlImport() {
689         
690         var opml_file = document.getElementById("opml_file");
691
692         if (opml_file.value.length == 0) {
693                 notify("Please select OPML file to upload.");
694                 return false;
695         } else {
696                 return true;
697         }
698 }
699
700 function updateFilterList() {
701
702         if (!xmlhttp_ready(xmlhttp)) {
703                 printLockingError();
704                 return
705         }
706
707 //      document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
708
709         p_notify("Loading, please wait...");
710
711         xmlhttp.open("GET", "backend.php?op=pref-filters", true);
712         xmlhttp.onreadystatechange=filterlist_callback;
713         xmlhttp.send(null);
714
715 }
716
717 function updateLabelList() {
718
719         if (!xmlhttp_ready(xmlhttp)) {
720                 printLockingError();
721                 return
722         }
723
724         p_notify("Loading, please wait...");
725
726 //      document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
727
728         xmlhttp.open("GET", "backend.php?op=pref-labels", true);
729         xmlhttp.onreadystatechange=labellist_callback;
730         xmlhttp.send(null);
731 }
732
733 function updatePrefsList() {
734
735         if (!xmlhttp_ready(xmlhttp)) {
736                 printLockingError();
737                 return
738         }
739
740         p_notify("Loading, please wait...");
741
742         xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
743         xmlhttp.onreadystatechange=prefslist_callback;
744         xmlhttp.send(null);
745
746 }
747
748 function selectTab(id) {
749
750         if (id == "feedConfig") {
751                 updateFeedList();
752         } else if (id == "filterConfig") {
753                 updateFilterList();
754         } else if (id == "labelConfig") {
755                 updateLabelList();
756         } else if (id == "genConfig") {
757                 updatePrefsList();
758         }
759
760         var tab = document.getElementById(active_tab + "Tab");
761
762         if (tab) {
763                 if (tab.className.match("Selected")) {
764                         tab.className = "prefsTab";
765                 }
766         }
767
768         tab = document.getElementById(id + "Tab");
769
770         if (tab) {
771                 if (!tab.className.match("Selected")) {
772                         tab.className = tab.className + "Selected";
773                 }
774         }
775
776         active_tab = id;
777
778 }
779
780 function init() {
781
782         // IE kludge
783
784         if (!xmlhttp) {
785                 document.getElementById("prefContent").innerHTML = 
786                         "<b>Fatal error:</b> This program needs XmlHttpRequest " + 
787                         "to function properly. Your browser doesn't seem to support it.";
788                 return;
789         }
790
791         selectTab("genConfig");
792
793         document.onkeydown = hotkey_handler;
794         notify("");
795
796 }
797
798 /*
799 var help_topic_id = false;
800
801 function do_dispOptionHelp() {
802
803         if (!xmlhttp_ready(xmlhttp))
804                 return;
805
806         xmlhttp.open("GET", "backend.php?op=pref-prefs&subop=getHelp&pn=" +
807                 param_escape(help_topic_id), true);
808         xmlhttp.onreadystatechange=gethelp_callback;
809         xmlhttp.send(null);
810
811 }
812
813 function dispOptionHelp(event, sender) {
814
815         help_topic_id = sender.id;
816
817 //      document.setTimeout("do_dispOptionHelp()", 100);
818
819 } */
820
821