]>
Commit | Line | Data |
---|---|---|
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 | ||
6 | var xmlhttp = false; | |
7 | ||
961513a3 | 8 | var active_feed = false; |
a0d53889 | 9 | var active_filter = false; |
961513a3 | 10 | |
007bda35 AD |
11 | /*@cc_on @*/ |
12 | /*@if (@_jscript_version >= 5) | |
13 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
14 | // and security blocked creation of the objects. | |
15 | try { | |
16 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
17 | } catch (e) { | |
18 | try { | |
19 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
20 | } catch (E) { | |
21 | xmlhttp = false; | |
22 | } | |
23 | } | |
24 | @end @*/ | |
25 | ||
26 | if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
27 | xmlhttp = new XMLHttpRequest(); | |
28 | } | |
29 | ||
007bda35 | 30 | function feedlist_callback() { |
a0d53889 | 31 | var container = document.getElementById('feedConfPane'); |
007bda35 AD |
32 | if (xmlhttp.readyState == 4) { |
33 | container.innerHTML=xmlhttp.responseText; | |
961513a3 AD |
34 | |
35 | if (active_feed) { | |
36 | var row = document.getElementById("FEEDR-" + active_feed); | |
37 | if (row) { | |
38 | if (!row.className.match("Selected")) { | |
39 | row.className = row.className + "Selected"; | |
40 | } | |
41 | } | |
42 | var checkbox = document.getElementById("FRCHK-" + active_feed); | |
43 | if (checkbox) { | |
44 | checkbox.checked = true; | |
45 | } | |
46 | } | |
007bda35 AD |
47 | } |
48 | } | |
49 | ||
a0d53889 AD |
50 | function filterlist_callback() { |
51 | var container = document.getElementById('filterConfPane'); | |
52 | if (xmlhttp.readyState == 4) { | |
53 | container.innerHTML=xmlhttp.responseText; | |
54 | ||
55 | if (active_filter) { | |
56 | var row = document.getElementById("FILRR-" + active_filter); | |
57 | if (row) { | |
58 | if (!row.className.match("Selected")) { | |
59 | row.className = row.className + "Selected"; | |
60 | } | |
61 | } | |
62 | var checkbox = document.getElementById("FICHK-" + active_filter); | |
63 | ||
64 | if (checkbox) { | |
65 | checkbox.checked = true; | |
66 | } | |
67 | } | |
68 | } | |
69 | } | |
70 | ||
0e091d38 AD |
71 | function notify_callback() { |
72 | var container = document.getElementById('notify'); | |
73 | if (xmlhttp.readyState == 4) { | |
74 | container.innerHTML=xmlhttp.responseText; | |
75 | } | |
76 | } | |
77 | ||
175847de | 78 | |
0e091d38 | 79 | function updateFeedList() { |
007bda35 | 80 | |
c0e5a40e | 81 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
82 | printLockingError(); |
83 | return | |
84 | } | |
85 | ||
a0d53889 | 86 | document.getElementById("feedConfPane").innerHTML = "Loading feeds, please wait..."; |
007bda35 AD |
87 | |
88 | xmlhttp.open("GET", "backend.php?op=pref-feeds", true); | |
89 | xmlhttp.onreadystatechange=feedlist_callback; | |
90 | xmlhttp.send(null); | |
91 | ||
92 | } | |
93 | ||
94 | function toggleSelectRow(sender) { | |
95 | var parent_row = sender.parentNode.parentNode; | |
96 | ||
97 | if (sender.checked) { | |
98 | if (!parent_row.className.match("Selected")) { | |
99 | parent_row.className = parent_row.className + "Selected"; | |
100 | } | |
101 | } else { | |
102 | if (parent_row.className.match("Selected")) { | |
103 | parent_row.className = parent_row.className.replace("Selected", ""); | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
de435974 AD |
108 | function addFilter() { |
109 | ||
110 | if (!xmlhttp_ready(xmlhttp)) { | |
111 | printLockingError(); | |
112 | return | |
113 | } | |
114 | ||
115 | var regexp = document.getElementById("fadd_regexp"); | |
116 | var match = document.getElementById("fadd_match"); | |
117 | ||
118 | if (regexp.value.length == 0) { | |
119 | notify("Missing filter expression."); | |
120 | } else { | |
121 | notify("Adding filter..."); | |
122 | ||
25cb5736 AD |
123 | var v_match = match[match.selectedIndex].text; |
124 | ||
de435974 | 125 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add®exp=" + |
25cb5736 | 126 | param_escape(regexp.value) + "&match=" + v_match, true); |
de435974 AD |
127 | |
128 | xmlhttp.onreadystatechange=filterlist_callback; | |
129 | xmlhttp.send(null); | |
130 | ||
131 | regexp.value = ""; | |
132 | } | |
133 | ||
134 | } | |
71ad3959 AD |
135 | function addFeed() { |
136 | ||
c0e5a40e | 137 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
138 | printLockingError(); |
139 | return | |
140 | } | |
141 | ||
331900c6 AD |
142 | var link = document.getElementById("fadd_link"); |
143 | ||
83fe4d6d | 144 | if (link.value.length == 0) { |
c753cd32 | 145 | notify("Missing feed URL."); |
331900c6 AD |
146 | } else { |
147 | notify("Adding feed..."); | |
148 | ||
149 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" + | |
150 | param_escape(link.value), true); | |
151 | xmlhttp.onreadystatechange=feedlist_callback; | |
152 | xmlhttp.send(null); | |
153 | ||
154 | link.value = ""; | |
155 | ||
156 | } | |
157 | ||
158 | } | |
159 | ||
a0d53889 AD |
160 | function editFilter(id) { |
161 | ||
162 | if (!xmlhttp_ready(xmlhttp)) { | |
163 | printLockingError(); | |
164 | return | |
165 | } | |
166 | ||
167 | active_filter = id; | |
168 | ||
169 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + | |
170 | param_escape(id), true); | |
171 | xmlhttp.onreadystatechange=filterlist_callback; | |
172 | xmlhttp.send(null); | |
173 | ||
174 | } | |
175 | ||
331900c6 AD |
176 | function editFeed(feed) { |
177 | ||
508a81e1 AD |
178 | // notify("Editing feed..."); |
179 | ||
c0e5a40e | 180 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
181 | printLockingError(); |
182 | return | |
183 | } | |
331900c6 | 184 | |
961513a3 AD |
185 | active_feed = feed; |
186 | ||
331900c6 AD |
187 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" + |
188 | param_escape(feed), true); | |
189 | xmlhttp.onreadystatechange=feedlist_callback; | |
190 | xmlhttp.send(null); | |
191 | ||
192 | } | |
193 | ||
a0d53889 AD |
194 | function getSelectedFilters() { |
195 | ||
196 | var content = document.getElementById("prefFilterList"); | |
197 | ||
198 | var sel_rows = new Array(); | |
199 | ||
200 | for (i = 0; i < content.rows.length; i++) { | |
201 | if (content.rows[i].className.match("Selected")) { | |
202 | var row_id = content.rows[i].id.replace("FILRR-", ""); | |
203 | sel_rows.push(row_id); | |
204 | } | |
205 | } | |
206 | ||
207 | return sel_rows; | |
208 | } | |
209 | ||
83fe4d6d | 210 | function getSelectedFeeds() { |
331900c6 AD |
211 | |
212 | var content = document.getElementById("prefFeedList"); | |
213 | ||
214 | var sel_rows = new Array(); | |
215 | ||
216 | for (i = 0; i < content.rows.length; i++) { | |
217 | if (content.rows[i].className.match("Selected")) { | |
218 | var row_id = content.rows[i].id.replace("FEEDR-", ""); | |
219 | sel_rows.push(row_id); | |
220 | } | |
221 | } | |
222 | ||
83fe4d6d AD |
223 | return sel_rows; |
224 | } | |
225 | ||
226 | function readSelectedFeeds() { | |
227 | ||
c0e5a40e | 228 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
229 | printLockingError(); |
230 | return | |
231 | } | |
232 | ||
83fe4d6d AD |
233 | var sel_rows = getSelectedFeeds(); |
234 | ||
235 | if (sel_rows.length > 0) { | |
236 | ||
237 | notify("Marking selected feeds as read..."); | |
238 | ||
0e091d38 | 239 | xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+ |
83fe4d6d | 240 | param_escape(sel_rows.toString()), true); |
0e091d38 | 241 | xmlhttp.onreadystatechange=notify_callback; |
83fe4d6d AD |
242 | xmlhttp.send(null); |
243 | ||
244 | } else { | |
245 | ||
c753cd32 | 246 | notify("Please select some feeds first."); |
83fe4d6d AD |
247 | |
248 | } | |
249 | } | |
250 | ||
251 | function unreadSelectedFeeds() { | |
252 | ||
c0e5a40e | 253 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
254 | printLockingError(); |
255 | return | |
256 | } | |
257 | ||
83fe4d6d AD |
258 | var sel_rows = getSelectedFeeds(); |
259 | ||
260 | if (sel_rows.length > 0) { | |
261 | ||
262 | notify("Marking selected feeds as unread..."); | |
263 | ||
0e091d38 | 264 | xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+ |
83fe4d6d | 265 | param_escape(sel_rows.toString()), true); |
0e091d38 | 266 | xmlhttp.onreadystatechange=notify_callback; |
83fe4d6d AD |
267 | xmlhttp.send(null); |
268 | ||
269 | } else { | |
270 | ||
c753cd32 | 271 | notify("Please select some feeds first."); |
83fe4d6d AD |
272 | |
273 | } | |
274 | } | |
275 | ||
276 | function removeSelectedFeeds() { | |
277 | ||
c0e5a40e | 278 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
279 | printLockingError(); |
280 | return | |
281 | } | |
282 | ||
83fe4d6d AD |
283 | var sel_rows = getSelectedFeeds(); |
284 | ||
331900c6 AD |
285 | if (sel_rows.length > 0) { |
286 | ||
287 | notify("Removing selected feeds..."); | |
288 | ||
289 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+ | |
290 | param_escape(sel_rows.toString()), true); | |
291 | xmlhttp.onreadystatechange=feedlist_callback; | |
292 | xmlhttp.send(null); | |
71ad3959 | 293 | |
71ad3959 | 294 | } else { |
331900c6 | 295 | |
c753cd32 | 296 | notify("Please select some feeds first."); |
331900c6 | 297 | |
71ad3959 AD |
298 | } |
299 | ||
300 | } | |
007bda35 | 301 | |
508a81e1 AD |
302 | function feedEditCancel() { |
303 | ||
c0e5a40e | 304 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
305 | printLockingError(); |
306 | return | |
307 | } | |
308 | ||
961513a3 AD |
309 | active_feed = false; |
310 | ||
508a81e1 AD |
311 | notify("Operation cancelled."); |
312 | ||
313 | xmlhttp.open("GET", "backend.php?op=pref-feeds", true); | |
314 | xmlhttp.onreadystatechange=feedlist_callback; | |
315 | xmlhttp.send(null); | |
316 | ||
317 | } | |
318 | ||
603c27f8 AD |
319 | function feedEditSave() { |
320 | ||
321 | var feed = active_feed; | |
508a81e1 | 322 | |
c0e5a40e | 323 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
324 | printLockingError(); |
325 | return | |
326 | } | |
327 | ||
603c27f8 AD |
328 | var link = document.getElementById("iedit_link").value; |
329 | var title = document.getElementById("iedit_title").value; | |
508a81e1 | 330 | |
603c27f8 | 331 | // notify("Saving feed."); |
508a81e1 AD |
332 | |
333 | if (link.length == 0) { | |
334 | notify("Feed link cannot be blank."); | |
335 | return; | |
336 | } | |
337 | ||
338 | if (title.length == 0) { | |
339 | notify("Feed title cannot be blank."); | |
340 | return; | |
341 | } | |
342 | ||
603c27f8 AD |
343 | active_feed = false; |
344 | ||
508a81e1 AD |
345 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" + |
346 | feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) ,true); | |
347 | xmlhttp.onreadystatechange=feedlist_callback; | |
348 | xmlhttp.send(null); | |
349 | ||
350 | } | |
351 | ||
a0d53889 AD |
352 | function filterEditCancel() { |
353 | ||
354 | if (!xmlhttp_ready(xmlhttp)) { | |
355 | printLockingError(); | |
356 | return | |
357 | } | |
358 | ||
359 | active_filter = false; | |
360 | ||
361 | notify("Operation cancelled."); | |
362 | ||
363 | xmlhttp.open("GET", "backend.php?op=pref-filters", true); | |
364 | xmlhttp.onreadystatechange=filterlist_callback; | |
365 | xmlhttp.send(null); | |
366 | ||
367 | } | |
368 | ||
369 | function filterEditSave() { | |
370 | ||
371 | var filter = active_filter; | |
372 | ||
373 | if (!xmlhttp_ready(xmlhttp)) { | |
374 | printLockingError(); | |
375 | return | |
376 | } | |
377 | ||
378 | var regexp = document.getElementById("iedit_regexp").value; | |
379 | var descr = document.getElementById("iedit_descr").value; | |
25cb5736 AD |
380 | var match = document.getElementById("iedit_match"); |
381 | ||
382 | var v_match = match[match.selectedIndex].text; | |
a0d53889 AD |
383 | |
384 | // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match); | |
385 | ||
386 | if (regexp.length == 0) { | |
387 | notify("Filter expression cannot be blank."); | |
388 | return; | |
389 | } | |
390 | ||
391 | active_filter = false; | |
392 | ||
393 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" + | |
394 | filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) + | |
25cb5736 | 395 | "&m=" + param_escape(v_match), true); |
a0d53889 AD |
396 | |
397 | xmlhttp.onreadystatechange=filterlist_callback; | |
398 | xmlhttp.send(null); | |
399 | ||
400 | } | |
401 | ||
402 | function removeSelectedFilters() { | |
403 | ||
404 | if (!xmlhttp_ready(xmlhttp)) { | |
405 | printLockingError(); | |
406 | return | |
407 | } | |
408 | ||
409 | var sel_rows = getSelectedFilters(); | |
410 | ||
411 | if (sel_rows.length > 0) { | |
412 | ||
413 | notify("Removing selected filters..."); | |
414 | ||
415 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+ | |
416 | param_escape(sel_rows.toString()), true); | |
417 | xmlhttp.onreadystatechange=filterlist_callback; | |
418 | xmlhttp.send(null); | |
419 | ||
420 | } else { | |
421 | notify("Please select some filters first."); | |
422 | } | |
423 | } | |
424 | ||
425 | ||
426 | function editSelectedFilter() { | |
427 | var rows = getSelectedFilters(); | |
428 | ||
429 | if (rows.length == 0) { | |
430 | notify("No filters are selected."); | |
431 | return; | |
432 | } | |
433 | ||
434 | if (rows.length > 1) { | |
435 | notify("Please select one filter."); | |
436 | return; | |
437 | } | |
438 | ||
439 | editFilter(rows[0]); | |
440 | ||
441 | } | |
442 | ||
443 | ||
508a81e1 AD |
444 | function editSelectedFeed() { |
445 | var rows = getSelectedFeeds(); | |
446 | ||
447 | if (rows.length == 0) { | |
448 | notify("No feeds are selected."); | |
449 | return; | |
450 | } | |
451 | ||
452 | if (rows.length > 1) { | |
453 | notify("Please select one feed."); | |
454 | return; | |
455 | } | |
456 | ||
457 | editFeed(rows[0]); | |
458 | ||
459 | } | |
460 | ||
13ad9102 AD |
461 | function localPiggieFunction(enable) { |
462 | if (enable) { | |
508a81e1 AD |
463 | piggie.style.display = "block"; |
464 | seq = ""; | |
465 | notify("I loveded it!!!"); | |
466 | } else { | |
467 | piggie.style.display = "none"; | |
468 | notify(""); | |
469 | } | |
508a81e1 AD |
470 | } |
471 | ||
9f311df6 AD |
472 | function validateOpmlImport() { |
473 | ||
474 | var opml_file = document.getElementById("opml_file"); | |
475 | ||
476 | if (opml_file.value.length == 0) { | |
477 | notify("Please select OPML file to upload."); | |
478 | return false; | |
479 | } else { | |
480 | return true; | |
481 | } | |
482 | } | |
483 | ||
a0d53889 AD |
484 | function updateFilterList() { |
485 | ||
486 | if (!xmlhttp_ready(xmlhttp)) { | |
487 | printLockingError(); | |
488 | return | |
489 | } | |
490 | ||
491 | document.getElementById("filterConfPane").innerHTML = "Loading filters, please wait..."; | |
492 | ||
493 | xmlhttp.open("GET", "backend.php?op=pref-filters", true); | |
494 | xmlhttp.onreadystatechange=filterlist_callback; | |
495 | xmlhttp.send(null); | |
496 | ||
497 | } | |
498 | ||
499 | function expandPane(id) { | |
500 | ||
501 | var container; | |
502 | ||
a0d53889 AD |
503 | container = document.getElementById(id); |
504 | ||
505 | if (id == "feedConfPane") { | |
506 | updateFeedList(); | |
507 | } else if (id == "filterConfPane") { | |
508 | updateFilterList(); | |
509 | } | |
a0d53889 AD |
510 | } |
511 | ||
007bda35 | 512 | function init() { |
e2ec66a8 AD |
513 | |
514 | // IE kludge | |
515 | ||
ad095c16 | 516 | if (!xmlhttp) { |
e2ec66a8 AD |
517 | document.getElementById("prefContent").innerHTML = |
518 | "<b>Fatal error:</b> This program needs XmlHttpRequest " + | |
519 | "to function properly. Your browser doesn't seem to support it."; | |
520 | return; | |
521 | } | |
522 | ||
a0d53889 | 523 | // updateFeedList(); |
508a81e1 | 524 | document.onkeydown = hotkey_handler; |
857a9270 AD |
525 | notify(""); |
526 | ||
007bda35 | 527 | } |