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