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