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