]> git.wh0rd.org - tt-rss.git/blob - prefs.js
updated TODO
[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
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
30 function feedlist_callback() {
31 var container = document.getElementById('feedConfPane');
32 if (xmlhttp.readyState == 4) {
33 container.innerHTML=xmlhttp.responseText;
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 }
47 }
48 }
49
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
71 function notify_callback() {
72 var container = document.getElementById('notify');
73 if (xmlhttp.readyState == 4) {
74 container.innerHTML=xmlhttp.responseText;
75 }
76 }
77
78
79 function updateFeedList() {
80
81 if (!xmlhttp_ready(xmlhttp)) {
82 printLockingError();
83 return
84 }
85
86 document.getElementById("feedConfPane").innerHTML = "Loading feeds, please wait...";
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
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&regexp=" +
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 }
133 function addFeed() {
134
135 if (!xmlhttp_ready(xmlhttp)) {
136 printLockingError();
137 return
138 }
139
140 var link = document.getElementById("fadd_link");
141
142 if (link.value.length == 0) {
143 notify("Missing feed URL.");
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
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
174 function editFeed(feed) {
175
176 // notify("Editing feed...");
177
178 if (!xmlhttp_ready(xmlhttp)) {
179 printLockingError();
180 return
181 }
182
183 active_feed = feed;
184
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
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
208 function getSelectedFeeds() {
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
221 return sel_rows;
222 }
223
224 function readSelectedFeeds() {
225
226 if (!xmlhttp_ready(xmlhttp)) {
227 printLockingError();
228 return
229 }
230
231 var sel_rows = getSelectedFeeds();
232
233 if (sel_rows.length > 0) {
234
235 notify("Marking selected feeds as read...");
236
237 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
238 param_escape(sel_rows.toString()), true);
239 xmlhttp.onreadystatechange=notify_callback;
240 xmlhttp.send(null);
241
242 } else {
243
244 notify("Please select some feeds first.");
245
246 }
247 }
248
249 function unreadSelectedFeeds() {
250
251 if (!xmlhttp_ready(xmlhttp)) {
252 printLockingError();
253 return
254 }
255
256 var sel_rows = getSelectedFeeds();
257
258 if (sel_rows.length > 0) {
259
260 notify("Marking selected feeds as unread...");
261
262 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
263 param_escape(sel_rows.toString()), true);
264 xmlhttp.onreadystatechange=notify_callback;
265 xmlhttp.send(null);
266
267 } else {
268
269 notify("Please select some feeds first.");
270
271 }
272 }
273
274 function removeSelectedFeeds() {
275
276 if (!xmlhttp_ready(xmlhttp)) {
277 printLockingError();
278 return
279 }
280
281 var sel_rows = getSelectedFeeds();
282
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);
291
292 } else {
293
294 notify("Please select some feeds first.");
295
296 }
297
298 }
299
300 function feedEditCancel() {
301
302 if (!xmlhttp_ready(xmlhttp)) {
303 printLockingError();
304 return
305 }
306
307 active_feed = false;
308
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
317 function feedEditSave() {
318
319 var feed = active_feed;
320
321 if (!xmlhttp_ready(xmlhttp)) {
322 printLockingError();
323 return
324 }
325
326 var link = document.getElementById("iedit_link").value;
327 var title = document.getElementById("iedit_title").value;
328
329 // notify("Saving feed.");
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
341 active_feed = false;
342
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
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
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
457 function localPiggieFunction(enable) {
458 if (enable) {
459 piggie.style.display = "block";
460 seq = "";
461 notify("I loveded it!!!");
462 } else {
463 piggie.style.display = "none";
464 notify("");
465 }
466 }
467
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
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
499 container = document.getElementById(id);
500
501 if (id == "feedConfPane") {
502 updateFeedList();
503 } else if (id == "filterConfPane") {
504 updateFilterList();
505 }
506 }
507
508 function init() {
509
510 // IE kludge
511
512 if (!xmlhttp) {
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
519 // updateFeedList();
520 document.onkeydown = hotkey_handler;
521 notify("");
522
523 }