]>
git.wh0rd.org - tt-rss.git/blob - prefs.js
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.
8 var active_feed
= false;
9 var active_filter
= false;
10 var active_label
= false;
13 /*@if (@_jscript_version >= 5)
14 // JScript gives us Conditional compilation, we can cope with old IE versions.
15 // and security blocked creation of the objects.
17 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
20 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
27 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
28 xmlhttp
= new XMLHttpRequest();
31 function feedlist_callback() {
32 var container
= document
.getElementById('feedConfPane');
33 if (xmlhttp
.readyState
== 4) {
34 container
.innerHTML
=xmlhttp
.responseText
;
37 var row
= document
.getElementById("FEEDR-" + active_feed
);
39 if (!row
.className
.match("Selected")) {
40 row
.className
= row
.className
+ "Selected";
43 var checkbox
= document
.getElementById("FRCHK-" + active_feed
);
45 checkbox
.checked
= true;
51 function filterlist_callback() {
52 var container
= document
.getElementById('filterConfPane');
53 if (xmlhttp
.readyState
== 4) {
54 container
.innerHTML
=xmlhttp
.responseText
;
57 var row
= document
.getElementById("FILRR-" + active_filter
);
59 if (!row
.className
.match("Selected")) {
60 row
.className
= row
.className
+ "Selected";
63 var checkbox
= document
.getElementById("FICHK-" + active_filter
);
66 checkbox
.checked
= true;
72 function labellist_callback() {
73 var container
= document
.getElementById('labelConfPane');
74 if (xmlhttp
.readyState
== 4) {
75 container
.innerHTML
=xmlhttp
.responseText
;
78 var row
= document
.getElementById("LILRR-" + active_label
);
80 if (!row
.className
.match("Selected")) {
81 row
.className
= row
.className
+ "Selected";
84 var checkbox
= document
.getElementById("LICHK-" + active_label
);
87 checkbox
.checked
= true;
92 function notify_callback() {
93 var container
= document
.getElementById('notify');
94 if (xmlhttp
.readyState
== 4) {
95 container
.innerHTML
=xmlhttp
.responseText
;
100 function updateFeedList() {
102 if (!xmlhttp_ready(xmlhttp
)) {
107 document
.getElementById("feedConfPane").innerHTML
= "Loading feeds, please wait...";
109 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
110 xmlhttp
.onreadystatechange
=feedlist_callback
;
115 function toggleSelectRow(sender
) {
116 var parent_row
= sender
.parentNode
.parentNode
;
118 if (sender
.checked
) {
119 if (!parent_row
.className
.match("Selected")) {
120 parent_row
.className
= parent_row
.className
+ "Selected";
123 if (parent_row
.className
.match("Selected")) {
124 parent_row
.className
= parent_row
.className
.replace("Selected", "");
129 function addLabel() {
131 if (!xmlhttp_ready(xmlhttp
)) {
136 var sqlexp
= document
.getElementById("ladd_expr");
138 if (sqlexp
.value
.length
== 0) {
139 notify("Missing SQL expression.");
141 notify("Adding label...");
143 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
144 param_escape(sqlexp
.value
), true);
146 xmlhttp
.onreadystatechange
=labellist_callback
;
154 function addFilter() {
156 if (!xmlhttp_ready(xmlhttp
)) {
161 var regexp
= document
.getElementById("fadd_regexp");
162 var match
= document
.getElementById("fadd_match");
164 if (regexp
.value
.length
== 0) {
165 notify("Missing filter expression.");
167 notify("Adding filter...");
169 var v_match
= match
[match
.selectedIndex
].text
;
171 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
172 param_escape(regexp
.value
) + "&match=" + v_match
, true);
174 xmlhttp
.onreadystatechange
=filterlist_callback
;
184 if (!xmlhttp_ready(xmlhttp
)) {
189 var link
= document
.getElementById("fadd_link");
191 if (link
.value
.length
== 0) {
192 notify("Missing feed URL.");
194 notify("Adding feed...");
196 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
197 param_escape(link
.value
), true);
198 xmlhttp
.onreadystatechange
=feedlist_callback
;
207 function editLabel(id
) {
209 if (!xmlhttp_ready(xmlhttp
)) {
216 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
217 param_escape(id
), true);
218 xmlhttp
.onreadystatechange
=labellist_callback
;
223 function editFilter(id
) {
225 if (!xmlhttp_ready(xmlhttp
)) {
232 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
233 param_escape(id
), true);
234 xmlhttp
.onreadystatechange
=filterlist_callback
;
239 function editFeed(feed
) {
241 // notify("Editing feed...");
243 if (!xmlhttp_ready(xmlhttp
)) {
250 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
251 param_escape(feed
), true);
252 xmlhttp
.onreadystatechange
=feedlist_callback
;
257 function getSelectedLabels() {
259 var content
= document
.getElementById("prefLabelList");
261 var sel_rows
= new Array();
263 for (i
= 0; i
< content
.rows
.length
; i
++) {
264 if (content
.rows
[i
].className
.match("Selected")) {
265 var row_id
= content
.rows
[i
].id
.replace("LILRR-", "");
266 sel_rows
.push(row_id
);
274 function getSelectedFilters() {
276 var content
= document
.getElementById("prefFilterList");
278 var sel_rows
= new Array();
280 for (i
= 0; i
< content
.rows
.length
; i
++) {
281 if (content
.rows
[i
].className
.match("Selected")) {
282 var row_id
= content
.rows
[i
].id
.replace("FILRR-", "");
283 sel_rows
.push(row_id
);
290 function getSelectedFeeds() {
292 var content
= document
.getElementById("prefFeedList");
294 var sel_rows
= new Array();
296 for (i
= 0; i
< content
.rows
.length
; i
++) {
297 if (content
.rows
[i
].className
.match("Selected")) {
298 var row_id
= content
.rows
[i
].id
.replace("FEEDR-", "");
299 sel_rows
.push(row_id
);
306 function readSelectedFeeds() {
308 if (!xmlhttp_ready(xmlhttp
)) {
313 var sel_rows
= getSelectedFeeds();
315 if (sel_rows
.length
> 0) {
317 notify("Marking selected feeds as read...");
319 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
320 param_escape(sel_rows
.toString()), true);
321 xmlhttp
.onreadystatechange
=notify_callback
;
326 notify("Please select some feeds first.");
331 function unreadSelectedFeeds() {
333 if (!xmlhttp_ready(xmlhttp
)) {
338 var sel_rows
= getSelectedFeeds();
340 if (sel_rows
.length
> 0) {
342 notify("Marking selected feeds as unread...");
344 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
345 param_escape(sel_rows
.toString()), true);
346 xmlhttp
.onreadystatechange
=notify_callback
;
351 notify("Please select some feeds first.");
356 function removeSelectedLabels() {
358 if (!xmlhttp_ready(xmlhttp
)) {
363 var sel_rows
= getSelectedLabels();
365 if (sel_rows
.length
> 0) {
367 notify("Removing selected labels...");
369 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
370 param_escape(sel_rows
.toString()), true);
371 xmlhttp
.onreadystatechange
=labellist_callback
;
375 notify("Please select some labels first.");
379 function removeSelectedFilters() {
381 if (!xmlhttp_ready(xmlhttp
)) {
386 var sel_rows
= getSelectedFilters();
388 if (sel_rows
.length
> 0) {
390 notify("Removing selected filters...");
392 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
393 param_escape(sel_rows
.toString()), true);
394 xmlhttp
.onreadystatechange
=filterlist_callback
;
398 notify("Please select some filters first.");
403 function removeSelectedFeeds() {
405 if (!xmlhttp_ready(xmlhttp
)) {
410 var sel_rows
= getSelectedFeeds();
412 if (sel_rows
.length
> 0) {
414 notify("Removing selected feeds...");
416 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
417 param_escape(sel_rows
.toString()), true);
418 xmlhttp
.onreadystatechange
=feedlist_callback
;
423 notify("Please select some feeds first.");
429 function feedEditCancel() {
431 if (!xmlhttp_ready(xmlhttp
)) {
438 notify("Operation cancelled.");
440 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
441 xmlhttp
.onreadystatechange
=feedlist_callback
;
446 function feedEditSave() {
448 var feed
= active_feed
;
450 if (!xmlhttp_ready(xmlhttp
)) {
455 var link
= document
.getElementById("iedit_link").value
;
456 var title
= document
.getElementById("iedit_title").value
;
457 var upd_intl
= document
.getElementById("iedit_updintl").value
;
459 // notify("Saving feed.");
462 notify("Update interval must be >= 0 (0 = default)");
467 if (link
.length
== 0) {
468 notify("Feed link cannot be blank.");
472 if (title
.length
== 0) {
473 notify("Feed title cannot be blank.");
479 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
480 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) +
481 "&ui=" + param_escape(upd_intl
), true);
482 xmlhttp
.onreadystatechange
=feedlist_callback
;
487 function labelEditCancel() {
489 if (!xmlhttp_ready(xmlhttp
)) {
494 active_label
= false;
496 notify("Operation cancelled.");
498 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
499 xmlhttp
.onreadystatechange
=labellist_callback
;
505 function filterEditCancel() {
507 if (!xmlhttp_ready(xmlhttp
)) {
512 active_filter
= false;
514 notify("Operation cancelled.");
516 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
517 xmlhttp
.onreadystatechange
=filterlist_callback
;
522 function labelEditSave() {
524 var label
= active_label
;
526 if (!xmlhttp_ready(xmlhttp
)) {
531 var sqlexp
= document
.getElementById("iedit_expr").value
;
532 var descr
= document
.getElementById("iedit_descr").value
;
534 // notify("Saving label " + sqlexp + ": " + descr);
536 if (sqlexp
.length
== 0) {
537 notify("SQL expression cannot be blank.");
541 if (descr
.length
== 0) {
542 notify("Caption cannot be blank.");
546 active_label
= false;
548 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
549 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
552 xmlhttp
.onreadystatechange
=labellist_callback
;
557 function filterEditSave() {
559 var filter
= active_filter
;
561 if (!xmlhttp_ready(xmlhttp
)) {
566 var regexp
= document
.getElementById("iedit_regexp").value
;
567 var descr
= document
.getElementById("iedit_descr").value
;
568 var match
= document
.getElementById("iedit_match");
570 var v_match
= match
[match
.selectedIndex
].text
;
572 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
574 if (regexp
.length
== 0) {
575 notify("Filter expression cannot be blank.");
579 active_filter
= false;
581 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
582 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
583 "&m=" + param_escape(v_match
), true);
585 xmlhttp
.onreadystatechange
=filterlist_callback
;
590 function editSelectedLabel() {
591 var rows
= getSelectedLabels();
593 if (rows
.length
== 0) {
594 notify("No labels are selected.");
598 if (rows
.length
> 1) {
599 notify("Please select one label.");
608 function editSelectedFilter() {
609 var rows
= getSelectedFilters();
611 if (rows
.length
== 0) {
612 notify("No filters are selected.");
616 if (rows
.length
> 1) {
617 notify("Please select one filter.");
626 function editSelectedFeed() {
627 var rows
= getSelectedFeeds();
629 if (rows
.length
== 0) {
630 notify("No feeds are selected.");
634 if (rows
.length
> 1) {
635 notify("Please select one feed.");
643 function localPiggieFunction(enable
) {
645 piggie
.style
.display
= "block";
647 notify("I loveded it!!!");
649 piggie
.style
.display
= "none";
654 function validateOpmlImport() {
656 var opml_file
= document
.getElementById("opml_file");
658 if (opml_file
.value
.length
== 0) {
659 notify("Please select OPML file to upload.");
666 function updateFilterList() {
668 if (!xmlhttp_ready(xmlhttp
)) {
673 document
.getElementById("filterConfPane").innerHTML
= "Loading filters, please wait...";
675 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
676 xmlhttp
.onreadystatechange
=filterlist_callback
;
681 function updateLabelList() {
683 if (!xmlhttp_ready(xmlhttp
)) {
688 document
.getElementById("labelConfPane").innerHTML
= "Loading labels, please wait...";
690 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
691 xmlhttp
.onreadystatechange
=labellist_callback
;
697 function expandPane(id
) {
701 container
= document
.getElementById(id
);
703 if (id
== "feedConfPane") {
705 } else if (id
== "filterConfPane") {
707 } else if (id
== "labelConfPane") {
717 document
.getElementById("prefContent").innerHTML
=
718 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
719 "to function properly. Your browser doesn't seem to support it.";
724 document
.onkeydown
= hotkey_handler
;