]> git.wh0rd.org - tt-rss.git/blame - prefs.js
reworked preferences dialog, start work on post filters (schema updated)
[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
71ad3959
AD
109function addFeed() {
110
c0e5a40e 111 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
112 printLockingError();
113 return
114 }
115
331900c6
AD
116 var link = document.getElementById("fadd_link");
117
83fe4d6d 118 if (link.value.length == 0) {
c753cd32 119 notify("Missing feed URL.");
331900c6
AD
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
a0d53889
AD
134function 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
331900c6
AD
150function editFeed(feed) {
151
508a81e1
AD
152// notify("Editing feed...");
153
c0e5a40e 154 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
155 printLockingError();
156 return
157 }
331900c6 158
961513a3
AD
159 active_feed = feed;
160
331900c6
AD
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
a0d53889
AD
168function 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
83fe4d6d 184function getSelectedFeeds() {
331900c6
AD
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
83fe4d6d
AD
197 return sel_rows;
198}
199
200function readSelectedFeeds() {
201
c0e5a40e 202 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
203 printLockingError();
204 return
205 }
206
83fe4d6d
AD
207 var sel_rows = getSelectedFeeds();
208
209 if (sel_rows.length > 0) {
210
211 notify("Marking selected feeds as read...");
212
0e091d38 213 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 214 param_escape(sel_rows.toString()), true);
0e091d38 215 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
216 xmlhttp.send(null);
217
218 } else {
219
c753cd32 220 notify("Please select some feeds first.");
83fe4d6d
AD
221
222 }
223}
224
225function unreadSelectedFeeds() {
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 unread...");
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 removeSelectedFeeds() {
251
c0e5a40e 252 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
253 printLockingError();
254 return
255 }
256
83fe4d6d
AD
257 var sel_rows = getSelectedFeeds();
258
331900c6
AD
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);
71ad3959 267
71ad3959 268 } else {
331900c6 269
c753cd32 270 notify("Please select some feeds first.");
331900c6 271
71ad3959
AD
272 }
273
274}
007bda35 275
508a81e1
AD
276function feedEditCancel() {
277
c0e5a40e 278 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
279 printLockingError();
280 return
281 }
282
961513a3
AD
283 active_feed = false;
284
508a81e1
AD
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
603c27f8
AD
293function feedEditSave() {
294
295 var feed = active_feed;
508a81e1 296
c0e5a40e 297 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
298 printLockingError();
299 return
300 }
301
603c27f8
AD
302 var link = document.getElementById("iedit_link").value;
303 var title = document.getElementById("iedit_title").value;
508a81e1 304
603c27f8 305// notify("Saving feed.");
508a81e1
AD
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
603c27f8
AD
317 active_feed = false;
318
508a81e1
AD
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
a0d53889
AD
326function 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
343function 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
374function 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
398function 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
508a81e1
AD
416function 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
13ad9102
AD
433function localPiggieFunction(enable) {
434 if (enable) {
508a81e1
AD
435 piggie.style.display = "block";
436 seq = "";
437 notify("I loveded it!!!");
438 } else {
439 piggie.style.display = "none";
440 notify("");
441 }
508a81e1
AD
442}
443
9f311df6
AD
444function 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
a0d53889
AD
456function 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
471function 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
007bda35 492function init() {
e2ec66a8
AD
493
494 // IE kludge
495
ad095c16 496 if (!xmlhttp) {
e2ec66a8
AD
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
a0d53889 503// updateFeedList();
508a81e1 504 document.onkeydown = hotkey_handler;
857a9270
AD
505 notify("");
506
007bda35 507}