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