]>
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
;
458 // notify("Saving feed.");
460 if (link
.length
== 0) {
461 notify("Feed link cannot be blank.");
465 if (title
.length
== 0) {
466 notify("Feed title cannot be blank.");
472 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
473 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) ,true);
474 xmlhttp
.onreadystatechange
=feedlist_callback
;
479 function labelEditCancel() {
481 if (!xmlhttp_ready(xmlhttp
)) {
486 active_label
= false;
488 notify("Operation cancelled.");
490 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
491 xmlhttp
.onreadystatechange
=labellist_callback
;
497 function filterEditCancel() {
499 if (!xmlhttp_ready(xmlhttp
)) {
504 active_filter
= false;
506 notify("Operation cancelled.");
508 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
509 xmlhttp
.onreadystatechange
=filterlist_callback
;
514 function labelEditSave() {
516 var label
= active_label
;
518 if (!xmlhttp_ready(xmlhttp
)) {
523 var sqlexp
= document
.getElementById("iedit_expr").value
;
524 var descr
= document
.getElementById("iedit_descr").value
;
526 // notify("Saving label " + sqlexp + ": " + descr);
528 if (sqlexp
.length
== 0) {
529 notify("SQL expression cannot be blank.");
533 if (descr
.length
== 0) {
534 notify("Caption cannot be blank.");
538 active_label
= false;
540 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
541 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
544 xmlhttp
.onreadystatechange
=labellist_callback
;
549 function filterEditSave() {
551 var filter
= active_filter
;
553 if (!xmlhttp_ready(xmlhttp
)) {
558 var regexp
= document
.getElementById("iedit_regexp").value
;
559 var descr
= document
.getElementById("iedit_descr").value
;
560 var match
= document
.getElementById("iedit_match");
562 var v_match
= match
[match
.selectedIndex
].text
;
564 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
566 if (regexp
.length
== 0) {
567 notify("Filter expression cannot be blank.");
571 active_filter
= false;
573 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
574 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
575 "&m=" + param_escape(v_match
), true);
577 xmlhttp
.onreadystatechange
=filterlist_callback
;
582 function editSelectedLabel() {
583 var rows
= getSelectedLabels();
585 if (rows
.length
== 0) {
586 notify("No labels are selected.");
590 if (rows
.length
> 1) {
591 notify("Please select one label.");
600 function editSelectedFilter() {
601 var rows
= getSelectedFilters();
603 if (rows
.length
== 0) {
604 notify("No filters are selected.");
608 if (rows
.length
> 1) {
609 notify("Please select one filter.");
618 function editSelectedFeed() {
619 var rows
= getSelectedFeeds();
621 if (rows
.length
== 0) {
622 notify("No feeds are selected.");
626 if (rows
.length
> 1) {
627 notify("Please select one feed.");
635 function localPiggieFunction(enable
) {
637 piggie
.style
.display
= "block";
639 notify("I loveded it!!!");
641 piggie
.style
.display
= "none";
646 function validateOpmlImport() {
648 var opml_file
= document
.getElementById("opml_file");
650 if (opml_file
.value
.length
== 0) {
651 notify("Please select OPML file to upload.");
658 function updateFilterList() {
660 if (!xmlhttp_ready(xmlhttp
)) {
665 document
.getElementById("filterConfPane").innerHTML
= "Loading filters, please wait...";
667 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
668 xmlhttp
.onreadystatechange
=filterlist_callback
;
673 function updateLabelList() {
675 if (!xmlhttp_ready(xmlhttp
)) {
680 document
.getElementById("labelConfPane").innerHTML
= "Loading labels, please wait...";
682 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
683 xmlhttp
.onreadystatechange
=labellist_callback
;
689 function expandPane(id
) {
693 container
= document
.getElementById(id
);
695 if (id
== "feedConfPane") {
697 } else if (id
== "filterConfPane") {
699 } else if (id
== "labelConfPane") {
709 document
.getElementById("prefContent").innerHTML
=
710 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
711 "to function properly. Your browser doesn't seem to support it.";
716 document
.onkeydown
= hotkey_handler
;