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