]>
Commit | Line | Data |
---|---|---|
1 | /* global dijit, __ */ | |
2 | ||
3 | let seq = ""; | |
4 | ||
5 | function notify_callback2(transport, sticky) { | |
6 | notify_info(transport.responseText, sticky); | |
7 | } | |
8 | ||
9 | function updateFeedList() { | |
10 | ||
11 | const user_search = $("feed_search"); | |
12 | let search = ""; | |
13 | if (user_search) { search = user_search.value; } | |
14 | ||
15 | xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { | |
16 | dijit.byId('feedConfigTab').attr('content', transport.responseText); | |
17 | selectTab("feedConfig", true); | |
18 | notify(""); | |
19 | }); | |
20 | } | |
21 | ||
22 | function checkInactiveFeeds() { | |
23 | xhrPost("backend.php", { op: "pref-feeds", method: "getinactivefeeds" }, (transport) => { | |
24 | if (parseInt(transport.responseText) > 0) { | |
25 | Element.show(dijit.byId("pref_feeds_inactive_btn").domNode); | |
26 | } | |
27 | }); | |
28 | } | |
29 | ||
30 | function updateUsersList(sort_key) { | |
31 | const user_search = $("user_search"); | |
32 | const search = user_search ? user_search.value : ""; | |
33 | ||
34 | const query = { op: "pref-users", sort: sort_key, search: search }; | |
35 | ||
36 | xhrPost("backend.php", query, (transport) => { | |
37 | dijit.byId('userConfigTab').attr('content', transport.responseText); | |
38 | selectTab("userConfig", true) | |
39 | notify(""); | |
40 | }); | |
41 | } | |
42 | ||
43 | function addUser() { | |
44 | const login = prompt(__("Please enter login:"), ""); | |
45 | ||
46 | if (login == null) { | |
47 | return false; | |
48 | } | |
49 | ||
50 | if (login == "") { | |
51 | alert(__("Can't create user: no login specified.")); | |
52 | return false; | |
53 | } | |
54 | ||
55 | notify_progress("Adding user..."); | |
56 | ||
57 | xhrPost("backend.php", { op: "pref-users", method: "add", login: login }, (transport) => { | |
58 | notify_callback2(transport); | |
59 | updateUsersList(); | |
60 | }); | |
61 | ||
62 | } | |
63 | ||
64 | function editUser(id) { | |
65 | ||
66 | const query = "backend.php?op=pref-users&method=edit&id=" + | |
67 | param_escape(id); | |
68 | ||
69 | if (dijit.byId("userEditDlg")) | |
70 | dijit.byId("userEditDlg").destroyRecursive(); | |
71 | ||
72 | const dialog = new dijit.Dialog({ | |
73 | id: "userEditDlg", | |
74 | title: __("User Editor"), | |
75 | style: "width: 600px", | |
76 | execute: function () { | |
77 | if (this.validate()) { | |
78 | notify_progress("Saving data...", true); | |
79 | ||
80 | xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { | |
81 | dialog.hide(); | |
82 | updateUsersList(); | |
83 | }); | |
84 | } | |
85 | }, | |
86 | href: query | |
87 | }); | |
88 | ||
89 | dialog.show(); | |
90 | } | |
91 | ||
92 | function editFilter(id) { | |
93 | ||
94 | const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); | |
95 | ||
96 | if (dijit.byId("feedEditDlg")) | |
97 | dijit.byId("feedEditDlg").destroyRecursive(); | |
98 | ||
99 | if (dijit.byId("filterEditDlg")) | |
100 | dijit.byId("filterEditDlg").destroyRecursive(); | |
101 | ||
102 | const dialog = new dijit.Dialog({ | |
103 | id: "filterEditDlg", | |
104 | title: __("Edit Filter"), | |
105 | style: "width: 600px", | |
106 | ||
107 | test: function () { | |
108 | const query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; | |
109 | ||
110 | editFilterTest(query); | |
111 | }, | |
112 | selectRules: function (select) { | |
113 | $$("#filterDlg_Matches input[type=checkbox]").each(function (e) { | |
114 | e.checked = select; | |
115 | if (select) | |
116 | e.parentNode.addClassName("Selected"); | |
117 | else | |
118 | e.parentNode.removeClassName("Selected"); | |
119 | }); | |
120 | }, | |
121 | selectActions: function (select) { | |
122 | $$("#filterDlg_Actions input[type=checkbox]").each(function (e) { | |
123 | e.checked = select; | |
124 | ||
125 | if (select) | |
126 | e.parentNode.addClassName("Selected"); | |
127 | else | |
128 | e.parentNode.removeClassName("Selected"); | |
129 | ||
130 | }); | |
131 | }, | |
132 | editRule: function (e) { | |
133 | const li = e.parentNode; | |
134 | const rule = li.getElementsByTagName("INPUT")[1].value; | |
135 | addFilterRule(li, rule); | |
136 | }, | |
137 | editAction: function (e) { | |
138 | const li = e.parentNode; | |
139 | const action = li.getElementsByTagName("INPUT")[1].value; | |
140 | addFilterAction(li, action); | |
141 | }, | |
142 | removeFilter: function () { | |
143 | const msg = __("Remove filter?"); | |
144 | ||
145 | if (confirm(msg)) { | |
146 | this.hide(); | |
147 | ||
148 | notify_progress("Removing filter..."); | |
149 | ||
150 | const query = { op: "pref-filters", method: "remove", ids: this.attr('value').id }; | |
151 | ||
152 | xhrPost("backend.php", query, () => { | |
153 | updateFilterList(); | |
154 | }); | |
155 | } | |
156 | }, | |
157 | addAction: function () { | |
158 | addFilterAction(); | |
159 | }, | |
160 | addRule: function () { | |
161 | addFilterRule(); | |
162 | }, | |
163 | deleteAction: function () { | |
164 | $$("#filterDlg_Actions li[class*=Selected]").each(function (e) { | |
165 | e.parentNode.removeChild(e) | |
166 | }); | |
167 | }, | |
168 | deleteRule: function () { | |
169 | $$("#filterDlg_Matches li[class*=Selected]").each(function (e) { | |
170 | e.parentNode.removeChild(e) | |
171 | }); | |
172 | }, | |
173 | execute: function () { | |
174 | if (this.validate()) { | |
175 | ||
176 | notify_progress("Saving data...", true); | |
177 | ||
178 | xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => { | |
179 | dialog.hide(); | |
180 | updateFilterList(); | |
181 | }); | |
182 | } | |
183 | }, | |
184 | href: query | |
185 | }); | |
186 | ||
187 | dialog.show(); | |
188 | } | |
189 | ||
190 | ||
191 | function getSelectedLabels() { | |
192 | const tree = dijit.byId("labelTree"); | |
193 | const items = tree.model.getCheckedItems(); | |
194 | const rv = []; | |
195 | ||
196 | items.each(function(item) { | |
197 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
198 | }); | |
199 | ||
200 | return rv; | |
201 | } | |
202 | ||
203 | function getSelectedUsers() { | |
204 | return getSelectedTableRowIds("prefUserList"); | |
205 | } | |
206 | ||
207 | function getSelectedFeeds() { | |
208 | const tree = dijit.byId("feedTree"); | |
209 | const items = tree.model.getCheckedItems(); | |
210 | const rv = []; | |
211 | ||
212 | items.each(function(item) { | |
213 | if (item.id[0].match("FEED:")) | |
214 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
215 | }); | |
216 | ||
217 | return rv; | |
218 | } | |
219 | ||
220 | function getSelectedCategories() { | |
221 | const tree = dijit.byId("feedTree"); | |
222 | const items = tree.model.getCheckedItems(); | |
223 | const rv = []; | |
224 | ||
225 | items.each(function(item) { | |
226 | if (item.id[0].match("CAT:")) | |
227 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
228 | }); | |
229 | ||
230 | return rv; | |
231 | } | |
232 | ||
233 | function getSelectedFilters() { | |
234 | const tree = dijit.byId("filterTree"); | |
235 | const items = tree.model.getCheckedItems(); | |
236 | const rv = []; | |
237 | ||
238 | items.each(function(item) { | |
239 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
240 | }); | |
241 | ||
242 | return rv; | |
243 | ||
244 | } | |
245 | ||
246 | function removeSelectedLabels() { | |
247 | ||
248 | const sel_rows = getSelectedLabels(); | |
249 | ||
250 | if (sel_rows.length > 0) { | |
251 | if (confirm(__("Remove selected labels?"))) { | |
252 | notify_progress("Removing selected labels..."); | |
253 | ||
254 | const query = { op: "pref-labels", method: "remove", | |
255 | ids: sel_rows.toString() }; | |
256 | ||
257 | xhrPost("backend.php", query, () => { | |
258 | updateLabelList(); | |
259 | }); | |
260 | } | |
261 | } else { | |
262 | alert(__("No labels are selected.")); | |
263 | } | |
264 | ||
265 | return false; | |
266 | } | |
267 | ||
268 | function removeSelectedUsers() { | |
269 | ||
270 | const sel_rows = getSelectedUsers(); | |
271 | ||
272 | if (sel_rows.length > 0) { | |
273 | ||
274 | if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { | |
275 | notify_progress("Removing selected users..."); | |
276 | ||
277 | const query = { op: "pref-users", method: "remove", | |
278 | ids: sel_rows.toString() }; | |
279 | ||
280 | xhrPost("backend.php", query, () => { | |
281 | updateUsersList(); | |
282 | }); | |
283 | } | |
284 | ||
285 | } else { | |
286 | alert(__("No users are selected.")); | |
287 | } | |
288 | ||
289 | return false; | |
290 | } | |
291 | ||
292 | function removeSelectedFilters() { | |
293 | ||
294 | const sel_rows = getSelectedFilters(); | |
295 | ||
296 | if (sel_rows.length > 0) { | |
297 | if (confirm(__("Remove selected filters?"))) { | |
298 | notify_progress("Removing selected filters..."); | |
299 | ||
300 | const query = { op: "pref-filters", method: "remove", | |
301 | ids: sel_rows.toString() }; | |
302 | ||
303 | xhrPost("backend.php", query, () => { | |
304 | updateFilterList(); | |
305 | }); | |
306 | } | |
307 | } else { | |
308 | alert(__("No filters are selected.")); | |
309 | } | |
310 | ||
311 | return false; | |
312 | } | |
313 | ||
314 | function removeSelectedFeeds() { | |
315 | ||
316 | const sel_rows = getSelectedFeeds(); | |
317 | ||
318 | if (sel_rows.length > 0) { | |
319 | if (confirm(__("Unsubscribe from selected feeds?"))) { | |
320 | ||
321 | notify_progress("Unsubscribing from selected feeds...", true); | |
322 | ||
323 | const query = { op: "pref-feeds", method: "remove", | |
324 | ids: sel_rows.toString() }; | |
325 | ||
326 | xhrPost("backend.php", query, () => { | |
327 | updateFeedList(); | |
328 | }); | |
329 | } | |
330 | ||
331 | } else { | |
332 | alert(__("No feeds are selected.")); | |
333 | } | |
334 | ||
335 | return false; | |
336 | } | |
337 | ||
338 | function editSelectedUser() { | |
339 | const rows = getSelectedUsers(); | |
340 | ||
341 | if (rows.length == 0) { | |
342 | alert(__("No users are selected.")); | |
343 | return; | |
344 | } | |
345 | ||
346 | if (rows.length > 1) { | |
347 | alert(__("Please select only one user.")); | |
348 | return; | |
349 | } | |
350 | ||
351 | notify(""); | |
352 | ||
353 | editUser(rows[0]); | |
354 | } | |
355 | ||
356 | function resetSelectedUserPass() { | |
357 | ||
358 | const rows = getSelectedUsers(); | |
359 | ||
360 | if (rows.length == 0) { | |
361 | alert(__("No users are selected.")); | |
362 | return; | |
363 | } | |
364 | ||
365 | if (rows.length > 1) { | |
366 | alert(__("Please select only one user.")); | |
367 | return; | |
368 | } | |
369 | ||
370 | if (confirm(__("Reset password of selected user?"))) { | |
371 | notify_progress("Resetting password for selected user..."); | |
372 | ||
373 | const id = rows[0]; | |
374 | ||
375 | xhrPost("backend.php", { op: "pref-users", method: "resetPass", id: id }, (transport) => { | |
376 | notify_info(transport.responseText, true); | |
377 | }); | |
378 | ||
379 | } | |
380 | } | |
381 | ||
382 | function selectedUserDetails() { | |
383 | ||
384 | const rows = getSelectedUsers(); | |
385 | ||
386 | if (rows.length == 0) { | |
387 | alert(__("No users are selected.")); | |
388 | return; | |
389 | } | |
390 | ||
391 | if (rows.length > 1) { | |
392 | alert(__("Please select only one user.")); | |
393 | return; | |
394 | } | |
395 | ||
396 | const query = "backend.php?op=pref-users&method=userdetails&id=" + param_escape(rows[0]); | |
397 | ||
398 | if (dijit.byId("userDetailsDlg")) | |
399 | dijit.byId("userDetailsDlg").destroyRecursive(); | |
400 | ||
401 | const dialog = new dijit.Dialog({ | |
402 | id: "userDetailsDlg", | |
403 | title: __("User details"), | |
404 | style: "width: 600px", | |
405 | execute: function () { | |
406 | dialog.hide(); | |
407 | }, | |
408 | href: query | |
409 | }); | |
410 | ||
411 | dialog.show(); | |
412 | } | |
413 | ||
414 | ||
415 | function editSelectedFilter() { | |
416 | const rows = getSelectedFilters(); | |
417 | ||
418 | if (rows.length == 0) { | |
419 | alert(__("No filters are selected.")); | |
420 | return; | |
421 | } | |
422 | ||
423 | if (rows.length > 1) { | |
424 | alert(__("Please select only one filter.")); | |
425 | return; | |
426 | } | |
427 | ||
428 | notify(""); | |
429 | ||
430 | editFilter(rows[0]); | |
431 | ||
432 | } | |
433 | ||
434 | function joinSelectedFilters() { | |
435 | const rows = getSelectedFilters(); | |
436 | ||
437 | if (rows.length == 0) { | |
438 | alert(__("No filters are selected.")); | |
439 | return; | |
440 | } | |
441 | ||
442 | if (confirm(__("Combine selected filters?"))) { | |
443 | notify_progress("Joining filters..."); | |
444 | ||
445 | xhrPost("backend.php", { op: "pref-filters", method: "join", ids: rows.toString() }, () => { | |
446 | updateFilterList(); | |
447 | }); | |
448 | } | |
449 | } | |
450 | ||
451 | function editSelectedFeed() { | |
452 | const rows = getSelectedFeeds(); | |
453 | ||
454 | if (rows.length == 0) { | |
455 | alert(__("No feeds are selected.")); | |
456 | return; | |
457 | } | |
458 | ||
459 | if (rows.length > 1) { | |
460 | return editSelectedFeeds(); | |
461 | } | |
462 | ||
463 | notify(""); | |
464 | ||
465 | editFeed(rows[0], {}); | |
466 | ||
467 | } | |
468 | ||
469 | function editSelectedFeeds() { | |
470 | const rows = getSelectedFeeds(); | |
471 | ||
472 | if (rows.length == 0) { | |
473 | alert(__("No feeds are selected.")); | |
474 | return; | |
475 | } | |
476 | ||
477 | notify_progress("Loading, please wait..."); | |
478 | ||
479 | if (dijit.byId("feedEditDlg")) | |
480 | dijit.byId("feedEditDlg").destroyRecursive(); | |
481 | ||
482 | xhrPost("backend.php", { op: "pref-feeds", method: "editfeeds", ids: rows.toString() }, (transport) => { | |
483 | notify(""); | |
484 | ||
485 | const dialog = new dijit.Dialog({ | |
486 | id: "feedEditDlg", | |
487 | title: __("Edit Multiple Feeds"), | |
488 | style: "width: 600px", | |
489 | getChildByName: function (name) { | |
490 | let rv = null; | |
491 | this.getChildren().each( | |
492 | function (child) { | |
493 | if (child.name == name) { | |
494 | rv = child; | |
495 | return; | |
496 | } | |
497 | }); | |
498 | return rv; | |
499 | }, | |
500 | toggleField: function (checkbox, elem, label) { | |
501 | this.getChildByName(elem).attr('disabled', !checkbox.checked); | |
502 | ||
503 | if ($(label)) | |
504 | if (checkbox.checked) | |
505 | $(label).removeClassName('insensitive'); | |
506 | else | |
507 | $(label).addClassName('insensitive'); | |
508 | ||
509 | }, | |
510 | execute: function () { | |
511 | if (this.validate() && confirm(__("Save changes to selected feeds?"))) { | |
512 | const query = this.attr('value'); | |
513 | ||
514 | /* normalize unchecked checkboxes because [] is not serialized */ | |
515 | ||
516 | Object.keys(query).each((key) => { | |
517 | let val = query[key]; | |
518 | ||
519 | if (typeof val == "object" && val.length == 0) | |
520 | query[key] = ["off"]; | |
521 | }); | |
522 | ||
523 | notify_progress("Saving data...", true); | |
524 | ||
525 | xhrPost("backend.php", query, () => { | |
526 | dialog.hide(); | |
527 | updateFeedList(); | |
528 | }); | |
529 | } | |
530 | }, | |
531 | content: transport.responseText | |
532 | }); | |
533 | ||
534 | dialog.show(); | |
535 | }); | |
536 | } | |
537 | ||
538 | function opmlImportComplete(iframe) { | |
539 | if (!iframe.contentDocument.body.innerHTML) return false; | |
540 | ||
541 | Element.show(iframe); | |
542 | ||
543 | notify(''); | |
544 | ||
545 | if (dijit.byId('opmlImportDlg')) | |
546 | dijit.byId('opmlImportDlg').destroyRecursive(); | |
547 | ||
548 | const content = iframe.contentDocument.body.innerHTML; | |
549 | ||
550 | const dialog = new dijit.Dialog({ | |
551 | id: "opmlImportDlg", | |
552 | title: __("OPML Import"), | |
553 | style: "width: 600px", | |
554 | onCancel: function () { | |
555 | window.location.reload(); | |
556 | }, | |
557 | execute: function () { | |
558 | window.location.reload(); | |
559 | }, | |
560 | content: content | |
561 | }); | |
562 | ||
563 | dialog.show(); | |
564 | } | |
565 | ||
566 | function opmlImport() { | |
567 | ||
568 | const opml_file = $("opml_file"); | |
569 | ||
570 | if (opml_file.value.length == 0) { | |
571 | alert(__("Please choose an OPML file first.")); | |
572 | return false; | |
573 | } else { | |
574 | notify_progress("Importing, please wait...", true); | |
575 | ||
576 | Element.show("upload_iframe"); | |
577 | ||
578 | return true; | |
579 | } | |
580 | } | |
581 | ||
582 | ||
583 | function updateFilterList() { | |
584 | const user_search = $("filter_search"); | |
585 | let search = ""; | |
586 | if (user_search) { search = user_search.value; } | |
587 | ||
588 | xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { | |
589 | dijit.byId('filterConfigTab').attr('content', transport.responseText); | |
590 | notify(""); | |
591 | }); | |
592 | } | |
593 | ||
594 | function updateLabelList() { | |
595 | xhrPost("backend.php", { op: "pref-labels" }, (transport) => { | |
596 | dijit.byId('labelConfigTab').attr('content', transport.responseText); | |
597 | notify(""); | |
598 | }); | |
599 | } | |
600 | ||
601 | function updatePrefsList() { | |
602 | xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { | |
603 | dijit.byId('genConfigTab').attr('content', transport.responseText); | |
604 | notify(""); | |
605 | }); | |
606 | } | |
607 | ||
608 | function updateSystemList() { | |
609 | xhrPost("backend.php", { op: "pref-system" }, (transport) => { | |
610 | dijit.byId('systemConfigTab').attr('content', transport.responseText); | |
611 | notify(""); | |
612 | }); | |
613 | } | |
614 | ||
615 | function selectTab(id, noupdate) { | |
616 | if (!noupdate) { | |
617 | notify_progress("Loading, please wait..."); | |
618 | ||
619 | switch (id) { | |
620 | case "feedConfig": | |
621 | updateFeedList(); | |
622 | break; | |
623 | case "filterConfig": | |
624 | updateFilterList(); | |
625 | break; | |
626 | case "labelConfig": | |
627 | updateLabelList(); | |
628 | break; | |
629 | case "genConfig": | |
630 | updatePrefsList(); | |
631 | break; | |
632 | case "userConfig": | |
633 | updateUsersList(); | |
634 | break; | |
635 | case "systemConfig": | |
636 | updateSystemList(); | |
637 | break; | |
638 | default: | |
639 | console.warn("unknown tab", id); | |
640 | } | |
641 | ||
642 | const tab = dijit.byId(id + "Tab"); | |
643 | dijit.byId("pref-tabs").selectChild(tab); | |
644 | ||
645 | } | |
646 | } | |
647 | ||
648 | function init_second_stage() { | |
649 | document.onkeydown = pref_hotkey_handler; | |
650 | loading_set_progress(50); | |
651 | notify(""); | |
652 | ||
653 | let tab = getURLParam('tab'); | |
654 | ||
655 | if (tab) { | |
656 | tab = dijit.byId(tab + "Tab"); | |
657 | if (tab) dijit.byId("pref-tabs").selectChild(tab); | |
658 | } | |
659 | ||
660 | const method = getURLParam('method'); | |
661 | ||
662 | if (method == 'editFeed') { | |
663 | const param = getURLParam('methodparam'); | |
664 | ||
665 | window.setTimeout(function() { editFeed(param) }, 100); | |
666 | } | |
667 | ||
668 | setInterval(hotkey_prefix_timeout, 5*1000); | |
669 | } | |
670 | ||
671 | function init() { | |
672 | window.onerror = function (message, filename, lineno, colno, error) { | |
673 | report_error(message, filename, lineno, colno, error); | |
674 | }; | |
675 | ||
676 | require(["dojo/_base/kernel", | |
677 | "dojo/ready", | |
678 | "dojo/parser", | |
679 | "dojo/_base/loader", | |
680 | "dojo/_base/html", | |
681 | "dijit/ColorPalette", | |
682 | "dijit/Dialog", | |
683 | "dijit/form/Button", | |
684 | "dijit/form/CheckBox", | |
685 | "dijit/form/DropDownButton", | |
686 | "dijit/form/FilteringSelect", | |
687 | "dijit/form/MultiSelect", | |
688 | "dijit/form/Form", | |
689 | "dijit/form/RadioButton", | |
690 | "dijit/form/ComboButton", | |
691 | "dijit/form/Select", | |
692 | "dijit/form/SimpleTextarea", | |
693 | "dijit/form/TextBox", | |
694 | "dijit/form/ValidationTextBox", | |
695 | "dijit/InlineEditBox", | |
696 | "dijit/layout/AccordionContainer", | |
697 | "dijit/layout/AccordionPane", | |
698 | "dijit/layout/BorderContainer", | |
699 | "dijit/layout/ContentPane", | |
700 | "dijit/layout/TabContainer", | |
701 | "dijit/Menu", | |
702 | "dijit/ProgressBar", | |
703 | "dijit/Toolbar", | |
704 | "dijit/Tree", | |
705 | "dijit/tree/dndSource", | |
706 | "dojo/data/ItemFileWriteStore", | |
707 | "lib/CheckBoxStoreModel", | |
708 | "lib/CheckBoxTree", | |
709 | "fox/PrefFeedStore", | |
710 | "fox/PrefFilterStore", | |
711 | "fox/PrefFeedTree", | |
712 | "fox/PrefFilterTree", | |
713 | "fox/PrefLabelTree"], function (dojo, ready, parser) { | |
714 | ||
715 | ready(function () { | |
716 | try { | |
717 | parser.parse(); | |
718 | ||
719 | loading_set_progress(50); | |
720 | ||
721 | const clientTzOffset = new Date().getTimezoneOffset() * 60; | |
722 | const params = { op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset }; | |
723 | ||
724 | xhrPost("backend.php", params, (transport) => { | |
725 | backend_sanity_check_callback(transport); | |
726 | }); | |
727 | ||
728 | } catch (e) { | |
729 | exception_error(e); | |
730 | } | |
731 | }); | |
732 | }); | |
733 | } | |
734 | ||
735 | ||
736 | function validatePrefsReset() { | |
737 | if (confirm(__("Reset to defaults?"))) { | |
738 | ||
739 | const query = "?op=pref-prefs&method=resetconfig"; | |
740 | ||
741 | xhrPost("backend.php", { op: "pref-prefs", method: "resetconfig" }, (transport) => { | |
742 | updatePrefsList(); | |
743 | notify_info(transport.responseText); | |
744 | }); | |
745 | } | |
746 | ||
747 | return false; | |
748 | } | |
749 | ||
750 | function pref_hotkey_handler(e) { | |
751 | if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; | |
752 | ||
753 | const action_name = keyevent_to_action(e); | |
754 | ||
755 | if (action_name) { | |
756 | switch (action_name) { | |
757 | case "feed_subscribe": | |
758 | quickAddFeed(); | |
759 | return false; | |
760 | case "create_label": | |
761 | addLabel(); | |
762 | return false; | |
763 | case "create_filter": | |
764 | quickAddFilter(); | |
765 | return false; | |
766 | case "help_dialog": | |
767 | helpDialog("main"); | |
768 | return false; | |
769 | default: | |
770 | console.log("unhandled action: " + action_name + "; keycode: " + e.which); | |
771 | } | |
772 | } | |
773 | } | |
774 | ||
775 | function removeCategory(id, item) { | |
776 | ||
777 | if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) { | |
778 | notify_progress("Removing category..."); | |
779 | ||
780 | const query = { op: "pref-feeds", method: "removeCat", | |
781 | ids: id }; | |
782 | ||
783 | xhrPost("backend.php", query, () => { | |
784 | notify(''); | |
785 | updateFeedList(); | |
786 | }); | |
787 | } | |
788 | } | |
789 | ||
790 | function removeSelectedCategories() { | |
791 | const sel_rows = getSelectedCategories(); | |
792 | ||
793 | if (sel_rows.length > 0) { | |
794 | if (confirm(__("Remove selected categories?"))) { | |
795 | notify_progress("Removing selected categories..."); | |
796 | ||
797 | const query = { op: "pref-feeds", method: "removeCat", | |
798 | ids: sel_rows.toString() }; | |
799 | ||
800 | xhrPost("backend.php", query, () => { | |
801 | updateFeedList(); | |
802 | }); | |
803 | } | |
804 | } else { | |
805 | alert(__("No categories are selected.")); | |
806 | } | |
807 | ||
808 | return false; | |
809 | } | |
810 | ||
811 | function createCategory() { | |
812 | const title = prompt(__("Category title:")); | |
813 | ||
814 | if (title) { | |
815 | notify_progress("Creating category..."); | |
816 | ||
817 | xhrPost("backend.php", { op: "pref-feeds", method: "addCat", cat: title }, () => { | |
818 | notify(''); | |
819 | updateFeedList(); | |
820 | }); | |
821 | } | |
822 | } | |
823 | ||
824 | function showInactiveFeeds() { | |
825 | const query = "backend.php?op=pref-feeds&method=inactiveFeeds"; | |
826 | ||
827 | if (dijit.byId("inactiveFeedsDlg")) | |
828 | dijit.byId("inactiveFeedsDlg").destroyRecursive(); | |
829 | ||
830 | const dialog = new dijit.Dialog({ | |
831 | id: "inactiveFeedsDlg", | |
832 | title: __("Feeds without recent updates"), | |
833 | style: "width: 600px", | |
834 | getSelectedFeeds: function () { | |
835 | return getSelectedTableRowIds("prefInactiveFeedList"); | |
836 | }, | |
837 | removeSelected: function () { | |
838 | const sel_rows = this.getSelectedFeeds(); | |
839 | ||
840 | if (sel_rows.length > 0) { | |
841 | if (confirm(__("Remove selected feeds?"))) { | |
842 | notify_progress("Removing selected feeds...", true); | |
843 | ||
844 | const query = { op: "pref-feeds", method: "remove", | |
845 | ids: sel_rows.toString() }; | |
846 | ||
847 | xhrPost("backend.php", query, () => { | |
848 | notify(''); | |
849 | dialog.hide(); | |
850 | updateFeedList(); | |
851 | }); | |
852 | } | |
853 | ||
854 | } else { | |
855 | alert(__("No feeds are selected.")); | |
856 | } | |
857 | }, | |
858 | execute: function () { | |
859 | if (this.validate()) { | |
860 | } | |
861 | }, | |
862 | href: query | |
863 | }); | |
864 | ||
865 | dialog.show(); | |
866 | } | |
867 | ||
868 | function opmlRegenKey() { | |
869 | if (confirm(__("Replace current OPML publishing address with a new one?"))) { | |
870 | notify_progress("Trying to change address...", true); | |
871 | ||
872 | xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => { | |
873 | if (reply) { | |
874 | const new_link = reply.link; | |
875 | const e = $('pub_opml_url'); | |
876 | ||
877 | if (new_link) { | |
878 | e.href = new_link; | |
879 | e.innerHTML = new_link; | |
880 | ||
881 | new Effect.Highlight(e); | |
882 | ||
883 | notify(''); | |
884 | ||
885 | } else { | |
886 | notify_error("Could not change feed URL."); | |
887 | } | |
888 | } | |
889 | }); | |
890 | } | |
891 | return false; | |
892 | } | |
893 | ||
894 | function labelColorReset() { | |
895 | const labels = getSelectedLabels(); | |
896 | ||
897 | if (labels.length > 0) { | |
898 | if (confirm(__("Reset selected labels to default colors?"))) { | |
899 | ||
900 | const query = { op: "pref-labels", method: "colorreset", | |
901 | ids: labels.toString() }; | |
902 | ||
903 | xhrPost("backend.php", query, () => { | |
904 | updateLabelList(); | |
905 | }); | |
906 | } | |
907 | ||
908 | } else { | |
909 | alert(__("No labels are selected.")); | |
910 | } | |
911 | } | |
912 | ||
913 | function inPreferences() { | |
914 | return true; | |
915 | } | |
916 | ||
917 | function editProfiles() { | |
918 | ||
919 | if (dijit.byId("profileEditDlg")) | |
920 | dijit.byId("profileEditDlg").destroyRecursive(); | |
921 | ||
922 | const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; | |
923 | ||
924 | const dialog = new dijit.Dialog({ | |
925 | id: "profileEditDlg", | |
926 | title: __("Settings Profiles"), | |
927 | style: "width: 600px", | |
928 | getSelectedProfiles: function () { | |
929 | return getSelectedTableRowIds("prefFeedProfileList"); | |
930 | }, | |
931 | removeSelected: function () { | |
932 | const sel_rows = this.getSelectedProfiles(); | |
933 | ||
934 | if (sel_rows.length > 0) { | |
935 | if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) { | |
936 | notify_progress("Removing selected profiles...", true); | |
937 | ||
938 | const query = { op: "rpc", method: "remprofiles", | |
939 | ids: sel_rows.toString() }; | |
940 | ||
941 | xhrPost("backend.php", query, () => { | |
942 | notify(''); | |
943 | editProfiles(); | |
944 | }); | |
945 | } | |
946 | ||
947 | } else { | |
948 | alert(__("No profiles are selected.")); | |
949 | } | |
950 | }, | |
951 | activateProfile: function () { | |
952 | const sel_rows = this.getSelectedProfiles(); | |
953 | ||
954 | if (sel_rows.length == 1) { | |
955 | if (confirm(__("Activate selected profile?"))) { | |
956 | notify_progress("Loading, please wait..."); | |
957 | ||
958 | xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() }, () => { | |
959 | window.location.reload(); | |
960 | }); | |
961 | } | |
962 | ||
963 | } else { | |
964 | alert(__("Please choose a profile to activate.")); | |
965 | } | |
966 | }, | |
967 | addProfile: function () { | |
968 | if (this.validate()) { | |
969 | notify_progress("Creating profile...", true); | |
970 | ||
971 | const query = { op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile }; | |
972 | ||
973 | xhrPost("backend.php", query, () => { | |
974 | notify(''); | |
975 | editProfiles(); | |
976 | }); | |
977 | ||
978 | } | |
979 | }, | |
980 | execute: function () { | |
981 | if (this.validate()) { | |
982 | } | |
983 | }, | |
984 | href: query | |
985 | }); | |
986 | ||
987 | dialog.show(); | |
988 | } | |
989 | ||
990 | /* | |
991 | function activatePrefProfile() { | |
992 | ||
993 | const sel_rows = getSelectedFeedCats(); | |
994 | ||
995 | if (sel_rows.length == 1) { | |
996 | ||
997 | const ok = confirm(__("Activate selected profile?")); | |
998 | ||
999 | if (ok) { | |
1000 | notify_progress("Loading, please wait..."); | |
1001 | ||
1002 | xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() }, () => { | |
1003 | window.location.reload(); | |
1004 | }); | |
1005 | } | |
1006 | ||
1007 | } else { | |
1008 | alert(__("Please choose a profile to activate.")); | |
1009 | } | |
1010 | ||
1011 | return false; | |
1012 | } */ | |
1013 | ||
1014 | function clearFeedAccessKeys() { | |
1015 | ||
1016 | if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { | |
1017 | notify_progress("Clearing URLs..."); | |
1018 | ||
1019 | xhrPost("backend.php", { op: "pref-feeds", method: "clearKeys" }, () => { | |
1020 | notify_info("Generated URLs cleared."); | |
1021 | }); | |
1022 | } | |
1023 | ||
1024 | return false; | |
1025 | } | |
1026 | ||
1027 | function resetFilterOrder() { | |
1028 | notify_progress("Loading, please wait..."); | |
1029 | ||
1030 | xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => { | |
1031 | updateFilterList(); | |
1032 | }); | |
1033 | } | |
1034 | ||
1035 | ||
1036 | function resetFeedOrder() { | |
1037 | notify_progress("Loading, please wait..."); | |
1038 | ||
1039 | xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => { | |
1040 | updateFeedList(); | |
1041 | }); | |
1042 | } | |
1043 | ||
1044 | function resetCatOrder() { | |
1045 | notify_progress("Loading, please wait..."); | |
1046 | ||
1047 | xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => { | |
1048 | updateFeedList(); | |
1049 | }); | |
1050 | } | |
1051 | ||
1052 | function editCat(id, item) { | |
1053 | const new_name = prompt(__('Rename category to:'), item.name); | |
1054 | ||
1055 | if (new_name && new_name != item.name) { | |
1056 | ||
1057 | notify_progress("Loading, please wait..."); | |
1058 | ||
1059 | xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { | |
1060 | updateFeedList(); | |
1061 | }); | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | function editLabel(id) { | |
1066 | const query = "backend.php?op=pref-labels&method=edit&id=" + | |
1067 | param_escape(id); | |
1068 | ||
1069 | if (dijit.byId("labelEditDlg")) | |
1070 | dijit.byId("labelEditDlg").destroyRecursive(); | |
1071 | ||
1072 | const dialog = new dijit.Dialog({ | |
1073 | id: "labelEditDlg", | |
1074 | title: __("Label Editor"), | |
1075 | style: "width: 600px", | |
1076 | setLabelColor: function (id, fg, bg) { | |
1077 | ||
1078 | let kind = ''; | |
1079 | let color = ''; | |
1080 | ||
1081 | if (fg && bg) { | |
1082 | kind = 'both'; | |
1083 | } else if (fg) { | |
1084 | kind = 'fg'; | |
1085 | color = fg; | |
1086 | } else if (bg) { | |
1087 | kind = 'bg'; | |
1088 | color = bg; | |
1089 | } | |
1090 | ||
1091 | const e = $("LICID-" + id); | |
1092 | ||
1093 | if (e) { | |
1094 | if (fg) e.style.color = fg; | |
1095 | if (bg) e.style.backgroundColor = bg; | |
1096 | } | |
1097 | ||
1098 | const query = { op: "pref-labels", method: "colorset", kind: kind, | |
1099 | ids: id, fg: fg, bg: bg, color: color }; | |
1100 | ||
1101 | xhrPost("backend.php", query, () => { | |
1102 | updateFilterList(); // maybe there's labels in there | |
1103 | }); | |
1104 | ||
1105 | }, | |
1106 | execute: function () { | |
1107 | if (this.validate()) { | |
1108 | const caption = this.attr('value').caption; | |
1109 | const fg_color = this.attr('value').fg_color; | |
1110 | const bg_color = this.attr('value').bg_color; | |
1111 | ||
1112 | dijit.byId('labelTree').setNameById(id, caption); | |
1113 | this.setLabelColor(id, fg_color, bg_color); | |
1114 | this.hide(); | |
1115 | ||
1116 | xhrPost("backend.php", this.attr('value'), () => { | |
1117 | updateFilterList(); // maybe there's labels in there | |
1118 | }); | |
1119 | } | |
1120 | }, | |
1121 | href: query | |
1122 | }); | |
1123 | ||
1124 | dialog.show(); | |
1125 | } | |
1126 | ||
1127 | ||
1128 | function customizeCSS() { | |
1129 | const query = "backend.php?op=pref-prefs&method=customizeCSS"; | |
1130 | ||
1131 | if (dijit.byId("cssEditDlg")) | |
1132 | dijit.byId("cssEditDlg").destroyRecursive(); | |
1133 | ||
1134 | const dialog = new dijit.Dialog({ | |
1135 | id: "cssEditDlg", | |
1136 | title: __("Customize stylesheet"), | |
1137 | style: "width: 600px", | |
1138 | execute: function () { | |
1139 | notify_progress('Saving data...', true); | |
1140 | ||
1141 | xhrPost("backend.php", this.attr('value'), () => { | |
1142 | window.location.reload(); | |
1143 | }); | |
1144 | ||
1145 | }, | |
1146 | href: query | |
1147 | }); | |
1148 | ||
1149 | dialog.show(); | |
1150 | } | |
1151 | ||
1152 | function insertSSLserial(value) { | |
1153 | dijit.byId("SSL_CERT_SERIAL").attr('value', value); | |
1154 | } | |
1155 | ||
1156 | function gotoExportOpml(filename, settings) { | |
1157 | const tmp = settings ? 1 : 0; | |
1158 | document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp; | |
1159 | } | |
1160 | ||
1161 | ||
1162 | function batchSubscribe() { | |
1163 | const query = "backend.php?op=pref-feeds&method=batchSubscribe"; | |
1164 | ||
1165 | // overlapping widgets | |
1166 | if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); | |
1167 | if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); | |
1168 | ||
1169 | const dialog = new dijit.Dialog({ | |
1170 | id: "batchSubDlg", | |
1171 | title: __("Batch subscribe"), | |
1172 | style: "width: 600px", | |
1173 | execute: function () { | |
1174 | if (this.validate()) { | |
1175 | notify_progress(__("Subscribing to feeds..."), true); | |
1176 | ||
1177 | xhrPost("backend.php", this.attr('value'), () => { | |
1178 | notify(""); | |
1179 | updateFeedList(); | |
1180 | dialog.hide(); | |
1181 | }); | |
1182 | } | |
1183 | }, | |
1184 | href: query | |
1185 | }); | |
1186 | ||
1187 | dialog.show(); | |
1188 | } | |
1189 | ||
1190 | function clearPluginData(name) { | |
1191 | if (confirm(__("Clear stored data for this plugin?"))) { | |
1192 | notify_progress("Loading, please wait..."); | |
1193 | ||
1194 | xhrPost("backend.php", { op: "pref-prefs", method: "clearplugindata", name: name }, () => { | |
1195 | notify(''); | |
1196 | updatePrefsList(); | |
1197 | }); | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | function clearSqlLog() { | |
1202 | ||
1203 | if (confirm(__("Clear all messages in the error log?"))) { | |
1204 | ||
1205 | notify_progress("Loading, please wait..."); | |
1206 | ||
1207 | xhrPost("backend.php", { op: "pref-system", method: "clearLog" }, () => { | |
1208 | updateSystemList(); | |
1209 | }); | |
1210 | ||
1211 | } | |
1212 | } | |
1213 | ||
1214 | function updateSelectedPrompt() { | |
1215 | // no-op shim for toggleSelectedRow() | |
1216 | } | |
1217 |