]> git.wh0rd.org - tt-rss.git/blame - prefs.js
more work on tag support
[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 9var active_filter = false;
48f0adb0 10var active_label = 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
48f0adb0
AD
72function labellist_callback() {
73 var container = document.getElementById('labelConfPane');
74 if (xmlhttp.readyState == 4) {
75 container.innerHTML=xmlhttp.responseText;
76
77 if (active_filter) {
78 var row = document.getElementById("LILRR-" + active_label);
79 if (row) {
80 if (!row.className.match("Selected")) {
81 row.className = row.className + "Selected";
82 }
83 }
84 var checkbox = document.getElementById("LICHK-" + active_label);
85
86 if (checkbox) {
87 checkbox.checked = true;
88 }
89 }
90 }
91}
0e091d38
AD
92function notify_callback() {
93 var container = document.getElementById('notify');
94 if (xmlhttp.readyState == 4) {
95 container.innerHTML=xmlhttp.responseText;
96 }
97}
98
175847de 99
0e091d38 100function updateFeedList() {
007bda35 101
c0e5a40e 102 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
103 printLockingError();
104 return
105 }
106
a0d53889 107 document.getElementById("feedConfPane").innerHTML = "Loading feeds, please wait...";
007bda35
AD
108
109 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
110 xmlhttp.onreadystatechange=feedlist_callback;
111 xmlhttp.send(null);
112
113}
114
115function toggleSelectRow(sender) {
116 var parent_row = sender.parentNode.parentNode;
117
118 if (sender.checked) {
119 if (!parent_row.className.match("Selected")) {
120 parent_row.className = parent_row.className + "Selected";
121 }
122 } else {
123 if (parent_row.className.match("Selected")) {
124 parent_row.className = parent_row.className.replace("Selected", "");
125 }
126 }
127}
128
48f0adb0
AD
129function addLabel() {
130
131 if (!xmlhttp_ready(xmlhttp)) {
132 printLockingError();
133 return
134 }
135
136 var sqlexp = document.getElementById("ladd_expr");
137
138 if (sqlexp.value.length == 0) {
139 notify("Missing SQL expression.");
140 } else {
141 notify("Adding label...");
142
143 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
144 param_escape(sqlexp.value), true);
145
146 xmlhttp.onreadystatechange=labellist_callback;
147 xmlhttp.send(null);
148
149 sqlexp.value = "";
150 }
151
152}
153
de435974
AD
154function addFilter() {
155
156 if (!xmlhttp_ready(xmlhttp)) {
157 printLockingError();
158 return
159 }
160
161 var regexp = document.getElementById("fadd_regexp");
162 var match = document.getElementById("fadd_match");
163
164 if (regexp.value.length == 0) {
165 notify("Missing filter expression.");
166 } else {
167 notify("Adding filter...");
168
25cb5736
AD
169 var v_match = match[match.selectedIndex].text;
170
de435974 171 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
25cb5736 172 param_escape(regexp.value) + "&match=" + v_match, true);
de435974
AD
173
174 xmlhttp.onreadystatechange=filterlist_callback;
175 xmlhttp.send(null);
176
177 regexp.value = "";
178 }
179
180}
48f0adb0 181
71ad3959
AD
182function addFeed() {
183
c0e5a40e 184 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
185 printLockingError();
186 return
187 }
188
331900c6
AD
189 var link = document.getElementById("fadd_link");
190
83fe4d6d 191 if (link.value.length == 0) {
c753cd32 192 notify("Missing feed URL.");
331900c6
AD
193 } else {
194 notify("Adding feed...");
195
196 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
197 param_escape(link.value), true);
198 xmlhttp.onreadystatechange=feedlist_callback;
199 xmlhttp.send(null);
200
201 link.value = "";
202
203 }
204
205}
206
48f0adb0
AD
207function editLabel(id) {
208
209 if (!xmlhttp_ready(xmlhttp)) {
210 printLockingError();
211 return
212 }
213
214 active_label = id;
215
216 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
217 param_escape(id), true);
218 xmlhttp.onreadystatechange=labellist_callback;
219 xmlhttp.send(null);
220
221}
222
a0d53889
AD
223function editFilter(id) {
224
225 if (!xmlhttp_ready(xmlhttp)) {
226 printLockingError();
227 return
228 }
229
230 active_filter = id;
231
232 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
233 param_escape(id), true);
234 xmlhttp.onreadystatechange=filterlist_callback;
235 xmlhttp.send(null);
236
237}
238
331900c6
AD
239function editFeed(feed) {
240
508a81e1
AD
241// notify("Editing feed...");
242
c0e5a40e 243 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
244 printLockingError();
245 return
246 }
331900c6 247
961513a3
AD
248 active_feed = feed;
249
331900c6
AD
250 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
251 param_escape(feed), true);
252 xmlhttp.onreadystatechange=feedlist_callback;
253 xmlhttp.send(null);
254
255}
256
48f0adb0
AD
257function getSelectedLabels() {
258
259 var content = document.getElementById("prefLabelList");
260
261 var sel_rows = new Array();
262
263 for (i = 0; i < content.rows.length; i++) {
264 if (content.rows[i].className.match("Selected")) {
265 var row_id = content.rows[i].id.replace("LILRR-", "");
266 sel_rows.push(row_id);
267 }
268 }
269
270 return sel_rows;
271}
272
273
a0d53889
AD
274function getSelectedFilters() {
275
276 var content = document.getElementById("prefFilterList");
277
278 var sel_rows = new Array();
279
280 for (i = 0; i < content.rows.length; i++) {
281 if (content.rows[i].className.match("Selected")) {
282 var row_id = content.rows[i].id.replace("FILRR-", "");
283 sel_rows.push(row_id);
284 }
285 }
286
287 return sel_rows;
288}
289
83fe4d6d 290function getSelectedFeeds() {
331900c6
AD
291
292 var content = document.getElementById("prefFeedList");
293
294 var sel_rows = new Array();
295
296 for (i = 0; i < content.rows.length; i++) {
297 if (content.rows[i].className.match("Selected")) {
298 var row_id = content.rows[i].id.replace("FEEDR-", "");
299 sel_rows.push(row_id);
300 }
301 }
302
83fe4d6d
AD
303 return sel_rows;
304}
305
306function readSelectedFeeds() {
307
c0e5a40e 308 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
309 printLockingError();
310 return
311 }
312
83fe4d6d
AD
313 var sel_rows = getSelectedFeeds();
314
315 if (sel_rows.length > 0) {
316
317 notify("Marking selected feeds as read...");
318
0e091d38 319 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 320 param_escape(sel_rows.toString()), true);
0e091d38 321 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
322 xmlhttp.send(null);
323
324 } else {
325
c753cd32 326 notify("Please select some feeds first.");
83fe4d6d
AD
327
328 }
329}
330
331function unreadSelectedFeeds() {
332
c0e5a40e 333 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
334 printLockingError();
335 return
336 }
337
83fe4d6d
AD
338 var sel_rows = getSelectedFeeds();
339
340 if (sel_rows.length > 0) {
341
342 notify("Marking selected feeds as unread...");
343
0e091d38 344 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 345 param_escape(sel_rows.toString()), true);
0e091d38 346 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
347 xmlhttp.send(null);
348
349 } else {
350
c753cd32 351 notify("Please select some feeds first.");
83fe4d6d
AD
352
353 }
354}
355
48f0adb0
AD
356function removeSelectedLabels() {
357
358 if (!xmlhttp_ready(xmlhttp)) {
359 printLockingError();
360 return
361 }
362
363 var sel_rows = getSelectedLabels();
364
365 if (sel_rows.length > 0) {
366
367 notify("Removing selected labels...");
368
369 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
370 param_escape(sel_rows.toString()), true);
371 xmlhttp.onreadystatechange=labellist_callback;
372 xmlhttp.send(null);
373
374 } else {
375 notify("Please select some labels first.");
376 }
377}
378
379function removeSelectedFilters() {
380
381 if (!xmlhttp_ready(xmlhttp)) {
382 printLockingError();
383 return
384 }
385
386 var sel_rows = getSelectedFilters();
387
388 if (sel_rows.length > 0) {
389
390 notify("Removing selected filters...");
391
392 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
393 param_escape(sel_rows.toString()), true);
394 xmlhttp.onreadystatechange=filterlist_callback;
395 xmlhttp.send(null);
396
397 } else {
398 notify("Please select some filters first.");
399 }
400}
401
402
83fe4d6d
AD
403function removeSelectedFeeds() {
404
c0e5a40e 405 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
406 printLockingError();
407 return
408 }
409
83fe4d6d
AD
410 var sel_rows = getSelectedFeeds();
411
331900c6
AD
412 if (sel_rows.length > 0) {
413
414 notify("Removing selected feeds...");
415
416 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
417 param_escape(sel_rows.toString()), true);
418 xmlhttp.onreadystatechange=feedlist_callback;
419 xmlhttp.send(null);
71ad3959 420
71ad3959 421 } else {
331900c6 422
c753cd32 423 notify("Please select some feeds first.");
331900c6 424
71ad3959
AD
425 }
426
427}
007bda35 428
508a81e1
AD
429function feedEditCancel() {
430
c0e5a40e 431 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
432 printLockingError();
433 return
434 }
435
961513a3
AD
436 active_feed = false;
437
508a81e1
AD
438 notify("Operation cancelled.");
439
440 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
441 xmlhttp.onreadystatechange=feedlist_callback;
442 xmlhttp.send(null);
443
444}
445
603c27f8
AD
446function feedEditSave() {
447
448 var feed = active_feed;
508a81e1 449
c0e5a40e 450 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
451 printLockingError();
452 return
453 }
454
603c27f8
AD
455 var link = document.getElementById("iedit_link").value;
456 var title = document.getElementById("iedit_title").value;
508a81e1 457
603c27f8 458// notify("Saving feed.");
508a81e1
AD
459
460 if (link.length == 0) {
461 notify("Feed link cannot be blank.");
462 return;
463 }
464
465 if (title.length == 0) {
466 notify("Feed title cannot be blank.");
467 return;
468 }
469
603c27f8
AD
470 active_feed = false;
471
508a81e1
AD
472 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
473 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) ,true);
474 xmlhttp.onreadystatechange=feedlist_callback;
475 xmlhttp.send(null);
476
477}
478
48f0adb0
AD
479function labelEditCancel() {
480
481 if (!xmlhttp_ready(xmlhttp)) {
482 printLockingError();
483 return
484 }
485
486 active_label = false;
487
488 notify("Operation cancelled.");
489
490 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
491 xmlhttp.onreadystatechange=labellist_callback;
492 xmlhttp.send(null);
493
494}
495
496
a0d53889
AD
497function filterEditCancel() {
498
499 if (!xmlhttp_ready(xmlhttp)) {
500 printLockingError();
501 return
502 }
503
504 active_filter = false;
505
506 notify("Operation cancelled.");
507
508 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
509 xmlhttp.onreadystatechange=filterlist_callback;
510 xmlhttp.send(null);
511
512}
513
48f0adb0
AD
514function labelEditSave() {
515
516 var label = active_label;
517
518 if (!xmlhttp_ready(xmlhttp)) {
519 printLockingError();
520 return
521 }
522
523 var sqlexp = document.getElementById("iedit_expr").value;
524 var descr = document.getElementById("iedit_descr").value;
525
526// notify("Saving label " + sqlexp + ": " + descr);
527
528 if (sqlexp.length == 0) {
529 notify("SQL expression cannot be blank.");
530 return;
531 }
532
533 if (descr.length == 0) {
534 notify("Caption cannot be blank.");
535 return;
536 }
537
538 active_label = false;
539
540 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
541 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
542 true);
543
544 xmlhttp.onreadystatechange=labellist_callback;
545 xmlhttp.send(null);
546
547}
548
a0d53889
AD
549function filterEditSave() {
550
551 var filter = active_filter;
552
553 if (!xmlhttp_ready(xmlhttp)) {
554 printLockingError();
555 return
556 }
557
558 var regexp = document.getElementById("iedit_regexp").value;
559 var descr = document.getElementById("iedit_descr").value;
25cb5736
AD
560 var match = document.getElementById("iedit_match");
561
562 var v_match = match[match.selectedIndex].text;
a0d53889
AD
563
564// notify("Saving filter " + filter + ": " + regexp + ", " + descr + ", " + match);
565
566 if (regexp.length == 0) {
567 notify("Filter expression cannot be blank.");
568 return;
569 }
570
571 active_filter = false;
572
573 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
574 filter + "&r=" + param_escape(regexp) + "&d=" + param_escape(descr) +
25cb5736 575 "&m=" + param_escape(v_match), true);
a0d53889
AD
576
577 xmlhttp.onreadystatechange=filterlist_callback;
578 xmlhttp.send(null);
579
580}
581
48f0adb0
AD
582function editSelectedLabel() {
583 var rows = getSelectedLabels();
a0d53889 584
48f0adb0
AD
585 if (rows.length == 0) {
586 notify("No labels are selected.");
587 return;
a0d53889
AD
588 }
589
48f0adb0
AD
590 if (rows.length > 1) {
591 notify("Please select one label.");
592 return;
593 }
a0d53889 594
48f0adb0 595 editLabel(rows[0]);
a0d53889 596
a0d53889
AD
597}
598
599
600function editSelectedFilter() {
601 var rows = getSelectedFilters();
602
603 if (rows.length == 0) {
604 notify("No filters are selected.");
605 return;
606 }
607
608 if (rows.length > 1) {
609 notify("Please select one filter.");
610 return;
611 }
612
613 editFilter(rows[0]);
614
615}
616
617
508a81e1
AD
618function editSelectedFeed() {
619 var rows = getSelectedFeeds();
620
621 if (rows.length == 0) {
622 notify("No feeds are selected.");
623 return;
624 }
625
626 if (rows.length > 1) {
627 notify("Please select one feed.");
628 return;
629 }
630
631 editFeed(rows[0]);
632
633}
634
13ad9102
AD
635function localPiggieFunction(enable) {
636 if (enable) {
508a81e1
AD
637 piggie.style.display = "block";
638 seq = "";
639 notify("I loveded it!!!");
640 } else {
641 piggie.style.display = "none";
642 notify("");
643 }
508a81e1
AD
644}
645
9f311df6
AD
646function validateOpmlImport() {
647
648 var opml_file = document.getElementById("opml_file");
649
650 if (opml_file.value.length == 0) {
651 notify("Please select OPML file to upload.");
652 return false;
653 } else {
654 return true;
655 }
656}
657
a0d53889
AD
658function updateFilterList() {
659
660 if (!xmlhttp_ready(xmlhttp)) {
661 printLockingError();
662 return
663 }
664
665 document.getElementById("filterConfPane").innerHTML = "Loading filters, please wait...";
666
667 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
668 xmlhttp.onreadystatechange=filterlist_callback;
669 xmlhttp.send(null);
670
671}
672
48f0adb0
AD
673function updateLabelList() {
674
675 if (!xmlhttp_ready(xmlhttp)) {
676 printLockingError();
677 return
678 }
679
680 document.getElementById("labelConfPane").innerHTML = "Loading labels, please wait...";
681
682 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
683 xmlhttp.onreadystatechange=labellist_callback;
684 xmlhttp.send(null);
685
686}
687
688
a0d53889
AD
689function expandPane(id) {
690
691 var container;
692
a0d53889
AD
693 container = document.getElementById(id);
694
695 if (id == "feedConfPane") {
696 updateFeedList();
697 } else if (id == "filterConfPane") {
698 updateFilterList();
48f0adb0
AD
699 } else if (id == "labelConfPane") {
700 updateLabelList();
a0d53889 701 }
a0d53889
AD
702}
703
007bda35 704function init() {
e2ec66a8
AD
705
706 // IE kludge
707
ad095c16 708 if (!xmlhttp) {
e2ec66a8
AD
709 document.getElementById("prefContent").innerHTML =
710 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
711 "to function properly. Your browser doesn't seem to support it.";
712 return;
713 }
714
a0d53889 715// updateFeedList();
508a81e1 716 document.onkeydown = hotkey_handler;
857a9270
AD
717 notify("");
718
007bda35 719}