]>
Commit | Line | Data |
---|---|---|
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®exp=" + | |
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 | var upd_intl = document.getElementById("iedit_updintl").value; | |
458 | ||
459 | // notify("Saving feed."); | |
460 | ||
461 | if (upd_intl < 0) { | |
462 | notify("Update interval must be >= 0 (0 = default)"); | |
463 | return; | |
464 | } | |
465 | ||
466 | ||
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 | ||
477 | active_feed = false; | |
478 | ||
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; | |
483 | xmlhttp.send(null); | |
484 | ||
485 | } | |
486 | ||
487 | function 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 | ||
505 | function 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 | ||
522 | function 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 | ||
557 | function 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; | |
568 | var match = document.getElementById("iedit_match"); | |
569 | ||
570 | var v_match = match[match.selectedIndex].text; | |
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) + | |
583 | "&m=" + param_escape(v_match), true); | |
584 | ||
585 | xmlhttp.onreadystatechange=filterlist_callback; | |
586 | xmlhttp.send(null); | |
587 | ||
588 | } | |
589 | ||
590 | function editSelectedLabel() { | |
591 | var rows = getSelectedLabels(); | |
592 | ||
593 | if (rows.length == 0) { | |
594 | notify("No labels are selected."); | |
595 | return; | |
596 | } | |
597 | ||
598 | if (rows.length > 1) { | |
599 | notify("Please select one label."); | |
600 | return; | |
601 | } | |
602 | ||
603 | editLabel(rows[0]); | |
604 | ||
605 | } | |
606 | ||
607 | ||
608 | function 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 | ||
626 | function 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 | ||
643 | function localPiggieFunction(enable) { | |
644 | if (enable) { | |
645 | piggie.style.display = "block"; | |
646 | seq = ""; | |
647 | notify("I loveded it!!!"); | |
648 | } else { | |
649 | piggie.style.display = "none"; | |
650 | notify(""); | |
651 | } | |
652 | } | |
653 | ||
654 | function 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 | ||
666 | function 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 | ||
681 | function 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 | ||
697 | function expandPane(id) { | |
698 | ||
699 | var container; | |
700 | ||
701 | container = document.getElementById(id); | |
702 | ||
703 | if (id == "feedConfPane") { | |
704 | updateFeedList(); | |
705 | } else if (id == "filterConfPane") { | |
706 | updateFilterList(); | |
707 | } else if (id == "labelConfPane") { | |
708 | updateLabelList(); | |
709 | } | |
710 | } | |
711 | ||
712 | function init() { | |
713 | ||
714 | // IE kludge | |
715 | ||
716 | if (!xmlhttp) { | |
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 | ||
723 | // updateFeedList(); | |
724 | document.onkeydown = hotkey_handler; | |
725 | notify(""); | |
726 | ||
727 | } |