]> git.wh0rd.org - tt-rss.git/blame - prefs.js
inline filter editor uses prototype
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
1var xmlhttp = false;
2
961513a3 3var active_feed = false;
91ff844a 4var active_feed_cat = false;
a0d53889 5var active_filter = false;
48f0adb0 6var active_label = false;
e6cb77a0 7var active_user = false;
f5a50b25 8var active_tab = false;
c6232e43 9var feed_to_expand = false;
f5a50b25 10
1cac3c31
AD
11var piggie_top = -400;
12var piggie_fwd = true;
13
007bda35
AD
14/*@cc_on @*/
15/*@if (@_jscript_version >= 5)
16// JScript gives us Conditional compilation, we can cope with old IE versions.
17// and security blocked creation of the objects.
18try {
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
20} catch (e) {
21 try {
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
23 } catch (E) {
24 xmlhttp = false;
25 }
26}
27@end @*/
28
29if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
30 xmlhttp = new XMLHttpRequest();
31}
32
c6232e43
AD
33function expand_feed_callback() {
34 if (xmlhttp.readyState == 4) {
35 try {
36 var container = document.getElementById("BRDET-" + feed_to_expand);
37 container.innerHTML=xmlhttp.responseText;
38 container.style.display = "block";
4d4200a8 39// p_notify("");
c6232e43
AD
40 } catch (e) {
41 exception_error("expand_feed_callback", e);
42 }
43 }
44}
45
007bda35 46function feedlist_callback() {
007bda35 47 if (xmlhttp.readyState == 4) {
47c6c988
AD
48 try {
49 var container = document.getElementById('prefContent');
50 container.innerHTML=xmlhttp.responseText;
a7f22b70
AD
51 selectTab("feedConfig", true);
52
47c6c988
AD
53 if (active_feed) {
54 var row = document.getElementById("FEEDR-" + active_feed);
55 if (row) {
56 if (!row.className.match("Selected")) {
57 row.className = row.className + "Selected";
58 }
59 }
60 var checkbox = document.getElementById("FRCHK-" + active_feed);
61 if (checkbox) {
62 checkbox.checked = true;
63 }
961513a3 64 }
7f74a9da 65 notify("");
47c6c988
AD
66 } catch (e) {
67 exception_error("feedlist_callback", e);
961513a3 68 }
007bda35
AD
69 }
70}
71
a0d53889 72function filterlist_callback() {
f5a50b25 73 var container = document.getElementById('prefContent');
a0d53889 74 if (xmlhttp.readyState == 4) {
f5a50b25 75
a0d53889
AD
76 container.innerHTML=xmlhttp.responseText;
77
78 if (active_filter) {
79 var row = document.getElementById("FILRR-" + active_filter);
80 if (row) {
81 if (!row.className.match("Selected")) {
82 row.className = row.className + "Selected";
83 }
84 }
85 var checkbox = document.getElementById("FICHK-" + active_filter);
86
87 if (checkbox) {
88 checkbox.checked = true;
89 }
90 }
7f74a9da 91 notify("");
a0d53889
AD
92 }
93}
94
48f0adb0 95function labellist_callback() {
f5a50b25 96 var container = document.getElementById('prefContent');
48f0adb0
AD
97 if (xmlhttp.readyState == 4) {
98 container.innerHTML=xmlhttp.responseText;
99
967955b7 100 if (active_label) {
48f0adb0
AD
101 var row = document.getElementById("LILRR-" + active_label);
102 if (row) {
103 if (!row.className.match("Selected")) {
104 row.className = row.className + "Selected";
105 }
106 }
107 var checkbox = document.getElementById("LICHK-" + active_label);
108
109 if (checkbox) {
110 checkbox.checked = true;
111 }
112 }
7f74a9da 113 notify("");
48f0adb0
AD
114 }
115}
4255b24c 116
c6232e43
AD
117function feed_browser_callback() {
118 var container = document.getElementById('prefContent');
119 if (xmlhttp.readyState == 4) {
120 container.innerHTML=xmlhttp.responseText;
7f74a9da 121 notify("");
c6232e43
AD
122 }
123}
124
e6cb77a0
AD
125function userlist_callback() {
126 var container = document.getElementById('prefContent');
127 if (xmlhttp.readyState == 4) {
128 container.innerHTML=xmlhttp.responseText;
129
1a7572cb
AD
130 if (active_user) {
131 var row = document.getElementById("UMRR-" + active_user);
e6cb77a0
AD
132 if (row) {
133 if (!row.className.match("Selected")) {
134 row.className = row.className + "Selected";
135 }
136 }
1a7572cb 137 var checkbox = document.getElementById("UMCHK-" + active_user);
e6cb77a0
AD
138
139 if (checkbox) {
140 checkbox.checked = true;
141 }
1a7572cb 142 }
7f74a9da 143 notify("");
e6cb77a0
AD
144 }
145}
146
4255b24c
AD
147function prefslist_callback() {
148 var container = document.getElementById('prefContent');
149 if (xmlhttp.readyState == 4) {
150
151 container.innerHTML=xmlhttp.responseText;
7f74a9da
AD
152
153 notify("");
4255b24c
AD
154 }
155}
156
b1895692
AD
157function gethelp_callback() {
158 var container = document.getElementById('prefHelpBox');
159 if (xmlhttp.readyState == 4) {
160
161 container.innerHTML = xmlhttp.responseText;
162 container.style.display = "block";
163
164 }
165}
4255b24c
AD
166
167
0e091d38
AD
168function notify_callback() {
169 var container = document.getElementById('notify');
170 if (xmlhttp.readyState == 4) {
171 container.innerHTML=xmlhttp.responseText;
172 }
173}
174
b83c7545 175function updateFeedList(sort_key) {
007bda35 176
c0e5a40e 177 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
178 printLockingError();
179 return
180 }
181
f5a50b25
AD
182// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
183
ce3bf408 184// p_notify("Loading, please wait...");
007bda35 185
f932bc9f
AD
186 var feed_search = document.getElementById("feed_search");
187 var search = "";
188 if (feed_search) { search = feed_search.value; }
189
b83c7545 190 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f
AD
191 "&sort=" + param_escape(sort_key) +
192 "&search=" + param_escape(search), true);
007bda35
AD
193 xmlhttp.onreadystatechange=feedlist_callback;
194 xmlhttp.send(null);
195
196}
197
e6cb77a0
AD
198function updateUsersList() {
199
200 if (!xmlhttp_ready(xmlhttp)) {
201 printLockingError();
202 return
203 }
204
205// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
206
ce3bf408 207// p_notify("Loading, please wait...");
e6cb77a0
AD
208
209 xmlhttp.open("GET", "backend.php?op=pref-users", true);
210 xmlhttp.onreadystatechange=userlist_callback;
211 xmlhttp.send(null);
212
213}
214
48f0adb0
AD
215function addLabel() {
216
217 if (!xmlhttp_ready(xmlhttp)) {
218 printLockingError();
219 return
220 }
221
222 var sqlexp = document.getElementById("ladd_expr");
223
224 if (sqlexp.value.length == 0) {
01b3e191 225 alert("Can't add label: missing SQL expression.");
48f0adb0
AD
226 } else {
227 notify("Adding label...");
228
229 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
230 param_escape(sqlexp.value), true);
231
232 xmlhttp.onreadystatechange=labellist_callback;
233 xmlhttp.send(null);
234
235 sqlexp.value = "";
236 }
237
238}
239
de435974
AD
240function addFilter() {
241
242 if (!xmlhttp_ready(xmlhttp)) {
243 printLockingError();
244 return
245 }
246
247 var regexp = document.getElementById("fadd_regexp");
248 var match = document.getElementById("fadd_match");
ead60402 249 var feed = document.getElementById("fadd_feed");
19c9cb11 250 var action = document.getElementById("fadd_action");
de435974
AD
251
252 if (regexp.value.length == 0) {
01b3e191 253 alert("Can't add filter: missing filter expression.");
de435974
AD
254 } else {
255 notify("Adding filter...");
256
25cb5736 257 var v_match = match[match.selectedIndex].text;
ead60402 258 var feed_id = feed[feed.selectedIndex].id;
19c9cb11 259 var action_id = action[action.selectedIndex].id;
ead60402 260
de435974 261 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
ead60402 262 param_escape(regexp.value) + "&match=" + v_match +
19c9cb11 263 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
de435974
AD
264
265 xmlhttp.onreadystatechange=filterlist_callback;
266 xmlhttp.send(null);
267
268 regexp.value = "";
269 }
270
271}
48f0adb0 272
71ad3959
AD
273function addFeed() {
274
c0e5a40e 275 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
276 printLockingError();
277 return
278 }
279
331900c6
AD
280 var link = document.getElementById("fadd_link");
281
83fe4d6d 282 if (link.value.length == 0) {
0ceded7a 283 alert("Error: No feed URL given.");
605f7d46 284 } else if (!isValidURL(link.value)) {
2371c520 285 alert("Error: Invalid feed URL.");
331900c6
AD
286 } else {
287 notify("Adding feed...");
288
289 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
290 param_escape(link.value), true);
291 xmlhttp.onreadystatechange=feedlist_callback;
292 xmlhttp.send(null);
293
294 link.value = "";
295
296 }
297
298}
299
91ff844a
AD
300function addFeedCat() {
301
302 if (!xmlhttp_ready(xmlhttp)) {
303 printLockingError();
304 return
305 }
306
307 var cat = document.getElementById("fadd_cat");
308
309 if (cat.value.length == 0) {
01b3e191 310 alert("Can't add category: no name specified.");
91ff844a
AD
311 } else {
312 notify("Adding feed category...");
313
314 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=addCat&cat=" +
315 param_escape(cat.value), true);
316 xmlhttp.onreadystatechange=feedlist_callback;
317 xmlhttp.send(null);
318
319 link.value = "";
320
321 }
322
323}
e6cb77a0
AD
324function addUser() {
325
326 if (!xmlhttp_ready(xmlhttp)) {
327 printLockingError();
328 return
329 }
330
331 var sqlexp = document.getElementById("uadd_box");
332
333 if (sqlexp.value.length == 0) {
01b3e191 334 alert("Can't add user: no login specified.");
e6cb77a0
AD
335 } else {
336 notify("Adding user...");
337
338 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
339 param_escape(sqlexp.value), true);
340
341 xmlhttp.onreadystatechange=userlist_callback;
342 xmlhttp.send(null);
343
344 sqlexp.value = "";
345 }
346
347}
348
48f0adb0
AD
349function editLabel(id) {
350
351 if (!xmlhttp_ready(xmlhttp)) {
352 printLockingError();
353 return
354 }
355
356 active_label = id;
357
358 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
359 param_escape(id), true);
360 xmlhttp.onreadystatechange=labellist_callback;
361 xmlhttp.send(null);
362
363}
364
e6cb77a0
AD
365function editUser(id) {
366
367 if (!xmlhttp_ready(xmlhttp)) {
368 printLockingError();
369 return
370 }
371
372 active_user = id;
373
374 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
375 param_escape(id), true);
376 xmlhttp.onreadystatechange=userlist_callback;
377 xmlhttp.send(null);
378
379}
380
a0d53889
AD
381function editFilter(id) {
382
383 if (!xmlhttp_ready(xmlhttp)) {
384 printLockingError();
385 return
386 }
387
388 active_filter = id;
389
390 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" +
391 param_escape(id), true);
392 xmlhttp.onreadystatechange=filterlist_callback;
393 xmlhttp.send(null);
394
395}
396
331900c6
AD
397function editFeed(feed) {
398
508a81e1
AD
399// notify("Editing feed...");
400
c0e5a40e 401 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
402 printLockingError();
403 return
404 }
331900c6 405
961513a3
AD
406 active_feed = feed;
407
673d54ca 408 // clean selection from all rows & select row being edited
0ea4fb50 409 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 410 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
411
412 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
413 param_escape(active_feed), true);
414
415 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
416 xmlhttp.send(null);
417
418}
419
91ff844a 420function editFeedCat(cat) {
48f0adb0 421
91ff844a
AD
422 if (!xmlhttp_ready(xmlhttp)) {
423 printLockingError();
424 return
48f0adb0
AD
425 }
426
91ff844a 427 active_feed_cat = cat;
e6cb77a0 428
91ff844a
AD
429 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
430 param_escape(cat), true);
431 xmlhttp.onreadystatechange=feedlist_callback;
432 xmlhttp.send(null);
e6cb77a0 433
e6cb77a0
AD
434}
435
91ff844a
AD
436function getSelectedLabels() {
437 return getSelectedTableRowIds("prefLabelList", "LILRR");
438}
48f0adb0 439
91ff844a
AD
440function getSelectedUsers() {
441 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
442}
443
83fe4d6d 444function getSelectedFeeds() {
91ff844a
AD
445 return getSelectedTableRowIds("prefFeedList", "FEEDR");
446}
331900c6 447
91ff844a
AD
448function getSelectedFilters() {
449 return getSelectedTableRowIds("prefFilterList", "FILRR");
450}
331900c6 451
91ff844a
AD
452function getSelectedFeedCats() {
453 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
454}
455
c0ae0fdb
AD
456function getSelectedFeedsFromBrowser() {
457
458 var list = document.getElementById("browseFeedList");
459 if (!list) list = document.getElementById("browseBigFeedList");
460
461 var selected = new Array();
462
463 for (i = 0; i < list.childNodes.length; i++) {
464 var child = list.childNodes[i];
465 if (child.id && child.id.match("FBROW-")) {
466 var id = child.id.replace("FBROW-", "");
467
468 var cb = document.getElementById("FBCHK-" + id);
469
470 if (cb.checked) {
471 selected.push(id);
472 }
473 }
474 }
475
476 return selected;
477}
478
91ff844a 479
01b3e191 480/*function readSelectedFeeds(read) {
83fe4d6d 481
c0e5a40e 482 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
483 printLockingError();
484 return
485 }
486
83fe4d6d
AD
487 var sel_rows = getSelectedFeeds();
488
489 if (sel_rows.length > 0) {
490
4f3a84f4
AD
491 if (!read) {
492 op = "unread";
493 } else {
494 op = "read";
495 }
83fe4d6d 496
4f3a84f4 497 notify("Marking selected feeds as " + op + "...");
83fe4d6d 498
4f3a84f4 499 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=" + op + "&ids="+
83fe4d6d 500 param_escape(sel_rows.toString()), true);
0e091d38 501 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
502 xmlhttp.send(null);
503
504 } else {
505
01b3e191 506 alert("No feeds are selected.");
83fe4d6d
AD
507
508 }
01b3e191 509} */
83fe4d6d 510
48f0adb0
AD
511function removeSelectedLabels() {
512
513 if (!xmlhttp_ready(xmlhttp)) {
514 printLockingError();
515 return
516 }
517
518 var sel_rows = getSelectedLabels();
519
520 if (sel_rows.length > 0) {
521
69668465 522 var ok = confirm("Remove selected labels?");
48f0adb0 523
69668465
AD
524 if (ok) {
525 notify("Removing selected labels...");
526
527 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
528 param_escape(sel_rows.toString()), true);
529 xmlhttp.onreadystatechange=labellist_callback;
530 xmlhttp.send(null);
531 }
48f0adb0 532 } else {
01b3e191 533 alert("No labels are selected.");
48f0adb0
AD
534 }
535}
536
e6cb77a0
AD
537function removeSelectedUsers() {
538
539 if (!xmlhttp_ready(xmlhttp)) {
540 printLockingError();
541 return
542 }
543
544 var sel_rows = getSelectedUsers();
545
546 if (sel_rows.length > 0) {
547
69668465 548 var ok = confirm("Remove selected users?");
e6cb77a0 549
69668465
AD
550 if (ok) {
551 notify("Removing selected users...");
552
553 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
554 param_escape(sel_rows.toString()), true);
555 xmlhttp.onreadystatechange=userlist_callback;
556 xmlhttp.send(null);
557 }
e6cb77a0
AD
558
559 } else {
01b3e191 560 alert("No users are selected.");
e6cb77a0
AD
561 }
562}
563
48f0adb0
AD
564function removeSelectedFilters() {
565
566 if (!xmlhttp_ready(xmlhttp)) {
567 printLockingError();
568 return
569 }
570
571 var sel_rows = getSelectedFilters();
572
573 if (sel_rows.length > 0) {
574
69668465 575 var ok = confirm("Remove selected filters?");
48f0adb0 576
69668465
AD
577 if (ok) {
578 notify("Removing selected filters...");
579
580 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
581 param_escape(sel_rows.toString()), true);
582 xmlhttp.onreadystatechange=filterlist_callback;
583 xmlhttp.send(null);
584 }
48f0adb0 585 } else {
01b3e191 586 alert("No filters are selected.");
48f0adb0
AD
587 }
588}
589
590
83fe4d6d
AD
591function removeSelectedFeeds() {
592
c0e5a40e 593 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
594 printLockingError();
595 return
596 }
597
83fe4d6d
AD
598 var sel_rows = getSelectedFeeds();
599
331900c6
AD
600 if (sel_rows.length > 0) {
601
1d7bf5a0 602 var ok = confirm("Unsubscribe from selected feeds?");
331900c6 603
69668465
AD
604 if (ok) {
605
1d7bf5a0 606 notify("Unsubscribing from selected feeds...");
69668465
AD
607
608 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
609 param_escape(sel_rows.toString()), true);
610 xmlhttp.onreadystatechange=feedlist_callback;
611 xmlhttp.send(null);
612 }
71ad3959 613
71ad3959 614 } else {
331900c6 615
01b3e191 616 alert("No feeds are selected.");
331900c6 617
71ad3959
AD
618 }
619
620}
007bda35 621
91ff844a
AD
622function removeSelectedFeedCats() {
623
624 if (!xmlhttp_ready(xmlhttp)) {
625 printLockingError();
626 return
627 }
628
629 var sel_rows = getSelectedFeedCats();
630
631 if (sel_rows.length > 0) {
632
69668465 633 var ok = confirm("Remove selected categories?");
91ff844a 634
69668465
AD
635 if (ok) {
636 notify("Removing selected categories...");
637
638 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
639 param_escape(sel_rows.toString()), true);
640 xmlhttp.onreadystatechange=feedlist_callback;
641 xmlhttp.send(null);
642 }
91ff844a
AD
643
644 } else {
645
01b3e191 646 alert("No categories are selected.");
91ff844a
AD
647
648 }
649
650}
651
508a81e1
AD
652function feedEditCancel() {
653
c0e5a40e 654 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
655 printLockingError();
656 return
657 }
658
327a3bbe
AD
659 closeInfoBox();
660
673d54ca 661 selectPrefRows('feed', false); // cleanup feed selection
508a81e1 662
673d54ca 663 active_feed = false;
c14b5566 664
508a81e1
AD
665}
666
91ff844a
AD
667function feedCatEditCancel() {
668
669 if (!xmlhttp_ready(xmlhttp)) {
670 printLockingError();
671 return
672 }
673
674 active_feed_cat = false;
675
0ceded7a 676// notify("Operation cancelled.");
91ff844a
AD
677
678 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
679 xmlhttp.onreadystatechange=feedlist_callback;
680 xmlhttp.send(null);
681
682}
683
603c27f8
AD
684function feedEditSave() {
685
47c6c988 686 try {
47c6c988
AD
687
688 if (!xmlhttp_ready(xmlhttp)) {
689 printLockingError();
690 return
691 }
ad815c71 692
14f69488 693 // FIXME: add parameter validation
e3c99f3b 694
14f69488 695 var query = Form.serialize("edit_feed_form");
b0da3a7b 696
47c6c988 697 active_feed = false;
508a81e1 698
14f69488 699 notify("Saving feed...");
673d54ca 700
47c6c988
AD
701 xmlhttp.open("POST", "backend.php", true);
702 xmlhttp.onreadystatechange=feedlist_callback;
703 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
704 xmlhttp.send(query);
705
c14b5566
AD
706 return false;
707
47c6c988
AD
708 } catch (e) {
709 exception_error("feedEditSave", e);
b0da3a7b 710 }
508a81e1
AD
711}
712
5ddadb4c
AD
713function feedCatEditSave() {
714
715 if (!xmlhttp_ready(xmlhttp)) {
716 printLockingError();
717 return
718 }
719
f0e81ffe 720 notify("Saving category...");
5ddadb4c
AD
721
722 var cat_title = document.getElementById("iedit_title").value;
723
724 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=saveCat&id=" +
725 param_escape(active_feed_cat) + "&title=" + param_escape(cat_title),
726 true);
727 xmlhttp.onreadystatechange=feedlist_callback;
728 xmlhttp.send(null);
729
730 active_feed_cat = false;
731
732}
733
734
d9dde1d6
AD
735function labelTest() {
736
737 var sqlexp = document.getElementById("iedit_expr").value;
738 var descr = document.getElementById("iedit_descr").value;
739
740 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
741 param_escape(sqlexp) + "&descr=" + param_escape(descr), true);
742
743 xmlhttp.onreadystatechange=infobox_callback;
744 xmlhttp.send(null);
745
746}
747
01c9c74a
AD
748function displayHelpInfobox(topic_id) {
749
750 xmlhttp.open("GET", "backend.php?op=help&tid=" +
751 param_escape(topic_id) + "&noheaders=1", true);
752
753 xmlhttp.onreadystatechange=infobox_callback;
754 xmlhttp.send(null);
755
756}
757
48f0adb0
AD
758function labelEditCancel() {
759
760 if (!xmlhttp_ready(xmlhttp)) {
761 printLockingError();
762 return
763 }
764
765 active_label = false;
766
0ceded7a 767// notify("Operation cancelled.");
48f0adb0
AD
768
769 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
770 xmlhttp.onreadystatechange=labellist_callback;
771 xmlhttp.send(null);
772
773}
774
e6cb77a0
AD
775function userEditCancel() {
776
777 if (!xmlhttp_ready(xmlhttp)) {
778 printLockingError();
779 return
780 }
781
782 active_user = false;
783
0ceded7a 784// notify("Operation cancelled.");
e6cb77a0
AD
785
786 xmlhttp.open("GET", "backend.php?op=pref-users", true);
787 xmlhttp.onreadystatechange=userlist_callback;
788 xmlhttp.send(null);
789
790}
48f0adb0 791
a0d53889
AD
792function filterEditCancel() {
793
794 if (!xmlhttp_ready(xmlhttp)) {
795 printLockingError();
796 return
797 }
798
799 active_filter = false;
800
0ceded7a 801// notify("Operation cancelled.");
a0d53889
AD
802
803 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
804 xmlhttp.onreadystatechange=filterlist_callback;
805 xmlhttp.send(null);
806
807}
808
48f0adb0
AD
809function labelEditSave() {
810
811 var label = active_label;
812
813 if (!xmlhttp_ready(xmlhttp)) {
814 printLockingError();
815 return
816 }
817
818 var sqlexp = document.getElementById("iedit_expr").value;
819 var descr = document.getElementById("iedit_descr").value;
820
821// notify("Saving label " + sqlexp + ": " + descr);
822
823 if (sqlexp.length == 0) {
824 notify("SQL expression cannot be blank.");
825 return;
826 }
827
828 if (descr.length == 0) {
829 notify("Caption cannot be blank.");
830 return;
831 }
832
f0e81ffe 833 notify("Saving label...");
dbd9e2f1 834
48f0adb0
AD
835 active_label = false;
836
837 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
838 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
839 true);
840
841 xmlhttp.onreadystatechange=labellist_callback;
842 xmlhttp.send(null);
843
844}
845
e6cb77a0
AD
846function userEditSave() {
847
848 var user = active_user;
849
850 if (!xmlhttp_ready(xmlhttp)) {
851 printLockingError();
852 return
853 }
854
855 var login = document.getElementById("iedit_ulogin").value;
5917a8e4
AD
856 var level = document.getElementById("iedit_ulevel");
857
858 level = level[level.selectedIndex].id;
859
72932a75 860 var email = document.getElementById("iedit_email").value;
e6cb77a0
AD
861
862 if (login.length == 0) {
863 notify("Login cannot be blank.");
864 return;
865 }
866
867 if (level.length == 0) {
868 notify("User level cannot be blank.");
869 return;
870 }
871
872 active_user = false;
873
f0e81ffe 874 notify("Saving user...");
dbd9e2f1 875
e6cb77a0 876 xmlhttp.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
72932a75
AD
877 user + "&l=" + param_escape(login) + "&al=" + param_escape(level) +
878 "&e=" + param_escape(email), true);
e6cb77a0 879
dbd9e2f1 880 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0
AD
881 xmlhttp.send(null);
882
883}
884
885
a0d53889
AD
886function filterEditSave() {
887
a0d53889
AD
888 if (!xmlhttp_ready(xmlhttp)) {
889 printLockingError();
890 return
891 }
892
7e939457 893 // FIXME: input validation
a0d53889 894
7e939457 895 notify("Saving filter...");
a0d53889
AD
896
897 active_filter = false;
898
7e939457 899 var query = Form.serialize("filter_edit_form");
dbd9e2f1 900
7e939457 901 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 902 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 903 xmlhttp.send(null);
a0d53889
AD
904
905}
906
48f0adb0
AD
907function editSelectedLabel() {
908 var rows = getSelectedLabels();
a0d53889 909
48f0adb0 910 if (rows.length == 0) {
01b3e191 911 alert("No labels are selected.");
48f0adb0 912 return;
a0d53889
AD
913 }
914
48f0adb0 915 if (rows.length > 1) {
01b3e191 916 alert("Please select only one label.");
48f0adb0
AD
917 return;
918 }
a0d53889 919
dbd9e2f1
AD
920 notify("");
921
48f0adb0 922 editLabel(rows[0]);
a0d53889 923
a0d53889
AD
924}
925
e6cb77a0
AD
926function editSelectedUser() {
927 var rows = getSelectedUsers();
928
929 if (rows.length == 0) {
01b3e191 930 alert("No users are selected.");
e6cb77a0
AD
931 return;
932 }
933
934 if (rows.length > 1) {
01b3e191 935 alert("Please select only one user.");
e6cb77a0
AD
936 return;
937 }
938
dbd9e2f1
AD
939 notify("");
940
e6cb77a0
AD
941 editUser(rows[0]);
942}
943
944function resetSelectedUserPass() {
945 var rows = getSelectedUsers();
946
947 if (rows.length == 0) {
01b3e191 948 alert("No users are selected.");
e6cb77a0
AD
949 return;
950 }
951
952 if (rows.length > 1) {
01b3e191 953 alert("Please select only one user.");
e6cb77a0
AD
954 return;
955 }
956
69668465 957 var ok = confirm("Reset password of selected user?");
e6cb77a0 958
69668465
AD
959 if (ok) {
960 notify("Resetting password for selected user...");
961
962 var id = rows[0];
963
964 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
965 param_escape(id), true);
966 xmlhttp.onreadystatechange=userlist_callback;
967 xmlhttp.send(null);
968 }
e6cb77a0
AD
969}
970
717f5e64 971function selectedUserDetails() {
e6cb77a0 972
1a7572cb
AD
973 if (!xmlhttp_ready(xmlhttp)) {
974 printLockingError();
975 return
976 }
977
717f5e64
AD
978 var rows = getSelectedUsers();
979
980 if (rows.length == 0) {
01b3e191 981 alert("No users are selected.");
717f5e64
AD
982 return;
983 }
984
985 if (rows.length > 1) {
01b3e191 986 alert("Please select only one user.");
717f5e64
AD
987 return;
988 }
989
990 var id = rows[0];
991
dbd9e2f1
AD
992 notify("");
993
1a7572cb 994 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
995 xmlhttp.onreadystatechange=infobox_callback;
996 xmlhttp.send(null);
997
998}
999
1000function selectedFeedDetails() {
1001
1002 if (!xmlhttp_ready(xmlhttp)) {
1003 printLockingError();
1004 return
1005 }
1006
1007 var rows = getSelectedFeeds();
1008
1009 if (rows.length == 0) {
01b3e191 1010 alert("No feeds are selected.");
c6c3a07f
AD
1011 return;
1012 }
1013
01b3e191
AD
1014 if (rows.length > 1) {
1015 notify("Please select only one feed.");
1016 return;
1017 }
c6c3a07f 1018
df268d47 1019// var id = rows[0];
c6c3a07f 1020
dbd9e2f1
AD
1021 notify("");
1022
df268d47
AD
1023 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1024 param_escape(rows.toString()), true);
c6c3a07f 1025 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1026 xmlhttp.send(null);
717f5e64
AD
1027
1028}
a0d53889
AD
1029
1030function editSelectedFilter() {
1031 var rows = getSelectedFilters();
1032
1033 if (rows.length == 0) {
01b3e191 1034 alert("No filters are selected.");
a0d53889
AD
1035 return;
1036 }
1037
1038 if (rows.length > 1) {
01b3e191 1039 alert("Please select only one filter.");
a0d53889
AD
1040 return;
1041 }
1042
dbd9e2f1
AD
1043 notify("");
1044
a0d53889
AD
1045 editFilter(rows[0]);
1046
1047}
1048
1049
508a81e1
AD
1050function editSelectedFeed() {
1051 var rows = getSelectedFeeds();
1052
1053 if (rows.length == 0) {
1054 notify("No feeds are selected.");
1055 return;
1056 }
1057
1058 if (rows.length > 1) {
1059 notify("Please select one feed.");
1060 return;
1061 }
1062
dbd9e2f1
AD
1063 notify("");
1064
508a81e1 1065 editFeed(rows[0]);
91ff844a
AD
1066
1067}
1068
1069function editSelectedFeedCat() {
1070 var rows = getSelectedFeedCats();
1071
1072 if (rows.length == 0) {
01b3e191 1073 alert("No categories are selected.");
91ff844a
AD
1074 return;
1075 }
1076
1077 if (rows.length > 1) {
01b3e191 1078 alert("Please select only one category.");
91ff844a
AD
1079 return;
1080 }
1081
1082 notify("");
1083
1084 editFeedCat(rows[0]);
508a81e1
AD
1085
1086}
1087
1cac3c31
AD
1088function piggie_callback() {
1089 var piggie = document.getElementById("piggie");
1090
1091 piggie.style.top = piggie_top;
e0b6a737
AD
1092 piggie.style.backgroundColor = "white";
1093 piggie.style.borderWidth = "1px";
1cac3c31
AD
1094
1095 if (piggie_fwd && piggie_top < 0) {
1096 setTimeout("piggie_callback()", 50);
1097 piggie_top = piggie_top + 10;
1098 } else if (piggie_fwd && piggie_top >= 0) {
1099 piggie_fwd = false;
1100 setTimeout("piggie_callback()", 50);
1101 } else if (!piggie_fwd && piggie_top > -400) {
1102 setTimeout("piggie_callback()", 50);
1103 piggie_top = piggie_top - 10;
1104 } else if (!piggie_fwd && piggie_top <= -400) {
1105 piggie.style.display = "none";
1106 piggie_fwd = true;
1107 }
1108}
1109
33377ef3
AD
1110var piggie_opacity = 0;
1111
1112function piggie2_callback() {
1113 var piggie = document.getElementById("piggie");
1114 piggie.style.top = 0;
1115 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1116 piggie.style.backgroundColor = "transparent";
1117 piggie.style.borderWidth = "0px";
33377ef3
AD
1118
1119 if (piggie_fwd && piggie_opacity < 1) {
1120 setTimeout("piggie2_callback()", 50);
1121 piggie_opacity = piggie_opacity + 0.03;
1122 } else if (piggie_fwd && piggie_opacity >= 1) {
1123 piggie_fwd = false;
1124 setTimeout("piggie2_callback()", 50);
1125 } else if (!piggie_fwd && piggie_opacity > 0) {
1126 setTimeout("piggie2_callback()", 50);
1127 piggie_opacity = piggie_opacity - 0.03;
1128 } else if (!piggie_fwd && piggie_opacity <= 0) {
1129 piggie.style.display = "none";
1130 piggie_fwd = true;
1131 }
1132}
1133
13ad9102
AD
1134function localPiggieFunction(enable) {
1135 if (enable) {
1cac3c31 1136 var piggie = document.getElementById("piggie");
508a81e1 1137 piggie.style.display = "block";
33377ef3 1138
292a8a12 1139 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
33377ef3
AD
1140 piggie2_callback();
1141 } else {
1142 piggie_callback();
1143 }
508a81e1 1144 }
508a81e1
AD
1145}
1146
9f311df6
AD
1147function validateOpmlImport() {
1148
1149 var opml_file = document.getElementById("opml_file");
1150
1151 if (opml_file.value.length == 0) {
01b3e191 1152 alert("No OPML file to upload.");
9f311df6
AD
1153 return false;
1154 } else {
1155 return true;
1156 }
1157}
1158
a0d53889
AD
1159function updateFilterList() {
1160
1161 if (!xmlhttp_ready(xmlhttp)) {
1162 printLockingError();
1163 return
1164 }
1165
f5a50b25
AD
1166// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1167
ce3bf408 1168// p_notify("Loading, please wait...");
a0d53889
AD
1169
1170 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1171 xmlhttp.onreadystatechange=filterlist_callback;
1172 xmlhttp.send(null);
1173
1174}
1175
48f0adb0
AD
1176function updateLabelList() {
1177
1178 if (!xmlhttp_ready(xmlhttp)) {
1179 printLockingError();
1180 return
1181 }
1182
ce3bf408 1183// p_notify("Loading, please wait...");
f5a50b25
AD
1184
1185// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1186
1187 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1188 xmlhttp.onreadystatechange=labellist_callback;
1189 xmlhttp.send(null);
48f0adb0
AD
1190}
1191
4255b24c
AD
1192function updatePrefsList() {
1193
1194 if (!xmlhttp_ready(xmlhttp)) {
1195 printLockingError();
1196 return
1197 }
1198
ce3bf408 1199// p_notify("Loading, please wait...");
4255b24c
AD
1200
1201 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1202 xmlhttp.onreadystatechange=prefslist_callback;
1203 xmlhttp.send(null);
1204
1205}
1206
a7f22b70
AD
1207function selectTab(id, noupdate) {
1208
1209// alert(id);
48f0adb0 1210
c6c3a07f
AD
1211 if (!xmlhttp_ready(xmlhttp)) {
1212 printLockingError();
1213 return
1214 }
1215
a7f22b70
AD
1216 if (!noupdate) {
1217
7f74a9da
AD
1218 notify("Loading, please wait...", true);
1219
673d54ca
AD
1220 // clean up all current selections, just in case
1221 active_feed = false;
1222 active_feed_cat = false;
1223 active_filter = false;
1224 active_label = false;
1225 active_user = false;
1226
a7f22b70
AD
1227 if (id == "feedConfig") {
1228 updateFeedList();
1229 } else if (id == "filterConfig") {
1230 updateFilterList();
1231 } else if (id == "labelConfig") {
1232 updateLabelList();
1233 } else if (id == "genConfig") {
1234 updatePrefsList();
1235 } else if (id == "userConfig") {
1236 updateUsersList();
1237 } else if (id == "feedBrowser") {
1238 updateBigFeedBrowser();
1239 }
a0d53889 1240 }
f5a50b25
AD
1241
1242 var tab = document.getElementById(active_tab + "Tab");
1243
1244 if (tab) {
1245 if (tab.className.match("Selected")) {
1246 tab.className = "prefsTab";
1247 }
1248 }
1249
1250 tab = document.getElementById(id + "Tab");
1251
1252 if (tab) {
1253 if (!tab.className.match("Selected")) {
1254 tab.className = tab.className + "Selected";
1255 }
1256 }
1257
1258 active_tab = id;
1259
4da47970
AD
1260 setCookie('ttrss_pref_acttab', active_tab);
1261
a0d53889
AD
1262}
1263
007bda35 1264function init() {
e2ec66a8 1265
7719618b
AD
1266 try {
1267
97dcd654
AD
1268 if (arguments.callee.done) return;
1269 arguments.callee.done = true;
1270
7719618b
AD
1271 // IE kludge
1272 if (!xmlhttp) {
1273 document.getElementById("prefContent").innerHTML =
1274 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1275 "to function properly. Your browser doesn't seem to support it.";
1276 return;
1277 }
4da47970
AD
1278
1279 active_tab = getCookie("ttrss_pref_acttab");
1280 if (!active_tab) active_tab = "genConfig";
1281 selectTab(active_tab);
7719618b
AD
1282
1283 document.onkeydown = hotkey_handler;
1284 notify("");
1285 } catch (e) {
1286 exception_error("init", e);
e2ec66a8 1287 }
007bda35 1288}
b1895692 1289
f932bc9f
AD
1290function categorizeSelectedFeeds() {
1291
1292 if (!xmlhttp_ready(xmlhttp)) {
1293 printLockingError();
1294 return
1295 }
1296
1297 var sel_rows = getSelectedFeeds();
1298
1299 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1300 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1301
1302 if (sel_rows.length > 0) {
1303
1304 notify("Changing category of selected feeds...");
1305
1306 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1307 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1308 xmlhttp.onreadystatechange=feedlist_callback;
1309 xmlhttp.send(null);
1310
1311 } else {
1312
01b3e191 1313 alert("No feeds are selected.");
f932bc9f
AD
1314
1315 }
1316
1317}
69668465
AD
1318
1319function validatePrefsReset() {
1320 return confirm("Reset to defaults?");
1321}
f9cb39ac 1322
6311acbe 1323function browseFeeds(limit) {
f9cb39ac
AD
1324
1325 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1326 xmlhttp.onreadystatechange=infobox_callback;
1327 xmlhttp.send(null);
1328
1329}
a0476535
AD
1330
1331function feedBrowserSubscribe() {
1332 try {
a0476535 1333
c0ae0fdb 1334 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1335
1336 if (selected.length > 0) {
1337 closeInfoBox();
1338 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1339 param_escape(selected.toString()), true);
1340 xmlhttp.onreadystatechange=feedlist_callback;
1341 xmlhttp.send(null);
1342 } else {
1343 alert("No feeds are selected.");
1344 }
1345
1346 } catch (e) {
1347 exception_error("feedBrowserSubscribe", e);
1348 }
1349}
c6232e43 1350
6311acbe 1351function updateBigFeedBrowser(limit) {
c6232e43
AD
1352
1353 if (!xmlhttp_ready(xmlhttp)) {
1354 printLockingError();
1355 return
1356 }
1357
ce3bf408 1358// p_notify("Loading, please wait...");
c6232e43 1359
6311acbe
AD
1360 var query = "backend.php?op=pref-feed-browser";
1361
1362 var limit_sel = document.getElementById("feedBrowserLimit");
1363
1364 if (limit_sel) {
1365 var limit = limit_sel[limit_sel.selectedIndex].value;
1366 query = query + "&limit=" + param_escape(limit);
1367 }
1368
1369 xmlhttp.open("GET", query, true);
c6232e43
AD
1370 xmlhttp.onreadystatechange=feed_browser_callback;
1371 xmlhttp.send(null);
c6232e43
AD
1372}
1373
c2b2aee0 1374function browserToggleExpand(id) {
c6232e43
AD
1375 try {
1376/* if (feed_to_expand && feed_to_expand != id) {
1377 var d = document.getElementById("BRDET-" + feed_to_expand);
1378 d.style.display = "none";
1379 } */
c2b2aee0 1380
ff725e9b
AD
1381 if (!xmlhttp_ready(xmlhttp)) {
1382 printLockingError();
1383 return
1384 }
1385
c2b2aee0
AD
1386 var d = document.getElementById("BRDET-" + id);
1387
1388 if (d.style.display == "block") {
1389 d.style.display = "none";
1390
1391 } else {
c6232e43 1392
c2b2aee0 1393 feed_to_expand = id;
c6232e43 1394
ff725e9b
AD
1395 d.style.display = "block";
1396 d.innerHTML = "Loading, please wait...";
1397
c2b2aee0
AD
1398 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1399 + param_escape(id), true);
1400 xmlhttp.onreadystatechange=expand_feed_callback;
1401 xmlhttp.send(null);
1402 }
c6232e43
AD
1403
1404 } catch (e) {
1405 exception_error("browserExpand", e);
1406 }
1407}
64dc5976
AD
1408
1409function validateNewPassword(form) {
1410 if (form.OLD_PASSWORD.value == "") {
1411 alert("Current password cannot be blank");
1412 return false;
1413 }
1414 if (form.NEW_PASSWORD.value == "") {
1415 alert("New password cannot be blank");
1416 return false;
1417 }
1418 return true;
1419}
ce3bf408
AD
1420
1421function selectPrefRows(kind, select) {
1422
1423 if (kind) {
1424 var opbarid = false;
1425 var nchk = false;
1426 var nrow = false;
1427 var lname = false;
1428
1429 if (kind == "feed") {
1430 opbarid = "feedOpToolbar";
1431 nrow = "FEEDR-";
1432 nchk = "FRCHK-";
1433 lname = "prefFeedList";
1434 } else if (kind == "fcat") {
1435 opbarid = "catOpToolbar";
1436 nrow = "FCATR-";
1437 nchk = "FCHK-";
1438 lname = "prefFeedCatList";
1439 } else if (kind == "filter") {
1440 opbarid = "filterOpToolbar";
1441 nrow = "FILRR-";
1442 nchk = "FICHK-";
1443 lname = "prefFilterList";
1444 } else if (kind == "label") {
1445 opbarid = "labelOpToolbar";
1446 nrow = "LILRR-";
1447 nchk = "LCHK-";
1448 lname = "prefLabelList";
1449 } else if (kind == "user") {
1450 opbarid = "userOpToolbar";
1451 nrow = "UMRR-";
1452 nchk = "UMCHK-";
1453 lname = "prefUserList";
1454 }
1455
1456 if (opbarid) {
1457 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1458 disableContainerChildren(opbarid, !select);
1459 }
1460
1461 }
1462}
1463
1464
1465function toggleSelectPrefRow(sender, kind) {
1466
1467 toggleSelectRow(sender);
1468
1469 if (kind) {
1470 var opbarid = false;
1471 var nsel = -1;
1472
1473 if (kind == "feed") {
1474 opbarid = "feedOpToolbar";
1475 nsel = getSelectedFeeds();
1476 } else if (kind == "fcat") {
1477 opbarid = "catOpToolbar";
1478 nsel = getSelectedFeedCats();
1479 } else if (kind == "filter") {
1480 opbarid = "filterOpToolbar";
1481 nsel = getSelectedFilters();
1482 } else if (kind == "label") {
1483 opbarid = "labelOpToolbar";
1484 nsel = getSelectedLabels();
1485 } else if (kind == "user") {
1486 opbarid = "userOpToolbar";
1487 nsel = getSelectedUsers();
1488 }
1489
1490 if (opbarid && nsel != -1) {
1491 disableContainerChildren(opbarid, nsel == false);
1492 }
1493
1494 }
1495}
1496
c0ae0fdb
AD
1497function toggleSelectFBListRow(sender) {
1498 toggleSelectListRow(sender);
1499 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1500}