]> git.wh0rd.org - tt-rss.git/blame - prefs.js
use prototype in form editor
[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;
508a81e1
AD
664}
665
91ff844a
AD
666function feedCatEditCancel() {
667
668 if (!xmlhttp_ready(xmlhttp)) {
669 printLockingError();
670 return
671 }
672
673 active_feed_cat = false;
674
0ceded7a 675// notify("Operation cancelled.");
91ff844a
AD
676
677 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
678 xmlhttp.onreadystatechange=feedlist_callback;
679 xmlhttp.send(null);
680
681}
682
603c27f8
AD
683function feedEditSave() {
684
47c6c988 685 try {
d148926e 686
47c6c988
AD
687 var feed = active_feed;
688
689 if (!xmlhttp_ready(xmlhttp)) {
690 printLockingError();
691 return
692 }
ad815c71 693
14f69488 694 // FIXME: add parameter validation
e3c99f3b 695
14f69488 696 var query = Form.serialize("edit_feed_form");
b0da3a7b 697
47c6c988 698 active_feed = false;
508a81e1 699
14f69488 700 notify("Saving feed...");
673d54ca 701
47c6c988
AD
702 xmlhttp.open("POST", "backend.php", true);
703 xmlhttp.onreadystatechange=feedlist_callback;
704 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
705 xmlhttp.send(query);
706
47c6c988
AD
707 } catch (e) {
708 exception_error("feedEditSave", e);
b0da3a7b 709 }
508a81e1
AD
710}
711
5ddadb4c
AD
712function feedCatEditSave() {
713
714 if (!xmlhttp_ready(xmlhttp)) {
715 printLockingError();
716 return
717 }
718
f0e81ffe 719 notify("Saving category...");
5ddadb4c
AD
720
721 var cat_title = document.getElementById("iedit_title").value;
722
723 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=saveCat&id=" +
724 param_escape(active_feed_cat) + "&title=" + param_escape(cat_title),
725 true);
726 xmlhttp.onreadystatechange=feedlist_callback;
727 xmlhttp.send(null);
728
729 active_feed_cat = false;
730
731}
732
733
d9dde1d6
AD
734function labelTest() {
735
736 var sqlexp = document.getElementById("iedit_expr").value;
737 var descr = document.getElementById("iedit_descr").value;
738
739 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
740 param_escape(sqlexp) + "&descr=" + param_escape(descr), true);
741
742 xmlhttp.onreadystatechange=infobox_callback;
743 xmlhttp.send(null);
744
745}
746
01c9c74a
AD
747function displayHelpInfobox(topic_id) {
748
749 xmlhttp.open("GET", "backend.php?op=help&tid=" +
750 param_escape(topic_id) + "&noheaders=1", true);
751
752 xmlhttp.onreadystatechange=infobox_callback;
753 xmlhttp.send(null);
754
755}
756
48f0adb0
AD
757function labelEditCancel() {
758
759 if (!xmlhttp_ready(xmlhttp)) {
760 printLockingError();
761 return
762 }
763
764 active_label = false;
765
0ceded7a 766// notify("Operation cancelled.");
48f0adb0
AD
767
768 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
769 xmlhttp.onreadystatechange=labellist_callback;
770 xmlhttp.send(null);
771
772}
773
e6cb77a0
AD
774function userEditCancel() {
775
776 if (!xmlhttp_ready(xmlhttp)) {
777 printLockingError();
778 return
779 }
780
781 active_user = false;
782
0ceded7a 783// notify("Operation cancelled.");
e6cb77a0
AD
784
785 xmlhttp.open("GET", "backend.php?op=pref-users", true);
786 xmlhttp.onreadystatechange=userlist_callback;
787 xmlhttp.send(null);
788
789}
48f0adb0 790
a0d53889
AD
791function filterEditCancel() {
792
793 if (!xmlhttp_ready(xmlhttp)) {
794 printLockingError();
795 return
796 }
797
798 active_filter = false;
799
0ceded7a 800// notify("Operation cancelled.");
a0d53889
AD
801
802 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
803 xmlhttp.onreadystatechange=filterlist_callback;
804 xmlhttp.send(null);
805
806}
807
48f0adb0
AD
808function labelEditSave() {
809
810 var label = active_label;
811
812 if (!xmlhttp_ready(xmlhttp)) {
813 printLockingError();
814 return
815 }
816
817 var sqlexp = document.getElementById("iedit_expr").value;
818 var descr = document.getElementById("iedit_descr").value;
819
820// notify("Saving label " + sqlexp + ": " + descr);
821
822 if (sqlexp.length == 0) {
823 notify("SQL expression cannot be blank.");
824 return;
825 }
826
827 if (descr.length == 0) {
828 notify("Caption cannot be blank.");
829 return;
830 }
831
f0e81ffe 832 notify("Saving label...");
dbd9e2f1 833
48f0adb0
AD
834 active_label = false;
835
836 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=editSave&id=" +
837 label + "&s=" + param_escape(sqlexp) + "&d=" + param_escape(descr),
838 true);
839
840 xmlhttp.onreadystatechange=labellist_callback;
841 xmlhttp.send(null);
842
843}
844
e6cb77a0
AD
845function userEditSave() {
846
847 var user = active_user;
848
849 if (!xmlhttp_ready(xmlhttp)) {
850 printLockingError();
851 return
852 }
853
854 var login = document.getElementById("iedit_ulogin").value;
5917a8e4
AD
855 var level = document.getElementById("iedit_ulevel");
856
857 level = level[level.selectedIndex].id;
858
72932a75 859 var email = document.getElementById("iedit_email").value;
e6cb77a0
AD
860
861 if (login.length == 0) {
862 notify("Login cannot be blank.");
863 return;
864 }
865
866 if (level.length == 0) {
867 notify("User level cannot be blank.");
868 return;
869 }
870
871 active_user = false;
872
f0e81ffe 873 notify("Saving user...");
dbd9e2f1 874
e6cb77a0 875 xmlhttp.open("GET", "backend.php?op=pref-users&subop=editSave&id=" +
72932a75
AD
876 user + "&l=" + param_escape(login) + "&al=" + param_escape(level) +
877 "&e=" + param_escape(email), true);
e6cb77a0 878
dbd9e2f1 879 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0
AD
880 xmlhttp.send(null);
881
882}
883
884
a0d53889
AD
885function filterEditSave() {
886
887 var filter = active_filter;
888
889 if (!xmlhttp_ready(xmlhttp)) {
890 printLockingError();
891 return
892 }
893
894 var regexp = document.getElementById("iedit_regexp").value;
25cb5736 895 var match = document.getElementById("iedit_match");
19c9cb11 896
25cb5736 897 var v_match = match[match.selectedIndex].text;
a0d53889 898
ead60402
AD
899 var feed = document.getElementById("iedit_feed");
900 var feed_id = feed[feed.selectedIndex].id;
901
19c9cb11
AD
902 var action = document.getElementById("iedit_filter_action");
903 var action_id = action[action.selectedIndex].id;
904
a0d53889 905 if (regexp.length == 0) {
01b3e191 906 alert("Can't save filter: match expression is blank.");
a0d53889
AD
907 return;
908 }
909
910 active_filter = false;
911
912 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=editSave&id=" +
01b3e191
AD
913 filter + "&r=" + param_escape(regexp) + "&m=" + param_escape(v_match) +
914 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
dbd9e2f1 915
f0e81ffe 916 notify("Saving filter...");
dbd9e2f1 917
a0d53889
AD
918 xmlhttp.onreadystatechange=filterlist_callback;
919 xmlhttp.send(null);
920
921}
922
48f0adb0
AD
923function editSelectedLabel() {
924 var rows = getSelectedLabels();
a0d53889 925
48f0adb0 926 if (rows.length == 0) {
01b3e191 927 alert("No labels are selected.");
48f0adb0 928 return;
a0d53889
AD
929 }
930
48f0adb0 931 if (rows.length > 1) {
01b3e191 932 alert("Please select only one label.");
48f0adb0
AD
933 return;
934 }
a0d53889 935
dbd9e2f1
AD
936 notify("");
937
48f0adb0 938 editLabel(rows[0]);
a0d53889 939
a0d53889
AD
940}
941
e6cb77a0
AD
942function editSelectedUser() {
943 var rows = getSelectedUsers();
944
945 if (rows.length == 0) {
01b3e191 946 alert("No users are selected.");
e6cb77a0
AD
947 return;
948 }
949
950 if (rows.length > 1) {
01b3e191 951 alert("Please select only one user.");
e6cb77a0
AD
952 return;
953 }
954
dbd9e2f1
AD
955 notify("");
956
e6cb77a0
AD
957 editUser(rows[0]);
958}
959
960function resetSelectedUserPass() {
961 var rows = getSelectedUsers();
962
963 if (rows.length == 0) {
01b3e191 964 alert("No users are selected.");
e6cb77a0
AD
965 return;
966 }
967
968 if (rows.length > 1) {
01b3e191 969 alert("Please select only one user.");
e6cb77a0
AD
970 return;
971 }
972
69668465 973 var ok = confirm("Reset password of selected user?");
e6cb77a0 974
69668465
AD
975 if (ok) {
976 notify("Resetting password for selected user...");
977
978 var id = rows[0];
979
980 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
981 param_escape(id), true);
982 xmlhttp.onreadystatechange=userlist_callback;
983 xmlhttp.send(null);
984 }
e6cb77a0
AD
985}
986
717f5e64 987function selectedUserDetails() {
e6cb77a0 988
1a7572cb
AD
989 if (!xmlhttp_ready(xmlhttp)) {
990 printLockingError();
991 return
992 }
993
717f5e64
AD
994 var rows = getSelectedUsers();
995
996 if (rows.length == 0) {
01b3e191 997 alert("No users are selected.");
717f5e64
AD
998 return;
999 }
1000
1001 if (rows.length > 1) {
01b3e191 1002 alert("Please select only one user.");
717f5e64
AD
1003 return;
1004 }
1005
1006 var id = rows[0];
1007
dbd9e2f1
AD
1008 notify("");
1009
1a7572cb 1010 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
1011 xmlhttp.onreadystatechange=infobox_callback;
1012 xmlhttp.send(null);
1013
1014}
1015
1016function selectedFeedDetails() {
1017
1018 if (!xmlhttp_ready(xmlhttp)) {
1019 printLockingError();
1020 return
1021 }
1022
1023 var rows = getSelectedFeeds();
1024
1025 if (rows.length == 0) {
01b3e191 1026 alert("No feeds are selected.");
c6c3a07f
AD
1027 return;
1028 }
1029
01b3e191
AD
1030 if (rows.length > 1) {
1031 notify("Please select only one feed.");
1032 return;
1033 }
c6c3a07f 1034
df268d47 1035// var id = rows[0];
c6c3a07f 1036
dbd9e2f1
AD
1037 notify("");
1038
df268d47
AD
1039 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
1040 param_escape(rows.toString()), true);
c6c3a07f 1041 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 1042 xmlhttp.send(null);
717f5e64
AD
1043
1044}
a0d53889
AD
1045
1046function editSelectedFilter() {
1047 var rows = getSelectedFilters();
1048
1049 if (rows.length == 0) {
01b3e191 1050 alert("No filters are selected.");
a0d53889
AD
1051 return;
1052 }
1053
1054 if (rows.length > 1) {
01b3e191 1055 alert("Please select only one filter.");
a0d53889
AD
1056 return;
1057 }
1058
dbd9e2f1
AD
1059 notify("");
1060
a0d53889
AD
1061 editFilter(rows[0]);
1062
1063}
1064
1065
508a81e1
AD
1066function editSelectedFeed() {
1067 var rows = getSelectedFeeds();
1068
1069 if (rows.length == 0) {
1070 notify("No feeds are selected.");
1071 return;
1072 }
1073
1074 if (rows.length > 1) {
1075 notify("Please select one feed.");
1076 return;
1077 }
1078
dbd9e2f1
AD
1079 notify("");
1080
508a81e1 1081 editFeed(rows[0]);
91ff844a
AD
1082
1083}
1084
1085function editSelectedFeedCat() {
1086 var rows = getSelectedFeedCats();
1087
1088 if (rows.length == 0) {
01b3e191 1089 alert("No categories are selected.");
91ff844a
AD
1090 return;
1091 }
1092
1093 if (rows.length > 1) {
01b3e191 1094 alert("Please select only one category.");
91ff844a
AD
1095 return;
1096 }
1097
1098 notify("");
1099
1100 editFeedCat(rows[0]);
508a81e1
AD
1101
1102}
1103
1cac3c31
AD
1104function piggie_callback() {
1105 var piggie = document.getElementById("piggie");
1106
1107 piggie.style.top = piggie_top;
e0b6a737
AD
1108 piggie.style.backgroundColor = "white";
1109 piggie.style.borderWidth = "1px";
1cac3c31
AD
1110
1111 if (piggie_fwd && piggie_top < 0) {
1112 setTimeout("piggie_callback()", 50);
1113 piggie_top = piggie_top + 10;
1114 } else if (piggie_fwd && piggie_top >= 0) {
1115 piggie_fwd = false;
1116 setTimeout("piggie_callback()", 50);
1117 } else if (!piggie_fwd && piggie_top > -400) {
1118 setTimeout("piggie_callback()", 50);
1119 piggie_top = piggie_top - 10;
1120 } else if (!piggie_fwd && piggie_top <= -400) {
1121 piggie.style.display = "none";
1122 piggie_fwd = true;
1123 }
1124}
1125
33377ef3
AD
1126var piggie_opacity = 0;
1127
1128function piggie2_callback() {
1129 var piggie = document.getElementById("piggie");
1130 piggie.style.top = 0;
1131 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1132 piggie.style.backgroundColor = "transparent";
1133 piggie.style.borderWidth = "0px";
33377ef3
AD
1134
1135 if (piggie_fwd && piggie_opacity < 1) {
1136 setTimeout("piggie2_callback()", 50);
1137 piggie_opacity = piggie_opacity + 0.03;
1138 } else if (piggie_fwd && piggie_opacity >= 1) {
1139 piggie_fwd = false;
1140 setTimeout("piggie2_callback()", 50);
1141 } else if (!piggie_fwd && piggie_opacity > 0) {
1142 setTimeout("piggie2_callback()", 50);
1143 piggie_opacity = piggie_opacity - 0.03;
1144 } else if (!piggie_fwd && piggie_opacity <= 0) {
1145 piggie.style.display = "none";
1146 piggie_fwd = true;
1147 }
1148}
1149
13ad9102
AD
1150function localPiggieFunction(enable) {
1151 if (enable) {
1cac3c31 1152 var piggie = document.getElementById("piggie");
508a81e1 1153 piggie.style.display = "block";
33377ef3 1154
292a8a12 1155 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
33377ef3
AD
1156 piggie2_callback();
1157 } else {
1158 piggie_callback();
1159 }
508a81e1 1160 }
508a81e1
AD
1161}
1162
9f311df6
AD
1163function validateOpmlImport() {
1164
1165 var opml_file = document.getElementById("opml_file");
1166
1167 if (opml_file.value.length == 0) {
01b3e191 1168 alert("No OPML file to upload.");
9f311df6
AD
1169 return false;
1170 } else {
1171 return true;
1172 }
1173}
1174
a0d53889
AD
1175function updateFilterList() {
1176
1177 if (!xmlhttp_ready(xmlhttp)) {
1178 printLockingError();
1179 return
1180 }
1181
f5a50b25
AD
1182// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1183
ce3bf408 1184// p_notify("Loading, please wait...");
a0d53889
AD
1185
1186 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1187 xmlhttp.onreadystatechange=filterlist_callback;
1188 xmlhttp.send(null);
1189
1190}
1191
48f0adb0
AD
1192function updateLabelList() {
1193
1194 if (!xmlhttp_ready(xmlhttp)) {
1195 printLockingError();
1196 return
1197 }
1198
ce3bf408 1199// p_notify("Loading, please wait...");
f5a50b25
AD
1200
1201// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1202
1203 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1204 xmlhttp.onreadystatechange=labellist_callback;
1205 xmlhttp.send(null);
48f0adb0
AD
1206}
1207
4255b24c
AD
1208function updatePrefsList() {
1209
1210 if (!xmlhttp_ready(xmlhttp)) {
1211 printLockingError();
1212 return
1213 }
1214
ce3bf408 1215// p_notify("Loading, please wait...");
4255b24c
AD
1216
1217 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1218 xmlhttp.onreadystatechange=prefslist_callback;
1219 xmlhttp.send(null);
1220
1221}
1222
a7f22b70
AD
1223function selectTab(id, noupdate) {
1224
1225// alert(id);
48f0adb0 1226
c6c3a07f
AD
1227 if (!xmlhttp_ready(xmlhttp)) {
1228 printLockingError();
1229 return
1230 }
1231
a7f22b70
AD
1232 if (!noupdate) {
1233
7f74a9da
AD
1234 notify("Loading, please wait...", true);
1235
673d54ca
AD
1236 // clean up all current selections, just in case
1237 active_feed = false;
1238 active_feed_cat = false;
1239 active_filter = false;
1240 active_label = false;
1241 active_user = false;
1242
a7f22b70
AD
1243 if (id == "feedConfig") {
1244 updateFeedList();
1245 } else if (id == "filterConfig") {
1246 updateFilterList();
1247 } else if (id == "labelConfig") {
1248 updateLabelList();
1249 } else if (id == "genConfig") {
1250 updatePrefsList();
1251 } else if (id == "userConfig") {
1252 updateUsersList();
1253 } else if (id == "feedBrowser") {
1254 updateBigFeedBrowser();
1255 }
a0d53889 1256 }
f5a50b25
AD
1257
1258 var tab = document.getElementById(active_tab + "Tab");
1259
1260 if (tab) {
1261 if (tab.className.match("Selected")) {
1262 tab.className = "prefsTab";
1263 }
1264 }
1265
1266 tab = document.getElementById(id + "Tab");
1267
1268 if (tab) {
1269 if (!tab.className.match("Selected")) {
1270 tab.className = tab.className + "Selected";
1271 }
1272 }
1273
1274 active_tab = id;
1275
4da47970
AD
1276 setCookie('ttrss_pref_acttab', active_tab);
1277
a0d53889
AD
1278}
1279
007bda35 1280function init() {
e2ec66a8 1281
7719618b
AD
1282 try {
1283
97dcd654
AD
1284 if (arguments.callee.done) return;
1285 arguments.callee.done = true;
1286
7719618b
AD
1287 // IE kludge
1288 if (!xmlhttp) {
1289 document.getElementById("prefContent").innerHTML =
1290 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1291 "to function properly. Your browser doesn't seem to support it.";
1292 return;
1293 }
4da47970
AD
1294
1295 active_tab = getCookie("ttrss_pref_acttab");
1296 if (!active_tab) active_tab = "genConfig";
1297 selectTab(active_tab);
7719618b
AD
1298
1299 document.onkeydown = hotkey_handler;
1300 notify("");
1301 } catch (e) {
1302 exception_error("init", e);
e2ec66a8 1303 }
007bda35 1304}
b1895692 1305
f932bc9f
AD
1306function categorizeSelectedFeeds() {
1307
1308 if (!xmlhttp_ready(xmlhttp)) {
1309 printLockingError();
1310 return
1311 }
1312
1313 var sel_rows = getSelectedFeeds();
1314
1315 var cat_sel = document.getElementById("sfeed_set_fcat");
1316 var cat_id = cat_sel[cat_sel.selectedIndex].id;
1317
1318 if (sel_rows.length > 0) {
1319
1320 notify("Changing category of selected feeds...");
1321
1322 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1323 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1324 xmlhttp.onreadystatechange=feedlist_callback;
1325 xmlhttp.send(null);
1326
1327 } else {
1328
01b3e191 1329 alert("No feeds are selected.");
f932bc9f
AD
1330
1331 }
1332
1333}
69668465
AD
1334
1335function validatePrefsReset() {
1336 return confirm("Reset to defaults?");
1337}
f9cb39ac 1338
6311acbe 1339function browseFeeds(limit) {
f9cb39ac
AD
1340
1341 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1342 xmlhttp.onreadystatechange=infobox_callback;
1343 xmlhttp.send(null);
1344
1345}
a0476535
AD
1346
1347function feedBrowserSubscribe() {
1348 try {
a0476535 1349
c0ae0fdb 1350 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1351
1352 if (selected.length > 0) {
1353 closeInfoBox();
1354 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1355 param_escape(selected.toString()), true);
1356 xmlhttp.onreadystatechange=feedlist_callback;
1357 xmlhttp.send(null);
1358 } else {
1359 alert("No feeds are selected.");
1360 }
1361
1362 } catch (e) {
1363 exception_error("feedBrowserSubscribe", e);
1364 }
1365}
c6232e43 1366
6311acbe 1367function updateBigFeedBrowser(limit) {
c6232e43
AD
1368
1369 if (!xmlhttp_ready(xmlhttp)) {
1370 printLockingError();
1371 return
1372 }
1373
ce3bf408 1374// p_notify("Loading, please wait...");
c6232e43 1375
6311acbe
AD
1376 var query = "backend.php?op=pref-feed-browser";
1377
1378 var limit_sel = document.getElementById("feedBrowserLimit");
1379
1380 if (limit_sel) {
1381 var limit = limit_sel[limit_sel.selectedIndex].value;
1382 query = query + "&limit=" + param_escape(limit);
1383 }
1384
1385 xmlhttp.open("GET", query, true);
c6232e43
AD
1386 xmlhttp.onreadystatechange=feed_browser_callback;
1387 xmlhttp.send(null);
c6232e43
AD
1388}
1389
c2b2aee0 1390function browserToggleExpand(id) {
c6232e43
AD
1391 try {
1392/* if (feed_to_expand && feed_to_expand != id) {
1393 var d = document.getElementById("BRDET-" + feed_to_expand);
1394 d.style.display = "none";
1395 } */
c2b2aee0 1396
ff725e9b
AD
1397 if (!xmlhttp_ready(xmlhttp)) {
1398 printLockingError();
1399 return
1400 }
1401
c2b2aee0
AD
1402 var d = document.getElementById("BRDET-" + id);
1403
1404 if (d.style.display == "block") {
1405 d.style.display = "none";
1406
1407 } else {
c6232e43 1408
c2b2aee0 1409 feed_to_expand = id;
c6232e43 1410
ff725e9b
AD
1411 d.style.display = "block";
1412 d.innerHTML = "Loading, please wait...";
1413
c2b2aee0
AD
1414 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1415 + param_escape(id), true);
1416 xmlhttp.onreadystatechange=expand_feed_callback;
1417 xmlhttp.send(null);
1418 }
c6232e43
AD
1419
1420 } catch (e) {
1421 exception_error("browserExpand", e);
1422 }
1423}
64dc5976
AD
1424
1425function validateNewPassword(form) {
1426 if (form.OLD_PASSWORD.value == "") {
1427 alert("Current password cannot be blank");
1428 return false;
1429 }
1430 if (form.NEW_PASSWORD.value == "") {
1431 alert("New password cannot be blank");
1432 return false;
1433 }
1434 return true;
1435}
ce3bf408
AD
1436
1437function selectPrefRows(kind, select) {
1438
1439 if (kind) {
1440 var opbarid = false;
1441 var nchk = false;
1442 var nrow = false;
1443 var lname = false;
1444
1445 if (kind == "feed") {
1446 opbarid = "feedOpToolbar";
1447 nrow = "FEEDR-";
1448 nchk = "FRCHK-";
1449 lname = "prefFeedList";
1450 } else if (kind == "fcat") {
1451 opbarid = "catOpToolbar";
1452 nrow = "FCATR-";
1453 nchk = "FCHK-";
1454 lname = "prefFeedCatList";
1455 } else if (kind == "filter") {
1456 opbarid = "filterOpToolbar";
1457 nrow = "FILRR-";
1458 nchk = "FICHK-";
1459 lname = "prefFilterList";
1460 } else if (kind == "label") {
1461 opbarid = "labelOpToolbar";
1462 nrow = "LILRR-";
1463 nchk = "LCHK-";
1464 lname = "prefLabelList";
1465 } else if (kind == "user") {
1466 opbarid = "userOpToolbar";
1467 nrow = "UMRR-";
1468 nchk = "UMCHK-";
1469 lname = "prefUserList";
1470 }
1471
1472 if (opbarid) {
1473 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1474 disableContainerChildren(opbarid, !select);
1475 }
1476
1477 }
1478}
1479
1480
1481function toggleSelectPrefRow(sender, kind) {
1482
1483 toggleSelectRow(sender);
1484
1485 if (kind) {
1486 var opbarid = false;
1487 var nsel = -1;
1488
1489 if (kind == "feed") {
1490 opbarid = "feedOpToolbar";
1491 nsel = getSelectedFeeds();
1492 } else if (kind == "fcat") {
1493 opbarid = "catOpToolbar";
1494 nsel = getSelectedFeedCats();
1495 } else if (kind == "filter") {
1496 opbarid = "filterOpToolbar";
1497 nsel = getSelectedFilters();
1498 } else if (kind == "label") {
1499 opbarid = "labelOpToolbar";
1500 nsel = getSelectedLabels();
1501 } else if (kind == "user") {
1502 opbarid = "userOpToolbar";
1503 nsel = getSelectedUsers();
1504 }
1505
1506 if (opbarid && nsel != -1) {
1507 disableContainerChildren(opbarid, nsel == false);
1508 }
1509
1510 }
1511}
1512
c0ae0fdb
AD
1513function toggleSelectFBListRow(sender) {
1514 toggleSelectListRow(sender);
1515 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1516}