]> git.wh0rd.org - tt-rss.git/blame - prefs.js
fix DAEMON_REFRESH_ONLY handling
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
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
6var xmlhttp = false;
7
961513a3 8var active_feed = false;
a0d53889 9var active_filter = false;
48f0adb0 10var active_label = false;
961513a3 11
007bda35
AD
12/*@cc_on @*/
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.
16try {
17 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
18} catch (e) {
19 try {
20 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
21 } catch (E) {
22 xmlhttp = false;
23 }
24}
25@end @*/
26
27if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
28 xmlhttp = new XMLHttpRequest();
29}
30
007bda35 31function feedlist_callback() {
a0d53889 32 var container = document.getElementById('feedConfPane');
007bda35
AD
33 if (xmlhttp.readyState == 4) {
34 container.innerHTML=xmlhttp.responseText;
961513a3
AD
35
36 if (active_feed) {
37 var row = document.getElementById("FEEDR-" + active_feed);
38 if (row) {
39 if (!row.className.match("Selected")) {
40 row.className = row.className + "Selected";
41 }
42 }
43 var checkbox = document.getElementById("FRCHK-" + active_feed);
44 if (checkbox) {
45 checkbox.checked = true;
46 }
47 }
007bda35
AD
48 }
49}
50
a0d53889
AD
51function filterlist_callback() {
52 var container = document.getElementById('filterConfPane');
53 if (xmlhttp.readyState == 4) {
54 container.innerHTML=xmlhttp.responseText;
55
56 if (active_filter) {
57 var row = document.getElementById("FILRR-" + active_filter);
58 if (row) {
59 if (!row.className.match("Selected")) {
60 row.className = row.className + "Selected";
61 }
62 }
63 var checkbox = document.getElementById("FICHK-" + active_filter);
64
65 if (checkbox) {
66 checkbox.checked = true;
67 }
68 }
69 }
70}
71
48f0adb0
AD
72function labellist_callback() {
73 var container = document.getElementById('labelConfPane');
74 if (xmlhttp.readyState == 4) {
75 container.innerHTML=xmlhttp.responseText;
76
77 if (active_filter) {
78 var row = document.getElementById("LILRR-" + active_label);
79 if (row) {
80 if (!row.className.match("Selected")) {
81 row.className = row.className + "Selected";
82 }
83 }
84 var checkbox = document.getElementById("LICHK-" + active_label);
85
86 if (checkbox) {
87 checkbox.checked = true;
88 }
89 }
90 }
91}
0e091d38
AD
92function notify_callback() {
93 var container = document.getElementById('notify');
94 if (xmlhttp.readyState == 4) {
95 container.innerHTML=xmlhttp.responseText;
96 }
97}
98
175847de 99
0e091d38 100function updateFeedList() {
007bda35 101
c0e5a40e 102 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
103 printLockingError();
104 return
105 }
106
a0d53889 107 document.getElementById("feedConfPane").innerHTML = "Loading feeds, please wait...";
007bda35
AD
108
109 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
110 xmlhttp.onreadystatechange=feedlist_callback;
111 xmlhttp.send(null);
112
113}
114
115function toggleSelectRow(sender) {
116 var parent_row = sender.parentNode.parentNode;
117
118 if (sender.checked) {
119 if (!parent_row.className.match("Selected")) {
120 parent_row.className = parent_row.className + "Selected";
121 }
122 } else {
123 if (parent_row.className.match("Selected")) {
124 parent_row.className = parent_row.className.replace("Selected", "");
125 }
126 }
127}
128
48f0adb0
AD
129function addLabel() {
130
131 if (!xmlhttp_ready(xmlhttp)) {
132 printLockingError();
133 return
134 }
135
136 var sqlexp = document.getElementById("ladd_expr");
137
138 if (sqlexp.value.length == 0) {
139 notify("Missing SQL expression.");
140 } else {
141 notify("Adding label...");
142
143 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
144 param_escape(sqlexp.value), true);
145
146 xmlhttp.onreadystatechange=labellist_callback;
147 xmlhttp.send(null);
148
149 sqlexp.value = "";
150 }
151
152}
153
de435974
AD
154function addFilter() {
155
156 if (!xmlhttp_ready(xmlhttp)) {
157 printLockingError();
158 return
159 }
160
161 var regexp = document.getElementById("fadd_regexp");
162 var match = document.getElementById("fadd_match");
163
164 if (regexp.value.length == 0) {
165 notify("Missing filter expression.");
166 } else {
167 notify("Adding filter...");
168
25cb5736
AD
169 var v_match = match[match.selectedIndex].text;
170
de435974 171 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
25cb5736 172 param_escape(regexp.value) + "&match=" + v_match, true);
de435974
AD
173
174 xmlhttp.onreadystatechange=filterlist_callback;
175 xmlhttp.send(null);
176
177 regexp.value = "";
178 }
179
180}
48f0adb0 181
71ad3959
AD
182function addFeed() {
183
c0e5a40e 184 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
185 printLockingError();
186 return
187 }
188
331900c6
AD
189 var link = document.getElementById("fadd_link");
190
83fe4d6d 191 if (link.value.length == 0) {
c753cd32 192 notify("Missing feed URL.");
331900c6
AD
193 } else {
194 notify("Adding feed...");
195
196 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
197 param_escape(link.value), true);
198 xmlhttp.onreadystatechange=feedlist_callback;
199 xmlhttp.send(null);
200
201 link.value = "";
202
203 }
204
205}
206
48f0adb0
AD
207function editLabel(id) {
208
209 if (!xmlhttp_ready(xmlhttp)) {
210 printLockingError();
211 return
212 }
213
214 active_label = id;
215
216 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
217 param_escape(id), true);
218 xmlhttp.onreadystatechange=labellist_callback;
219 xmlhttp.send(null);
220
221}
222
a0d53889
AD
223function editFilter(id) {
224
225 if (!xmlhttp_ready(xmlhttp)) {
226 printLockingError();
227 return
228 }
229
230 active_filter = id;
231
232 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
233 param_escape(id), true);
234 xmlhttp.onreadystatechange=filterlist_callback;
235 xmlhttp.send(null);
236
237}
238
331900c6
AD
239function editFeed(feed) {
240
508a81e1
AD
241// notify("Editing feed...");
242
c0e5a40e 243 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
244 printLockingError();
245 return
246 }
331900c6 247
961513a3
AD
248 active_feed = feed;
249
331900c6
AD
250 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
251 param_escape(feed), true);
252 xmlhttp.onreadystatechange=feedlist_callback;
253 xmlhttp.send(null);
254
255}
256
48f0adb0
AD
257function getSelectedLabels() {
258
259 var content = document.getElementById("prefLabelList");
260
261 var sel_rows = new Array();
262
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);
267 }
268 }
269
270 return sel_rows;
271}
272
273
a0d53889
AD
274function getSelectedFilters() {
275
276 var content = document.getElementById("prefFilterList");
277
278 var sel_rows = new Array();
279
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);
284 }
285 }
286
287 return sel_rows;
288}
289
83fe4d6d 290function getSelectedFeeds() {
331900c6
AD
291
292 var content = document.getElementById("prefFeedList");
293
294 var sel_rows = new Array();
295
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);
300 }
301 }
302
83fe4d6d
AD
303 return sel_rows;
304}
305
306function readSelectedFeeds() {
307
c0e5a40e 308 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
309 printLockingError();
310 return
311 }
312
83fe4d6d
AD
313 var sel_rows = getSelectedFeeds();
314
315 if (sel_rows.length > 0) {
316
317 notify("Marking selected feeds as read...");
318
0e091d38 319 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 320 param_escape(sel_rows.toString()), true);
0e091d38 321 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
322 xmlhttp.send(null);
323
324 } else {
325
c753cd32 326 notify("Please select some feeds first.");
83fe4d6d
AD
327
328 }
329}
330
331function unreadSelectedFeeds() {
332
c0e5a40e 333 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
334 printLockingError();
335 return
336 }
337
83fe4d6d
AD
338 var sel_rows = getSelectedFeeds();
339
340 if (sel_rows.length > 0) {
341
342 notify("Marking selected feeds as unread...");
343
0e091d38 344 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 345 param_escape(sel_rows.toString()), true);
0e091d38 346 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
347 xmlhttp.send(null);
348
349 } else {
350
c753cd32 351 notify("Please select some feeds first.");
83fe4d6d
AD
352
353 }
354}
355
48f0adb0
AD
356function removeSelectedLabels() {
357
358 if (!xmlhttp_ready(xmlhttp)) {
359 printLockingError();
360 return
361 }
362
363 var sel_rows = getSelectedLabels();
364
365 if (sel_rows.length > 0) {
366
367 notify("Removing selected labels...");
368
369 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
370 param_escape(sel_rows.toString()), true);
371 xmlhttp.onreadystatechange=labellist_callback;
372 xmlhttp.send(null);
373
374 } else {
375 notify("Please select some labels first.");
376 }
377}
378
379function removeSelectedFilters() {
380
381 if (!xmlhttp_ready(xmlhttp)) {
382 printLockingError();
383 return
384 }
385
386 var sel_rows = getSelectedFilters();
387
388 if (sel_rows.length > 0) {
389
390 notify("Removing selected filters...");
391
392 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
393 param_escape(sel_rows.toString()), true);
394 xmlhttp.onreadystatechange=filterlist_callback;
395 xmlhttp.send(null);
396
397 } else {
398 notify("Please select some filters first.");
399 }
400}
401
402
83fe4d6d
AD
403function removeSelectedFeeds() {
404
c0e5a40e 405 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
406 printLockingError();
407 return
408 }
409
83fe4d6d
AD
410 var sel_rows = getSelectedFeeds();
411
331900c6
AD
412 if (sel_rows.length > 0) {
413
414 notify("Removing selected feeds...");
415
416 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
417 param_escape(sel_rows.toString()), true);
418 xmlhttp.onreadystatechange=feedlist_callback;
419 xmlhttp.send(null);
71ad3959 420
71ad3959 421 } else {
331900c6 422
c753cd32 423 notify("Please select some feeds first.");
331900c6 424
71ad3959
AD
425 }
426
427}
007bda35 428
508a81e1
AD
429function feedEditCancel() {
430
c0e5a40e 431 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
432 printLockingError();
433 return
434 }
435
961513a3
AD
436 active_feed = false;
437
508a81e1
AD
438 notify("Operation cancelled.");
439
440 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
441 xmlhttp.onreadystatechange=feedlist_callback;
442 xmlhttp.send(null);
443
444}
445
603c27f8
AD
446function feedEditSave() {
447
448 var feed = active_feed;
508a81e1 449
c0e5a40e 450 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
451 printLockingError();
452 return
453 }
454
603c27f8
AD
455 var link = document.getElementById("iedit_link").value;
456 var title = document.getElementById("iedit_title").value;
d148926e 457 var upd_intl = document.getElementById("iedit_updintl").value;
508a81e1 458
603c27f8 459// notify("Saving feed.");
508a81e1 460
d148926e
AD
461 if (upd_intl < 0) {
462 notify("Update interval must be &gt;= 0 (0 = default)");
463 return;
464 }
465
466
508a81e1
AD
467 if (link.length == 0) {
468 notify("Feed link cannot be blank.");
469 return;
470 }
471
472 if (title.length == 0) {
473 notify("Feed title cannot be blank.");
474 return;
475 }
476
603c27f8
AD
477 active_feed = false;
478
508a81e1 479 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
d148926e
AD
480 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) +
481 "&ui=" + param_escape(upd_intl), true);
508a81e1
AD
482 xmlhttp.onreadystatechange=feedlist_callback;
483 xmlhttp.send(null);
484
485}
486
48f0adb0
AD
487function labelEditCancel() {
488
489 if (!xmlhttp_ready(xmlhttp)) {
490 printLockingError();
491 return
492 }
493
494 active_label = false;
495
496 notify("Operation cancelled.");
497
498 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
499 xmlhttp.onreadystatechange=labellist_callback;
500 xmlhttp.send(null);
501
502}
503
504
a0d53889
AD
505function filterEditCancel() {
506
507 if (!xmlhttp_ready(xmlhttp)) {
508 printLockingError();
509 return
510 }
511
512 active_filter = false;
513
514 notify("Operation cancelled.");
515
516 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
517 xmlhttp.onreadystatechange=filterlist_callback;
518 xmlhttp.send(null);
519
520}
521
48f0adb0
AD
522function labelEditSave() {
523
524 var label = active_label;
525
526 if (!xmlhttp_ready(xmlhttp)) {
527 printLockingError();
528 return
529 }
530
531 var sqlexp = document.getElementById("iedit_expr").value;
532 var descr = document.getElementById("iedit_descr").value;
533
534// notify("Saving label " + sqlexp + ": " + descr);
535
536 if (sqlexp.length == 0) {
537 notify("SQL expression cannot be blank.");
538 return;
539 }
540
541 if (descr.length == 0) {
542 notify("Caption cannot be blank.");
543 return;
544 }
545
546 active_label = false;
547
548 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
549 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
550 true);
551
552 xmlhttp.onreadystatechange=labellist_callback;
553 xmlhttp.send(null);
554
555}
556
a0d53889
AD
557function filterEditSave() {
558
559 var filter = active_filter;
560
561 if (!xmlhttp_ready(xmlhttp)) {
562 printLockingError();
563 return
564 }
565
566 var regexp = document.getElementById("iedit_regexp").value;
567 var descr = document.getElementById("iedit_descr").value;
25cb5736
AD
568 var match = document.getElementById("iedit_match");
569
570 var v_match = match[match.selectedIndex].text;
a0d53889
AD
571
572// notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
573
574 if (regexp.length == 0) {
575 notify("Filter expression cannot be blank.");
576 return;
577 }
578
579 active_filter = false;
580
581 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
582 filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
25cb5736 583 "&m=" + param_escape(v_match), true);
a0d53889
AD
584
585 xmlhttp.onreadystatechange=filterlist_callback;
586 xmlhttp.send(null);
587
588}
589
48f0adb0
AD
590function editSelectedLabel() {
591 var rows = getSelectedLabels();
a0d53889 592
48f0adb0
AD
593 if (rows.length == 0) {
594 notify("No labels are selected.");
595 return;
a0d53889
AD
596 }
597
48f0adb0
AD
598 if (rows.length > 1) {
599 notify("Please select one label.");
600 return;
601 }
a0d53889 602
48f0adb0 603 editLabel(rows[0]);
a0d53889 604
a0d53889
AD
605}
606
607
608function editSelectedFilter() {
609 var rows = getSelectedFilters();
610
611 if (rows.length == 0) {
612 notify("No filters are selected.");
613 return;
614 }
615
616 if (rows.length > 1) {
617 notify("Please select one filter.");
618 return;
619 }
620
621 editFilter(rows[0]);
622
623}
624
625
508a81e1
AD
626function editSelectedFeed() {
627 var rows = getSelectedFeeds();
628
629 if (rows.length == 0) {
630 notify("No feeds are selected.");
631 return;
632 }
633
634 if (rows.length > 1) {
635 notify("Please select one feed.");
636 return;
637 }
638
639 editFeed(rows[0]);
640
641}
642
13ad9102
AD
643function localPiggieFunction(enable) {
644 if (enable) {
508a81e1
AD
645 piggie.style.display = "block";
646 seq = "";
647 notify("I loveded it!!!");
648 } else {
649 piggie.style.display = "none";
650 notify("");
651 }
508a81e1
AD
652}
653
9f311df6
AD
654function validateOpmlImport() {
655
656 var opml_file = document.getElementById("opml_file");
657
658 if (opml_file.value.length == 0) {
659 notify("Please select OPML file to upload.");
660 return false;
661 } else {
662 return true;
663 }
664}
665
a0d53889
AD
666function updateFilterList() {
667
668 if (!xmlhttp_ready(xmlhttp)) {
669 printLockingError();
670 return
671 }
672
673 document.getElementById("filterConfPane").innerHTML = "Loading filters, please wait...";
674
675 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
676 xmlhttp.onreadystatechange=filterlist_callback;
677 xmlhttp.send(null);
678
679}
680
48f0adb0
AD
681function updateLabelList() {
682
683 if (!xmlhttp_ready(xmlhttp)) {
684 printLockingError();
685 return
686 }
687
688 document.getElementById("labelConfPane").innerHTML = "Loading labels, please wait...";
689
690 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
691 xmlhttp.onreadystatechange=labellist_callback;
692 xmlhttp.send(null);
693
694}
695
696
a0d53889
AD
697function expandPane(id) {
698
699 var container;
700
a0d53889
AD
701 container = document.getElementById(id);
702
703 if (id == "feedConfPane") {
704 updateFeedList();
705 } else if (id == "filterConfPane") {
706 updateFilterList();
48f0adb0
AD
707 } else if (id == "labelConfPane") {
708 updateLabelList();
a0d53889 709 }
a0d53889
AD
710}
711
007bda35 712function init() {
e2ec66a8
AD
713
714 // IE kludge
715
ad095c16 716 if (!xmlhttp) {
e2ec66a8
AD
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.";
720 return;
721 }
722
a0d53889 723// updateFeedList();
508a81e1 724 document.onkeydown = hotkey_handler;
857a9270
AD
725 notify("");
726
007bda35 727}