]> git.wh0rd.org - tt-rss.git/blame - js/prefs.js
mostly implement async filter test dialog
[tt-rss.git] / js / prefs.js
CommitLineData
a7565293
AD
1var init_params = new Array();
2
746dcf42 3var hotkey_prefix = false;
78935092 4var hotkey_prefix_pressed = false;
7a09510c 5
a998dbef
AD
6var seq = "";
7
66665fba
AD
8function notify_callback2(transport, sticky) {
9 notify_info(transport.responseText, sticky);
60715b53
AD
10}
11
b83c7545 12function updateFeedList(sort_key) {
16270276
AD
13
14 var user_search = $("feed_search");
15 var search = "";
16 if (user_search) { search = user_search.value; }
17
b4e75b2a 18 new Ajax.Request("backend.php", {
16270276 19 parameters: "?op=pref-feeds&search=" + param_escape(search),
fb5662de 20 onComplete: function(transport) {
cbe50c80
AD
21 dijit.byId('feedConfigTab').attr('content', transport.responseText);
22 selectTab("feedConfig", true);
23 notify("");
60715b53 24 } });
007bda35
AD
25}
26
f9c1f8b0
AD
27function checkInactiveFeeds() {
28 try {
29 new Ajax.Request("backend.php", {
30 parameters: "?op=pref-feeds&method=getinactivefeeds",
31 onComplete: function(transport) {
32 if (parseInt(transport.responseText) > 0) {
33 Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
34 }
35 } });
36
37 } catch (e) {
38 exception_error("checkInactiveFeeds", e);
39 }
40}
373266eb 41
79ec0f2f 42function updateUsersList(sort_key) {
fbf7d545 43 try {
acac8448 44 var user_search = $("user_search");
fbf7d545
AD
45 var search = "";
46 if (user_search) { search = user_search.value; }
fb5662de 47
b4e75b2a 48 var query = "?op=pref-users&sort="
fbf7d545
AD
49 + param_escape(sort_key) +
50 "&search=" + param_escape(search);
fb5662de 51
b4e75b2a
AD
52 new Ajax.Request("backend.php", {
53 parameters: query,
fb5662de 54 onComplete: function(transport) {
66665fba
AD
55 dijit.byId('userConfigTab').attr('content', transport.responseText);
56 selectTab("userConfig", true)
57 notify("");
fbf7d545 58 } });
e6cb77a0 59
fbf7d545
AD
60 } catch (e) {
61 exception_error("updateUsersList", e);
62 }
e6cb77a0
AD
63}
64
e6cb77a0
AD
65function addUser() {
66
fbf7d545 67 try {
e6cb77a0 68
eb70b777 69 var login = prompt(__("Please enter login:"), "");
fb5662de
AD
70
71 if (login == null) {
eb70b777
AD
72 return false;
73 }
fb5662de 74
eb70b777
AD
75 if (login == "") {
76 alert(__("Can't create user: no login specified."));
77 return false;
fbf7d545 78 }
fb5662de 79
eb70b777 80 notify_progress("Adding user...");
fb5662de 81
f30ef1fa 82 var query = "?op=pref-users&method=add&login=" +
eb70b777 83 param_escape(login);
fb5662de 84
b4e75b2a
AD
85 new Ajax.Request("backend.php", {
86 parameters: query,
fb5662de 87 onComplete: function(transport) {
66665fba
AD
88 notify_callback2(transport);
89 updateUsersList();
eb70b777 90 } });
e6cb77a0 91
fbf7d545
AD
92 } catch (e) {
93 exception_error("addUser", e);
e6cb77a0 94 }
e6cb77a0
AD
95}
96
a998dbef 97function editUser(id, event) {
e6cb77a0 98
163723c4 99 try {
222a61c2 100 var query = "backend.php?op=pref-users&method=edit&id=" +
163723c4
AD
101 param_escape(id);
102
222a61c2
AD
103 if (dijit.byId("userEditDlg"))
104 dijit.byId("userEditDlg").destroyRecursive();
105
106 dialog = new dijit.Dialog({
107 id: "userEditDlg",
108 title: __("User Editor"),
109 style: "width: 600px",
110 execute: function() {
111 if (this.validate()) {
222a61c2
AD
112 notify_progress("Saving data...", true);
113
114 var query = dojo.formToQuery("user_edit_form");
115
116 new Ajax.Request("backend.php", {
117 parameters: query,
118 onComplete: function(transport) {
119 dialog.hide();
120 updateUsersList();
121 }});
122 }
123 },
124 href: query});
125
126 dialog.show();
e6cb77a0 127
163723c4
AD
128 } catch (e) {
129 exception_error("editUser", e);
130 }
fb5662de 131
e6cb77a0
AD
132}
133
261226a3 134function editFilterTest(query) {
163723c4 135 try {
a0d53889 136
261226a3
AD
137 if (dijit.byId("filterTestDlg"))
138 dijit.byId("filterTestDlg").destroyRecursive();
d90868d7 139
261226a3
AD
140 var test_dlg = new dijit.Dialog({
141 id: "filterTestDlg",
142 title: "Test Filter",
d90868d7 143 style: "width: 600px",
261226a3
AD
144 results: 0,
145 limit: 100,
146 max_offset: 10000,
147 getTestResults: function(query, offset) {
148 var updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit;
a007c18d 149
261226a3 150 console.log("getTestResults:" + offset);
4e02f582 151
261226a3
AD
152 new Ajax.Request("backend.php", {
153 parameters: updquery,
154 onComplete: function (transport) {
155 try {
156 var result = JSON.parse(transport.responseText);
4e02f582 157
261226a3
AD
158 if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
159 test_dlg.results += result.size();
a007c18d 160
261226a3 161 console.log("got results:" + result.size());
a007c18d 162
261226a3
AD
163 $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
164 .replace("%f", test_dlg.results)
165 .replace("%d", offset);
a007c18d 166
261226a3 167 console.log(offset + " " + test_dlg.max_offset);
a007c18d 168
261226a3
AD
169 for (var i = 0; i < result.size(); i++) {
170 var tmp = new Element("table");
171 tmp.innerHTML = result[i];
172 dojo.parser.parse(tmp);
a007c18d 173
261226a3
AD
174 $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
175 }
a007c18d 176
261226a3 177 if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
a007c18d 178
261226a3
AD
179 // get the next batch
180 window.setTimeout(function () {
181 test_dlg.getTestResults(query, offset + test_dlg.limit);
182 }, 0);
a007c18d 183
261226a3
AD
184 } else {
185 // all done
a007c18d 186
261226a3 187 Element.hide("prefFilterLoadingIndicator");
a007c18d 188
261226a3
AD
189 if (test_dlg.results == 0) {
190 $("prefFilterTestResultList").innerHTML = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
191 $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
192 } else {
193 $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
194 .replace("%d", test_dlg.results);
a007c18d
AD
195 }
196
261226a3 197 }
a007c18d 198
261226a3
AD
199 } else if (!result) {
200 console.log("getTestResults: can't parse results object");
a007c18d 201
261226a3 202 Element.hide("prefFilterLoadingIndicator");
a007c18d 203
261226a3 204 notify_error("Error while trying to get filter test results.");
a007c18d 205
261226a3
AD
206 } else {
207 console.log("getTestResults: dialog closed, bailing out.");
208 }
209 } catch (e) {
210 exception_error("editFilterTest/inner", e);
211 }
a007c18d 212
261226a3
AD
213 } });
214 },
215 href: query});
4e02f582 216
261226a3
AD
217 dojo.connect(test_dlg, "onLoad", null, function(e) {
218 test_dlg.getTestResults(query, 0);
219 });
220
221 test_dlg.show();
222
223 } catch (e) {
224 exception_error("editFilterTest", e);
225 }
226}
227
228function editFilter(id) {
229 try {
230
231 var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id);
232
233 if (dijit.byId("feedEditDlg"))
234 dijit.byId("feedEditDlg").destroyRecursive();
235
236 if (dijit.byId("filterEditDlg"))
237 dijit.byId("filterEditDlg").destroyRecursive();
238
239 dialog = new dijit.Dialog({
240 id: "filterEditDlg",
241 title: __("Edit Filter"),
242 style: "width: 600px",
243
244 test: function() {
245 var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
a007c18d 246
261226a3 247 editFilterTest(query);
4e02f582 248 },
ec630524
AD
249 selectRules: function(select) {
250 $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
251 e.checked = select;
252 if (select)
253 e.parentNode.addClassName("Selected");
254 else
255 e.parentNode.removeClassName("Selected");
256 });
257 },
258 selectActions: function(select) {
259 $$("#filterDlg_Actions input[type=checkbox]").each(function(e) {
260 e.checked = select;
261
262 if (select)
263 e.parentNode.addClassName("Selected");
264 else
265 e.parentNode.removeClassName("Selected");
266
267 });
268 },
6aff7845
AD
269 editRule: function(e) {
270 var li = e.parentNode;
271 var rule = li.getElementsByTagName("INPUT")[1].value;
272 addFilterRule(li, rule);
273 },
274 editAction: function(e) {
275 var li = e.parentNode;
276 var action = li.getElementsByTagName("INPUT")[1].value;
277 addFilterAction(li, action);
278 },
90e4e726 279 removeFilter: function() {
6aff7845 280 var msg = __("Remove filter?");
fb5662de 281
90e4e726
AD
282 if (confirm(msg)) {
283 this.hide();
284
285 notify_progress("Removing filter...");
fb5662de 286
90e4e726
AD
287 var id = this.attr('value').id;
288
f30ef1fa 289 var query = "?op=pref-filters&method=remove&ids="+
90e4e726
AD
290 param_escape(id);
291
292 new Ajax.Request("backend.php", {
293 parameters: query,
294 onComplete: function(transport) {
295 updateFilterList();
296 } });
297 }
298 },
6aff7845
AD
299 addAction: function() { addFilterAction(); },
300 addRule: function() { addFilterRule(); },
301 deleteAction: function() {
302 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
303 },
304 deleteRule: function() {
305 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) });
5593784a 306 },
d90868d7
AD
307 execute: function() {
308 if (this.validate()) {
141fb6e3 309
6aff7845 310 notify_progress("Saving data...", true);
141fb6e3 311
6aff7845 312 var query = dojo.formToQuery("filter_edit_form");
141fb6e3 313
6aff7845
AD
314 console.log(query);
315
316 new Ajax.Request("backend.php", {
141fb6e3 317 parameters: query,
d90868d7 318 onComplete: function(transport) {
6aff7845
AD
319 dialog.hide();
320 updateFilterList();
321 }});
d90868d7
AD
322 }
323 },
324 href: query});
325
326 dialog.show();
a998dbef 327
a0d53889 328
163723c4
AD
329 } catch (e) {
330 exception_error("editFilter", e);
331 }
a0d53889
AD
332}
333
91ff844a 334function getSelectedLabels() {
fb8b2153
AD
335 var tree = dijit.byId("labelTree");
336 var items = tree.model.getCheckedItems();
337 var rv = [];
338
339 items.each(function(item) {
340 rv.push(tree.model.store.getValue(item, 'bare_id'));
341 });
342
343 return rv;
91ff844a 344}
48f0adb0 345
91ff844a 346function getSelectedUsers() {
e69fb880 347 return getSelectedTableRowIds("prefUserList");
a0d53889
AD
348}
349
83fe4d6d 350function getSelectedFeeds() {
1985a5e0
AD
351 var tree = dijit.byId("feedTree");
352 var items = tree.model.getCheckedItems();
353 var rv = [];
354
355 items.each(function(item) {
7c227bb3
AD
356 if (item.id[0].match("FEED:"))
357 rv.push(tree.model.store.getValue(item, 'bare_id'));
1985a5e0
AD
358 });
359
360 return rv;
91ff844a 361}
331900c6 362
fd26d5bf
AD
363function getSelectedCategories() {
364 var tree = dijit.byId("feedTree");
365 var items = tree.model.getCheckedItems();
366 var rv = [];
367
368 items.each(function(item) {
369 if (item.id[0].match("CAT:"))
370 rv.push(tree.model.store.getValue(item, 'bare_id'));
371 });
372
373 return rv;
374}
375
91ff844a 376function getSelectedFilters() {
a740f4b5
AD
377 var tree = dijit.byId("filterTree");
378 var items = tree.model.getCheckedItems();
379 var rv = [];
380
381 items.each(function(item) {
382 rv.push(tree.model.store.getValue(item, 'bare_id'));
383 });
384
385 return rv;
386
91ff844a 387}
331900c6 388
48f0adb0
AD
389function removeSelectedLabels() {
390
48f0adb0
AD
391 var sel_rows = getSelectedLabels();
392
393 if (sel_rows.length > 0) {
394
f56e3080 395 var ok = confirm(__("Remove selected labels?"));
48f0adb0 396
69668465 397 if (ok) {
42c32916 398 notify_progress("Removing selected labels...");
fb5662de 399
f30ef1fa 400 var query = "?op=pref-labels&method=remove&ids="+
a796bfc1
AD
401 param_escape(sel_rows.toString());
402
b4e75b2a
AD
403 new Ajax.Request("backend.php", {
404 parameters: query,
a796bfc1 405 onComplete: function(transport) {
cbe50c80 406 updateLabelList();
a796bfc1
AD
407 } });
408
69668465 409 }
48f0adb0 410 } else {
89cb787e 411 alert(__("No labels are selected."));
48f0adb0 412 }
90ac84df
AD
413
414 return false;
48f0adb0
AD
415}
416
e6cb77a0
AD
417function removeSelectedUsers() {
418
fbf7d545 419 try {
e6cb77a0 420
fbf7d545 421 var sel_rows = getSelectedUsers();
fb5662de 422
fbf7d545 423 if (sel_rows.length > 0) {
fb5662de 424
50e7dd7d 425 var ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed."));
fb5662de 426
fbf7d545
AD
427 if (ok) {
428 notify_progress("Removing selected users...");
fb5662de 429
f30ef1fa 430 var query = "?op=pref-users&method=remove&ids="+
fbf7d545 431 param_escape(sel_rows.toString());
fb5662de 432
b4e75b2a
AD
433 new Ajax.Request("backend.php", {
434 parameters: query,
fb5662de 435 onComplete: function(transport) {
66665fba 436 updateUsersList();
fbf7d545 437 } });
fb5662de 438
fbf7d545 439 }
fb5662de 440
fbf7d545
AD
441 } else {
442 alert(__("No users are selected."));
69668465 443 }
e6cb77a0 444
fbf7d545
AD
445 } catch (e) {
446 exception_error("removeSelectedUsers", e);
e6cb77a0 447 }
90ac84df
AD
448
449 return false;
e6cb77a0
AD
450}
451
48f0adb0
AD
452function removeSelectedFilters() {
453
23e51f40 454 try {
48f0adb0 455
23e51f40 456 var sel_rows = getSelectedFilters();
fb5662de 457
23e51f40 458 if (sel_rows.length > 0) {
fb5662de 459
23e51f40 460 var ok = confirm(__("Remove selected filters?"));
fb5662de 461
23e51f40
AD
462 if (ok) {
463 notify_progress("Removing selected filters...");
fb5662de 464
f30ef1fa 465 var query = "?op=pref-filters&method=remove&ids="+
23e51f40 466 param_escape(sel_rows.toString());
fb5662de 467
b4e75b2a
AD
468 new Ajax.Request("backend.php", {
469 parameters: query,
23e51f40 470 onComplete: function(transport) {
687d246b
AD
471 updateFilterList();
472 } });
23e51f40
AD
473 }
474 } else {
475 alert(__("No filters are selected."));
69668465 476 }
23e51f40
AD
477
478 } catch (e) {
479 exception_error("removeSelectedFilters", e);
48f0adb0 480 }
90ac84df
AD
481
482 return false;
48f0adb0
AD
483}
484
485
83fe4d6d
AD
486function removeSelectedFeeds() {
487
a796bfc1 488 try {
69668465 489
a796bfc1 490 var sel_rows = getSelectedFeeds();
fb5662de 491
a796bfc1 492 if (sel_rows.length > 0) {
fb5662de 493
a796bfc1 494 var ok = confirm(__("Unsubscribe from selected feeds?"));
fb5662de 495
a796bfc1 496 if (ok) {
fb5662de 497
b6a6e262 498 notify_progress("Unsubscribing from selected feeds...", true);
fb5662de 499
f30ef1fa 500 var query = "?op=pref-feeds&method=remove&ids="+
a796bfc1 501 param_escape(sel_rows.toString());
b6a6e262 502
84c7b824 503 console.log(query);
b6a6e262 504
b4e75b2a
AD
505 new Ajax.Request("backend.php", {
506 parameters: query,
a796bfc1 507 onComplete: function(transport) {
b6a6e262 508 updateFeedList();
a796bfc1
AD
509 } });
510 }
fb5662de 511
a796bfc1
AD
512 } else {
513 alert(__("No feeds are selected."));
69668465 514 }
71ad3959 515
a796bfc1
AD
516 } catch (e) {
517 exception_error("removeSelectedFeeds", e);
71ad3959 518 }
fb5662de 519
90ac84df 520 return false;
71ad3959 521}
007bda35 522
c4a36709
AD
523function clearSelectedFeeds() {
524
c4a36709
AD
525 var sel_rows = getSelectedFeeds();
526
527 if (sel_rows.length > 1) {
528 alert(__("Please select only one feed."));
529 return;
530 }
531
532 if (sel_rows.length > 0) {
533
534 var ok = confirm(__("Erase all non-starred articles in selected feed?"));
535
536 if (ok) {
537 notify_progress("Clearing selected feed...");
538 clearFeedArticles(sel_rows[0]);
539 }
540
541 } else {
542
543 alert(__("No feeds are selected."));
544
545 }
fb5662de 546
c4a36709
AD
547 return false;
548}
549
e88a65f4
AD
550function purgeSelectedFeeds() {
551
e88a65f4
AD
552 var sel_rows = getSelectedFeeds();
553
554 if (sel_rows.length > 0) {
555
556 var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0");
557
558 if (pr != undefined) {
559 notify_progress("Purging selected feed...");
560
f30ef1fa 561 var query = "?op=rpc&method=purge&ids="+
e88a65f4
AD
562 param_escape(sel_rows.toString()) + "&days=" + pr;
563
84c7b824 564 console.log(query);
e88a65f4 565
b4e75b2a
AD
566 new Ajax.Request("prefs.php", {
567 parameters: query,
e88a65f4
AD
568 onComplete: function(transport) {
569 notify('');
570 } });
571 }
572
573 } else {
574
575 alert(__("No feeds are selected."));
576
577 }
fb5662de 578
e88a65f4
AD
579 return false;
580}
581
e6cb77a0
AD
582function editSelectedUser() {
583 var rows = getSelectedUsers();
584
585 if (rows.length == 0) {
f3977cf5 586 alert(__("No users are selected."));
e6cb77a0
AD
587 return;
588 }
589
590 if (rows.length > 1) {
f3977cf5 591 alert(__("Please select only one user."));
e6cb77a0
AD
592 return;
593 }
594
dbd9e2f1
AD
595 notify("");
596
e6cb77a0
AD
597 editUser(rows[0]);
598}
599
600function resetSelectedUserPass() {
e6cb77a0 601
fbf7d545 602 try {
e6cb77a0 603
fbf7d545 604 var rows = getSelectedUsers();
fb5662de 605
fbf7d545
AD
606 if (rows.length == 0) {
607 alert(__("No users are selected."));
608 return;
609 }
fb5662de 610
fbf7d545
AD
611 if (rows.length > 1) {
612 alert(__("Please select only one user."));
613 return;
614 }
fb5662de 615
fbf7d545 616 var ok = confirm(__("Reset password of selected user?"));
fb5662de 617
fbf7d545
AD
618 if (ok) {
619 notify_progress("Resetting password for selected user...");
fb5662de 620
fbf7d545 621 var id = rows[0];
fb5662de 622
f30ef1fa 623 var query = "?op=pref-users&method=resetPass&id=" +
fbf7d545 624 param_escape(id);
fb5662de 625
b4e75b2a
AD
626 new Ajax.Request("backend.php", {
627 parameters: query,
fb5662de 628 onComplete: function(transport) {
478d4067 629 notify_info(transport.responseText, true);
fbf7d545 630 } });
fb5662de 631
fbf7d545
AD
632 }
633
634 } catch (e) {
635 exception_error("resetSelectedUserPass", e);
69668465 636 }
e6cb77a0
AD
637}
638
717f5e64 639function selectedUserDetails() {
e6cb77a0 640
350468d0 641 try {
717f5e64 642
350468d0 643 var rows = getSelectedUsers();
fb5662de 644
350468d0
AD
645 if (rows.length == 0) {
646 alert(__("No users are selected."));
647 return;
648 }
fb5662de 649
350468d0
AD
650 if (rows.length > 1) {
651 alert(__("Please select only one user."));
652 return;
653 }
fb5662de 654
350468d0 655 var id = rows[0];
fb5662de 656
d9afd9b2
AD
657 var query = "backend.php?op=pref-users&method=userdetails&id=" + id;
658
659 if (dijit.byId("userDetailsDlg"))
660 dijit.byId("userDetailsDlg").destroyRecursive();
661
662 dialog = new dijit.Dialog({
663 id: "userDetailsDlg",
664 title: __("User details"),
665 style: "width: 600px",
666 execute: function() {
667 dialog.hide();
668 },
669 href: query});
670
671 dialog.show();
717f5e64 672
350468d0
AD
673 } catch (e) {
674 exception_error("selectedUserDetails", e);
717f5e64 675 }
c6c3a07f
AD
676}
677
a0d53889
AD
678
679function editSelectedFilter() {
680 var rows = getSelectedFilters();
681
682 if (rows.length == 0) {
f3977cf5 683 alert(__("No filters are selected."));
a0d53889
AD
684 return;
685 }
686
687 if (rows.length > 1) {
f3977cf5 688 alert(__("Please select only one filter."));
a0d53889
AD
689 return;
690 }
691
dbd9e2f1
AD
692 notify("");
693
a0d53889
AD
694 editFilter(rows[0]);
695
696}
697
6aff7845
AD
698function joinSelectedFilters() {
699 var rows = getSelectedFilters();
700
701 if (rows.length == 0) {
702 alert(__("No filters are selected."));
703 return;
704 }
705
706 var ok = confirm(__("Combine selected filters?"));
707
708 if (ok) {
709 notify_progress("Joining filters...");
710
711 var query = "?op=pref-filters&method=join&ids="+
712 param_escape(rows.toString());
713
714 console.log(query);
715
716 new Ajax.Request("backend.php", {
717 parameters: query,
718 onComplete: function(transport) {
719 updateFilterList();
720 } });
721 }
722}
a0d53889 723
508a81e1
AD
724function editSelectedFeed() {
725 var rows = getSelectedFeeds();
726
727 if (rows.length == 0) {
f3977cf5 728 alert(__("No feeds are selected."));
508a81e1
AD
729 return;
730 }
731
732 if (rows.length > 1) {
1e5548db 733 return editSelectedFeeds();
508a81e1
AD
734 }
735
dbd9e2f1
AD
736 notify("");
737
951906dc 738 editFeed(rows[0], {});
91ff844a
AD
739
740}
741
758e1c4a
AD
742function editSelectedFeeds() {
743
350468d0
AD
744 try {
745 var rows = getSelectedFeeds();
fb5662de 746
350468d0
AD
747 if (rows.length == 0) {
748 alert(__("No feeds are selected."));
749 return;
750 }
fb5662de 751
755c8f95 752 notify_progress("Loading, please wait...");
fb5662de 753
f30ef1fa 754 var query = "backend.php?op=pref-feeds&method=editfeeds&ids=" +
350468d0 755 param_escape(rows.toString());
758e1c4a 756
755c8f95
AD
757 console.log(query);
758
05acc0d6
AD
759 if (dijit.byId("feedEditDlg"))
760 dijit.byId("feedEditDlg").destroyRecursive();
761
755c8f95
AD
762 new Ajax.Request("backend.php", {
763 parameters: query,
764 onComplete: function(transport) {
05acc0d6 765
755c8f95
AD
766 notify("");
767
768 var dialog = new dijit.Dialog({
769 id: "feedEditDlg",
770 title: __("Edit Multiple Feeds"),
771 style: "width: 600px",
772 getChildByName: function (name) {
e331188f 773 var rv = null;
755c8f95
AD
774 this.getChildren().each(
775 function(child) {
776 if (child.name == name) {
777 rv = child;
778 return;
779 }
780 });
781 return rv;
782 },
783 toggleField: function (checkbox, elem, label) {
784 this.getChildByName(elem).attr('disabled', !checkbox.checked);
785
786 if ($(label))
787 if (checkbox.checked)
788 $(label).removeClassName('insensitive');
789 else
790 $(label).addClassName('insensitive');
791
792 },
793 execute: function() {
794 if (this.validate() && confirm(__("Save changes to selected feeds?"))) {
795 var query = dojo.objectToQuery(this.attr('value'));
796
797 /* Form.serialize ignores unchecked checkboxes */
798
755c8f95
AD
799 if (!query.match("&private=") &&
800 this.getChildByName('private').attr('disabled') == false) {
801 query = query + "&private=false";
802 }
fb5662de 803
755c8f95
AD
804 try {
805 if (!query.match("&cache_images=") &&
806 this.getChildByName('cache_images').attr('disabled') == false) {
807 query = query + "&cache_images=false";
808 }
809 } catch (e) { }
fb5662de 810
bfd61d3f
AD
811 try {
812 if (!query.match("&hide_images=") &&
813 this.getChildByName('hide_images').attr('disabled') == false) {
814 query = query + "&hide_images=false";
815 }
816 } catch (e) { }
817
755c8f95
AD
818 if (!query.match("&include_in_digest=") &&
819 this.getChildByName('include_in_digest').attr('disabled') == false) {
820 query = query + "&include_in_digest=false";
821 }
fb5662de 822
755c8f95
AD
823 if (!query.match("&always_display_enclosures=") &&
824 this.getChildByName('always_display_enclosures').attr('disabled') == false) {
825 query = query + "&always_display_enclosures=false";
826 }
05acc0d6 827
755c8f95
AD
828 if (!query.match("&mark_unread_on_update=") &&
829 this.getChildByName('mark_unread_on_update').attr('disabled') == false) {
830 query = query + "&mark_unread_on_update=false";
831 }
dd04ea81 832
755c8f95 833 console.log(query);
dd04ea81 834
755c8f95 835 notify_progress("Saving data...", true);
fb5662de 836
755c8f95
AD
837 new Ajax.Request("backend.php", {
838 parameters: query,
839 onComplete: function(transport) {
840 dialog.hide();
841 updateFeedList();
e331188f 842 }});
755c8f95
AD
843 }
844 },
845 content: transport.responseText});
05acc0d6 846
755c8f95 847 dialog.show();
05acc0d6 848
755c8f95 849 } });
758e1c4a 850
350468d0
AD
851 } catch (e) {
852 exception_error("editSelectedFeeds", e);
758e1c4a 853 }
758e1c4a
AD
854}
855
e1218480
AD
856function opmlImportComplete(iframe) {
857 try {
858 if (!iframe.contentDocument.body.innerHTML) return false;
859
55f34b81
AD
860 Element.show(iframe);
861
e1218480
AD
862 notify('');
863
864 if (dijit.byId('opmlImportDlg'))
865 dijit.byId('opmlImportDlg').destroyRecursive();
866
867 var content = iframe.contentDocument.body.innerHTML;
868
869 dialog = new dijit.Dialog({
870 id: "opmlImportDlg",
871 title: __("OPML Import"),
872 style: "width: 600px",
873 onCancel: function() {
fb5662de 874 updateFeedList();
34aa9e20
AD
875 updateFilterList();
876 updateLabelList();
877 },
878 execute: function() {
879 updateFeedList();
880 updateFilterList();
881 updateLabelList();
882 this.hide();
e1218480
AD
883 },
884 content: content});
885
886 dialog.show();
887
888 } catch (e) {
889 exception_error("opmlImportComplete", e);
890 }
891}
892
b6a6e262 893function opmlImport() {
fb5662de 894
acac8448 895 var opml_file = $("opml_file");
9f311df6
AD
896
897 if (opml_file.value.length == 0) {
d2d75353 898 alert(__("Please choose an OPML file first."));
9f311df6
AD
899 return false;
900 } else {
4d7cd9ed 901 notify_progress("Importing, please wait...", true);
55f34b81
AD
902
903 Element.show("upload_iframe");
904
9f311df6
AD
905 return true;
906 }
907}
908
55f34b81 909
05acc0d6 910function updateFilterList() {
310fa2dd
AD
911 var user_search = $("filter_search");
912 var search = "";
913 if (user_search) { search = user_search.value; }
914
05acc0d6 915 new Ajax.Request("backend.php", {
310fa2dd 916 parameters: "?op=pref-filters&search=" + param_escape(search),
05acc0d6 917 onComplete: function(transport) {
66665fba
AD
918 dijit.byId('filterConfigTab').attr('content', transport.responseText);
919 notify("");
05acc0d6 920 } });
a0d53889
AD
921}
922
05acc0d6
AD
923function updateLabelList() {
924 new Ajax.Request("backend.php", {
925 parameters: "?op=pref-labels",
926 onComplete: function(transport) {
cbe50c80
AD
927 dijit.byId('labelConfigTab').attr('content', transport.responseText);
928 notify("");
05acc0d6 929 } });
48f0adb0
AD
930}
931
4255b24c 932function updatePrefsList() {
b4e75b2a 933 new Ajax.Request("backend.php", {
05acc0d6 934 parameters: "?op=pref-prefs",
fb5662de 935 onComplete: function(transport) {
cbe50c80
AD
936 dijit.byId('genConfigTab').attr('content', transport.responseText);
937 notify("");
e9802ead 938 } });
4255b24c
AD
939}
940
2cbdc95b
AD
941function updateSystemList() {
942 new Ajax.Request("backend.php", {
943 parameters: "?op=pref-system",
944 onComplete: function(transport) {
945 dijit.byId('systemConfigTab').attr('content', transport.responseText);
946 notify("");
947 } });
948}
949
f30ef1fa 950function selectTab(id, noupdate, method) {
b2caf812 951 try {
b2caf812 952 if (!noupdate) {
9e31e1b9 953 notify_progress("Loading, please wait...");
d15f8675 954
b2caf812
AD
955 if (id == "feedConfig") {
956 updateFeedList();
957 } else if (id == "filterConfig") {
958 updateFilterList();
959 } else if (id == "labelConfig") {
960 updateLabelList();
961 } else if (id == "genConfig") {
962 updatePrefsList();
963 } else if (id == "userConfig") {
964 updateUsersList();
2cbdc95b
AD
965 } else if (id == "systemConfig") {
966 updateSystemList();
b2caf812 967 }
d62796de
AD
968
969 var tab = dijit.byId(id + "Tab");
970 dijit.byId("pref-tabs").selectChild(tab);
971
f5a50b25 972 }
fb5662de 973
b2caf812
AD
974 } catch (e) {
975 exception_error("selectTab", e);
a7565293 976 }
a7565293
AD
977}
978
a7565293 979function init_second_stage() {
b2caf812 980 try {
4da47970 981
d437c8cf 982 document.onkeydown = pref_hotkey_handler;
fcc36744 983 loading_set_progress(50);
d62796de
AD
984 notify("");
985
556e5b46 986 dojo.addOnLoad(function() {
a8328019 987 var tab = getURLParam('tab');
556e5b46 988
a8328019
AD
989 if (tab) {
990 tab = dijit.byId(tab + "Tab");
991 if (tab) dijit.byId("pref-tabs").selectChild(tab);
992 }
b01b1b38 993
f30ef1fa 994 var method = getURLParam('method');
b01b1b38 995
f30ef1fa
AD
996 if (method == 'editFeed') {
997 var param = getURLParam('methodparam');
b01b1b38
AD
998
999 window.setTimeout('editFeed(' + param + ')', 100);
1000 }
05acc0d6 1001 });
556e5b46 1002
78935092
AD
1003 setTimeout("hotkey_prefix_timeout()", 5*1000);
1004
b2caf812
AD
1005 } catch (e) {
1006 exception_error("init_second_stage", e);
1007 }
a0d53889
AD
1008}
1009
007bda35 1010function init() {
e2ec66a8 1011
7719618b 1012 try {
1985a5e0 1013 dojo.registerModulePath("lib", "..");
107d0cf3 1014 dojo.registerModulePath("fox", "../../js/");
1985a5e0 1015
1354d172
AD
1016 dojo.require("dijit.ColorPalette");
1017 dojo.require("dijit.Dialog");
1018 dojo.require("dijit.form.Button");
1019 dojo.require("dijit.form.CheckBox");
1020 dojo.require("dijit.form.DropDownButton");
1021 dojo.require("dijit.form.FilteringSelect");
1022 dojo.require("dijit.form.Form");
1023 dojo.require("dijit.form.RadioButton");
1024 dojo.require("dijit.form.Select");
1025 dojo.require("dijit.form.SimpleTextarea");
1026 dojo.require("dijit.form.TextBox");
1027 dojo.require("dijit.form.ValidationTextBox");
1028 dojo.require("dijit.InlineEditBox");
1029 dojo.require("dijit.layout.AccordionContainer");
1030 dojo.require("dijit.layout.BorderContainer");
1031 dojo.require("dijit.layout.ContentPane");
1032 dojo.require("dijit.layout.TabContainer");
1033 dojo.require("dijit.Menu");
1034 dojo.require("dijit.ProgressBar");
1035 dojo.require("dijit.ProgressBar");
1036 dojo.require("dijit.Toolbar");
1037 dojo.require("dijit.Tree");
1038 dojo.require("dijit.tree.dndSource");
1039 dojo.require("dojo.data.ItemFileWriteStore");
1040
1985a5e0 1041 dojo.require("lib.CheckBoxTree");
2148e0d5 1042 dojo.require("fox.PrefFeedTree");
a740f4b5 1043 dojo.require("fox.PrefFilterTree");
fb8b2153 1044 dojo.require("fox.PrefLabelTree");
fcf70c51 1045
a089699c
AD
1046 dojo.parser.parse();
1047
df1c35f4
AD
1048 dojo.addOnLoad(function() {
1049 loading_set_progress(50);
fbf7d545 1050
6bfc97da
AD
1051 var clientTzOffset = new Date().getTimezoneOffset() * 60;
1052
df1c35f4 1053 new Ajax.Request("backend.php", {
6bfc97da
AD
1054 parameters: {op: "rpc", method: "sanityCheck",
1055 clientTzOffset: clientTzOffset },
fb5662de 1056 onComplete: function(transport) {
df1c35f4
AD
1057 backend_sanity_check_callback(transport);
1058 } });
1059 });
a7565293 1060
7719618b
AD
1061 } catch (e) {
1062 exception_error("init", e);
e2ec66a8 1063 }
007bda35 1064}
b1895692 1065
69668465 1066function validatePrefsReset() {
b652c1b7
AD
1067 try {
1068 var ok = confirm(__("Reset to defaults?"));
1069
1070 if (ok) {
1071
1395083e 1072 query = "?op=pref-prefs&method=resetconfig";
84c7b824 1073 console.log(query);
b652c1b7 1074
e9802ead
AD
1075 new Ajax.Request("backend.php", {
1076 parameters: query,
fb5662de 1077 onComplete: function(transport) {
bf878338
AD
1078 updatePrefsList();
1079 notify_info(transport.responseText);
e9802ead
AD
1080 } });
1081
b652c1b7
AD
1082 }
1083
1084 } catch (e) {
d9084cf2 1085 exception_error("validatePrefsReset", e);
b652c1b7
AD
1086 }
1087
1088 return false;
1089
69668465 1090}
f9cb39ac 1091
d437c8cf
AD
1092function pref_hotkey_handler(e) {
1093 try {
b8cb4d08 1094
e33b0b80 1095 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
18606807 1096
e331188f 1097 var keycode = false;
746dcf42
AD
1098 var shift_key = false;
1099
78935092
AD
1100 var cmdline = $('cmdline');
1101
746dcf42
AD
1102 try {
1103 shift_key = e.shiftKey;
1104 } catch (e) {
1105
1106 }
1107
d437c8cf
AD
1108 if (window.event) {
1109 keycode = window.event.keyCode;
1110 } else if (e) {
1111 keycode = e.which;
1112 }
746dcf42 1113
eec498c3
AD
1114 var keychar = String.fromCharCode(keycode);
1115
746dcf42 1116 if (keycode == 27) { // escape
746dcf42 1117 hotkey_prefix = false;
fb5662de 1118 }
746dcf42 1119
746dcf42 1120 if (keycode == 16) return; // ignore lone shift
49c6c279 1121 if (keycode == 17) return; // ignore lone ctrl
746dcf42 1122
b8cb4d08
AD
1123 if (!shift_key) keychar = keychar.toLowerCase();
1124
1125 var hotkeys = getInitParam("hotkeys");
1126
1127 if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
78935092
AD
1128
1129 var date = new Date();
1130 var ts = Math.round(date.getTime() / 1000);
1131
b8cb4d08 1132 hotkey_prefix = keychar;
78935092
AD
1133 hotkey_prefix_pressed = ts;
1134
1135 cmdline.innerHTML = keychar;
1136 Element.show(cmdline);
1137
b8cb4d08 1138 return true;
746dcf42
AD
1139 }
1140
78935092
AD
1141 Element.hide(cmdline);
1142
b8cb4d08
AD
1143 var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
1144 hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
1145 hotkey_prefix = false;
8d727bfc 1146
b8cb4d08
AD
1147 var hotkey_action = false;
1148 var hotkeys = getInitParam("hotkeys");
746dcf42 1149
b8cb4d08
AD
1150 for (sequence in hotkeys[1]) {
1151 if (sequence == hotkey) {
1152 hotkey_action = hotkeys[1][sequence];
1153 break;
746dcf42
AD
1154 }
1155 }
1156
b8cb4d08
AD
1157 switch (hotkey_action) {
1158 case "feed_subscribe":
1159 quickAddFeed();
4ba1f8bb 1160 return false;
b8cb4d08
AD
1161 case "create_label":
1162 addLabel();
4ba1f8bb 1163 return false;
b8cb4d08
AD
1164 case "create_filter":
1165 quickAddFilter();
4ba1f8bb 1166 return false;
b8cb4d08
AD
1167 case "help_dialog":
1168 //helpDialog("prefs");
1169 return false;
1170 default:
1171 console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
d437c8cf 1172 }
d437c8cf
AD
1173
1174 } catch (e) {
b8cb4d08 1175 exception_error("hotkey_handler", e);
d437c8cf
AD
1176 }
1177}
1178
5ef071e0 1179function removeCategory(id, item) {
a349077c 1180 try {
350468d0 1181
5ef071e0 1182 var ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name));
da1f74c9 1183
5ef071e0 1184 if (ok) {
28537341 1185 var query = "?op=pref-feeds&method=removeCat&ids="+
5ef071e0 1186 param_escape(id);
fb5662de 1187
5ef071e0 1188 notify_progress("Removing category...");
fb5662de 1189
5ef071e0
AD
1190 new Ajax.Request("backend.php", {
1191 parameters: query,
1192 onComplete: function(transport) {
1193 notify('');
1194 updateFeedList();
1195 } });
1196 }
fb5662de 1197
5ef071e0
AD
1198 } catch (e) {
1199 exception_error("removeCategory", e);
1200 }
1201}
fb5662de 1202
fd26d5bf
AD
1203function removeSelectedCategories() {
1204
1205 var sel_rows = getSelectedCategories();
1206
1207 if (sel_rows.length > 0) {
1208
1209 var ok = confirm(__("Remove selected categories?"));
1210
1211 if (ok) {
1212 notify_progress("Removing selected categories...");
1213
1214 var query = "?op=pref-feeds&method=removeCat&ids="+
1215 param_escape(sel_rows.toString());
1216
1217 new Ajax.Request("backend.php", {
1218 parameters: query,
1219 onComplete: function(transport) {
1220 updateFeedList();
1221 } });
1222
1223 }
1224 } else {
1225 alert(__("No categories are selected."));
1226 }
1227
1228 return false;
1229}
1230
5ef071e0
AD
1231function createCategory() {
1232 try {
1233 var title = prompt(__("Category title:"));
fb5662de 1234
5ef071e0 1235 if (title) {
da1f74c9 1236
5ef071e0 1237 notify_progress("Creating category...");
da1f74c9 1238
28537341 1239 var query = "?op=pref-feeds&method=addCat&cat=" +
5ef071e0 1240 param_escape(title);
da1f74c9 1241
5ef071e0
AD
1242 new Ajax.Request("backend.php", {
1243 parameters: query,
1244 onComplete: function(transport) {
1245 notify('');
1246 updateFeedList();
1247 } });
1248 }
5ba53dde 1249
a349077c 1250 } catch (e) {
5ef071e0 1251 exception_error("createCategory", e);
a349077c 1252 }
9c483746 1253}
a3656a41 1254
8ffd2011
AD
1255function showInactiveFeeds() {
1256 try {
bc6fa236 1257 var query = "backend.php?op=pref-feeds&method=inactiveFeeds";
8ffd2011
AD
1258
1259 if (dijit.byId("inactiveFeedsDlg"))
1260 dijit.byId("inactiveFeedsDlg").destroyRecursive();
1261
1262 dialog = new dijit.Dialog({
1263 id: "inactiveFeedsDlg",
1264 title: __("Feeds without recent updates"),
1265 style: "width: 600px",
1266 getSelectedFeeds: function() {
1267 return getSelectedTableRowIds("prefInactiveFeedList");
1268 },
1269 removeSelected: function() {
1270 var sel_rows = this.getSelectedFeeds();
1271
1272 console.log(sel_rows);
1273
1274 if (sel_rows.length > 0) {
1275 var ok = confirm(__("Remove selected feeds?"));
1276
1277 if (ok) {
1278 notify_progress("Removing selected feeds...", true);
1279
f30ef1fa 1280 var query = "?op=pref-feeds&method=remove&ids="+
8ffd2011
AD
1281 param_escape(sel_rows.toString());
1282
1283 new Ajax.Request("backend.php", {
1284 parameters: query,
1285 onComplete: function(transport) {
1286 notify('');
1287 dialog.hide();
1288 updateFeedList();
1289 } });
1290 }
1291
1292 } else {
1293 alert(__("No feeds are selected."));
1294 }
1295 },
1296 execute: function() {
1297 if (this.validate()) {
1298 }
1299 },
1300 href: query});
1301
1302 dialog.show();
1303
1304 } catch (e) {
1305 exception_error("showInactiveFeeds", e);
1306 }
1307
1308}
1309
ef7b7bbd
MK
1310function opmlRegenKey() {
1311
1312 try {
1313 var ok = confirm(__("Replace current OPML publishing address with a new one?"));
fb5662de 1314
ef7b7bbd 1315 if (ok) {
fb5662de 1316
ef7b7bbd 1317 notify_progress("Trying to change address...", true);
fb5662de 1318
195187c4 1319 var query = "?op=pref-feeds&method=regenOPMLKey";
fb5662de 1320
ef7b7bbd
MK
1321 new Ajax.Request("backend.php", {
1322 parameters: query,
1323 onComplete: function(transport) {
91d16ff1
AD
1324 var reply = JSON.parse(transport.responseText);
1325
1326 var new_link = reply.link;
fb5662de 1327
ef7b7bbd 1328 var e = $('pub_opml_url');
fb5662de 1329
ef7b7bbd 1330 if (new_link) {
91d16ff1
AD
1331 e.href = new_link;
1332 e.innerHTML = new_link;
fb5662de 1333
ef7b7bbd
MK
1334 new Effect.Highlight(e);
1335
1336 notify('');
fb5662de 1337
ef7b7bbd
MK
1338 } else {
1339 notify_error("Could not change feed URL.");
1340 }
1341 } });
1342 }
1343 } catch (e) {
1344 exception_error("opmlRegenKey", e);
1345 }
1346 return false;
1347}
c4a36709
AD
1348
1349function feedActionChange() {
1350 try {
acac8448 1351 var chooser = $("feedActionChooser");
c4a36709
AD
1352 var opid = chooser[chooser.selectedIndex].value;
1353
1354 chooser.selectedIndex = 0;
1355 feedActionGo(opid);
1356 } catch (e) {
1357 exception_error("feedActionChange", e);
1358 }
1359}
1360
fb5662de 1361function feedActionGo(op) {
c4a36709
AD
1362 try {
1363 if (op == "facEdit") {
cd935c42
AD
1364
1365 var rows = getSelectedFeeds();
1366
1367 if (rows.length > 1) {
1368 editSelectedFeeds();
1369 } else {
1370 editSelectedFeed();
1371 }
c4a36709
AD
1372 }
1373
1374 if (op == "facClear") {
1375 clearSelectedFeeds();
1376 }
1377
1378 if (op == "facPurge") {
1379 purgeSelectedFeeds();
1380 }
1381
e88a65f4
AD
1382 if (op == "facEditCats") {
1383 editFeedCats();
1384 }
1385
fee840fb
AD
1386 if (op == "facRescore") {
1387 rescoreSelectedFeeds();
1388 }
1389
c4a36709
AD
1390 if (op == "facUnsubscribe") {
1391 removeSelectedFeeds();
1392 }
1393
1394 } catch (e) {
1395 exception_error("feedActionGo", e);
1396
1397 }
1398}
1399
1400function clearFeedArticles(feed_id) {
1401
1402 notify_progress("Clearing feed...");
1403
f30ef1fa 1404 var query = "?op=pref-feeds&quiet=1&method=clear&id=" + feed_id;
c4a36709 1405
b4e75b2a
AD
1406 new Ajax.Request("backend.php", {
1407 parameters: query,
c4a36709
AD
1408 onComplete: function(transport) {
1409 notify('');
1410 } });
1411
1412 return false;
1413}
1414
fee840fb
AD
1415function rescoreSelectedFeeds() {
1416
fee840fb
AD
1417 var sel_rows = getSelectedFeeds();
1418
1419 if (sel_rows.length > 0) {
1420
ef1b0366
AD
1421 //var ok = confirm(__("Rescore last 100 articles in selected feeds?"));
1422 var ok = confirm(__("Rescore articles in selected feeds?"));
fee840fb
AD
1423
1424 if (ok) {
3df4869b 1425 notify_progress("Rescoring selected feeds...", true);
fb5662de 1426
f30ef1fa 1427 var query = "?op=pref-feeds&method=rescore&quiet=1&ids="+
60715b53
AD
1428 param_escape(sel_rows.toString());
1429
b4e75b2a
AD
1430 new Ajax.Request("backend.php", {
1431 parameters: query,
60715b53
AD
1432 onComplete: function(transport) {
1433 notify_callback2(transport);
1434 } });
1435
fee840fb
AD
1436 }
1437 } else {
1438 alert(__("No feeds are selected."));
1439 }
1440
1441 return false;
1442}
c4a36709 1443
95a948a5 1444function rescore_all_feeds() {
60715b53 1445 var ok = confirm(__("Rescore all articles? This operation may take a lot of time."));
95a948a5 1446
60715b53
AD
1447 if (ok) {
1448 notify_progress("Rescoring feeds...", true);
95a948a5 1449
f30ef1fa 1450 var query = "?op=pref-feeds&method=rescoreAll&quiet=1";
60715b53 1451
b4e75b2a
AD
1452 new Ajax.Request("backend.php", {
1453 parameters: query,
60715b53
AD
1454 onComplete: function(transport) {
1455 notify_callback2(transport);
1456 } });
1457 }
a80b05ea 1458}
a44db887 1459
b8776a07
AD
1460function labelColorReset() {
1461 try {
1462 var labels = getSelectedLabels();
1463
f695cdb2
AD
1464 if (labels.length > 0) {
1465 var ok = confirm(__("Reset selected labels to default colors?"));
b8776a07 1466
f695cdb2 1467 if (ok) {
cbe50c80 1468 var query = "?op=pref-labels&method=colorreset&ids="+
f695cdb2 1469 param_escape(labels.toString());
b8776a07 1470
f695cdb2
AD
1471 new Ajax.Request("backend.php", {
1472 parameters: query,
1473 onComplete: function(transport) {
cbe50c80 1474 updateLabelList();
b8776a07 1475 } });
f695cdb2
AD
1476 }
1477
1478 } else {
1479 alert(__("No labels are selected."));
b8776a07
AD
1480 }
1481
1482 } catch (e) {
1483 exception_error("labelColorReset", e);
1484 }
1485}
1486
b6ba48c1 1487
a5819bb3
AD
1488function inPreferences() {
1489 return true;
1490}
d9084cf2
AD
1491
1492function editProfiles() {
22988692
AD
1493 try {
1494
1495 if (dijit.byId("profileEditDlg"))
1496 dijit.byId("profileEditDlg").destroyRecursive();
1497
9d76e754 1498 var query = "backend.php?op=pref-prefs&method=editPrefProfiles";
22988692
AD
1499
1500 dialog = new dijit.Dialog({
1501 id: "profileEditDlg",
1502 title: __("Settings Profiles"),
1503 style: "width: 600px",
1504 getSelectedProfiles: function() {
1505 return getSelectedTableRowIds("prefFeedProfileList");
1506 },
1507 removeSelected: function() {
1508 var sel_rows = this.getSelectedProfiles();
fb5662de
AD
1509
1510 if (sel_rows.length > 0) {
22988692 1511 var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed."));
fb5662de 1512
22988692
AD
1513 if (ok) {
1514 notify_progress("Removing selected profiles...", true);
fb5662de 1515
f30ef1fa 1516 var query = "?op=rpc&method=remprofiles&ids="+
22988692 1517 param_escape(sel_rows.toString());
fb5662de 1518
22988692
AD
1519 new Ajax.Request("backend.php", {
1520 parameters: query,
1521 onComplete: function(transport) {
1522 notify('');
1523 editProfiles();
1524 } });
fb5662de 1525
22988692 1526 }
fb5662de
AD
1527
1528 } else {
1529 alert(__("No profiles are selected."));
22988692
AD
1530 }
1531 },
1532 activateProfile: function() {
1533 var sel_rows = this.getSelectedProfiles();
fb5662de 1534
22988692 1535 if (sel_rows.length == 1) {
fb5662de 1536
22988692 1537 var ok = confirm(__("Activate selected profile?"));
fb5662de 1538
22988692
AD
1539 if (ok) {
1540 notify_progress("Loading, please wait...");
fb5662de 1541
f30ef1fa 1542 var query = "?op=rpc&method=setprofile&id="+
22988692 1543 param_escape(sel_rows.toString());
fb5662de 1544
22988692
AD
1545 new Ajax.Request("backend.php", {
1546 parameters: query,
1547 onComplete: function(transport) {
1548 window.location.reload();
1549 } });
1550 }
fb5662de 1551
22988692
AD
1552 } else {
1553 alert(__("Please choose a profile to activate."));
fb5662de
AD
1554 }
1555 },
22988692
AD
1556 addProfile: function() {
1557 if (this.validate()) {
1558 notify_progress("Creating profile...", true);
1559
f30ef1fa 1560 var query = "?op=rpc&method=addprofile&title=" +
22988692
AD
1561 param_escape(dialog.attr('value').newprofile);
1562
1563 new Ajax.Request("backend.php", {
1564 parameters: query,
1565 onComplete: function(transport) {
1566 notify('');
1567 editProfiles();
1568 } });
1569
1570 }
1571 },
1572 execute: function() {
1573 if (this.validate()) {
1574 }
1575 },
1576 href: query});
1577
1578 dialog.show();
1579 } catch (e) {
1580 exception_error("editProfiles", e);
1581 }
d9084cf2
AD
1582}
1583
1584function activatePrefProfile() {
1585
1586 var sel_rows = getSelectedFeedCats();
1587
1588 if (sel_rows.length == 1) {
1589
1590 var ok = confirm(__("Activate selected profile?"));
1591
1592 if (ok) {
1593 notify_progress("Loading, please wait...");
fb5662de 1594
f30ef1fa 1595 var query = "?op=rpc&method=setprofile&id="+
d9084cf2
AD
1596 param_escape(sel_rows.toString());
1597
1598 new Ajax.Request("backend.php", {
1599 parameters: query,
1600 onComplete: function(transport) {
1601 window.location.reload();
1602 } });
1603 }
1604
1605 } else {
1606 alert(__("Please choose a profile to activate."));
1607 }
1608
1609 return false;
1610}
1611
8d86f15f
AD
1612function clearFeedAccessKeys() {
1613
1614 var ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?"));
1615
1616 if (ok) {
1617 notify_progress("Clearing URLs...");
1618
195187c4 1619 var query = "?op=pref-feeds&method=clearKeys";
8d86f15f
AD
1620
1621 new Ajax.Request("backend.php", {
1622 parameters: query,
fb5662de 1623 onComplete: function(transport) {
8d86f15f
AD
1624 notify_info("Generated URLs cleared.");
1625 } });
1626 }
fb5662de 1627
8d86f15f
AD
1628 return false;
1629}
1630
a86ba0a6
AD
1631function resetFilterOrder() {
1632 try {
1633 notify_progress("Loading, please wait...");
1634
1635 new Ajax.Request("backend.php", {
1636 parameters: "?op=pref-filters&method=filtersortreset",
1637 onComplete: function(transport) {
1638 updateFilterList();
1639 } });
1640
1641
1642 } catch (e) {
1643 exception_error("resetFilterOrder");
1644 }
1645}
1646
1647
7b8a143f
AD
1648function resetFeedOrder() {
1649 try {
1650 notify_progress("Loading, please wait...");
1651
1652 new Ajax.Request("backend.php", {
f30ef1fa 1653 parameters: "?op=pref-feeds&method=feedsortreset",
7b8a143f 1654 onComplete: function(transport) {
fb5662de 1655 updateFeedList();
7b8a143f
AD
1656 } });
1657
1658
1659 } catch (e) {
1660 exception_error("resetFeedOrder");
1661 }
1662}
1663
1664function resetCatOrder() {
1665 try {
1666 notify_progress("Loading, please wait...");
1667
1668 new Ajax.Request("backend.php", {
f30ef1fa 1669 parameters: "?op=pref-feeds&method=catsortreset",
7b8a143f 1670 onComplete: function(transport) {
fb5662de 1671 updateFeedList();
7b8a143f
AD
1672 } });
1673
1674
1675 } catch (e) {
1676 exception_error("resetCatOrder");
1677 }
1678}
1679
1680function editCat(id, item, event) {
1681 try {
1682 var new_name = prompt(__('Rename category to:'), item.name);
1683
1684 if (new_name && new_name != item.name) {
1685
1686 notify_progress("Loading, please wait...");
1687
1688 new Ajax.Request("backend.php", {
1689 parameters: {
fb5662de 1690 op: 'pref-feeds',
f30ef1fa 1691 method: 'renamecat',
7b8a143f
AD
1692 id: id,
1693 title: new_name,
1694 },
1695 onComplete: function(transport) {
fb5662de 1696 updateFeedList();
7b8a143f
AD
1697 } });
1698 }
1699
1700 } catch (e) {
1701 exception_error("editCat", e);
1702 }
1703}
fb8b2153
AD
1704
1705function editLabel(id, event) {
1706 try {
f30ef1fa 1707 var query = "backend.php?op=pref-labels&method=edit&id=" +
fb8b2153
AD
1708 param_escape(id);
1709
48b05a29
AD
1710 if (dijit.byId("labelEditDlg"))
1711 dijit.byId("labelEditDlg").destroyRecursive();
1712
1713 dialog = new dijit.Dialog({
1714 id: "labelEditDlg",
1715 title: __("Label Editor"),
1716 style: "width: 600px",
05acc0d6
AD
1717 setLabelColor: function(id, fg, bg) {
1718
1719 var kind = '';
1720 var color = '';
fb5662de 1721
05acc0d6
AD
1722 if (fg && bg) {
1723 kind = 'both';
1724 } else if (fg) {
1725 kind = 'fg';
1726 color = fg;
1727 } else if (bg) {
1728 kind = 'bg';
1729 color = bg;
1730 }
fb5662de 1731
cbe50c80 1732 var query = "?op=pref-labels&method=colorset&kind="+kind+
fb5662de 1733 "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) +
05acc0d6 1734 "&bg=" + param_escape(bg) + "&color=" + param_escape(color);
fb5662de 1735
05acc0d6 1736 // console.log(query);
fb5662de 1737
05acc0d6 1738 var e = $("LICID-" + id);
fb5662de
AD
1739
1740 if (e) {
05acc0d6
AD
1741 if (fg) e.style.color = fg;
1742 if (bg) e.style.backgroundColor = bg;
1743 }
fb5662de 1744
05acc0d6
AD
1745 new Ajax.Request("backend.php", { parameters: query });
1746
1747 updateFilterList();
1748 },
48b05a29
AD
1749 execute: function() {
1750 if (this.validate()) {
48b05a29
AD
1751 var caption = this.attr('value').caption;
1752 var fg_color = this.attr('value').fg_color;
1753 var bg_color = this.attr('value').bg_color;
1754 var query = dojo.objectToQuery(this.attr('value'));
1755
1756 dijit.byId('labelTree').setNameById(id, caption);
05acc0d6 1757 this.setLabelColor(id, fg_color, bg_color);
48b05a29
AD
1758 this.hide();
1759
1760 new Ajax.Request("backend.php", {
1761 parameters: query,
1762 onComplete: function(transport) {
fb5662de 1763 updateFilterList();
48b05a29
AD
1764 } });
1765 }
1766 },
1767 href: query});
fb8b2153 1768
48b05a29 1769 dialog.show();
fb8b2153
AD
1770
1771 } catch (e) {
1772 exception_error("editLabel", e);
1773 }
1774}
018caf6f 1775
88e4e597
AD
1776
1777function customizeCSS() {
1778 try {
00e34741 1779 var query = "backend.php?op=pref-prefs&method=customizeCSS";
88e4e597
AD
1780
1781 if (dijit.byId("cssEditDlg"))
1782 dijit.byId("cssEditDlg").destroyRecursive();
1783
1784 dialog = new dijit.Dialog({
1785 id: "cssEditDlg",
1786 title: __("Customize stylesheet"),
1787 style: "width: 600px",
1788 execute: function() {
1789 notify_progress('Saving data...', true);
1790 new Ajax.Request("backend.php", {
1791 parameters: dojo.objectToQuery(this.attr('value')),
fb5662de 1792 onComplete: function(transport) {
88e4e597
AD
1793 notify('');
1794 window.location.reload();
1795 } });
1796
1797 },
1798 href: query});
1799
1800 dialog.show();
1801
1802 } catch (e) {
1803 exception_error("customizeCSS", e);
1804 }
1805}
3d72afa1
AD
1806
1807function insertSSLserial(value) {
1808 try {
1809 dijit.byId("SSL_CERT_SERIAL").attr('value', value);
1810 } catch (e) {
1811 exception_error("insertSSLcerial", e);
1812 }
1813}
373266eb 1814
41f68571
AD
1815function gotoExportOpml(filename, settings) {
1816 tmp = settings ? 1 : 0;
d75409bf 1817 document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
41f68571
AD
1818}
1819
1820
33f0fdd0
AD
1821function batchSubscribe() {
1822 try {
201bb1ca 1823 var query = "backend.php?op=pref-feeds&method=batchSubscribe";
33f0fdd0 1824
c714cee7
AD
1825 // overlapping widgets
1826 if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive();
1827 if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive();
33f0fdd0
AD
1828
1829 var dialog = new dijit.Dialog({
1830 id: "batchSubDlg",
1831 title: __("Batch subscribe"),
1832 style: "width: 600px",
1833 execute: function() {
1834 if (this.validate()) {
1835 console.log(dojo.objectToQuery(this.attr('value')));
1836
1837 notify_progress(__("Subscribing to feeds..."), true);
1838
1839 new Ajax.Request("backend.php", {
1840 parameters: dojo.objectToQuery(this.attr('value')),
1841 onComplete: function(transport) {
4b298c86
AD
1842 notify("");
1843 updateFeedList();
1844 dialog.hide();
33f0fdd0
AD
1845 } });
1846 }
1847 },
1848 href: query});
1849
1850 dialog.show();
1851 } catch (e) {
1852 exception_error("batchSubscribe", e);
1853 }
1854}
55f34b81 1855
27211afe 1856
f9ebb32c
AD
1857function toggleAdvancedPrefs() {
1858 try {
1859 notify_progress("Loading, please wait...");
1860
1861 new Ajax.Request("backend.php", {
1862 parameters: "?op=pref-prefs&method=toggleadvanced",
1863 onComplete: function(transport) {
1864 updatePrefsList();
1865 } });
1866
1867 } catch (e) {
1868 exception_error("toggleAdvancedPrefs", e);
1869 }
1870}
5d9abb1e
AD
1871
1872function clearPluginData(name) {
1873 try {
1874 if (confirm(__("Clear stored data for this plugin?"))) {
1875 notify_progress("Loading, please wait...");
1876
1877 new Ajax.Request("backend.php", {
1878 parameters: "?op=pref-prefs&method=clearplugindata&name=" + param_escape(name),
1879 onComplete: function(transport) {
1880 notify('');
1881 updatePrefsList();
1882 } });
1883 }
1884 } catch (e) {
1885 exception_error("clearPluginData", e);
1886 }
1887}
52e7b5a0
AD
1888
1889function clearSqlLog() {
1890
1891 if (confirm(__("Clear all messages in the error log?"))) {
1892
1893 notify_progress("Loading, please wait...");
1894 var query = "?op=pref-system&method=clearLog";
1895
1896 new Ajax.Request("backend.php", {
1897 parameters: query,
1898 onComplete: function(transport) {
1899 updateSystemList();
1900 } });
1901
1902 }
1903}
1904
1905