]>
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 | ||
123 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add®exp=" + | |
124 | param_escape(regexp.value) + "&match=" + match.value, true); | |
125 | ||
126 | xmlhttp.onreadystatechange=filterlist_callback; | |
127 | xmlhttp.send(null); | |
128 | ||
129 | regexp.value = ""; | |
130 | } | |
131 | ||
132 | } | |
71ad3959 AD |
133 | function addFeed() { |
134 | ||
c0e5a40e | 135 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
136 | printLockingError(); |
137 | return | |
138 | } | |
139 | ||
331900c6 AD |
140 | var link = document.getElementById("fadd_link"); |
141 | ||
83fe4d6d | 142 | if (link.value.length == 0) { |
c753cd32 | 143 | notify("Missing feed URL."); |
331900c6 AD |
144 | } else { |
145 | notify("Adding feed..."); | |
146 | ||
147 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" + | |
148 | param_escape(link.value), true); | |
149 | xmlhttp.onreadystatechange=feedlist_callback; | |
150 | xmlhttp.send(null); | |
151 | ||
152 | link.value = ""; | |
153 | ||
154 | } | |
155 | ||
156 | } | |
157 | ||
a0d53889 AD |
158 | function editFilter(id) { |
159 | ||
160 | if (!xmlhttp_ready(xmlhttp)) { | |
161 | printLockingError(); | |
162 | return | |
163 | } | |
164 | ||
165 | active_filter = id; | |
166 | ||
167 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + | |
168 | param_escape(id), true); | |
169 | xmlhttp.onreadystatechange=filterlist_callback; | |
170 | xmlhttp.send(null); | |
171 | ||
172 | } | |
173 | ||
331900c6 AD |
174 | function editFeed(feed) { |
175 | ||
508a81e1 AD |
176 | // notify("Editing feed..."); |
177 | ||
c0e5a40e | 178 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
179 | printLockingError(); |
180 | return | |
181 | } | |
331900c6 | 182 | |
961513a3 AD |
183 | active_feed = feed; |
184 | ||
331900c6 AD |
185 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" + |
186 | param_escape(feed), true); | |
187 | xmlhttp.onreadystatechange=feedlist_callback; | |
188 | xmlhttp.send(null); | |
189 | ||
190 | } | |
191 | ||
a0d53889 AD |
192 | function getSelectedFilters() { |
193 | ||
194 | var content = document.getElementById("prefFilterList"); | |
195 | ||
196 | var sel_rows = new Array(); | |
197 | ||
198 | for (i = 0; i < content.rows.length; i++) { | |
199 | if (content.rows[i].className.match("Selected")) { | |
200 | var row_id = content.rows[i].id.replace("FILRR-", ""); | |
201 | sel_rows.push(row_id); | |
202 | } | |
203 | } | |
204 | ||
205 | return sel_rows; | |
206 | } | |
207 | ||
83fe4d6d | 208 | function getSelectedFeeds() { |
331900c6 AD |
209 | |
210 | var content = document.getElementById("prefFeedList"); | |
211 | ||
212 | var sel_rows = new Array(); | |
213 | ||
214 | for (i = 0; i < content.rows.length; i++) { | |
215 | if (content.rows[i].className.match("Selected")) { | |
216 | var row_id = content.rows[i].id.replace("FEEDR-", ""); | |
217 | sel_rows.push(row_id); | |
218 | } | |
219 | } | |
220 | ||
83fe4d6d AD |
221 | return sel_rows; |
222 | } | |
223 | ||
224 | function readSelectedFeeds() { | |
225 | ||
c0e5a40e | 226 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
227 | printLockingError(); |
228 | return | |
229 | } | |
230 | ||
83fe4d6d AD |
231 | var sel_rows = getSelectedFeeds(); |
232 | ||
233 | if (sel_rows.length > 0) { | |
234 | ||
235 | notify("Marking selected feeds as read..."); | |
236 | ||
0e091d38 | 237 | xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+ |
83fe4d6d | 238 | param_escape(sel_rows.toString()), true); |
0e091d38 | 239 | xmlhttp.onreadystatechange=notify_callback; |
83fe4d6d AD |
240 | xmlhttp.send(null); |
241 | ||
242 | } else { | |
243 | ||
c753cd32 | 244 | notify("Please select some feeds first."); |
83fe4d6d AD |
245 | |
246 | } | |
247 | } | |
248 | ||
249 | function unreadSelectedFeeds() { | |
250 | ||
c0e5a40e | 251 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
252 | printLockingError(); |
253 | return | |
254 | } | |
255 | ||
83fe4d6d AD |
256 | var sel_rows = getSelectedFeeds(); |
257 | ||
258 | if (sel_rows.length > 0) { | |
259 | ||
260 | notify("Marking selected feeds as unread..."); | |
261 | ||
0e091d38 | 262 | xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+ |
83fe4d6d | 263 | param_escape(sel_rows.toString()), true); |
0e091d38 | 264 | xmlhttp.onreadystatechange=notify_callback; |
83fe4d6d AD |
265 | xmlhttp.send(null); |
266 | ||
267 | } else { | |
268 | ||
c753cd32 | 269 | notify("Please select some feeds first."); |
83fe4d6d AD |
270 | |
271 | } | |
272 | } | |
273 | ||
274 | function removeSelectedFeeds() { | |
275 | ||
c0e5a40e | 276 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
277 | printLockingError(); |
278 | return | |
279 | } | |
280 | ||
83fe4d6d AD |
281 | var sel_rows = getSelectedFeeds(); |
282 | ||
331900c6 AD |
283 | if (sel_rows.length > 0) { |
284 | ||
285 | notify("Removing selected feeds..."); | |
286 | ||
287 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+ | |
288 | param_escape(sel_rows.toString()), true); | |
289 | xmlhttp.onreadystatechange=feedlist_callback; | |
290 | xmlhttp.send(null); | |
71ad3959 | 291 | |
71ad3959 | 292 | } else { |
331900c6 | 293 | |
c753cd32 | 294 | notify("Please select some feeds first."); |
331900c6 | 295 | |
71ad3959 AD |
296 | } |
297 | ||
298 | } | |
007bda35 | 299 | |
508a81e1 AD |
300 | function feedEditCancel() { |
301 | ||
c0e5a40e | 302 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
303 | printLockingError(); |
304 | return | |
305 | } | |
306 | ||
961513a3 AD |
307 | active_feed = false; |
308 | ||
508a81e1 AD |
309 | notify("Operation cancelled."); |
310 | ||
311 | xmlhttp.open("GET", "backend.php?op=pref-feeds", true); | |
312 | xmlhttp.onreadystatechange=feedlist_callback; | |
313 | xmlhttp.send(null); | |
314 | ||
315 | } | |
316 | ||
603c27f8 AD |
317 | function feedEditSave() { |
318 | ||
319 | var feed = active_feed; | |
508a81e1 | 320 | |
c0e5a40e | 321 | if (!xmlhttp_ready(xmlhttp)) { |
508a81e1 AD |
322 | printLockingError(); |
323 | return | |
324 | } | |
325 | ||
603c27f8 AD |
326 | var link = document.getElementById("iedit_link").value; |
327 | var title = document.getElementById("iedit_title").value; | |
508a81e1 | 328 | |
603c27f8 | 329 | // notify("Saving feed."); |
508a81e1 AD |
330 | |
331 | if (link.length == 0) { | |
332 | notify("Feed link cannot be blank."); | |
333 | return; | |
334 | } | |
335 | ||
336 | if (title.length == 0) { | |
337 | notify("Feed title cannot be blank."); | |
338 | return; | |
339 | } | |
340 | ||
603c27f8 AD |
341 | active_feed = false; |
342 | ||
508a81e1 AD |
343 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" + |
344 | feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) ,true); | |
345 | xmlhttp.onreadystatechange=feedlist_callback; | |
346 | xmlhttp.send(null); | |
347 | ||
348 | } | |
349 | ||
a0d53889 AD |
350 | function filterEditCancel() { |
351 | ||
352 | if (!xmlhttp_ready(xmlhttp)) { | |
353 | printLockingError(); | |
354 | return | |
355 | } | |
356 | ||
357 | active_filter = false; | |
358 | ||
359 | notify("Operation cancelled."); | |
360 | ||
361 | xmlhttp.open("GET", "backend.php?op=pref-filters", true); | |
362 | xmlhttp.onreadystatechange=filterlist_callback; | |
363 | xmlhttp.send(null); | |
364 | ||
365 | } | |
366 | ||
367 | function filterEditSave() { | |
368 | ||
369 | var filter = active_filter; | |
370 | ||
371 | if (!xmlhttp_ready(xmlhttp)) { | |
372 | printLockingError(); | |
373 | return | |
374 | } | |
375 | ||
376 | var regexp = document.getElementById("iedit_regexp").value; | |
377 | var descr = document.getElementById("iedit_descr").value; | |
378 | var match = document.getElementById("iedit_match").value; | |
379 | ||
380 | // notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match); | |
381 | ||
382 | if (regexp.length == 0) { | |
383 | notify("Filter expression cannot be blank."); | |
384 | return; | |
385 | } | |
386 | ||
387 | active_filter = false; | |
388 | ||
389 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" + | |
390 | filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) + | |
391 | "&m=" + param_escape(match), true); | |
392 | ||
393 | xmlhttp.onreadystatechange=filterlist_callback; | |
394 | xmlhttp.send(null); | |
395 | ||
396 | } | |
397 | ||
398 | function removeSelectedFilters() { | |
399 | ||
400 | if (!xmlhttp_ready(xmlhttp)) { | |
401 | printLockingError(); | |
402 | return | |
403 | } | |
404 | ||
405 | var sel_rows = getSelectedFilters(); | |
406 | ||
407 | if (sel_rows.length > 0) { | |
408 | ||
409 | notify("Removing selected filters..."); | |
410 | ||
411 | xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+ | |
412 | param_escape(sel_rows.toString()), true); | |
413 | xmlhttp.onreadystatechange=filterlist_callback; | |
414 | xmlhttp.send(null); | |
415 | ||
416 | } else { | |
417 | notify("Please select some filters first."); | |
418 | } | |
419 | } | |
420 | ||
421 | ||
422 | function editSelectedFilter() { | |
423 | var rows = getSelectedFilters(); | |
424 | ||
425 | if (rows.length == 0) { | |
426 | notify("No filters are selected."); | |
427 | return; | |
428 | } | |
429 | ||
430 | if (rows.length > 1) { | |
431 | notify("Please select one filter."); | |
432 | return; | |
433 | } | |
434 | ||
435 | editFilter(rows[0]); | |
436 | ||
437 | } | |
438 | ||
439 | ||
508a81e1 AD |
440 | function editSelectedFeed() { |
441 | var rows = getSelectedFeeds(); | |
442 | ||
443 | if (rows.length == 0) { | |
444 | notify("No feeds are selected."); | |
445 | return; | |
446 | } | |
447 | ||
448 | if (rows.length > 1) { | |
449 | notify("Please select one feed."); | |
450 | return; | |
451 | } | |
452 | ||
453 | editFeed(rows[0]); | |
454 | ||
455 | } | |
456 | ||
13ad9102 AD |
457 | function localPiggieFunction(enable) { |
458 | if (enable) { | |
508a81e1 AD |
459 | piggie.style.display = "block"; |
460 | seq = ""; | |
461 | notify("I loveded it!!!"); | |
462 | } else { | |
463 | piggie.style.display = "none"; | |
464 | notify(""); | |
465 | } | |
508a81e1 AD |
466 | } |
467 | ||
9f311df6 AD |
468 | function validateOpmlImport() { |
469 | ||
470 | var opml_file = document.getElementById("opml_file"); | |
471 | ||
472 | if (opml_file.value.length == 0) { | |
473 | notify("Please select OPML file to upload."); | |
474 | return false; | |
475 | } else { | |
476 | return true; | |
477 | } | |
478 | } | |
479 | ||
a0d53889 AD |
480 | function updateFilterList() { |
481 | ||
482 | if (!xmlhttp_ready(xmlhttp)) { | |
483 | printLockingError(); | |
484 | return | |
485 | } | |
486 | ||
487 | document.getElementById("filterConfPane").innerHTML = "Loading filters, please wait..."; | |
488 | ||
489 | xmlhttp.open("GET", "backend.php?op=pref-filters", true); | |
490 | xmlhttp.onreadystatechange=filterlist_callback; | |
491 | xmlhttp.send(null); | |
492 | ||
493 | } | |
494 | ||
495 | function expandPane(id) { | |
496 | ||
497 | var container; | |
498 | ||
a0d53889 AD |
499 | container = document.getElementById(id); |
500 | ||
501 | if (id == "feedConfPane") { | |
502 | updateFeedList(); | |
503 | } else if (id == "filterConfPane") { | |
504 | updateFilterList(); | |
505 | } | |
a0d53889 AD |
506 | } |
507 | ||
007bda35 | 508 | function init() { |
e2ec66a8 AD |
509 | |
510 | // IE kludge | |
511 | ||
ad095c16 | 512 | if (!xmlhttp) { |
e2ec66a8 AD |
513 | document.getElementById("prefContent").innerHTML = |
514 | "<b>Fatal error:</b> This program needs XmlHttpRequest " + | |
515 | "to function properly. Your browser doesn't seem to support it."; | |
516 | return; | |
517 | } | |
518 | ||
a0d53889 | 519 | // updateFeedList(); |
508a81e1 | 520 | document.onkeydown = hotkey_handler; |
857a9270 AD |
521 | notify(""); |
522 | ||
007bda35 | 523 | } |