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