]> git.wh0rd.org - tt-rss.git/blame - prefs.js
filter editor uses prototype
[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
07164479
AD
341 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
342 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
a0d53889 343
07164479
AD
344 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
345 xmlhttp.onreadystatechange=infobox_callback;
a0d53889 346 xmlhttp.send(null);
a0d53889
AD
347}
348
331900c6
AD
349function editFeed(feed) {
350
508a81e1
AD
351// notify("Editing feed...");
352
c0e5a40e 353 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
354 printLockingError();
355 return
356 }
331900c6 357
673d54ca 358 // clean selection from all rows & select row being edited
0ea4fb50 359 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 360 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
361
362 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
3c5783b7 363 param_escape(feed), true);
0ea4fb50
AD
364
365 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
366 xmlhttp.send(null);
367
368}
369
91ff844a 370function editFeedCat(cat) {
48f0adb0 371
91ff844a
AD
372 if (!xmlhttp_ready(xmlhttp)) {
373 printLockingError();
374 return
48f0adb0
AD
375 }
376
91ff844a 377 active_feed_cat = cat;
e6cb77a0 378
91ff844a
AD
379 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
380 param_escape(cat), true);
381 xmlhttp.onreadystatechange=feedlist_callback;
382 xmlhttp.send(null);
e6cb77a0 383
e6cb77a0
AD
384}
385
91ff844a
AD
386function getSelectedLabels() {
387 return getSelectedTableRowIds("prefLabelList", "LILRR");
388}
48f0adb0 389
91ff844a
AD
390function getSelectedUsers() {
391 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
392}
393
83fe4d6d 394function getSelectedFeeds() {
91ff844a
AD
395 return getSelectedTableRowIds("prefFeedList", "FEEDR");
396}
331900c6 397
91ff844a
AD
398function getSelectedFilters() {
399 return getSelectedTableRowIds("prefFilterList", "FILRR");
400}
331900c6 401
91ff844a
AD
402function getSelectedFeedCats() {
403 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
404}
405
c0ae0fdb
AD
406function getSelectedFeedsFromBrowser() {
407
408 var list = document.getElementById("browseFeedList");
409 if (!list) list = document.getElementById("browseBigFeedList");
410
411 var selected = new Array();
412
413 for (i = 0; i < list.childNodes.length; i++) {
414 var child = list.childNodes[i];
415 if (child.id && child.id.match("FBROW-")) {
416 var id = child.id.replace("FBROW-", "");
417
418 var cb = document.getElementById("FBCHK-" + id);
419
420 if (cb.checked) {
421 selected.push(id);
422 }
423 }
424 }
425
426 return selected;
427}
428
48f0adb0
AD
429function removeSelectedLabels() {
430
431 if (!xmlhttp_ready(xmlhttp)) {
432 printLockingError();
433 return
434 }
435
436 var sel_rows = getSelectedLabels();
437
438 if (sel_rows.length > 0) {
439
69668465 440 var ok = confirm("Remove selected labels?");
48f0adb0 441
69668465
AD
442 if (ok) {
443 notify("Removing selected labels...");
444
445 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
446 param_escape(sel_rows.toString()), true);
447 xmlhttp.onreadystatechange=labellist_callback;
448 xmlhttp.send(null);
449 }
48f0adb0 450 } else {
01b3e191 451 alert("No labels are selected.");
48f0adb0
AD
452 }
453}
454
e6cb77a0
AD
455function removeSelectedUsers() {
456
457 if (!xmlhttp_ready(xmlhttp)) {
458 printLockingError();
459 return
460 }
461
462 var sel_rows = getSelectedUsers();
463
464 if (sel_rows.length > 0) {
465
69668465 466 var ok = confirm("Remove selected users?");
e6cb77a0 467
69668465
AD
468 if (ok) {
469 notify("Removing selected users...");
470
471 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
472 param_escape(sel_rows.toString()), true);
473 xmlhttp.onreadystatechange=userlist_callback;
474 xmlhttp.send(null);
475 }
e6cb77a0
AD
476
477 } else {
01b3e191 478 alert("No users are selected.");
e6cb77a0
AD
479 }
480}
481
48f0adb0
AD
482function removeSelectedFilters() {
483
484 if (!xmlhttp_ready(xmlhttp)) {
485 printLockingError();
486 return
487 }
488
489 var sel_rows = getSelectedFilters();
490
491 if (sel_rows.length > 0) {
492
69668465 493 var ok = confirm("Remove selected filters?");
48f0adb0 494
69668465
AD
495 if (ok) {
496 notify("Removing selected filters...");
497
498 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
499 param_escape(sel_rows.toString()), true);
500 xmlhttp.onreadystatechange=filterlist_callback;
501 xmlhttp.send(null);
502 }
48f0adb0 503 } else {
01b3e191 504 alert("No filters are selected.");
48f0adb0
AD
505 }
506}
507
508
83fe4d6d
AD
509function removeSelectedFeeds() {
510
c0e5a40e 511 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
512 printLockingError();
513 return
514 }
515
83fe4d6d
AD
516 var sel_rows = getSelectedFeeds();
517
331900c6
AD
518 if (sel_rows.length > 0) {
519
1d7bf5a0 520 var ok = confirm("Unsubscribe from selected feeds?");
331900c6 521
69668465
AD
522 if (ok) {
523
1d7bf5a0 524 notify("Unsubscribing from selected feeds...");
69668465
AD
525
526 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
527 param_escape(sel_rows.toString()), true);
528 xmlhttp.onreadystatechange=feedlist_callback;
529 xmlhttp.send(null);
530 }
71ad3959 531
71ad3959 532 } else {
331900c6 533
01b3e191 534 alert("No feeds are selected.");
331900c6 535
71ad3959
AD
536 }
537
538}
007bda35 539
91ff844a
AD
540function removeSelectedFeedCats() {
541
542 if (!xmlhttp_ready(xmlhttp)) {
543 printLockingError();
544 return
545 }
546
547 var sel_rows = getSelectedFeedCats();
548
549 if (sel_rows.length > 0) {
550
69668465 551 var ok = confirm("Remove selected categories?");
91ff844a 552
69668465
AD
553 if (ok) {
554 notify("Removing selected categories...");
555
556 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
557 param_escape(sel_rows.toString()), true);
558 xmlhttp.onreadystatechange=feedlist_callback;
559 xmlhttp.send(null);
560 }
91ff844a
AD
561
562 } else {
563
01b3e191 564 alert("No categories are selected.");
91ff844a
AD
565
566 }
567
568}
569
508a81e1
AD
570function feedEditCancel() {
571
c0e5a40e 572 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
573 printLockingError();
574 return
575 }
576
327a3bbe
AD
577 closeInfoBox();
578
673d54ca 579 selectPrefRows('feed', false); // cleanup feed selection
508a81e1
AD
580
581}
582
91ff844a
AD
583function feedCatEditCancel() {
584
585 if (!xmlhttp_ready(xmlhttp)) {
586 printLockingError();
587 return
588 }
589
590 active_feed_cat = false;
591
0ceded7a 592// notify("Operation cancelled.");
91ff844a
AD
593
594 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
595 xmlhttp.onreadystatechange=feedlist_callback;
596 xmlhttp.send(null);
597
598}
599
603c27f8
AD
600function feedEditSave() {
601
47c6c988 602 try {
47c6c988
AD
603
604 if (!xmlhttp_ready(xmlhttp)) {
605 printLockingError();
606 return
607 }
ad815c71 608
14f69488 609 // FIXME: add parameter validation
e3c99f3b 610
14f69488 611 var query = Form.serialize("edit_feed_form");
b0da3a7b 612
14f69488 613 notify("Saving feed...");
673d54ca 614
47c6c988
AD
615 xmlhttp.open("POST", "backend.php", true);
616 xmlhttp.onreadystatechange=feedlist_callback;
617 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
618 xmlhttp.send(query);
619
59a543f0
AD
620 closeInfoBox();
621
c14b5566
AD
622 return false;
623
47c6c988
AD
624 } catch (e) {
625 exception_error("feedEditSave", e);
b0da3a7b 626 }
508a81e1
AD
627}
628
5ddadb4c
AD
629function feedCatEditSave() {
630
631 if (!xmlhttp_ready(xmlhttp)) {
632 printLockingError();
633 return
634 }
635
f0e81ffe 636 notify("Saving category...");
5ddadb4c 637
0666e120
AD
638 var query = Form.serialize("feed_cat_edit_form");
639
640 xmlhttp.open("GET", "backend.php?" + query, true);
5ddadb4c
AD
641 xmlhttp.onreadystatechange=feedlist_callback;
642 xmlhttp.send(null);
643
644 active_feed_cat = false;
645
646}
647
648
d9dde1d6
AD
649function labelTest() {
650
f3120e5a
AD
651 var form = document.forms['label_edit_form'];
652
653 var sql_exp = form.sql_exp.value;
654 var description = form.description.value;
d9dde1d6
AD
655
656 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
f3120e5a 657 param_escape(sql_exp) + "&descr=" + param_escape(description), true);
d9dde1d6
AD
658
659 xmlhttp.onreadystatechange=infobox_callback;
660 xmlhttp.send(null);
661
662}
663
01c9c74a
AD
664function displayHelpInfobox(topic_id) {
665
666 xmlhttp.open("GET", "backend.php?op=help&tid=" +
667 param_escape(topic_id) + "&noheaders=1", true);
668
669 xmlhttp.onreadystatechange=infobox_callback;
670 xmlhttp.send(null);
671
672}
673
48f0adb0
AD
674function labelEditCancel() {
675
676 if (!xmlhttp_ready(xmlhttp)) {
677 printLockingError();
678 return
679 }
680
681 active_label = false;
682
0ceded7a 683// notify("Operation cancelled.");
48f0adb0
AD
684
685 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
686 xmlhttp.onreadystatechange=labellist_callback;
687 xmlhttp.send(null);
688
689}
690
e6cb77a0
AD
691function userEditCancel() {
692
693 if (!xmlhttp_ready(xmlhttp)) {
694 printLockingError();
695 return
696 }
697
3c5783b7 698 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 699 closeInfoBox();
e6cb77a0 700}
48f0adb0 701
a0d53889
AD
702function filterEditCancel() {
703
704 if (!xmlhttp_ready(xmlhttp)) {
705 printLockingError();
706 return
707 }
07164479
AD
708
709 selectPrefRows('filter', false); // cleanup feed selection
710 closeInfoBox();
a0d53889
AD
711}
712
48f0adb0
AD
713function labelEditSave() {
714
715 var label = active_label;
716
717 if (!xmlhttp_ready(xmlhttp)) {
718 printLockingError();
719 return
720 }
721
3c5783b7
AD
722 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
723 var description = document.forms["label_edit_form"].description.value;
48f0adb0 724
3c5783b7
AD
725 if (sql_exp.length == 0) {
726 alert("SQL Expression cannot be blank.");
48f0adb0
AD
727 return;
728 }
729
3c5783b7
AD
730 if (description.length == 0) {
731 alert("Caption field cannot be blank.");
48f0adb0 732 return;
3c5783b7 733 }
48f0adb0 734
f0e81ffe 735 notify("Saving label...");
dbd9e2f1 736
48f0adb0
AD
737 active_label = false;
738
f3120e5a
AD
739 query = Form.serialize("label_edit_form");
740
741 xmlhttp.open("GET", "backend.php?" + query, true);
48f0adb0
AD
742
743 xmlhttp.onreadystatechange=labellist_callback;
744 xmlhttp.send(null);
745
746}
747
e6cb77a0
AD
748function userEditSave() {
749
e6cb77a0
AD
750 if (!xmlhttp_ready(xmlhttp)) {
751 printLockingError();
752 return
753 }
754
3c5783b7 755 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
756
757 if (login.length == 0) {
3c5783b7 758 alert("Login field cannot be blank.");
e6cb77a0
AD
759 return;
760 }
3c5783b7 761
f0e81ffe 762 notify("Saving user...");
3c5783b7
AD
763
764 var query = Form.serialize("user_edit_form");
765
766 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 767 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 768 xmlhttp.send(null);
e6cb77a0
AD
769}
770
771
a0d53889
AD
772function filterEditSave() {
773
a0d53889
AD
774 if (!xmlhttp_ready(xmlhttp)) {
775 printLockingError();
776 return
777 }
778
3c5783b7
AD
779 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
780
781 if (reg_exp.length == 0) {
782 alert("Filter expression field cannot be blank.");
783 return;
784 }
a0d53889 785
7e939457 786 notify("Saving filter...");
a0d53889 787
7e939457 788 var query = Form.serialize("filter_edit_form");
dbd9e2f1 789
07164479
AD
790 closeInfoBox();
791
7e939457 792 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 793 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 794 xmlhttp.send(null);
a0d53889
AD
795
796}
797
48f0adb0
AD
798function editSelectedLabel() {
799 var rows = getSelectedLabels();
a0d53889 800
48f0adb0 801 if (rows.length == 0) {
01b3e191 802 alert("No labels are selected.");
48f0adb0 803 return;
a0d53889
AD
804 }
805
48f0adb0 806 if (rows.length > 1) {
01b3e191 807 alert("Please select only one label.");
48f0adb0
AD
808 return;
809 }
a0d53889 810
dbd9e2f1
AD
811 notify("");
812
48f0adb0 813 editLabel(rows[0]);
a0d53889 814
a0d53889
AD
815}
816
e6cb77a0
AD
817function editSelectedUser() {
818 var rows = getSelectedUsers();
819
820 if (rows.length == 0) {
01b3e191 821 alert("No users are selected.");
e6cb77a0
AD
822 return;
823 }
824
825 if (rows.length > 1) {
01b3e191 826 alert("Please select only one user.");
e6cb77a0
AD
827 return;
828 }
829
dbd9e2f1
AD
830 notify("");
831
e6cb77a0
AD
832 editUser(rows[0]);
833}
834
835function resetSelectedUserPass() {
836 var rows = getSelectedUsers();
837
838 if (rows.length == 0) {
01b3e191 839 alert("No users are selected.");
e6cb77a0
AD
840 return;
841 }
842
843 if (rows.length > 1) {
01b3e191 844 alert("Please select only one user.");
e6cb77a0
AD
845 return;
846 }
847
69668465 848 var ok = confirm("Reset password of selected user?");
e6cb77a0 849
69668465
AD
850 if (ok) {
851 notify("Resetting password for selected user...");
852
853 var id = rows[0];
854
855 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
856 param_escape(id), true);
857 xmlhttp.onreadystatechange=userlist_callback;
858 xmlhttp.send(null);
859 }
e6cb77a0
AD
860}
861
717f5e64 862function selectedUserDetails() {
e6cb77a0 863
1a7572cb
AD
864 if (!xmlhttp_ready(xmlhttp)) {
865 printLockingError();
866 return
867 }
868
717f5e64
AD
869 var rows = getSelectedUsers();
870
871 if (rows.length == 0) {
01b3e191 872 alert("No users are selected.");
717f5e64
AD
873 return;
874 }
875
876 if (rows.length > 1) {
01b3e191 877 alert("Please select only one user.");
717f5e64
AD
878 return;
879 }
880
881 var id = rows[0];
882
dbd9e2f1
AD
883 notify("");
884
1a7572cb 885 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
886 xmlhttp.onreadystatechange=infobox_callback;
887 xmlhttp.send(null);
888
889}
890
891function selectedFeedDetails() {
892
893 if (!xmlhttp_ready(xmlhttp)) {
894 printLockingError();
895 return
896 }
897
898 var rows = getSelectedFeeds();
899
900 if (rows.length == 0) {
01b3e191 901 alert("No feeds are selected.");
c6c3a07f
AD
902 return;
903 }
904
01b3e191
AD
905 if (rows.length > 1) {
906 notify("Please select only one feed.");
907 return;
908 }
c6c3a07f 909
df268d47 910// var id = rows[0];
c6c3a07f 911
dbd9e2f1
AD
912 notify("");
913
df268d47
AD
914 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
915 param_escape(rows.toString()), true);
c6c3a07f 916 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 917 xmlhttp.send(null);
717f5e64
AD
918
919}
a0d53889
AD
920
921function editSelectedFilter() {
922 var rows = getSelectedFilters();
923
924 if (rows.length == 0) {
01b3e191 925 alert("No filters are selected.");
a0d53889
AD
926 return;
927 }
928
929 if (rows.length > 1) {
01b3e191 930 alert("Please select only one filter.");
a0d53889
AD
931 return;
932 }
933
dbd9e2f1
AD
934 notify("");
935
a0d53889
AD
936 editFilter(rows[0]);
937
938}
939
940
508a81e1
AD
941function editSelectedFeed() {
942 var rows = getSelectedFeeds();
943
944 if (rows.length == 0) {
945 notify("No feeds are selected.");
946 return;
947 }
948
949 if (rows.length > 1) {
950 notify("Please select one feed.");
951 return;
952 }
953
dbd9e2f1
AD
954 notify("");
955
508a81e1 956 editFeed(rows[0]);
91ff844a
AD
957
958}
959
960function editSelectedFeedCat() {
961 var rows = getSelectedFeedCats();
962
963 if (rows.length == 0) {
01b3e191 964 alert("No categories are selected.");
91ff844a
AD
965 return;
966 }
967
968 if (rows.length > 1) {
01b3e191 969 alert("Please select only one category.");
91ff844a
AD
970 return;
971 }
972
973 notify("");
974
975 editFeedCat(rows[0]);
508a81e1
AD
976
977}
978
1cac3c31
AD
979function piggie_callback() {
980 var piggie = document.getElementById("piggie");
981
982 piggie.style.top = piggie_top;
e0b6a737
AD
983 piggie.style.backgroundColor = "white";
984 piggie.style.borderWidth = "1px";
1cac3c31
AD
985
986 if (piggie_fwd && piggie_top < 0) {
987 setTimeout("piggie_callback()", 50);
988 piggie_top = piggie_top + 10;
989 } else if (piggie_fwd && piggie_top >= 0) {
990 piggie_fwd = false;
991 setTimeout("piggie_callback()", 50);
992 } else if (!piggie_fwd && piggie_top > -400) {
993 setTimeout("piggie_callback()", 50);
994 piggie_top = piggie_top - 10;
995 } else if (!piggie_fwd && piggie_top <= -400) {
996 piggie.style.display = "none";
997 piggie_fwd = true;
998 }
999}
1000
33377ef3
AD
1001var piggie_opacity = 0;
1002
1003function piggie2_callback() {
1004 var piggie = document.getElementById("piggie");
1005 piggie.style.top = 0;
1006 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1007 piggie.style.backgroundColor = "transparent";
1008 piggie.style.borderWidth = "0px";
33377ef3
AD
1009
1010 if (piggie_fwd && piggie_opacity < 1) {
1011 setTimeout("piggie2_callback()", 50);
1012 piggie_opacity = piggie_opacity + 0.03;
1013 } else if (piggie_fwd && piggie_opacity >= 1) {
1014 piggie_fwd = false;
1015 setTimeout("piggie2_callback()", 50);
1016 } else if (!piggie_fwd && piggie_opacity > 0) {
1017 setTimeout("piggie2_callback()", 50);
1018 piggie_opacity = piggie_opacity - 0.03;
1019 } else if (!piggie_fwd && piggie_opacity <= 0) {
1020 piggie.style.display = "none";
1021 piggie_fwd = true;
1022 }
1023}
1024
13ad9102
AD
1025function localPiggieFunction(enable) {
1026 if (enable) {
1cac3c31 1027 var piggie = document.getElementById("piggie");
508a81e1 1028 piggie.style.display = "block";
33377ef3 1029
292a8a12 1030 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
33377ef3
AD
1031 piggie2_callback();
1032 } else {
1033 piggie_callback();
1034 }
508a81e1 1035 }
508a81e1
AD
1036}
1037
9f311df6
AD
1038function validateOpmlImport() {
1039
1040 var opml_file = document.getElementById("opml_file");
1041
1042 if (opml_file.value.length == 0) {
01b3e191 1043 alert("No OPML file to upload.");
9f311df6
AD
1044 return false;
1045 } else {
1046 return true;
1047 }
1048}
1049
a0d53889
AD
1050function updateFilterList() {
1051
1052 if (!xmlhttp_ready(xmlhttp)) {
1053 printLockingError();
1054 return
1055 }
1056
f5a50b25
AD
1057// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1058
ce3bf408 1059// p_notify("Loading, please wait...");
a0d53889
AD
1060
1061 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1062 xmlhttp.onreadystatechange=filterlist_callback;
1063 xmlhttp.send(null);
1064
1065}
1066
48f0adb0
AD
1067function updateLabelList() {
1068
1069 if (!xmlhttp_ready(xmlhttp)) {
1070 printLockingError();
1071 return
1072 }
1073
ce3bf408 1074// p_notify("Loading, please wait...");
f5a50b25
AD
1075
1076// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1077
1078 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1079 xmlhttp.onreadystatechange=labellist_callback;
1080 xmlhttp.send(null);
48f0adb0
AD
1081}
1082
4255b24c
AD
1083function updatePrefsList() {
1084
1085 if (!xmlhttp_ready(xmlhttp)) {
1086 printLockingError();
1087 return
1088 }
1089
ce3bf408 1090// p_notify("Loading, please wait...");
4255b24c
AD
1091
1092 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1093 xmlhttp.onreadystatechange=prefslist_callback;
1094 xmlhttp.send(null);
1095
1096}
1097
a7f22b70
AD
1098function selectTab(id, noupdate) {
1099
1100// alert(id);
48f0adb0 1101
c6c3a07f
AD
1102 if (!xmlhttp_ready(xmlhttp)) {
1103 printLockingError();
1104 return
1105 }
1106
a7f22b70
AD
1107 if (!noupdate) {
1108
7f74a9da
AD
1109 notify("Loading, please wait...", true);
1110
59a543f0
AD
1111 // close active infobox if needed
1112 closeInfoBox();
1113
673d54ca 1114 // clean up all current selections, just in case
673d54ca 1115 active_feed_cat = false;
673d54ca 1116 active_label = false;
673d54ca 1117
a7f22b70
AD
1118 if (id == "feedConfig") {
1119 updateFeedList();
1120 } else if (id == "filterConfig") {
1121 updateFilterList();
1122 } else if (id == "labelConfig") {
1123 updateLabelList();
1124 } else if (id == "genConfig") {
1125 updatePrefsList();
1126 } else if (id == "userConfig") {
1127 updateUsersList();
1128 } else if (id == "feedBrowser") {
1129 updateBigFeedBrowser();
1130 }
a0d53889 1131 }
f5a50b25
AD
1132
1133 var tab = document.getElementById(active_tab + "Tab");
1134
1135 if (tab) {
1136 if (tab.className.match("Selected")) {
1137 tab.className = "prefsTab";
1138 }
1139 }
1140
1141 tab = document.getElementById(id + "Tab");
1142
1143 if (tab) {
1144 if (!tab.className.match("Selected")) {
1145 tab.className = tab.className + "Selected";
1146 }
1147 }
1148
1149 active_tab = id;
1150
4da47970
AD
1151 setCookie('ttrss_pref_acttab', active_tab);
1152
a0d53889
AD
1153}
1154
007bda35 1155function init() {
e2ec66a8 1156
7719618b
AD
1157 try {
1158
97dcd654
AD
1159 if (arguments.callee.done) return;
1160 arguments.callee.done = true;
1161
7719618b
AD
1162 // IE kludge
1163 if (!xmlhttp) {
1164 document.getElementById("prefContent").innerHTML =
1165 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1166 "to function properly. Your browser doesn't seem to support it.";
1167 return;
1168 }
4da47970
AD
1169
1170 active_tab = getCookie("ttrss_pref_acttab");
1171 if (!active_tab) active_tab = "genConfig";
1172 selectTab(active_tab);
7719618b
AD
1173
1174 document.onkeydown = hotkey_handler;
1175 notify("");
1176 } catch (e) {
1177 exception_error("init", e);
e2ec66a8 1178 }
007bda35 1179}
b1895692 1180
f932bc9f
AD
1181function categorizeSelectedFeeds() {
1182
1183 if (!xmlhttp_ready(xmlhttp)) {
1184 printLockingError();
1185 return
1186 }
1187
1188 var sel_rows = getSelectedFeeds();
1189
1190 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1191 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1192
1193 if (sel_rows.length > 0) {
1194
1195 notify("Changing category of selected feeds...");
1196
1197 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1198 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1199 xmlhttp.onreadystatechange=feedlist_callback;
1200 xmlhttp.send(null);
1201
1202 } else {
1203
01b3e191 1204 alert("No feeds are selected.");
f932bc9f
AD
1205
1206 }
1207
1208}
69668465
AD
1209
1210function validatePrefsReset() {
1211 return confirm("Reset to defaults?");
1212}
f9cb39ac 1213
6311acbe 1214function browseFeeds(limit) {
f9cb39ac
AD
1215
1216 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1217 xmlhttp.onreadystatechange=infobox_callback;
1218 xmlhttp.send(null);
1219
1220}
a0476535
AD
1221
1222function feedBrowserSubscribe() {
1223 try {
a0476535 1224
c0ae0fdb 1225 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1226
1227 if (selected.length > 0) {
1228 closeInfoBox();
1229 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1230 param_escape(selected.toString()), true);
1231 xmlhttp.onreadystatechange=feedlist_callback;
1232 xmlhttp.send(null);
1233 } else {
1234 alert("No feeds are selected.");
1235 }
1236
1237 } catch (e) {
1238 exception_error("feedBrowserSubscribe", e);
1239 }
1240}
c6232e43 1241
6311acbe 1242function updateBigFeedBrowser(limit) {
c6232e43
AD
1243
1244 if (!xmlhttp_ready(xmlhttp)) {
1245 printLockingError();
1246 return
1247 }
1248
ce3bf408 1249// p_notify("Loading, please wait...");
c6232e43 1250
6311acbe
AD
1251 var query = "backend.php?op=pref-feed-browser";
1252
1253 var limit_sel = document.getElementById("feedBrowserLimit");
1254
1255 if (limit_sel) {
1256 var limit = limit_sel[limit_sel.selectedIndex].value;
1257 query = query + "&limit=" + param_escape(limit);
1258 }
1259
1260 xmlhttp.open("GET", query, true);
c6232e43
AD
1261 xmlhttp.onreadystatechange=feed_browser_callback;
1262 xmlhttp.send(null);
c6232e43
AD
1263}
1264
c2b2aee0 1265function browserToggleExpand(id) {
c6232e43
AD
1266 try {
1267/* if (feed_to_expand && feed_to_expand != id) {
1268 var d = document.getElementById("BRDET-" + feed_to_expand);
1269 d.style.display = "none";
1270 } */
c2b2aee0 1271
ff725e9b
AD
1272 if (!xmlhttp_ready(xmlhttp)) {
1273 printLockingError();
1274 return
1275 }
1276
c2b2aee0
AD
1277 var d = document.getElementById("BRDET-" + id);
1278
1279 if (d.style.display == "block") {
1280 d.style.display = "none";
1281
1282 } else {
c6232e43 1283
c2b2aee0 1284 feed_to_expand = id;
c6232e43 1285
ff725e9b
AD
1286 d.style.display = "block";
1287 d.innerHTML = "Loading, please wait...";
1288
c2b2aee0
AD
1289 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1290 + param_escape(id), true);
1291 xmlhttp.onreadystatechange=expand_feed_callback;
1292 xmlhttp.send(null);
1293 }
c6232e43
AD
1294
1295 } catch (e) {
1296 exception_error("browserExpand", e);
1297 }
1298}
64dc5976
AD
1299
1300function validateNewPassword(form) {
1301 if (form.OLD_PASSWORD.value == "") {
88103301 1302 alert("Old password cannot be blank");
64dc5976
AD
1303 return false;
1304 }
1305 if (form.NEW_PASSWORD.value == "") {
1306 alert("New password cannot be blank");
1307 return false;
1308 }
1309 return true;
1310}
ce3bf408
AD
1311
1312function selectPrefRows(kind, select) {
1313
1314 if (kind) {
1315 var opbarid = false;
1316 var nchk = false;
1317 var nrow = false;
1318 var lname = false;
1319
1320 if (kind == "feed") {
1321 opbarid = "feedOpToolbar";
1322 nrow = "FEEDR-";
1323 nchk = "FRCHK-";
1324 lname = "prefFeedList";
1325 } else if (kind == "fcat") {
1326 opbarid = "catOpToolbar";
1327 nrow = "FCATR-";
1328 nchk = "FCHK-";
1329 lname = "prefFeedCatList";
1330 } else if (kind == "filter") {
1331 opbarid = "filterOpToolbar";
1332 nrow = "FILRR-";
1333 nchk = "FICHK-";
1334 lname = "prefFilterList";
1335 } else if (kind == "label") {
1336 opbarid = "labelOpToolbar";
1337 nrow = "LILRR-";
1338 nchk = "LCHK-";
1339 lname = "prefLabelList";
1340 } else if (kind == "user") {
1341 opbarid = "userOpToolbar";
1342 nrow = "UMRR-";
1343 nchk = "UMCHK-";
1344 lname = "prefUserList";
1345 }
1346
1347 if (opbarid) {
1348 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1349 disableContainerChildren(opbarid, !select);
1350 }
1351
1352 }
1353}
1354
1355
1356function toggleSelectPrefRow(sender, kind) {
1357
1358 toggleSelectRow(sender);
1359
1360 if (kind) {
1361 var opbarid = false;
1362 var nsel = -1;
1363
1364 if (kind == "feed") {
1365 opbarid = "feedOpToolbar";
1366 nsel = getSelectedFeeds();
1367 } else if (kind == "fcat") {
1368 opbarid = "catOpToolbar";
1369 nsel = getSelectedFeedCats();
1370 } else if (kind == "filter") {
1371 opbarid = "filterOpToolbar";
1372 nsel = getSelectedFilters();
1373 } else if (kind == "label") {
1374 opbarid = "labelOpToolbar";
1375 nsel = getSelectedLabels();
1376 } else if (kind == "user") {
1377 opbarid = "userOpToolbar";
1378 nsel = getSelectedUsers();
1379 }
1380
1381 if (opbarid && nsel != -1) {
1382 disableContainerChildren(opbarid, nsel == false);
1383 }
1384
1385 }
1386}
1387
c0ae0fdb
AD
1388function toggleSelectFBListRow(sender) {
1389 toggleSelectListRow(sender);
1390 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1391}