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