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