]>
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;
12 var active_tab
= false;
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.
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
29 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
30 xmlhttp
= new XMLHttpRequest();
33 function feedlist_callback() {
34 var container
= document
.getElementById('prefContent');
35 if (xmlhttp
.readyState
== 4) {
36 container
.innerHTML
=xmlhttp
.responseText
;
38 var row
= document
.getElementById("FEEDR-" + active_feed
);
40 if (!row
.className
.match("Selected")) {
41 row
.className
= row
.className
+ "Selected";
44 var checkbox
= document
.getElementById("FRCHK-" + active_feed
);
46 checkbox
.checked
= true;
53 function filterlist_callback() {
54 var container
= document
.getElementById('prefContent');
55 if (xmlhttp
.readyState
== 4) {
57 container
.innerHTML
=xmlhttp
.responseText
;
60 var row
= document
.getElementById("FILRR-" + active_filter
);
62 if (!row
.className
.match("Selected")) {
63 row
.className
= row
.className
+ "Selected";
66 var checkbox
= document
.getElementById("FICHK-" + active_filter
);
69 checkbox
.checked
= true;
76 function labellist_callback() {
77 var container
= document
.getElementById('prefContent');
78 if (xmlhttp
.readyState
== 4) {
79 container
.innerHTML
=xmlhttp
.responseText
;
82 var row
= document
.getElementById("LILRR-" + active_label
);
84 if (!row
.className
.match("Selected")) {
85 row
.className
= row
.className
+ "Selected";
88 var checkbox
= document
.getElementById("LICHK-" + active_label
);
91 checkbox
.checked
= true;
97 function notify_callback() {
98 var container
= document
.getElementById('notify');
99 if (xmlhttp
.readyState
== 4) {
100 container
.innerHTML
=xmlhttp
.responseText
;
105 function updateFeedList() {
107 if (!xmlhttp_ready(xmlhttp
)) {
112 // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
114 p_notify("Loading, please wait...");
116 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
117 xmlhttp
.onreadystatechange
=feedlist_callback
;
122 function toggleSelectRow(sender
) {
123 var parent_row
= sender
.parentNode
.parentNode
;
125 if (sender
.checked
) {
126 if (!parent_row
.className
.match("Selected")) {
127 parent_row
.className
= parent_row
.className
+ "Selected";
130 if (parent_row
.className
.match("Selected")) {
131 parent_row
.className
= parent_row
.className
.replace("Selected", "");
136 function addLabel() {
138 if (!xmlhttp_ready(xmlhttp
)) {
143 var sqlexp
= document
.getElementById("ladd_expr");
145 if (sqlexp
.value
.length
== 0) {
146 notify("Missing SQL expression.");
148 notify("Adding label...");
150 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
151 param_escape(sqlexp
.value
), true);
153 xmlhttp
.onreadystatechange
=labellist_callback
;
161 function addFilter() {
163 if (!xmlhttp_ready(xmlhttp
)) {
168 var regexp
= document
.getElementById("fadd_regexp");
169 var match
= document
.getElementById("fadd_match");
171 if (regexp
.value
.length
== 0) {
172 notify("Missing filter expression.");
174 notify("Adding filter...");
176 var v_match
= match
[match
.selectedIndex
].text
;
178 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=add®exp=" +
179 param_escape(regexp
.value
) + "&match=" + v_match
, true);
181 xmlhttp
.onreadystatechange
=filterlist_callback
;
191 if (!xmlhttp_ready(xmlhttp
)) {
196 var link
= document
.getElementById("fadd_link");
198 if (link
.value
.length
== 0) {
199 notify("Missing feed URL.");
201 notify("Adding feed...");
203 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
204 param_escape(link
.value
), true);
205 xmlhttp
.onreadystatechange
=feedlist_callback
;
214 function editLabel(id
) {
216 if (!xmlhttp_ready(xmlhttp
)) {
223 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
224 param_escape(id
), true);
225 xmlhttp
.onreadystatechange
=labellist_callback
;
230 function editFilter(id
) {
232 if (!xmlhttp_ready(xmlhttp
)) {
239 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
240 param_escape(id
), true);
241 xmlhttp
.onreadystatechange
=filterlist_callback
;
246 function editFeed(feed
) {
248 // notify("Editing feed...");
250 if (!xmlhttp_ready(xmlhttp
)) {
257 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
258 param_escape(feed
), true);
259 xmlhttp
.onreadystatechange
=feedlist_callback
;
264 function getSelectedLabels() {
266 var content
= document
.getElementById("prefLabelList");
268 var sel_rows
= new Array();
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
);
281 function getSelectedFilters() {
283 var content
= document
.getElementById("prefFilterList");
285 var sel_rows
= new Array();
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
);
297 function getSelectedFeeds() {
299 var content
= document
.getElementById("prefFeedList");
301 var sel_rows
= new Array();
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
);
313 function readSelectedFeeds() {
315 if (!xmlhttp_ready(xmlhttp
)) {
320 var sel_rows
= getSelectedFeeds();
322 if (sel_rows
.length
> 0) {
324 notify("Marking selected feeds as read...");
326 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
327 param_escape(sel_rows
.toString()), true);
328 xmlhttp
.onreadystatechange
=notify_callback
;
333 notify("Please select some feeds first.");
338 function unreadSelectedFeeds() {
340 if (!xmlhttp_ready(xmlhttp
)) {
345 var sel_rows
= getSelectedFeeds();
347 if (sel_rows
.length
> 0) {
349 notify("Marking selected feeds as unread...");
351 xmlhttp
.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
352 param_escape(sel_rows
.toString()), true);
353 xmlhttp
.onreadystatechange
=notify_callback
;
358 notify("Please select some feeds first.");
363 function removeSelectedLabels() {
365 if (!xmlhttp_ready(xmlhttp
)) {
370 var sel_rows
= getSelectedLabels();
372 if (sel_rows
.length
> 0) {
374 notify("Removing selected labels...");
376 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
377 param_escape(sel_rows
.toString()), true);
378 xmlhttp
.onreadystatechange
=labellist_callback
;
382 notify("Please select some labels first.");
386 function removeSelectedFilters() {
388 if (!xmlhttp_ready(xmlhttp
)) {
393 var sel_rows
= getSelectedFilters();
395 if (sel_rows
.length
> 0) {
397 notify("Removing selected filters...");
399 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
400 param_escape(sel_rows
.toString()), true);
401 xmlhttp
.onreadystatechange
=filterlist_callback
;
405 notify("Please select some filters first.");
410 function removeSelectedFeeds() {
412 if (!xmlhttp_ready(xmlhttp
)) {
417 var sel_rows
= getSelectedFeeds();
419 if (sel_rows
.length
> 0) {
421 notify("Removing selected feeds...");
423 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
424 param_escape(sel_rows
.toString()), true);
425 xmlhttp
.onreadystatechange
=feedlist_callback
;
430 notify("Please select some feeds first.");
436 function feedEditCancel() {
438 if (!xmlhttp_ready(xmlhttp
)) {
445 notify("Operation cancelled.");
447 xmlhttp
.open("GET", "backend.php?op=pref-feeds", true);
448 xmlhttp
.onreadystatechange
=feedlist_callback
;
453 function feedEditSave() {
455 var feed
= active_feed
;
457 if (!xmlhttp_ready(xmlhttp
)) {
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 var purge_intl
= document
.getElementById("iedit_purgintl").value
;
467 // notify("Saving feed.");
469 /* if (upd_intl < 0) {
470 notify("Update interval must be >= 0 (0 = default)");
474 if (purge_intl < 0) {
475 notify("Purge days must be >= 0 (0 = default)");
479 if (link
.length
== 0) {
480 notify("Feed link cannot be blank.");
484 if (title
.length
== 0) {
485 notify("Feed title cannot be blank.");
491 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
492 feed
+ "&l=" + param_escape(link
) + "&t=" + param_escape(title
) +
493 "&ui=" + param_escape(upd_intl
) + "&pi=" + param_escape(purge_intl
), true);
494 xmlhttp
.onreadystatechange
=feedlist_callback
;
499 function labelEditCancel() {
501 if (!xmlhttp_ready(xmlhttp
)) {
506 active_label
= false;
508 notify("Operation cancelled.");
510 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
511 xmlhttp
.onreadystatechange
=labellist_callback
;
517 function filterEditCancel() {
519 if (!xmlhttp_ready(xmlhttp
)) {
524 active_filter
= false;
526 notify("Operation cancelled.");
528 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
529 xmlhttp
.onreadystatechange
=filterlist_callback
;
534 function labelEditSave() {
536 var label
= active_label
;
538 if (!xmlhttp_ready(xmlhttp
)) {
543 var sqlexp
= document
.getElementById("iedit_expr").value
;
544 var descr
= document
.getElementById("iedit_descr").value
;
546 // notify("Saving label " + sqlexp + ": " + descr);
548 if (sqlexp
.length
== 0) {
549 notify("SQL expression cannot be blank.");
553 if (descr
.length
== 0) {
554 notify("Caption cannot be blank.");
558 active_label
= false;
560 xmlhttp
.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
561 label
+ "&s=" + param_escape(sqlexp
) + "&d=" + param_escape(descr
),
564 xmlhttp
.onreadystatechange
=labellist_callback
;
569 function filterEditSave() {
571 var filter
= active_filter
;
573 if (!xmlhttp_ready(xmlhttp
)) {
578 var regexp
= document
.getElementById("iedit_regexp").value
;
579 var descr
= document
.getElementById("iedit_descr").value
;
580 var match
= document
.getElementById("iedit_match");
582 var v_match
= match
[match
.selectedIndex
].text
;
584 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
586 if (regexp
.length
== 0) {
587 notify("Filter expression cannot be blank.");
591 active_filter
= false;
593 xmlhttp
.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
594 filter
+ "&r=" + param_escape(regexp
) + "&d=" + param_escape(descr
) +
595 "&m=" + param_escape(v_match
), true);
597 xmlhttp
.onreadystatechange
=filterlist_callback
;
602 function editSelectedLabel() {
603 var rows
= getSelectedLabels();
605 if (rows
.length
== 0) {
606 notify("No labels are selected.");
610 if (rows
.length
> 1) {
611 notify("Please select one label.");
620 function editSelectedFilter() {
621 var rows
= getSelectedFilters();
623 if (rows
.length
== 0) {
624 notify("No filters are selected.");
628 if (rows
.length
> 1) {
629 notify("Please select one filter.");
638 function editSelectedFeed() {
639 var rows
= getSelectedFeeds();
641 if (rows
.length
== 0) {
642 notify("No feeds are selected.");
646 if (rows
.length
> 1) {
647 notify("Please select one feed.");
655 function localPiggieFunction(enable
) {
657 piggie
.style
.display
= "block";
659 notify("I loveded it!!!");
661 piggie
.style
.display
= "none";
666 function validateOpmlImport() {
668 var opml_file
= document
.getElementById("opml_file");
670 if (opml_file
.value
.length
== 0) {
671 notify("Please select OPML file to upload.");
678 function updateFilterList() {
680 if (!xmlhttp_ready(xmlhttp
)) {
685 // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
687 p_notify("Loading, please wait...");
689 xmlhttp
.open("GET", "backend.php?op=pref-filters", true);
690 xmlhttp
.onreadystatechange
=filterlist_callback
;
695 function updateLabelList() {
697 if (!xmlhttp_ready(xmlhttp
)) {
702 p_notify("Loading, please wait...");
704 // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
706 xmlhttp
.open("GET", "backend.php?op=pref-labels", true);
707 xmlhttp
.onreadystatechange
=labellist_callback
;
711 function selectTab(id
) {
713 if (id
== "feedConfig") {
715 } else if (id
== "filterConfig") {
717 } else if (id
== "labelConfig") {
721 var tab
= document
.getElementById(active_tab
+ "Tab");
724 if (tab
.className
.match("Selected")) {
725 tab
.className
= "prefsTab";
729 tab
= document
.getElementById(id
+ "Tab");
732 if (!tab
.className
.match("Selected")) {
733 tab
.className
= tab
.className
+ "Selected";
746 document
.getElementById("prefContent").innerHTML
=
747 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
748 "to function properly. Your browser doesn't seem to support it.";
752 selectTab("feedConfig");
754 document
.onkeydown
= hotkey_handler
;