]> git.wh0rd.org - tt-rss.git/blob - prefs.js
patch (from h3) to connect to PGSQL through unix socket
[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 /*@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.
16 try {
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
27 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
28 xmlhttp = new XMLHttpRequest();
29 }
30
31 function feedlist_callback() {
32 var container = document.getElementById('feedConfPane');
33 if (xmlhttp.readyState == 4) {
34 container.innerHTML=xmlhttp.responseText;
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 }
48 }
49 }
50
51 function 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
72 function 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 }
92 function notify_callback() {
93 var container = document.getElementById('notify');
94 if (xmlhttp.readyState == 4) {
95 container.innerHTML=xmlhttp.responseText;
96 }
97 }
98
99
100 function updateFeedList() {
101
102 if (!xmlhttp_ready(xmlhttp)) {
103 printLockingError();
104 return
105 }
106
107 document.getElementById("feedConfPane").innerHTML = "Loading feeds, please wait...";
108
109 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
110 xmlhttp.onreadystatechange=feedlist_callback;
111 xmlhttp.send(null);
112
113 }
114
115 function 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
129 function 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
154 function 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
169 var v_match = match[match.selectedIndex].text;
170
171 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
172 param_escape(regexp.value) + "&match=" + v_match, true);
173
174 xmlhttp.onreadystatechange=filterlist_callback;
175 xmlhttp.send(null);
176
177 regexp.value = "";
178 }
179
180 }
181
182 function addFeed() {
183
184 if (!xmlhttp_ready(xmlhttp)) {
185 printLockingError();
186 return
187 }
188
189 var link = document.getElementById("fadd_link");
190
191 if (link.value.length == 0) {
192 notify("Missing feed URL.");
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
207 function 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
223 function 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
239 function editFeed(feed) {
240
241 // notify("Editing feed...");
242
243 if (!xmlhttp_ready(xmlhttp)) {
244 printLockingError();
245 return
246 }
247
248 active_feed = feed;
249
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
257 function 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
274 function 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
290 function getSelectedFeeds() {
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
303 return sel_rows;
304 }
305
306 function readSelectedFeeds() {
307
308 if (!xmlhttp_ready(xmlhttp)) {
309 printLockingError();
310 return
311 }
312
313 var sel_rows = getSelectedFeeds();
314
315 if (sel_rows.length > 0) {
316
317 notify("Marking selected feeds as read...");
318
319 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
320 param_escape(sel_rows.toString()), true);
321 xmlhttp.onreadystatechange=notify_callback;
322 xmlhttp.send(null);
323
324 } else {
325
326 notify("Please select some feeds first.");
327
328 }
329 }
330
331 function unreadSelectedFeeds() {
332
333 if (!xmlhttp_ready(xmlhttp)) {
334 printLockingError();
335 return
336 }
337
338 var sel_rows = getSelectedFeeds();
339
340 if (sel_rows.length > 0) {
341
342 notify("Marking selected feeds as unread...");
343
344 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
345 param_escape(sel_rows.toString()), true);
346 xmlhttp.onreadystatechange=notify_callback;
347 xmlhttp.send(null);
348
349 } else {
350
351 notify("Please select some feeds first.");
352
353 }
354 }
355
356 function 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
379 function 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
403 function removeSelectedFeeds() {
404
405 if (!xmlhttp_ready(xmlhttp)) {
406 printLockingError();
407 return
408 }
409
410 var sel_rows = getSelectedFeeds();
411
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);
420
421 } else {
422
423 notify("Please select some feeds first.");
424
425 }
426
427 }
428
429 function feedEditCancel() {
430
431 if (!xmlhttp_ready(xmlhttp)) {
432 printLockingError();
433 return
434 }
435
436 active_feed = false;
437
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
446 function feedEditSave() {
447
448 var feed = active_feed;
449
450 if (!xmlhttp_ready(xmlhttp)) {
451 printLockingError();
452 return
453 }
454
455 var link = document.getElementById("iedit_link").value;
456 var title = document.getElementById("iedit_title").value;
457
458 // notify("Saving feed.");
459
460 if (link.length == 0) {
461 notify("Feed link cannot be blank.");
462 return;
463 }
464
465 if (title.length == 0) {
466 notify("Feed title cannot be blank.");
467 return;
468 }
469
470 active_feed = false;
471
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;
475 xmlhttp.send(null);
476
477 }
478
479 function labelEditCancel() {
480
481 if (!xmlhttp_ready(xmlhttp)) {
482 printLockingError();
483 return
484 }
485
486 active_label = false;
487
488 notify("Operation cancelled.");
489
490 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
491 xmlhttp.onreadystatechange=labellist_callback;
492 xmlhttp.send(null);
493
494 }
495
496
497 function filterEditCancel() {
498
499 if (!xmlhttp_ready(xmlhttp)) {
500 printLockingError();
501 return
502 }
503
504 active_filter = false;
505
506 notify("Operation cancelled.");
507
508 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
509 xmlhttp.onreadystatechange=filterlist_callback;
510 xmlhttp.send(null);
511
512 }
513
514 function labelEditSave() {
515
516 var label = active_label;
517
518 if (!xmlhttp_ready(xmlhttp)) {
519 printLockingError();
520 return
521 }
522
523 var sqlexp = document.getElementById("iedit_expr").value;
524 var descr = document.getElementById("iedit_descr").value;
525
526 // notify("Saving label " + sqlexp + ": " + descr);
527
528 if (sqlexp.length == 0) {
529 notify("SQL expression cannot be blank.");
530 return;
531 }
532
533 if (descr.length == 0) {
534 notify("Caption cannot be blank.");
535 return;
536 }
537
538 active_label = false;
539
540 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
541 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
542 true);
543
544 xmlhttp.onreadystatechange=labellist_callback;
545 xmlhttp.send(null);
546
547 }
548
549 function filterEditSave() {
550
551 var filter = active_filter;
552
553 if (!xmlhttp_ready(xmlhttp)) {
554 printLockingError();
555 return
556 }
557
558 var regexp = document.getElementById("iedit_regexp").value;
559 var descr = document.getElementById("iedit_descr").value;
560 var match = document.getElementById("iedit_match");
561
562 var v_match = match[match.selectedIndex].text;
563
564 // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
565
566 if (regexp.length == 0) {
567 notify("Filter expression cannot be blank.");
568 return;
569 }
570
571 active_filter = false;
572
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);
576
577 xmlhttp.onreadystatechange=filterlist_callback;
578 xmlhttp.send(null);
579
580 }
581
582 function editSelectedLabel() {
583 var rows = getSelectedLabels();
584
585 if (rows.length == 0) {
586 notify("No labels are selected.");
587 return;
588 }
589
590 if (rows.length > 1) {
591 notify("Please select one label.");
592 return;
593 }
594
595 editLabel(rows[0]);
596
597 }
598
599
600 function editSelectedFilter() {
601 var rows = getSelectedFilters();
602
603 if (rows.length == 0) {
604 notify("No filters are selected.");
605 return;
606 }
607
608 if (rows.length > 1) {
609 notify("Please select one filter.");
610 return;
611 }
612
613 editFilter(rows[0]);
614
615 }
616
617
618 function editSelectedFeed() {
619 var rows = getSelectedFeeds();
620
621 if (rows.length == 0) {
622 notify("No feeds are selected.");
623 return;
624 }
625
626 if (rows.length > 1) {
627 notify("Please select one feed.");
628 return;
629 }
630
631 editFeed(rows[0]);
632
633 }
634
635 function localPiggieFunction(enable) {
636 if (enable) {
637 piggie.style.display = "block";
638 seq = "";
639 notify("I loveded it!!!");
640 } else {
641 piggie.style.display = "none";
642 notify("");
643 }
644 }
645
646 function validateOpmlImport() {
647
648 var opml_file = document.getElementById("opml_file");
649
650 if (opml_file.value.length == 0) {
651 notify("Please select OPML file to upload.");
652 return false;
653 } else {
654 return true;
655 }
656 }
657
658 function updateFilterList() {
659
660 if (!xmlhttp_ready(xmlhttp)) {
661 printLockingError();
662 return
663 }
664
665 document.getElementById("filterConfPane").innerHTML = "Loading filters, please wait...";
666
667 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
668 xmlhttp.onreadystatechange=filterlist_callback;
669 xmlhttp.send(null);
670
671 }
672
673 function updateLabelList() {
674
675 if (!xmlhttp_ready(xmlhttp)) {
676 printLockingError();
677 return
678 }
679
680 document.getElementById("labelConfPane").innerHTML = "Loading labels, please wait...";
681
682 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
683 xmlhttp.onreadystatechange=labellist_callback;
684 xmlhttp.send(null);
685
686 }
687
688
689 function expandPane(id) {
690
691 var container;
692
693 container = document.getElementById(id);
694
695 if (id == "feedConfPane") {
696 updateFeedList();
697 } else if (id == "filterConfPane") {
698 updateFilterList();
699 } else if (id == "labelConfPane") {
700 updateLabelList();
701 }
702 }
703
704 function init() {
705
706 // IE kludge
707
708 if (!xmlhttp) {
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.";
712 return;
713 }
714
715 // updateFeedList();
716 document.onkeydown = hotkey_handler;
717 notify("");
718
719 }