]>
Commit | Line | Data |
---|---|---|
1 | var init_params = new Array(); | |
2 | ||
3 | var hotkey_prefix = false; | |
4 | var hotkey_prefix_pressed = false; | |
5 | ||
6 | var seq = ""; | |
7 | ||
8 | function notify_callback2(transport, sticky) { | |
9 | notify_info(transport.responseText, sticky); | |
10 | } | |
11 | ||
12 | function updateFeedList(sort_key) { | |
13 | ||
14 | var user_search = $("feed_search"); | |
15 | var search = ""; | |
16 | if (user_search) { search = user_search.value; } | |
17 | ||
18 | new Ajax.Request("backend.php", { | |
19 | parameters: "?op=pref-feeds&search=" + param_escape(search), | |
20 | onComplete: function(transport) { | |
21 | dijit.byId('feedConfigTab').attr('content', transport.responseText); | |
22 | selectTab("feedConfig", true); | |
23 | notify(""); | |
24 | } }); | |
25 | } | |
26 | ||
27 | function updateInstanceList(sort_key) { | |
28 | new Ajax.Request("backend.php", { | |
29 | parameters: "?op=pref-instances&sort=" + param_escape(sort_key), | |
30 | onComplete: function(transport) { | |
31 | dijit.byId('instanceConfigTab').attr('content', transport.responseText); | |
32 | selectTab("instanceConfig", true); | |
33 | notify(""); | |
34 | } }); | |
35 | } | |
36 | ||
37 | function updateUsersList(sort_key) { | |
38 | try { | |
39 | var user_search = $("user_search"); | |
40 | var search = ""; | |
41 | if (user_search) { search = user_search.value; } | |
42 | ||
43 | var query = "?op=pref-users&sort=" | |
44 | + param_escape(sort_key) + | |
45 | "&search=" + param_escape(search); | |
46 | ||
47 | new Ajax.Request("backend.php", { | |
48 | parameters: query, | |
49 | onComplete: function(transport) { | |
50 | dijit.byId('userConfigTab').attr('content', transport.responseText); | |
51 | selectTab("userConfig", true) | |
52 | notify(""); | |
53 | } }); | |
54 | ||
55 | } catch (e) { | |
56 | exception_error("updateUsersList", e); | |
57 | } | |
58 | } | |
59 | ||
60 | function addUser() { | |
61 | ||
62 | try { | |
63 | ||
64 | var login = prompt(__("Please enter login:"), ""); | |
65 | ||
66 | if (login == null) { | |
67 | return false; | |
68 | } | |
69 | ||
70 | if (login == "") { | |
71 | alert(__("Can't create user: no login specified.")); | |
72 | return false; | |
73 | } | |
74 | ||
75 | notify_progress("Adding user..."); | |
76 | ||
77 | var query = "?op=pref-users&method=add&login=" + | |
78 | param_escape(login); | |
79 | ||
80 | new Ajax.Request("backend.php", { | |
81 | parameters: query, | |
82 | onComplete: function(transport) { | |
83 | notify_callback2(transport); | |
84 | updateUsersList(); | |
85 | } }); | |
86 | ||
87 | } catch (e) { | |
88 | exception_error("addUser", e); | |
89 | } | |
90 | } | |
91 | ||
92 | function editUser(id, event) { | |
93 | ||
94 | try { | |
95 | if (!event || !event.ctrlKey) { | |
96 | ||
97 | notify_progress("Loading, please wait..."); | |
98 | ||
99 | selectTableRows('prefUserList', 'none'); | |
100 | selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true); | |
101 | ||
102 | var query = "?op=pref-users&method=edit&id=" + | |
103 | param_escape(id); | |
104 | ||
105 | new Ajax.Request("backend.php", { | |
106 | parameters: query, | |
107 | onComplete: function(transport) { | |
108 | infobox_callback2(transport); | |
109 | document.forms['user_edit_form'].login.focus(); | |
110 | } }); | |
111 | ||
112 | } else if (event.ctrlKey) { | |
113 | var cb = $('UMCHK-' + id); | |
114 | cb.checked = !cb.checked; | |
115 | toggleSelectRow(cb); | |
116 | } | |
117 | ||
118 | } catch (e) { | |
119 | exception_error("editUser", e); | |
120 | } | |
121 | ||
122 | } | |
123 | ||
124 | function editFilter(id) { | |
125 | try { | |
126 | ||
127 | var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); | |
128 | ||
129 | if (dijit.byId("feedEditDlg")) | |
130 | dijit.byId("feedEditDlg").destroyRecursive(); | |
131 | ||
132 | if (dijit.byId("filterEditDlg")) | |
133 | dijit.byId("filterEditDlg").destroyRecursive(); | |
134 | ||
135 | dialog = new dijit.Dialog({ | |
136 | id: "filterEditDlg", | |
137 | title: __("Edit Filter"), | |
138 | style: "width: 600px", | |
139 | removeFilter: function() { | |
140 | var title = this.attr('value').reg_exp; | |
141 | var msg = __("Remove filter %s?").replace("%s", title); | |
142 | ||
143 | if (confirm(msg)) { | |
144 | this.hide(); | |
145 | ||
146 | notify_progress("Removing filter..."); | |
147 | ||
148 | var id = this.attr('value').id; | |
149 | ||
150 | var query = "?op=pref-filters&method=remove&ids="+ | |
151 | param_escape(id); | |
152 | ||
153 | new Ajax.Request("backend.php", { | |
154 | parameters: query, | |
155 | onComplete: function(transport) { | |
156 | updateFilterList(); | |
157 | } }); | |
158 | } | |
159 | }, | |
160 | test: function() { | |
161 | if (this.validate()) { | |
162 | ||
163 | if (dijit.byId("filterTestDlg")) | |
164 | dijit.byId("filterTestDlg").destroyRecursive(); | |
165 | ||
166 | tdialog = new dijit.Dialog({ | |
167 | id: "filterTestDlg", | |
168 | title: __("Filter Test Results"), | |
169 | style: "width: 600px", | |
170 | href: "backend.php?savemode=test&" + | |
171 | dojo.objectToQuery(dialog.attr('value')), | |
172 | }); | |
173 | ||
174 | tdialog.show(); | |
175 | ||
176 | } | |
177 | }, | |
178 | execute: function() { | |
179 | if (this.validate()) { | |
180 | ||
181 | var query = "?op=rpc&method=verifyRegexp®_exp=" + | |
182 | param_escape(dialog.attr('value').reg_exp); | |
183 | ||
184 | notify_progress("Verifying regular expression..."); | |
185 | ||
186 | new Ajax.Request("backend.php", { | |
187 | parameters: query, | |
188 | onComplete: function(transport) { | |
189 | var reply = JSON.parse(transport.responseText); | |
190 | ||
191 | if (reply) { | |
192 | notify(''); | |
193 | ||
194 | if (!reply['status']) { | |
195 | alert("Match regular expression seems to be invalid."); | |
196 | return; | |
197 | } else { | |
198 | notify_progress("Saving data...", true); | |
199 | ||
200 | console.log(dojo.objectToQuery(dialog.attr('value'))); | |
201 | ||
202 | new Ajax.Request("backend.php", { | |
203 | parameters: dojo.objectToQuery(dialog.attr('value')), | |
204 | onComplete: function(transport) { | |
205 | dialog.hide(); | |
206 | updateFilterList(); | |
207 | }}); | |
208 | } | |
209 | } | |
210 | }}); | |
211 | } | |
212 | }, | |
213 | href: query}); | |
214 | ||
215 | dialog.show(); | |
216 | ||
217 | ||
218 | } catch (e) { | |
219 | exception_error("editFilter", e); | |
220 | } | |
221 | } | |
222 | ||
223 | function getSelectedLabels() { | |
224 | var tree = dijit.byId("labelTree"); | |
225 | var items = tree.model.getCheckedItems(); | |
226 | var rv = []; | |
227 | ||
228 | items.each(function(item) { | |
229 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
230 | }); | |
231 | ||
232 | return rv; | |
233 | } | |
234 | ||
235 | function getSelectedUsers() { | |
236 | return getSelectedTableRowIds("prefUserList"); | |
237 | } | |
238 | ||
239 | function getSelectedFeeds() { | |
240 | var tree = dijit.byId("feedTree"); | |
241 | var items = tree.model.getCheckedItems(); | |
242 | var rv = []; | |
243 | ||
244 | items.each(function(item) { | |
245 | if (item.id[0].match("FEED:")) | |
246 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
247 | }); | |
248 | ||
249 | return rv; | |
250 | } | |
251 | ||
252 | function getSelectedFilters() { | |
253 | var tree = dijit.byId("filterTree"); | |
254 | var items = tree.model.getCheckedItems(); | |
255 | var rv = []; | |
256 | ||
257 | items.each(function(item) { | |
258 | rv.push(tree.model.store.getValue(item, 'bare_id')); | |
259 | }); | |
260 | ||
261 | return rv; | |
262 | ||
263 | } | |
264 | ||
265 | /* function getSelectedFeedCats() { | |
266 | return getSelectedTableRowIds("prefFeedCatList"); | |
267 | } */ | |
268 | ||
269 | function removeSelectedLabels() { | |
270 | ||
271 | var sel_rows = getSelectedLabels(); | |
272 | ||
273 | if (sel_rows.length > 0) { | |
274 | ||
275 | var ok = confirm(__("Remove selected labels?")); | |
276 | ||
277 | if (ok) { | |
278 | notify_progress("Removing selected labels..."); | |
279 | ||
280 | var query = "?op=pref-labels&method=remove&ids="+ | |
281 | param_escape(sel_rows.toString()); | |
282 | ||
283 | new Ajax.Request("backend.php", { | |
284 | parameters: query, | |
285 | onComplete: function(transport) { | |
286 | updateLabelList(); | |
287 | } }); | |
288 | ||
289 | } | |
290 | } else { | |
291 | alert(__("No labels are selected.")); | |
292 | } | |
293 | ||
294 | return false; | |
295 | } | |
296 | ||
297 | function removeSelectedUsers() { | |
298 | ||
299 | try { | |
300 | ||
301 | var sel_rows = getSelectedUsers(); | |
302 | ||
303 | if (sel_rows.length > 0) { | |
304 | ||
305 | var ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed.")); | |
306 | ||
307 | if (ok) { | |
308 | notify_progress("Removing selected users..."); | |
309 | ||
310 | var query = "?op=pref-users&method=remove&ids="+ | |
311 | param_escape(sel_rows.toString()); | |
312 | ||
313 | new Ajax.Request("backend.php", { | |
314 | parameters: query, | |
315 | onComplete: function(transport) { | |
316 | updateUsersList(); | |
317 | } }); | |
318 | ||
319 | } | |
320 | ||
321 | } else { | |
322 | alert(__("No users are selected.")); | |
323 | } | |
324 | ||
325 | } catch (e) { | |
326 | exception_error("removeSelectedUsers", e); | |
327 | } | |
328 | ||
329 | return false; | |
330 | } | |
331 | ||
332 | function removeSelectedFilters() { | |
333 | ||
334 | try { | |
335 | ||
336 | var sel_rows = getSelectedFilters(); | |
337 | ||
338 | if (sel_rows.length > 0) { | |
339 | ||
340 | var ok = confirm(__("Remove selected filters?")); | |
341 | ||
342 | if (ok) { | |
343 | notify_progress("Removing selected filters..."); | |
344 | ||
345 | var query = "?op=pref-filters&method=remove&ids="+ | |
346 | param_escape(sel_rows.toString()); | |
347 | ||
348 | new Ajax.Request("backend.php", { | |
349 | parameters: query, | |
350 | onComplete: function(transport) { | |
351 | updateFilterList(); | |
352 | } }); | |
353 | } | |
354 | } else { | |
355 | alert(__("No filters are selected.")); | |
356 | } | |
357 | ||
358 | } catch (e) { | |
359 | exception_error("removeSelectedFilters", e); | |
360 | } | |
361 | ||
362 | return false; | |
363 | } | |
364 | ||
365 | ||
366 | function removeSelectedFeeds() { | |
367 | ||
368 | try { | |
369 | ||
370 | var sel_rows = getSelectedFeeds(); | |
371 | ||
372 | if (sel_rows.length > 0) { | |
373 | ||
374 | var ok = confirm(__("Unsubscribe from selected feeds?")); | |
375 | ||
376 | if (ok) { | |
377 | ||
378 | notify_progress("Unsubscribing from selected feeds...", true); | |
379 | ||
380 | var query = "?op=pref-feeds&method=remove&ids="+ | |
381 | param_escape(sel_rows.toString()); | |
382 | ||
383 | console.log(query); | |
384 | ||
385 | new Ajax.Request("backend.php", { | |
386 | parameters: query, | |
387 | onComplete: function(transport) { | |
388 | updateFeedList(); | |
389 | } }); | |
390 | } | |
391 | ||
392 | } else { | |
393 | alert(__("No feeds are selected.")); | |
394 | } | |
395 | ||
396 | } catch (e) { | |
397 | exception_error("removeSelectedFeeds", e); | |
398 | } | |
399 | ||
400 | return false; | |
401 | } | |
402 | ||
403 | function clearSelectedFeeds() { | |
404 | ||
405 | var sel_rows = getSelectedFeeds(); | |
406 | ||
407 | if (sel_rows.length > 1) { | |
408 | alert(__("Please select only one feed.")); | |
409 | return; | |
410 | } | |
411 | ||
412 | if (sel_rows.length > 0) { | |
413 | ||
414 | var ok = confirm(__("Erase all non-starred articles in selected feed?")); | |
415 | ||
416 | if (ok) { | |
417 | notify_progress("Clearing selected feed..."); | |
418 | clearFeedArticles(sel_rows[0]); | |
419 | } | |
420 | ||
421 | } else { | |
422 | ||
423 | alert(__("No feeds are selected.")); | |
424 | ||
425 | } | |
426 | ||
427 | return false; | |
428 | } | |
429 | ||
430 | function purgeSelectedFeeds() { | |
431 | ||
432 | var sel_rows = getSelectedFeeds(); | |
433 | ||
434 | if (sel_rows.length > 0) { | |
435 | ||
436 | var pr = prompt(__("How many days of articles to keep (0 - use default)?"), "0"); | |
437 | ||
438 | if (pr != undefined) { | |
439 | notify_progress("Purging selected feed..."); | |
440 | ||
441 | var query = "?op=rpc&method=purge&ids="+ | |
442 | param_escape(sel_rows.toString()) + "&days=" + pr; | |
443 | ||
444 | console.log(query); | |
445 | ||
446 | new Ajax.Request("prefs.php", { | |
447 | parameters: query, | |
448 | onComplete: function(transport) { | |
449 | notify(''); | |
450 | } }); | |
451 | } | |
452 | ||
453 | } else { | |
454 | ||
455 | alert(__("No feeds are selected.")); | |
456 | ||
457 | } | |
458 | ||
459 | return false; | |
460 | } | |
461 | ||
462 | function userEditCancel() { | |
463 | closeInfoBox(); | |
464 | return false; | |
465 | } | |
466 | ||
467 | function userEditSave() { | |
468 | ||
469 | try { | |
470 | ||
471 | var login = document.forms["user_edit_form"].login.value; | |
472 | ||
473 | if (login.length == 0) { | |
474 | alert(__("Login field cannot be blank.")); | |
475 | return; | |
476 | } | |
477 | ||
478 | notify_progress("Saving user..."); | |
479 | ||
480 | closeInfoBox(); | |
481 | ||
482 | var query = Form.serialize("user_edit_form"); | |
483 | ||
484 | new Ajax.Request("backend.php", { | |
485 | parameters: query, | |
486 | onComplete: function(transport) { | |
487 | updateUsersList(); | |
488 | } }); | |
489 | ||
490 | } catch (e) { | |
491 | exception_error("userEditSave", e); | |
492 | } | |
493 | ||
494 | return false; | |
495 | ||
496 | } | |
497 | ||
498 | ||
499 | function editSelectedUser() { | |
500 | var rows = getSelectedUsers(); | |
501 | ||
502 | if (rows.length == 0) { | |
503 | alert(__("No users are selected.")); | |
504 | return; | |
505 | } | |
506 | ||
507 | if (rows.length > 1) { | |
508 | alert(__("Please select only one user.")); | |
509 | return; | |
510 | } | |
511 | ||
512 | notify(""); | |
513 | ||
514 | editUser(rows[0]); | |
515 | } | |
516 | ||
517 | function resetSelectedUserPass() { | |
518 | ||
519 | try { | |
520 | ||
521 | var rows = getSelectedUsers(); | |
522 | ||
523 | if (rows.length == 0) { | |
524 | alert(__("No users are selected.")); | |
525 | return; | |
526 | } | |
527 | ||
528 | if (rows.length > 1) { | |
529 | alert(__("Please select only one user.")); | |
530 | return; | |
531 | } | |
532 | ||
533 | var ok = confirm(__("Reset password of selected user?")); | |
534 | ||
535 | if (ok) { | |
536 | notify_progress("Resetting password for selected user..."); | |
537 | ||
538 | var id = rows[0]; | |
539 | ||
540 | var query = "?op=pref-users&method=resetPass&id=" + | |
541 | param_escape(id); | |
542 | ||
543 | new Ajax.Request("backend.php", { | |
544 | parameters: query, | |
545 | onComplete: function(transport) { | |
546 | notify_info(transport.responseText); | |
547 | } }); | |
548 | ||
549 | } | |
550 | ||
551 | } catch (e) { | |
552 | exception_error("resetSelectedUserPass", e); | |
553 | } | |
554 | } | |
555 | ||
556 | function selectedUserDetails() { | |
557 | ||
558 | try { | |
559 | ||
560 | var rows = getSelectedUsers(); | |
561 | ||
562 | if (rows.length == 0) { | |
563 | alert(__("No users are selected.")); | |
564 | return; | |
565 | } | |
566 | ||
567 | if (rows.length > 1) { | |
568 | alert(__("Please select only one user.")); | |
569 | return; | |
570 | } | |
571 | ||
572 | notify_progress("Loading, please wait..."); | |
573 | ||
574 | var id = rows[0]; | |
575 | ||
576 | var query = "?op=pref-users&method=userdetails&id=" + id; | |
577 | ||
578 | new Ajax.Request("backend.php", { | |
579 | parameters: query, | |
580 | onComplete: function(transport) { | |
581 | infobox_callback2(transport); | |
582 | } }); | |
583 | } catch (e) { | |
584 | exception_error("selectedUserDetails", e); | |
585 | } | |
586 | } | |
587 | ||
588 | ||
589 | function editSelectedFilter() { | |
590 | var rows = getSelectedFilters(); | |
591 | ||
592 | if (rows.length == 0) { | |
593 | alert(__("No filters are selected.")); | |
594 | return; | |
595 | } | |
596 | ||
597 | if (rows.length > 1) { | |
598 | alert(__("Please select only one filter.")); | |
599 | return; | |
600 | } | |
601 | ||
602 | notify(""); | |
603 | ||
604 | editFilter(rows[0]); | |
605 | ||
606 | } | |
607 | ||
608 | ||
609 | function editSelectedFeed() { | |
610 | var rows = getSelectedFeeds(); | |
611 | ||
612 | if (rows.length == 0) { | |
613 | alert(__("No feeds are selected.")); | |
614 | return; | |
615 | } | |
616 | ||
617 | if (rows.length > 1) { | |
618 | return editSelectedFeeds(); | |
619 | } | |
620 | ||
621 | notify(""); | |
622 | ||
623 | editFeed(rows[0], {}); | |
624 | ||
625 | } | |
626 | ||
627 | function editSelectedFeeds() { | |
628 | ||
629 | try { | |
630 | var rows = getSelectedFeeds(); | |
631 | ||
632 | if (rows.length == 0) { | |
633 | alert(__("No feeds are selected.")); | |
634 | return; | |
635 | } | |
636 | ||
637 | notify_progress("Loading, please wait..."); | |
638 | ||
639 | var query = "backend.php?op=pref-feeds&method=editfeeds&ids=" + | |
640 | param_escape(rows.toString()); | |
641 | ||
642 | console.log(query); | |
643 | ||
644 | if (dijit.byId("feedEditDlg")) | |
645 | dijit.byId("feedEditDlg").destroyRecursive(); | |
646 | ||
647 | new Ajax.Request("backend.php", { | |
648 | parameters: query, | |
649 | onComplete: function(transport) { | |
650 | ||
651 | notify(""); | |
652 | ||
653 | var dialog = new dijit.Dialog({ | |
654 | id: "feedEditDlg", | |
655 | title: __("Edit Multiple Feeds"), | |
656 | style: "width: 600px", | |
657 | getChildByName: function (name) { | |
658 | var rv = null; | |
659 | this.getChildren().each( | |
660 | function(child) { | |
661 | if (child.name == name) { | |
662 | rv = child; | |
663 | return; | |
664 | } | |
665 | }); | |
666 | return rv; | |
667 | }, | |
668 | toggleField: function (checkbox, elem, label) { | |
669 | this.getChildByName(elem).attr('disabled', !checkbox.checked); | |
670 | ||
671 | if ($(label)) | |
672 | if (checkbox.checked) | |
673 | $(label).removeClassName('insensitive'); | |
674 | else | |
675 | $(label).addClassName('insensitive'); | |
676 | ||
677 | }, | |
678 | execute: function() { | |
679 | if (this.validate() && confirm(__("Save changes to selected feeds?"))) { | |
680 | var query = dojo.objectToQuery(this.attr('value')); | |
681 | ||
682 | /* Form.serialize ignores unchecked checkboxes */ | |
683 | ||
684 | if (!query.match("&rtl_content=") && | |
685 | this.getChildByName('rtl_content').attr('disabled') == false) { | |
686 | query = query + "&rtl_content=false"; | |
687 | } | |
688 | ||
689 | if (!query.match("&private=") && | |
690 | this.getChildByName('private').attr('disabled') == false) { | |
691 | query = query + "&private=false"; | |
692 | } | |
693 | ||
694 | try { | |
695 | if (!query.match("&cache_images=") && | |
696 | this.getChildByName('cache_images').attr('disabled') == false) { | |
697 | query = query + "&cache_images=false"; | |
698 | } | |
699 | } catch (e) { } | |
700 | ||
701 | if (!query.match("&include_in_digest=") && | |
702 | this.getChildByName('include_in_digest').attr('disabled') == false) { | |
703 | query = query + "&include_in_digest=false"; | |
704 | } | |
705 | ||
706 | if (!query.match("&always_display_enclosures=") && | |
707 | this.getChildByName('always_display_enclosures').attr('disabled') == false) { | |
708 | query = query + "&always_display_enclosures=false"; | |
709 | } | |
710 | ||
711 | if (!query.match("&mark_unread_on_update=") && | |
712 | this.getChildByName('mark_unread_on_update').attr('disabled') == false) { | |
713 | query = query + "&mark_unread_on_update=false"; | |
714 | } | |
715 | ||
716 | if (!query.match("&update_on_checksum_change=") && | |
717 | this.getChildByName('update_on_checksum_change').attr('disabled') == false) { | |
718 | query = query + "&update_on_checksum_change=false"; | |
719 | } | |
720 | ||
721 | console.log(query); | |
722 | ||
723 | notify_progress("Saving data...", true); | |
724 | ||
725 | new Ajax.Request("backend.php", { | |
726 | parameters: query, | |
727 | onComplete: function(transport) { | |
728 | dialog.hide(); | |
729 | updateFeedList(); | |
730 | }}); | |
731 | } | |
732 | }, | |
733 | content: transport.responseText}); | |
734 | ||
735 | dialog.show(); | |
736 | ||
737 | } }); | |
738 | ||
739 | } catch (e) { | |
740 | exception_error("editSelectedFeeds", e); | |
741 | } | |
742 | } | |
743 | ||
744 | function piggie(enable) { | |
745 | if (enable) { | |
746 | console.log("I LOVEDED IT!"); | |
747 | var piggie = $("piggie"); | |
748 | ||
749 | Element.show(piggie); | |
750 | Position.Center(piggie); | |
751 | Effect.Puff(piggie); | |
752 | ||
753 | } | |
754 | } | |
755 | ||
756 | function opmlImportComplete(iframe) { | |
757 | try { | |
758 | if (!iframe.contentDocument.body.innerHTML) return false; | |
759 | ||
760 | Element.show(iframe); | |
761 | ||
762 | notify(''); | |
763 | ||
764 | if (dijit.byId('opmlImportDlg')) | |
765 | dijit.byId('opmlImportDlg').destroyRecursive(); | |
766 | ||
767 | var content = iframe.contentDocument.body.innerHTML; | |
768 | ||
769 | dialog = new dijit.Dialog({ | |
770 | id: "opmlImportDlg", | |
771 | title: __("OPML Import"), | |
772 | style: "width: 600px", | |
773 | onCancel: function() { | |
774 | updateFeedList(); | |
775 | updateFilterList(); | |
776 | updateLabelList(); | |
777 | }, | |
778 | execute: function() { | |
779 | updateFeedList(); | |
780 | updateFilterList(); | |
781 | updateLabelList(); | |
782 | this.hide(); | |
783 | }, | |
784 | content: content}); | |
785 | ||
786 | dialog.show(); | |
787 | ||
788 | } catch (e) { | |
789 | exception_error("opmlImportComplete", e); | |
790 | } | |
791 | } | |
792 | ||
793 | function opmlImport() { | |
794 | ||
795 | var opml_file = $("opml_file"); | |
796 | ||
797 | if (opml_file.value.length == 0) { | |
798 | alert(__("Please choose an OPML file first.")); | |
799 | return false; | |
800 | } else { | |
801 | notify_progress("Importing, please wait...", true); | |
802 | ||
803 | Element.show("upload_iframe"); | |
804 | ||
805 | return true; | |
806 | } | |
807 | } | |
808 | ||
809 | function importData() { | |
810 | ||
811 | var file = $("export_file"); | |
812 | ||
813 | if (file.value.length == 0) { | |
814 | alert(__("Please choose the file first.")); | |
815 | return false; | |
816 | } else { | |
817 | notify_progress("Importing, please wait...", true); | |
818 | ||
819 | Element.show("data_upload_iframe"); | |
820 | ||
821 | return true; | |
822 | } | |
823 | } | |
824 | ||
825 | ||
826 | function updateFilterList() { | |
827 | var user_search = $("filter_search"); | |
828 | var search = ""; | |
829 | if (user_search) { search = user_search.value; } | |
830 | ||
831 | new Ajax.Request("backend.php", { | |
832 | parameters: "?op=pref-filters&search=" + param_escape(search), | |
833 | onComplete: function(transport) { | |
834 | dijit.byId('filterConfigTab').attr('content', transport.responseText); | |
835 | notify(""); | |
836 | } }); | |
837 | } | |
838 | ||
839 | function updateLabelList() { | |
840 | new Ajax.Request("backend.php", { | |
841 | parameters: "?op=pref-labels", | |
842 | onComplete: function(transport) { | |
843 | dijit.byId('labelConfigTab').attr('content', transport.responseText); | |
844 | notify(""); | |
845 | } }); | |
846 | } | |
847 | ||
848 | function updatePrefsList() { | |
849 | new Ajax.Request("backend.php", { | |
850 | parameters: "?op=pref-prefs", | |
851 | onComplete: function(transport) { | |
852 | dijit.byId('genConfigTab').attr('content', transport.responseText); | |
853 | notify(""); | |
854 | } }); | |
855 | } | |
856 | ||
857 | function selectTab(id, noupdate, method) { | |
858 | try { | |
859 | if (!noupdate) { | |
860 | notify_progress("Loading, please wait..."); | |
861 | ||
862 | if (id == "feedConfig") { | |
863 | updateFeedList(); | |
864 | } else if (id == "filterConfig") { | |
865 | updateFilterList(); | |
866 | } else if (id == "labelConfig") { | |
867 | updateLabelList(); | |
868 | } else if (id == "genConfig") { | |
869 | updatePrefsList(); | |
870 | } else if (id == "userConfig") { | |
871 | updateUsersList(); | |
872 | } | |
873 | ||
874 | var tab = dijit.byId(id + "Tab"); | |
875 | dijit.byId("pref-tabs").selectChild(tab); | |
876 | ||
877 | } | |
878 | ||
879 | } catch (e) { | |
880 | exception_error("selectTab", e); | |
881 | } | |
882 | } | |
883 | ||
884 | function init_second_stage() { | |
885 | try { | |
886 | ||
887 | document.onkeydown = pref_hotkey_handler; | |
888 | loading_set_progress(50); | |
889 | notify(""); | |
890 | ||
891 | dojo.addOnLoad(function() { | |
892 | var tab = getURLParam('tab'); | |
893 | ||
894 | if (tab) { | |
895 | tab = dijit.byId(tab + "Tab"); | |
896 | if (tab) dijit.byId("pref-tabs").selectChild(tab); | |
897 | } | |
898 | ||
899 | var method = getURLParam('method'); | |
900 | ||
901 | if (method == 'editFeed') { | |
902 | var param = getURLParam('methodparam'); | |
903 | ||
904 | window.setTimeout('editFeed(' + param + ')', 100); | |
905 | } | |
906 | }); | |
907 | ||
908 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
909 | ||
910 | } catch (e) { | |
911 | exception_error("init_second_stage", e); | |
912 | } | |
913 | } | |
914 | ||
915 | function init() { | |
916 | ||
917 | try { | |
918 | dojo.registerModulePath("lib", ".."); | |
919 | dojo.registerModulePath("fox", "../../js/"); | |
920 | ||
921 | dojo.require("lib.CheckBoxTree"); | |
922 | dojo.require("fox.PrefFeedTree"); | |
923 | dojo.require("fox.PrefFilterTree"); | |
924 | dojo.require("fox.PrefLabelTree"); | |
925 | ||
926 | dojo.parser.parse(); | |
927 | ||
928 | dojo.addOnLoad(function() { | |
929 | loading_set_progress(50); | |
930 | ||
931 | new Ajax.Request("backend.php", { | |
932 | parameters: {op: "rpc", method: "sanityCheck"}, | |
933 | onComplete: function(transport) { | |
934 | backend_sanity_check_callback(transport); | |
935 | } }); | |
936 | }); | |
937 | ||
938 | } catch (e) { | |
939 | exception_error("init", e); | |
940 | } | |
941 | } | |
942 | ||
943 | function validatePrefsReset() { | |
944 | try { | |
945 | var ok = confirm(__("Reset to defaults?")); | |
946 | ||
947 | if (ok) { | |
948 | ||
949 | query = "?op=pref-prefs&method=resetconfig"; | |
950 | console.log(query); | |
951 | ||
952 | new Ajax.Request("backend.php", { | |
953 | parameters: query, | |
954 | onComplete: function(transport) { | |
955 | var msg = transport.responseText; | |
956 | if (msg.match("PREFS_THEME_CHANGED")) { | |
957 | window.location.reload(); | |
958 | } else { | |
959 | notify_info(msg); | |
960 | selectTab(); | |
961 | } | |
962 | } }); | |
963 | ||
964 | } | |
965 | ||
966 | } catch (e) { | |
967 | exception_error("validatePrefsReset", e); | |
968 | } | |
969 | ||
970 | return false; | |
971 | ||
972 | } | |
973 | ||
974 | ||
975 | function pref_hotkey_handler(e) { | |
976 | try { | |
977 | if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; | |
978 | ||
979 | var keycode = false; | |
980 | var shift_key = false; | |
981 | ||
982 | var cmdline = $('cmdline'); | |
983 | ||
984 | try { | |
985 | shift_key = e.shiftKey; | |
986 | } catch (e) { | |
987 | ||
988 | } | |
989 | ||
990 | if (window.event) { | |
991 | keycode = window.event.keyCode; | |
992 | } else if (e) { | |
993 | keycode = e.which; | |
994 | } | |
995 | ||
996 | var keychar = String.fromCharCode(keycode); | |
997 | ||
998 | if (keycode == 27) { // escape | |
999 | if (Element.visible("hotkey_help_overlay")) { | |
1000 | Element.hide("hotkey_help_overlay"); | |
1001 | } | |
1002 | hotkey_prefix = false; | |
1003 | closeInfoBox(); | |
1004 | } | |
1005 | ||
1006 | if (keycode == 16) return; // ignore lone shift | |
1007 | if (keycode == 17) return; // ignore lone ctrl | |
1008 | ||
1009 | if ((keycode == 67 || keycode == 71) && !hotkey_prefix) { | |
1010 | hotkey_prefix = keycode; | |
1011 | ||
1012 | var date = new Date(); | |
1013 | var ts = Math.round(date.getTime() / 1000); | |
1014 | ||
1015 | hotkey_prefix_pressed = ts; | |
1016 | ||
1017 | cmdline.innerHTML = keychar; | |
1018 | Element.show(cmdline); | |
1019 | ||
1020 | console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar); | |
1021 | return; | |
1022 | } | |
1023 | ||
1024 | if (Element.visible("hotkey_help_overlay")) { | |
1025 | Element.hide("hotkey_help_overlay"); | |
1026 | } | |
1027 | ||
1028 | if (keycode == 13 || keycode == 27) { | |
1029 | seq = ""; | |
1030 | } else { | |
1031 | seq = seq + "" + keycode; | |
1032 | } | |
1033 | ||
1034 | /* Global hotkeys */ | |
1035 | ||
1036 | Element.hide(cmdline); | |
1037 | ||
1038 | if (!hotkey_prefix) { | |
1039 | ||
1040 | if ((keycode == 191 || keychar == '?') && shift_key) { // ? | |
1041 | showHelp(); | |
1042 | return false; | |
1043 | } | |
1044 | ||
1045 | if (keycode == 191 || keychar == '/') { // / | |
1046 | var search_boxes = new Array("label_search", | |
1047 | "feed_search", "filter_search", "user_search", "feed_browser_search"); | |
1048 | ||
1049 | for (var i = 0; i < search_boxes.length; i++) { | |
1050 | var elem = $(search_boxes[i]); | |
1051 | if (elem) { | |
1052 | $(search_boxes[i]).focus(); | |
1053 | return false; | |
1054 | } | |
1055 | } | |
1056 | } | |
1057 | } | |
1058 | ||
1059 | /* Prefix c */ | |
1060 | ||
1061 | if (hotkey_prefix == 67) { // c | |
1062 | hotkey_prefix = false; | |
1063 | ||
1064 | if (keycode == 70) { // f | |
1065 | quickAddFilter(); | |
1066 | return false; | |
1067 | } | |
1068 | ||
1069 | if (keycode == 83) { // s | |
1070 | quickAddFeed(); | |
1071 | return false; | |
1072 | } | |
1073 | ||
1074 | if (keycode == 85) { // u | |
1075 | // no-op | |
1076 | } | |
1077 | ||
1078 | if (keycode == 67) { // c | |
1079 | editFeedCats(); | |
1080 | return false; | |
1081 | } | |
1082 | ||
1083 | if (keycode == 84 && shift_key) { // T | |
1084 | feedBrowser(); | |
1085 | return false; | |
1086 | } | |
1087 | ||
1088 | } | |
1089 | ||
1090 | /* Prefix g */ | |
1091 | ||
1092 | if (hotkey_prefix == 71) { // g | |
1093 | ||
1094 | hotkey_prefix = false; | |
1095 | ||
1096 | if (keycode == 49 && $("genConfigTab")) { // 1 | |
1097 | selectTab("genConfig"); | |
1098 | return false; | |
1099 | } | |
1100 | ||
1101 | if (keycode == 50 && $("feedConfigTab")) { // 2 | |
1102 | selectTab("feedConfig"); | |
1103 | return false; | |
1104 | } | |
1105 | ||
1106 | if (keycode == 51 && $("filterConfigTab")) { // 4 | |
1107 | selectTab("filterConfig"); | |
1108 | return false; | |
1109 | } | |
1110 | ||
1111 | if (keycode == 52 && $("labelConfigTab")) { // 5 | |
1112 | selectTab("labelConfig"); | |
1113 | return false; | |
1114 | } | |
1115 | ||
1116 | if (keycode == 53 && $("userConfigTab")) { // 6 | |
1117 | selectTab("userConfig"); | |
1118 | return false; | |
1119 | } | |
1120 | ||
1121 | if (keycode == 88) { // x | |
1122 | return gotoMain(); | |
1123 | } | |
1124 | ||
1125 | } | |
1126 | ||
1127 | if ($("piggie")) { | |
1128 | if (seq.match("8073717369")) { | |
1129 | seq = ""; | |
1130 | piggie(true); | |
1131 | } else { | |
1132 | piggie(false); | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | if (hotkey_prefix) { | |
1137 | console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar); | |
1138 | } else { | |
1139 | console.log("KP: CODE=" + keycode + " CHAR=" + keychar); | |
1140 | } | |
1141 | ||
1142 | } catch (e) { | |
1143 | exception_error("pref_hotkey_handler", e); | |
1144 | } | |
1145 | } | |
1146 | ||
1147 | function editFeedCats() { | |
1148 | try { | |
1149 | var query = "backend.php?op=pref-feeds&method=editCats"; | |
1150 | ||
1151 | if (dijit.byId("feedCatEditDlg")) | |
1152 | dijit.byId("feedCatEditDlg").destroyRecursive(); | |
1153 | ||
1154 | dialog = new dijit.Dialog({ | |
1155 | id: "feedCatEditDlg", | |
1156 | title: __("Feed Categories"), | |
1157 | style: "width: 600px", | |
1158 | getSelectedCategories: function() { | |
1159 | return getSelectedTableRowIds("prefFeedCatList"); | |
1160 | }, | |
1161 | removeSelected: function() { | |
1162 | var sel_rows = this.getSelectedCategories(); | |
1163 | ||
1164 | if (sel_rows.length > 0) { | |
1165 | var ok = confirm(__("Remove selected categories?")); | |
1166 | ||
1167 | if (ok) { | |
1168 | notify_progress("Removing selected categories...", true); | |
1169 | ||
1170 | var query = "?op=pref-feeds&method=editCats&action=remove&ids="+ | |
1171 | param_escape(sel_rows.toString()); | |
1172 | ||
1173 | new Ajax.Request("backend.php", { | |
1174 | parameters: query, | |
1175 | onComplete: function(transport) { | |
1176 | notify(''); | |
1177 | dialog.attr('content', transport.responseText); | |
1178 | updateFeedList(); | |
1179 | } }); | |
1180 | ||
1181 | } | |
1182 | ||
1183 | } else { | |
1184 | alert(__("No categories are selected.")); | |
1185 | } | |
1186 | }, | |
1187 | addCategory: function() { | |
1188 | if (this.validate()) { | |
1189 | notify_progress("Creating category..."); | |
1190 | ||
1191 | var query = "?op=pref-feeds&method=editCats&action=add&cat=" + | |
1192 | param_escape(this.attr('value').newcat); | |
1193 | ||
1194 | new Ajax.Request("backend.php", { | |
1195 | parameters: query, | |
1196 | onComplete: function(transport) { | |
1197 | notify(''); | |
1198 | dialog.attr('content', transport.responseText); | |
1199 | updateFeedList(); | |
1200 | } }); | |
1201 | } | |
1202 | }, | |
1203 | execute: function() { | |
1204 | if (this.validate()) { | |
1205 | } | |
1206 | }, | |
1207 | href: query}); | |
1208 | ||
1209 | dialog.show(); | |
1210 | ||
1211 | } catch (e) { | |
1212 | exception_error("editFeedCats", e); | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | function showInactiveFeeds() { | |
1217 | try { | |
1218 | var query = "backend.php?op=dlg&method=inactiveFeeds"; | |
1219 | ||
1220 | if (dijit.byId("inactiveFeedsDlg")) | |
1221 | dijit.byId("inactiveFeedsDlg").destroyRecursive(); | |
1222 | ||
1223 | dialog = new dijit.Dialog({ | |
1224 | id: "inactiveFeedsDlg", | |
1225 | title: __("Feeds without recent updates"), | |
1226 | style: "width: 600px", | |
1227 | getSelectedFeeds: function() { | |
1228 | return getSelectedTableRowIds("prefInactiveFeedList"); | |
1229 | }, | |
1230 | removeSelected: function() { | |
1231 | var sel_rows = this.getSelectedFeeds(); | |
1232 | ||
1233 | console.log(sel_rows); | |
1234 | ||
1235 | if (sel_rows.length > 0) { | |
1236 | var ok = confirm(__("Remove selected feeds?")); | |
1237 | ||
1238 | if (ok) { | |
1239 | notify_progress("Removing selected feeds...", true); | |
1240 | ||
1241 | var query = "?op=pref-feeds&method=remove&ids="+ | |
1242 | param_escape(sel_rows.toString()); | |
1243 | ||
1244 | new Ajax.Request("backend.php", { | |
1245 | parameters: query, | |
1246 | onComplete: function(transport) { | |
1247 | notify(''); | |
1248 | dialog.hide(); | |
1249 | updateFeedList(); | |
1250 | } }); | |
1251 | } | |
1252 | ||
1253 | } else { | |
1254 | alert(__("No feeds are selected.")); | |
1255 | } | |
1256 | }, | |
1257 | execute: function() { | |
1258 | if (this.validate()) { | |
1259 | } | |
1260 | }, | |
1261 | href: query}); | |
1262 | ||
1263 | dialog.show(); | |
1264 | ||
1265 | } catch (e) { | |
1266 | exception_error("showInactiveFeeds", e); | |
1267 | } | |
1268 | ||
1269 | } | |
1270 | ||
1271 | function opmlRegenKey() { | |
1272 | ||
1273 | try { | |
1274 | var ok = confirm(__("Replace current OPML publishing address with a new one?")); | |
1275 | ||
1276 | if (ok) { | |
1277 | ||
1278 | notify_progress("Trying to change address...", true); | |
1279 | ||
1280 | var query = "?op=rpc&method=regenOPMLKey"; | |
1281 | ||
1282 | new Ajax.Request("backend.php", { | |
1283 | parameters: query, | |
1284 | onComplete: function(transport) { | |
1285 | var reply = JSON.parse(transport.responseText); | |
1286 | ||
1287 | var new_link = reply.link; | |
1288 | ||
1289 | var e = $('pub_opml_url'); | |
1290 | ||
1291 | if (new_link) { | |
1292 | e.href = new_link; | |
1293 | e.innerHTML = new_link; | |
1294 | ||
1295 | new Effect.Highlight(e); | |
1296 | ||
1297 | notify(''); | |
1298 | ||
1299 | } else { | |
1300 | notify_error("Could not change feed URL."); | |
1301 | } | |
1302 | } }); | |
1303 | } | |
1304 | } catch (e) { | |
1305 | exception_error("opmlRegenKey", e); | |
1306 | } | |
1307 | return false; | |
1308 | } | |
1309 | ||
1310 | function feedActionChange() { | |
1311 | try { | |
1312 | var chooser = $("feedActionChooser"); | |
1313 | var opid = chooser[chooser.selectedIndex].value; | |
1314 | ||
1315 | chooser.selectedIndex = 0; | |
1316 | feedActionGo(opid); | |
1317 | } catch (e) { | |
1318 | exception_error("feedActionChange", e); | |
1319 | } | |
1320 | } | |
1321 | ||
1322 | function feedActionGo(op) { | |
1323 | try { | |
1324 | if (op == "facEdit") { | |
1325 | ||
1326 | var rows = getSelectedFeeds(); | |
1327 | ||
1328 | if (rows.length > 1) { | |
1329 | editSelectedFeeds(); | |
1330 | } else { | |
1331 | editSelectedFeed(); | |
1332 | } | |
1333 | } | |
1334 | ||
1335 | if (op == "facClear") { | |
1336 | clearSelectedFeeds(); | |
1337 | } | |
1338 | ||
1339 | if (op == "facPurge") { | |
1340 | purgeSelectedFeeds(); | |
1341 | } | |
1342 | ||
1343 | if (op == "facEditCats") { | |
1344 | editFeedCats(); | |
1345 | } | |
1346 | ||
1347 | if (op == "facRescore") { | |
1348 | rescoreSelectedFeeds(); | |
1349 | } | |
1350 | ||
1351 | if (op == "facUnsubscribe") { | |
1352 | removeSelectedFeeds(); | |
1353 | } | |
1354 | ||
1355 | } catch (e) { | |
1356 | exception_error("feedActionGo", e); | |
1357 | ||
1358 | } | |
1359 | } | |
1360 | ||
1361 | function clearFeedArticles(feed_id) { | |
1362 | ||
1363 | notify_progress("Clearing feed..."); | |
1364 | ||
1365 | var query = "?op=pref-feeds&quiet=1&method=clear&id=" + feed_id; | |
1366 | ||
1367 | new Ajax.Request("backend.php", { | |
1368 | parameters: query, | |
1369 | onComplete: function(transport) { | |
1370 | notify(''); | |
1371 | } }); | |
1372 | ||
1373 | return false; | |
1374 | } | |
1375 | ||
1376 | function rescoreSelectedFeeds() { | |
1377 | ||
1378 | var sel_rows = getSelectedFeeds(); | |
1379 | ||
1380 | if (sel_rows.length > 0) { | |
1381 | ||
1382 | //var ok = confirm(__("Rescore last 100 articles in selected feeds?")); | |
1383 | var ok = confirm(__("Rescore articles in selected feeds?")); | |
1384 | ||
1385 | if (ok) { | |
1386 | notify_progress("Rescoring selected feeds...", true); | |
1387 | ||
1388 | var query = "?op=pref-feeds&method=rescore&quiet=1&ids="+ | |
1389 | param_escape(sel_rows.toString()); | |
1390 | ||
1391 | new Ajax.Request("backend.php", { | |
1392 | parameters: query, | |
1393 | onComplete: function(transport) { | |
1394 | notify_callback2(transport); | |
1395 | } }); | |
1396 | ||
1397 | } | |
1398 | } else { | |
1399 | alert(__("No feeds are selected.")); | |
1400 | } | |
1401 | ||
1402 | return false; | |
1403 | } | |
1404 | ||
1405 | function rescore_all_feeds() { | |
1406 | var ok = confirm(__("Rescore all articles? This operation may take a lot of time.")); | |
1407 | ||
1408 | if (ok) { | |
1409 | notify_progress("Rescoring feeds...", true); | |
1410 | ||
1411 | var query = "?op=pref-feeds&method=rescoreAll&quiet=1"; | |
1412 | ||
1413 | new Ajax.Request("backend.php", { | |
1414 | parameters: query, | |
1415 | onComplete: function(transport) { | |
1416 | notify_callback2(transport); | |
1417 | } }); | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | function labelColorReset() { | |
1422 | try { | |
1423 | var labels = getSelectedLabels(); | |
1424 | ||
1425 | if (labels.length > 0) { | |
1426 | var ok = confirm(__("Reset selected labels to default colors?")); | |
1427 | ||
1428 | if (ok) { | |
1429 | var query = "?op=pref-labels&method=colorreset&ids="+ | |
1430 | param_escape(labels.toString()); | |
1431 | ||
1432 | new Ajax.Request("backend.php", { | |
1433 | parameters: query, | |
1434 | onComplete: function(transport) { | |
1435 | updateLabelList(); | |
1436 | } }); | |
1437 | } | |
1438 | ||
1439 | } else { | |
1440 | alert(__("No labels are selected.")); | |
1441 | } | |
1442 | ||
1443 | } catch (e) { | |
1444 | exception_error("labelColorReset", e); | |
1445 | } | |
1446 | } | |
1447 | ||
1448 | ||
1449 | function inPreferences() { | |
1450 | return true; | |
1451 | } | |
1452 | ||
1453 | function editProfiles() { | |
1454 | try { | |
1455 | ||
1456 | if (dijit.byId("profileEditDlg")) | |
1457 | dijit.byId("profileEditDlg").destroyRecursive(); | |
1458 | ||
1459 | var query = "backend.php?op=dlg&method=editPrefProfiles"; | |
1460 | ||
1461 | dialog = new dijit.Dialog({ | |
1462 | id: "profileEditDlg", | |
1463 | title: __("Settings Profiles"), | |
1464 | style: "width: 600px", | |
1465 | getSelectedProfiles: function() { | |
1466 | return getSelectedTableRowIds("prefFeedProfileList"); | |
1467 | }, | |
1468 | removeSelected: function() { | |
1469 | var sel_rows = this.getSelectedProfiles(); | |
1470 | ||
1471 | if (sel_rows.length > 0) { | |
1472 | var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed.")); | |
1473 | ||
1474 | if (ok) { | |
1475 | notify_progress("Removing selected profiles...", true); | |
1476 | ||
1477 | var query = "?op=rpc&method=remprofiles&ids="+ | |
1478 | param_escape(sel_rows.toString()); | |
1479 | ||
1480 | new Ajax.Request("backend.php", { | |
1481 | parameters: query, | |
1482 | onComplete: function(transport) { | |
1483 | notify(''); | |
1484 | editProfiles(); | |
1485 | } }); | |
1486 | ||
1487 | } | |
1488 | ||
1489 | } else { | |
1490 | alert(__("No profiles are selected.")); | |
1491 | } | |
1492 | }, | |
1493 | activateProfile: function() { | |
1494 | var sel_rows = this.getSelectedProfiles(); | |
1495 | ||
1496 | if (sel_rows.length == 1) { | |
1497 | ||
1498 | var ok = confirm(__("Activate selected profile?")); | |
1499 | ||
1500 | if (ok) { | |
1501 | notify_progress("Loading, please wait..."); | |
1502 | ||
1503 | var query = "?op=rpc&method=setprofile&id="+ | |
1504 | param_escape(sel_rows.toString()); | |
1505 | ||
1506 | new Ajax.Request("backend.php", { | |
1507 | parameters: query, | |
1508 | onComplete: function(transport) { | |
1509 | window.location.reload(); | |
1510 | } }); | |
1511 | } | |
1512 | ||
1513 | } else { | |
1514 | alert(__("Please choose a profile to activate.")); | |
1515 | } | |
1516 | }, | |
1517 | addProfile: function() { | |
1518 | if (this.validate()) { | |
1519 | notify_progress("Creating profile...", true); | |
1520 | ||
1521 | var query = "?op=rpc&method=addprofile&title=" + | |
1522 | param_escape(dialog.attr('value').newprofile); | |
1523 | ||
1524 | new Ajax.Request("backend.php", { | |
1525 | parameters: query, | |
1526 | onComplete: function(transport) { | |
1527 | notify(''); | |
1528 | editProfiles(); | |
1529 | } }); | |
1530 | ||
1531 | } | |
1532 | }, | |
1533 | execute: function() { | |
1534 | if (this.validate()) { | |
1535 | } | |
1536 | }, | |
1537 | href: query}); | |
1538 | ||
1539 | dialog.show(); | |
1540 | } catch (e) { | |
1541 | exception_error("editProfiles", e); | |
1542 | } | |
1543 | } | |
1544 | ||
1545 | function activatePrefProfile() { | |
1546 | ||
1547 | var sel_rows = getSelectedFeedCats(); | |
1548 | ||
1549 | if (sel_rows.length == 1) { | |
1550 | ||
1551 | var ok = confirm(__("Activate selected profile?")); | |
1552 | ||
1553 | if (ok) { | |
1554 | notify_progress("Loading, please wait..."); | |
1555 | ||
1556 | var query = "?op=rpc&method=setprofile&id="+ | |
1557 | param_escape(sel_rows.toString()); | |
1558 | ||
1559 | new Ajax.Request("backend.php", { | |
1560 | parameters: query, | |
1561 | onComplete: function(transport) { | |
1562 | window.location.reload(); | |
1563 | } }); | |
1564 | } | |
1565 | ||
1566 | } else { | |
1567 | alert(__("Please choose a profile to activate.")); | |
1568 | } | |
1569 | ||
1570 | return false; | |
1571 | } | |
1572 | ||
1573 | function clearFeedAccessKeys() { | |
1574 | ||
1575 | var ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?")); | |
1576 | ||
1577 | if (ok) { | |
1578 | notify_progress("Clearing URLs..."); | |
1579 | ||
1580 | var query = "?op=rpc&method=clearKeys"; | |
1581 | ||
1582 | new Ajax.Request("backend.php", { | |
1583 | parameters: query, | |
1584 | onComplete: function(transport) { | |
1585 | notify_info("Generated URLs cleared."); | |
1586 | } }); | |
1587 | } | |
1588 | ||
1589 | return false; | |
1590 | } | |
1591 | ||
1592 | function clearArticleAccessKeys() { | |
1593 | ||
1594 | var ok = confirm(__("This will invalidate all previously shared article URLs. Continue?")); | |
1595 | ||
1596 | if (ok) { | |
1597 | notify_progress("Clearing URLs..."); | |
1598 | ||
1599 | var query = "?op=rpc&method=clearArticleKeys"; | |
1600 | ||
1601 | new Ajax.Request("backend.php", { | |
1602 | parameters: query, | |
1603 | onComplete: function(transport) { | |
1604 | notify_info("Shared URLs cleared."); | |
1605 | } }); | |
1606 | } | |
1607 | ||
1608 | return false; | |
1609 | } | |
1610 | function resetFeedOrder() { | |
1611 | try { | |
1612 | notify_progress("Loading, please wait..."); | |
1613 | ||
1614 | new Ajax.Request("backend.php", { | |
1615 | parameters: "?op=pref-feeds&method=feedsortreset", | |
1616 | onComplete: function(transport) { | |
1617 | updateFeedList(); | |
1618 | } }); | |
1619 | ||
1620 | ||
1621 | } catch (e) { | |
1622 | exception_error("resetFeedOrder"); | |
1623 | } | |
1624 | } | |
1625 | ||
1626 | function resetCatOrder() { | |
1627 | try { | |
1628 | notify_progress("Loading, please wait..."); | |
1629 | ||
1630 | new Ajax.Request("backend.php", { | |
1631 | parameters: "?op=pref-feeds&method=catsortreset", | |
1632 | onComplete: function(transport) { | |
1633 | updateFeedList(); | |
1634 | } }); | |
1635 | ||
1636 | ||
1637 | } catch (e) { | |
1638 | exception_error("resetCatOrder"); | |
1639 | } | |
1640 | } | |
1641 | ||
1642 | function toggleHiddenFeedCats() { | |
1643 | try { | |
1644 | notify_progress("Loading, please wait..."); | |
1645 | ||
1646 | new Ajax.Request("backend.php", { | |
1647 | parameters: "?op=pref-feeds&method=togglehiddenfeedcats", | |
1648 | onComplete: function(transport) { | |
1649 | updateFeedList(); | |
1650 | } }); | |
1651 | ||
1652 | } catch (e) { | |
1653 | exception_error("toggleHiddenFeedCats"); | |
1654 | } | |
1655 | } | |
1656 | ||
1657 | function editCat(id, item, event) { | |
1658 | try { | |
1659 | var new_name = prompt(__('Rename category to:'), item.name); | |
1660 | ||
1661 | if (new_name && new_name != item.name) { | |
1662 | ||
1663 | notify_progress("Loading, please wait..."); | |
1664 | ||
1665 | new Ajax.Request("backend.php", { | |
1666 | parameters: { | |
1667 | op: 'pref-feeds', | |
1668 | method: 'renamecat', | |
1669 | id: id, | |
1670 | title: new_name, | |
1671 | }, | |
1672 | onComplete: function(transport) { | |
1673 | updateFeedList(); | |
1674 | } }); | |
1675 | } | |
1676 | ||
1677 | } catch (e) { | |
1678 | exception_error("editCat", e); | |
1679 | } | |
1680 | } | |
1681 | ||
1682 | function editLabel(id, event) { | |
1683 | try { | |
1684 | var query = "backend.php?op=pref-labels&method=edit&id=" + | |
1685 | param_escape(id); | |
1686 | ||
1687 | if (dijit.byId("labelEditDlg")) | |
1688 | dijit.byId("labelEditDlg").destroyRecursive(); | |
1689 | ||
1690 | dialog = new dijit.Dialog({ | |
1691 | id: "labelEditDlg", | |
1692 | title: __("Label Editor"), | |
1693 | style: "width: 600px", | |
1694 | setLabelColor: function(id, fg, bg) { | |
1695 | ||
1696 | var kind = ''; | |
1697 | var color = ''; | |
1698 | ||
1699 | if (fg && bg) { | |
1700 | kind = 'both'; | |
1701 | } else if (fg) { | |
1702 | kind = 'fg'; | |
1703 | color = fg; | |
1704 | } else if (bg) { | |
1705 | kind = 'bg'; | |
1706 | color = bg; | |
1707 | } | |
1708 | ||
1709 | var query = "?op=pref-labels&method=colorset&kind="+kind+ | |
1710 | "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) + | |
1711 | "&bg=" + param_escape(bg) + "&color=" + param_escape(color); | |
1712 | ||
1713 | // console.log(query); | |
1714 | ||
1715 | var e = $("LICID-" + id); | |
1716 | ||
1717 | if (e) { | |
1718 | if (fg) e.style.color = fg; | |
1719 | if (bg) e.style.backgroundColor = bg; | |
1720 | } | |
1721 | ||
1722 | new Ajax.Request("backend.php", { parameters: query }); | |
1723 | ||
1724 | updateFilterList(); | |
1725 | }, | |
1726 | execute: function() { | |
1727 | if (this.validate()) { | |
1728 | var caption = this.attr('value').caption; | |
1729 | var fg_color = this.attr('value').fg_color; | |
1730 | var bg_color = this.attr('value').bg_color; | |
1731 | var query = dojo.objectToQuery(this.attr('value')); | |
1732 | ||
1733 | dijit.byId('labelTree').setNameById(id, caption); | |
1734 | this.setLabelColor(id, fg_color, bg_color); | |
1735 | this.hide(); | |
1736 | ||
1737 | new Ajax.Request("backend.php", { | |
1738 | parameters: query, | |
1739 | onComplete: function(transport) { | |
1740 | updateFilterList(); | |
1741 | } }); | |
1742 | } | |
1743 | }, | |
1744 | href: query}); | |
1745 | ||
1746 | dialog.show(); | |
1747 | ||
1748 | } catch (e) { | |
1749 | exception_error("editLabel", e); | |
1750 | } | |
1751 | } | |
1752 | ||
1753 | function clearTwitterCredentials() { | |
1754 | try { | |
1755 | var ok = confirm(__("This will clear your stored authentication information for Twitter. Continue?")); | |
1756 | ||
1757 | if (ok) { | |
1758 | notify_progress("Clearing credentials..."); | |
1759 | ||
1760 | var query = "?op=pref-feeds&method=remtwitterinfo"; | |
1761 | ||
1762 | new Ajax.Request("backend.php", { | |
1763 | parameters: query, | |
1764 | onComplete: function(transport) { | |
1765 | notify_info("Twitter credentials have been cleared."); | |
1766 | updateFeedList(); | |
1767 | } }); | |
1768 | } | |
1769 | ||
1770 | } catch (e) { | |
1771 | exception_error("clearTwitterCredentials", e); | |
1772 | } | |
1773 | } | |
1774 | ||
1775 | function customizeCSS() { | |
1776 | try { | |
1777 | var query = "backend.php?op=dlg&method=customizeCSS"; | |
1778 | ||
1779 | if (dijit.byId("cssEditDlg")) | |
1780 | dijit.byId("cssEditDlg").destroyRecursive(); | |
1781 | ||
1782 | dialog = new dijit.Dialog({ | |
1783 | id: "cssEditDlg", | |
1784 | title: __("Customize stylesheet"), | |
1785 | style: "width: 600px", | |
1786 | execute: function() { | |
1787 | notify_progress('Saving data...', true); | |
1788 | new Ajax.Request("backend.php", { | |
1789 | parameters: dojo.objectToQuery(this.attr('value')), | |
1790 | onComplete: function(transport) { | |
1791 | notify(''); | |
1792 | window.location.reload(); | |
1793 | } }); | |
1794 | ||
1795 | }, | |
1796 | href: query}); | |
1797 | ||
1798 | dialog.show(); | |
1799 | ||
1800 | } catch (e) { | |
1801 | exception_error("customizeCSS", e); | |
1802 | } | |
1803 | } | |
1804 | ||
1805 | function insertSSLserial(value) { | |
1806 | try { | |
1807 | dijit.byId("SSL_CERT_SERIAL").attr('value', value); | |
1808 | } catch (e) { | |
1809 | exception_error("insertSSLcerial", e); | |
1810 | } | |
1811 | } | |
1812 | ||
1813 | function getSelectedInstances() { | |
1814 | return getSelectedTableRowIds("prefInstanceList"); | |
1815 | } | |
1816 | ||
1817 | function addInstance() { | |
1818 | try { | |
1819 | var query = "backend.php?op=dlg&method=addInstance"; | |
1820 | ||
1821 | if (dijit.byId("instanceAddDlg")) | |
1822 | dijit.byId("instanceAddDlg").destroyRecursive(); | |
1823 | ||
1824 | dialog = new dijit.Dialog({ | |
1825 | id: "instanceAddDlg", | |
1826 | title: __("Link Instance"), | |
1827 | style: "width: 600px", | |
1828 | regenKey: function() { | |
1829 | new Ajax.Request("backend.php", { | |
1830 | parameters: "?op=rpc&method=genHash", | |
1831 | onComplete: function(transport) { | |
1832 | var reply = JSON.parse(transport.responseText); | |
1833 | if (reply) | |
1834 | dijit.byId('instance_add_key').attr('value', reply.hash); | |
1835 | ||
1836 | } }); | |
1837 | }, | |
1838 | execute: function() { | |
1839 | if (this.validate()) { | |
1840 | console.warn(dojo.objectToQuery(this.attr('value'))); | |
1841 | ||
1842 | notify_progress('Saving data...', true); | |
1843 | new Ajax.Request("backend.php", { | |
1844 | parameters: dojo.objectToQuery(this.attr('value')), | |
1845 | onComplete: function(transport) { | |
1846 | dialog.hide(); | |
1847 | notify(''); | |
1848 | updateInstanceList(); | |
1849 | } }); | |
1850 | } | |
1851 | }, | |
1852 | href: query, | |
1853 | }); | |
1854 | ||
1855 | dialog.show(); | |
1856 | ||
1857 | } catch (e) { | |
1858 | exception_error("addInstance", e); | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | function editInstance(id, event) { | |
1863 | try { | |
1864 | if (!event || !event.ctrlKey) { | |
1865 | ||
1866 | selectTableRows('prefInstanceList', 'none'); | |
1867 | selectTableRowById('LIRR-'+id, 'LICHK-'+id, true); | |
1868 | ||
1869 | var query = "backend.php?op=pref-instances&method=edit&id=" + | |
1870 | param_escape(id); | |
1871 | ||
1872 | if (dijit.byId("instanceEditDlg")) | |
1873 | dijit.byId("instanceEditDlg").destroyRecursive(); | |
1874 | ||
1875 | dialog = new dijit.Dialog({ | |
1876 | id: "instanceEditDlg", | |
1877 | title: __("Edit Instance"), | |
1878 | style: "width: 600px", | |
1879 | regenKey: function() { | |
1880 | new Ajax.Request("backend.php", { | |
1881 | parameters: "?op=rpc&method=genHash", | |
1882 | onComplete: function(transport) { | |
1883 | var reply = JSON.parse(transport.responseText); | |
1884 | if (reply) | |
1885 | dijit.byId('instance_edit_key').attr('value', reply.hash); | |
1886 | ||
1887 | } }); | |
1888 | }, | |
1889 | execute: function() { | |
1890 | if (this.validate()) { | |
1891 | // console.warn(dojo.objectToQuery(this.attr('value'))); | |
1892 | ||
1893 | notify_progress('Saving data...', true); | |
1894 | new Ajax.Request("backend.php", { | |
1895 | parameters: dojo.objectToQuery(this.attr('value')), | |
1896 | onComplete: function(transport) { | |
1897 | dialog.hide(); | |
1898 | notify(''); | |
1899 | updateInstanceList(); | |
1900 | } }); | |
1901 | } | |
1902 | }, | |
1903 | href: query, | |
1904 | }); | |
1905 | ||
1906 | dialog.show(); | |
1907 | ||
1908 | } else if (event.ctrlKey) { | |
1909 | var cb = $('LICHK-' + id); | |
1910 | cb.checked = !cb.checked; | |
1911 | toggleSelectRow(cb); | |
1912 | } | |
1913 | ||
1914 | ||
1915 | } catch (e) { | |
1916 | exception_error("editInstance", e); | |
1917 | } | |
1918 | } | |
1919 | ||
1920 | function removeSelectedInstances() { | |
1921 | try { | |
1922 | var sel_rows = getSelectedInstances(); | |
1923 | ||
1924 | if (sel_rows.length > 0) { | |
1925 | ||
1926 | var ok = confirm(__("Remove selected instances?")); | |
1927 | ||
1928 | if (ok) { | |
1929 | notify_progress("Removing selected instances..."); | |
1930 | ||
1931 | var query = "?op=pref-instances&method=remove&ids="+ | |
1932 | param_escape(sel_rows.toString()); | |
1933 | ||
1934 | new Ajax.Request("backend.php", { | |
1935 | parameters: query, | |
1936 | onComplete: function(transport) { | |
1937 | notify(''); | |
1938 | updateInstanceList(); | |
1939 | } }); | |
1940 | } | |
1941 | ||
1942 | } else { | |
1943 | alert(__("No instances are selected.")); | |
1944 | } | |
1945 | ||
1946 | } catch (e) { | |
1947 | exception_error("removeInstance", e); | |
1948 | } | |
1949 | } | |
1950 | ||
1951 | function editSelectedInstance() { | |
1952 | var rows = getSelectedInstances(); | |
1953 | ||
1954 | if (rows.length == 0) { | |
1955 | alert(__("No instances are selected.")); | |
1956 | return; | |
1957 | } | |
1958 | ||
1959 | if (rows.length > 1) { | |
1960 | alert(__("Please select only one instance.")); | |
1961 | return; | |
1962 | } | |
1963 | ||
1964 | notify(""); | |
1965 | ||
1966 | editInstance(rows[0]); | |
1967 | } | |
1968 | ||
1969 | function showHelp() { | |
1970 | try { | |
1971 | new Ajax.Request("backend.php", { | |
1972 | parameters: "?op=backend&method=help&topic=prefs", | |
1973 | onComplete: function(transport) { | |
1974 | $("hotkey_help_overlay").innerHTML = transport.responseText; | |
1975 | Effect.Appear("hotkey_help_overlay", {duration : 0.3}); | |
1976 | } }); | |
1977 | ||
1978 | } catch (e) { | |
1979 | exception_error("showHelp", e); | |
1980 | } | |
1981 | } | |
1982 | ||
1983 | function exportData() { | |
1984 | try { | |
1985 | ||
1986 | var query = "backend.php?op=dlg&method=exportData"; | |
1987 | ||
1988 | if (dijit.byId("dataExportDlg")) | |
1989 | dijit.byId("dataExportDlg").destroyRecursive(); | |
1990 | ||
1991 | var exported = 0; | |
1992 | ||
1993 | dialog = new dijit.Dialog({ | |
1994 | id: "dataExportDlg", | |
1995 | title: __("Export Data"), | |
1996 | style: "width: 600px", | |
1997 | prepare: function() { | |
1998 | ||
1999 | notify_progress("Loading, please wait..."); | |
2000 | ||
2001 | new Ajax.Request("backend.php", { | |
2002 | parameters: "?op=rpc&method=exportrun&offset=" + exported, | |
2003 | onComplete: function(transport) { | |
2004 | try { | |
2005 | var rv = JSON.parse(transport.responseText); | |
2006 | ||
2007 | if (rv && rv.exported != undefined) { | |
2008 | if (rv.exported > 0) { | |
2009 | ||
2010 | exported += rv.exported; | |
2011 | ||
2012 | $("export_status_message").innerHTML = | |
2013 | "<img src='images/indicator_tiny.gif'> " + | |
2014 | "Exported %d articles, please wait...".replace("%d", | |
2015 | exported); | |
2016 | ||
2017 | setTimeout('dijit.byId("dataExportDlg").prepare()', 2000); | |
2018 | ||
2019 | } else { | |
2020 | ||
2021 | $("export_status_message").innerHTML = | |
2022 | __("Finished, exported %d articles. You can download the data <a class='visibleLink' href='%u'>here</a>.") | |
2023 | .replace("%d", exported) | |
2024 | .replace("%u", "backend.php?op=rpc&subop=exportget"); | |
2025 | ||
2026 | exported = 0; | |
2027 | ||
2028 | } | |
2029 | ||
2030 | } else { | |
2031 | $("export_status_message").innerHTML = | |
2032 | "Error occured, could not export data."; | |
2033 | } | |
2034 | } catch (e) { | |
2035 | exception_error("exportData", e, transport.responseText); | |
2036 | } | |
2037 | ||
2038 | notify(''); | |
2039 | ||
2040 | } }); | |
2041 | ||
2042 | }, | |
2043 | execute: function() { | |
2044 | if (this.validate()) { | |
2045 | ||
2046 | ||
2047 | ||
2048 | } | |
2049 | }, | |
2050 | href: query}); | |
2051 | ||
2052 | dialog.show(); | |
2053 | ||
2054 | ||
2055 | } catch (e) { | |
2056 | exception_error("exportData", e); | |
2057 | } | |
2058 | } | |
2059 | ||
2060 | function dataImportComplete(iframe) { | |
2061 | try { | |
2062 | if (!iframe.contentDocument.body.innerHTML) return false; | |
2063 | ||
2064 | Element.hide(iframe); | |
2065 | ||
2066 | notify(''); | |
2067 | ||
2068 | if (dijit.byId('dataImportDlg')) | |
2069 | dijit.byId('dataImportDlg').destroyRecursive(); | |
2070 | ||
2071 | var content = iframe.contentDocument.body.innerHTML; | |
2072 | ||
2073 | dialog = new dijit.Dialog({ | |
2074 | id: "dataImportDlg", | |
2075 | title: __("Data Import"), | |
2076 | style: "width: 600px", | |
2077 | onCancel: function() { | |
2078 | ||
2079 | }, | |
2080 | content: content}); | |
2081 | ||
2082 | dialog.show(); | |
2083 | ||
2084 | } catch (e) { | |
2085 | exception_error("dataImportComplete", e); | |
2086 | } | |
2087 | } | |
2088 | ||
2089 | function gotoExportOpml(filename, settings) { | |
2090 | tmp = settings ? 1 : 0; | |
2091 | document.location.href = "opml.php?op=Export&filename=" + filename + "&settings=" + tmp; | |
2092 | } | |
2093 | ||
2094 | ||
2095 | function batchSubscribe() { | |
2096 | try { | |
2097 | var query = "backend.php?op=dlg&method=batchSubscribe"; | |
2098 | ||
2099 | if (dijit.byId("batchSubDlg")) | |
2100 | dijit.byId("batchSubDlg").destroyRecursive(); | |
2101 | ||
2102 | var dialog = new dijit.Dialog({ | |
2103 | id: "batchSubDlg", | |
2104 | title: __("Batch subscribe"), | |
2105 | style: "width: 600px", | |
2106 | execute: function() { | |
2107 | if (this.validate()) { | |
2108 | console.log(dojo.objectToQuery(this.attr('value'))); | |
2109 | ||
2110 | notify_progress(__("Subscribing to feeds..."), true); | |
2111 | ||
2112 | new Ajax.Request("backend.php", { | |
2113 | parameters: dojo.objectToQuery(this.attr('value')), | |
2114 | onComplete: function(transport) { | |
2115 | this.hide(); | |
2116 | } }); | |
2117 | } | |
2118 | }, | |
2119 | href: query}); | |
2120 | ||
2121 | dialog.show(); | |
2122 | } catch (e) { | |
2123 | exception_error("batchSubscribe", e); | |
2124 | } | |
2125 | } | |
2126 |