]>
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 | notify(''); | |
758 | ||
759 | if (dijit.byId('opmlImportDlg')) | |
760 | dijit.byId('opmlImportDlg').destroyRecursive(); | |
761 | ||
762 | var content = iframe.contentDocument.body.innerHTML; | |
763 | ||
764 | dialog = new dijit.Dialog({ | |
765 | id: "opmlImportDlg", | |
766 | title: __("OPML Import"), | |
767 | style: "width: 600px", | |
768 | onCancel: function() { | |
769 | updateFeedList(); | |
770 | updateFilterList(); | |
771 | updateLabelList(); | |
772 | }, | |
773 | execute: function() { | |
774 | updateFeedList(); | |
775 | updateFilterList(); | |
776 | updateLabelList(); | |
777 | this.hide(); | |
778 | }, | |
779 | content: content}); | |
780 | ||
781 | dialog.show(); | |
782 | ||
783 | } catch (e) { | |
784 | exception_error("opmlImportComplete", e); | |
785 | } | |
786 | } | |
787 | ||
788 | function opmlImport() { | |
789 | ||
790 | var opml_file = $("opml_file"); | |
791 | ||
792 | if (opml_file.value.length == 0) { | |
793 | alert(__("Please choose an OPML file first.")); | |
794 | return false; | |
795 | } else { | |
796 | notify_progress("Importing, please wait...", true); | |
797 | return true; | |
798 | } | |
799 | } | |
800 | ||
801 | function updateFilterList() { | |
802 | new Ajax.Request("backend.php", { | |
803 | parameters: "?op=pref-filters", | |
804 | onComplete: function(transport) { | |
805 | dijit.byId('filterConfigTab').attr('content', transport.responseText); | |
806 | notify(""); | |
807 | } }); | |
808 | } | |
809 | ||
810 | function updateLabelList() { | |
811 | new Ajax.Request("backend.php", { | |
812 | parameters: "?op=pref-labels", | |
813 | onComplete: function(transport) { | |
814 | dijit.byId('labelConfigTab').attr('content', transport.responseText); | |
815 | notify(""); | |
816 | } }); | |
817 | } | |
818 | ||
819 | function updatePrefsList() { | |
820 | new Ajax.Request("backend.php", { | |
821 | parameters: "?op=pref-prefs", | |
822 | onComplete: function(transport) { | |
823 | dijit.byId('genConfigTab').attr('content', transport.responseText); | |
824 | notify(""); | |
825 | } }); | |
826 | } | |
827 | ||
828 | function selectTab(id, noupdate, method) { | |
829 | try { | |
830 | if (!noupdate) { | |
831 | notify_progress("Loading, please wait..."); | |
832 | ||
833 | if (id == "feedConfig") { | |
834 | updateFeedList(); | |
835 | } else if (id == "filterConfig") { | |
836 | updateFilterList(); | |
837 | } else if (id == "labelConfig") { | |
838 | updateLabelList(); | |
839 | } else if (id == "genConfig") { | |
840 | updatePrefsList(); | |
841 | } else if (id == "userConfig") { | |
842 | updateUsersList(); | |
843 | } | |
844 | ||
845 | var tab = dijit.byId(id + "Tab"); | |
846 | dijit.byId("pref-tabs").selectChild(tab); | |
847 | ||
848 | } | |
849 | ||
850 | } catch (e) { | |
851 | exception_error("selectTab", e); | |
852 | } | |
853 | } | |
854 | ||
855 | function init_second_stage() { | |
856 | try { | |
857 | ||
858 | document.onkeydown = pref_hotkey_handler; | |
859 | loading_set_progress(50); | |
860 | notify(""); | |
861 | ||
862 | dojo.addOnLoad(function() { | |
863 | var tab = getURLParam('tab'); | |
864 | ||
865 | if (tab) { | |
866 | tab = dijit.byId(tab + "Tab"); | |
867 | if (tab) dijit.byId("pref-tabs").selectChild(tab); | |
868 | } | |
869 | ||
870 | var method = getURLParam('method'); | |
871 | ||
872 | if (method == 'editFeed') { | |
873 | var param = getURLParam('methodparam'); | |
874 | ||
875 | window.setTimeout('editFeed(' + param + ')', 100); | |
876 | } | |
877 | }); | |
878 | ||
879 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
880 | ||
881 | } catch (e) { | |
882 | exception_error("init_second_stage", e); | |
883 | } | |
884 | } | |
885 | ||
886 | function init() { | |
887 | ||
888 | try { | |
889 | dojo.registerModulePath("lib", ".."); | |
890 | dojo.registerModulePath("fox", "../../js/"); | |
891 | ||
892 | dojo.require("lib.CheckBoxTree"); | |
893 | dojo.require("fox.PrefFeedTree"); | |
894 | dojo.require("fox.PrefFilterTree"); | |
895 | dojo.require("fox.PrefLabelTree"); | |
896 | ||
897 | dojo.parser.parse(); | |
898 | ||
899 | dojo.addOnLoad(function() { | |
900 | loading_set_progress(50); | |
901 | ||
902 | new Ajax.Request("backend.php", { | |
903 | parameters: {op: "rpc", method: "sanityCheck"}, | |
904 | onComplete: function(transport) { | |
905 | backend_sanity_check_callback(transport); | |
906 | } }); | |
907 | }); | |
908 | ||
909 | } catch (e) { | |
910 | exception_error("init", e); | |
911 | } | |
912 | } | |
913 | ||
914 | function validatePrefsReset() { | |
915 | try { | |
916 | var ok = confirm(__("Reset to defaults?")); | |
917 | ||
918 | if (ok) { | |
919 | ||
920 | query = "?op=pref-prefs&method=resetconfig"; | |
921 | console.log(query); | |
922 | ||
923 | new Ajax.Request("backend.php", { | |
924 | parameters: query, | |
925 | onComplete: function(transport) { | |
926 | var msg = transport.responseText; | |
927 | if (msg.match("PREFS_THEME_CHANGED")) { | |
928 | window.location.reload(); | |
929 | } else { | |
930 | notify_info(msg); | |
931 | selectTab(); | |
932 | } | |
933 | } }); | |
934 | ||
935 | } | |
936 | ||
937 | } catch (e) { | |
938 | exception_error("validatePrefsReset", e); | |
939 | } | |
940 | ||
941 | return false; | |
942 | ||
943 | } | |
944 | ||
945 | ||
946 | function pref_hotkey_handler(e) { | |
947 | try { | |
948 | if (e.target.nodeName == "INPUT") return; | |
949 | ||
950 | var keycode = false; | |
951 | var shift_key = false; | |
952 | ||
953 | var cmdline = $('cmdline'); | |
954 | ||
955 | try { | |
956 | shift_key = e.shiftKey; | |
957 | } catch (e) { | |
958 | ||
959 | } | |
960 | ||
961 | if (window.event) { | |
962 | keycode = window.event.keyCode; | |
963 | } else if (e) { | |
964 | keycode = e.which; | |
965 | } | |
966 | ||
967 | var keychar = String.fromCharCode(keycode); | |
968 | ||
969 | if (keycode == 27) { // escape | |
970 | if (Element.visible("hotkey_help_overlay")) { | |
971 | Element.hide("hotkey_help_overlay"); | |
972 | } | |
973 | hotkey_prefix = false; | |
974 | closeInfoBox(); | |
975 | } | |
976 | ||
977 | if (keycode == 16) return; // ignore lone shift | |
978 | if (keycode == 17) return; // ignore lone ctrl | |
979 | ||
980 | if ((keycode == 67 || keycode == 71) && !hotkey_prefix) { | |
981 | hotkey_prefix = keycode; | |
982 | ||
983 | var date = new Date(); | |
984 | var ts = Math.round(date.getTime() / 1000); | |
985 | ||
986 | hotkey_prefix_pressed = ts; | |
987 | ||
988 | cmdline.innerHTML = keychar; | |
989 | Element.show(cmdline); | |
990 | ||
991 | console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar); | |
992 | return; | |
993 | } | |
994 | ||
995 | if (Element.visible("hotkey_help_overlay")) { | |
996 | Element.hide("hotkey_help_overlay"); | |
997 | } | |
998 | ||
999 | if (keycode == 13 || keycode == 27) { | |
1000 | seq = ""; | |
1001 | } else { | |
1002 | seq = seq + "" + keycode; | |
1003 | } | |
1004 | ||
1005 | /* Global hotkeys */ | |
1006 | ||
1007 | Element.hide(cmdline); | |
1008 | ||
1009 | if (!hotkey_prefix) { | |
1010 | ||
1011 | if ((keycode == 191 || keychar == '?') && shift_key) { // ? | |
1012 | showHelp(); | |
1013 | return false; | |
1014 | } | |
1015 | ||
1016 | if (keycode == 191 || keychar == '/') { // / | |
1017 | var search_boxes = new Array("label_search", | |
1018 | "feed_search", "filter_search", "user_search", "feed_browser_search"); | |
1019 | ||
1020 | for (var i = 0; i < search_boxes.length; i++) { | |
1021 | var elem = $(search_boxes[i]); | |
1022 | if (elem) { | |
1023 | $(search_boxes[i]).focus(); | |
1024 | return false; | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | /* Prefix c */ | |
1031 | ||
1032 | if (hotkey_prefix == 67) { // c | |
1033 | hotkey_prefix = false; | |
1034 | ||
1035 | if (keycode == 70) { // f | |
1036 | quickAddFilter(); | |
1037 | return false; | |
1038 | } | |
1039 | ||
1040 | if (keycode == 83) { // s | |
1041 | quickAddFeed(); | |
1042 | return false; | |
1043 | } | |
1044 | ||
1045 | if (keycode == 85) { // u | |
1046 | // no-op | |
1047 | } | |
1048 | ||
1049 | if (keycode == 67) { // c | |
1050 | editFeedCats(); | |
1051 | return false; | |
1052 | } | |
1053 | ||
1054 | if (keycode == 84 && shift_key) { // T | |
1055 | feedBrowser(); | |
1056 | return false; | |
1057 | } | |
1058 | ||
1059 | } | |
1060 | ||
1061 | /* Prefix g */ | |
1062 | ||
1063 | if (hotkey_prefix == 71) { // g | |
1064 | ||
1065 | hotkey_prefix = false; | |
1066 | ||
1067 | if (keycode == 49 && $("genConfigTab")) { // 1 | |
1068 | selectTab("genConfig"); | |
1069 | return false; | |
1070 | } | |
1071 | ||
1072 | if (keycode == 50 && $("feedConfigTab")) { // 2 | |
1073 | selectTab("feedConfig"); | |
1074 | return false; | |
1075 | } | |
1076 | ||
1077 | if (keycode == 51 && $("filterConfigTab")) { // 4 | |
1078 | selectTab("filterConfig"); | |
1079 | return false; | |
1080 | } | |
1081 | ||
1082 | if (keycode == 52 && $("labelConfigTab")) { // 5 | |
1083 | selectTab("labelConfig"); | |
1084 | return false; | |
1085 | } | |
1086 | ||
1087 | if (keycode == 53 && $("userConfigTab")) { // 6 | |
1088 | selectTab("userConfig"); | |
1089 | return false; | |
1090 | } | |
1091 | ||
1092 | if (keycode == 88) { // x | |
1093 | return gotoMain(); | |
1094 | } | |
1095 | ||
1096 | } | |
1097 | ||
1098 | if ($("piggie")) { | |
1099 | if (seq.match("8073717369")) { | |
1100 | seq = ""; | |
1101 | piggie(true); | |
1102 | } else { | |
1103 | piggie(false); | |
1104 | } | |
1105 | } | |
1106 | ||
1107 | if (hotkey_prefix) { | |
1108 | console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar); | |
1109 | } else { | |
1110 | console.log("KP: CODE=" + keycode + " CHAR=" + keychar); | |
1111 | } | |
1112 | ||
1113 | } catch (e) { | |
1114 | exception_error("pref_hotkey_handler", e); | |
1115 | } | |
1116 | } | |
1117 | ||
1118 | function editFeedCats() { | |
1119 | try { | |
1120 | var query = "backend.php?op=pref-feeds&method=editCats"; | |
1121 | ||
1122 | if (dijit.byId("feedCatEditDlg")) | |
1123 | dijit.byId("feedCatEditDlg").destroyRecursive(); | |
1124 | ||
1125 | dialog = new dijit.Dialog({ | |
1126 | id: "feedCatEditDlg", | |
1127 | title: __("Feed Categories"), | |
1128 | style: "width: 600px", | |
1129 | getSelectedCategories: function() { | |
1130 | return getSelectedTableRowIds("prefFeedCatList"); | |
1131 | }, | |
1132 | removeSelected: function() { | |
1133 | var sel_rows = this.getSelectedCategories(); | |
1134 | ||
1135 | if (sel_rows.length > 0) { | |
1136 | var ok = confirm(__("Remove selected categories?")); | |
1137 | ||
1138 | if (ok) { | |
1139 | notify_progress("Removing selected categories...", true); | |
1140 | ||
1141 | var query = "?op=pref-feeds&method=editCats&action=remove&ids="+ | |
1142 | param_escape(sel_rows.toString()); | |
1143 | ||
1144 | new Ajax.Request("backend.php", { | |
1145 | parameters: query, | |
1146 | onComplete: function(transport) { | |
1147 | notify(''); | |
1148 | dialog.attr('content', transport.responseText); | |
1149 | updateFeedList(); | |
1150 | } }); | |
1151 | ||
1152 | } | |
1153 | ||
1154 | } else { | |
1155 | alert(__("No categories are selected.")); | |
1156 | } | |
1157 | }, | |
1158 | addCategory: function() { | |
1159 | if (this.validate()) { | |
1160 | notify_progress("Creating category..."); | |
1161 | ||
1162 | var query = "?op=pref-feeds&method=editCats&action=add&cat=" + | |
1163 | param_escape(this.attr('value').newcat); | |
1164 | ||
1165 | new Ajax.Request("backend.php", { | |
1166 | parameters: query, | |
1167 | onComplete: function(transport) { | |
1168 | notify(''); | |
1169 | dialog.attr('content', transport.responseText); | |
1170 | updateFeedList(); | |
1171 | } }); | |
1172 | } | |
1173 | }, | |
1174 | execute: function() { | |
1175 | if (this.validate()) { | |
1176 | } | |
1177 | }, | |
1178 | href: query}); | |
1179 | ||
1180 | dialog.show(); | |
1181 | ||
1182 | } catch (e) { | |
1183 | exception_error("editFeedCats", e); | |
1184 | } | |
1185 | } | |
1186 | ||
1187 | function showInactiveFeeds() { | |
1188 | try { | |
1189 | var query = "backend.php?op=dlg&method=inactiveFeeds"; | |
1190 | ||
1191 | if (dijit.byId("inactiveFeedsDlg")) | |
1192 | dijit.byId("inactiveFeedsDlg").destroyRecursive(); | |
1193 | ||
1194 | dialog = new dijit.Dialog({ | |
1195 | id: "inactiveFeedsDlg", | |
1196 | title: __("Feeds without recent updates"), | |
1197 | style: "width: 600px", | |
1198 | getSelectedFeeds: function() { | |
1199 | return getSelectedTableRowIds("prefInactiveFeedList"); | |
1200 | }, | |
1201 | removeSelected: function() { | |
1202 | var sel_rows = this.getSelectedFeeds(); | |
1203 | ||
1204 | console.log(sel_rows); | |
1205 | ||
1206 | if (sel_rows.length > 0) { | |
1207 | var ok = confirm(__("Remove selected feeds?")); | |
1208 | ||
1209 | if (ok) { | |
1210 | notify_progress("Removing selected feeds...", true); | |
1211 | ||
1212 | var query = "?op=pref-feeds&method=remove&ids="+ | |
1213 | param_escape(sel_rows.toString()); | |
1214 | ||
1215 | new Ajax.Request("backend.php", { | |
1216 | parameters: query, | |
1217 | onComplete: function(transport) { | |
1218 | notify(''); | |
1219 | dialog.hide(); | |
1220 | updateFeedList(); | |
1221 | } }); | |
1222 | } | |
1223 | ||
1224 | } else { | |
1225 | alert(__("No feeds are selected.")); | |
1226 | } | |
1227 | }, | |
1228 | execute: function() { | |
1229 | if (this.validate()) { | |
1230 | } | |
1231 | }, | |
1232 | href: query}); | |
1233 | ||
1234 | dialog.show(); | |
1235 | ||
1236 | } catch (e) { | |
1237 | exception_error("showInactiveFeeds", e); | |
1238 | } | |
1239 | ||
1240 | } | |
1241 | ||
1242 | function opmlRegenKey() { | |
1243 | ||
1244 | try { | |
1245 | var ok = confirm(__("Replace current OPML publishing address with a new one?")); | |
1246 | ||
1247 | if (ok) { | |
1248 | ||
1249 | notify_progress("Trying to change address...", true); | |
1250 | ||
1251 | var query = "?op=rpc&method=regenOPMLKey"; | |
1252 | ||
1253 | new Ajax.Request("backend.php", { | |
1254 | parameters: query, | |
1255 | onComplete: function(transport) { | |
1256 | var reply = JSON.parse(transport.responseText); | |
1257 | ||
1258 | var new_link = reply.link; | |
1259 | ||
1260 | var e = $('pub_opml_url'); | |
1261 | ||
1262 | if (new_link) { | |
1263 | e.href = new_link; | |
1264 | e.innerHTML = new_link; | |
1265 | ||
1266 | new Effect.Highlight(e); | |
1267 | ||
1268 | notify(''); | |
1269 | ||
1270 | } else { | |
1271 | notify_error("Could not change feed URL."); | |
1272 | } | |
1273 | } }); | |
1274 | } | |
1275 | } catch (e) { | |
1276 | exception_error("opmlRegenKey", e); | |
1277 | } | |
1278 | return false; | |
1279 | } | |
1280 | ||
1281 | function feedActionChange() { | |
1282 | try { | |
1283 | var chooser = $("feedActionChooser"); | |
1284 | var opid = chooser[chooser.selectedIndex].value; | |
1285 | ||
1286 | chooser.selectedIndex = 0; | |
1287 | feedActionGo(opid); | |
1288 | } catch (e) { | |
1289 | exception_error("feedActionChange", e); | |
1290 | } | |
1291 | } | |
1292 | ||
1293 | function feedActionGo(op) { | |
1294 | try { | |
1295 | if (op == "facEdit") { | |
1296 | ||
1297 | var rows = getSelectedFeeds(); | |
1298 | ||
1299 | if (rows.length > 1) { | |
1300 | editSelectedFeeds(); | |
1301 | } else { | |
1302 | editSelectedFeed(); | |
1303 | } | |
1304 | } | |
1305 | ||
1306 | if (op == "facClear") { | |
1307 | clearSelectedFeeds(); | |
1308 | } | |
1309 | ||
1310 | if (op == "facPurge") { | |
1311 | purgeSelectedFeeds(); | |
1312 | } | |
1313 | ||
1314 | if (op == "facEditCats") { | |
1315 | editFeedCats(); | |
1316 | } | |
1317 | ||
1318 | if (op == "facRescore") { | |
1319 | rescoreSelectedFeeds(); | |
1320 | } | |
1321 | ||
1322 | if (op == "facUnsubscribe") { | |
1323 | removeSelectedFeeds(); | |
1324 | } | |
1325 | ||
1326 | } catch (e) { | |
1327 | exception_error("feedActionGo", e); | |
1328 | ||
1329 | } | |
1330 | } | |
1331 | ||
1332 | function clearFeedArticles(feed_id) { | |
1333 | ||
1334 | notify_progress("Clearing feed..."); | |
1335 | ||
1336 | var query = "?op=pref-feeds&quiet=1&method=clear&id=" + feed_id; | |
1337 | ||
1338 | new Ajax.Request("backend.php", { | |
1339 | parameters: query, | |
1340 | onComplete: function(transport) { | |
1341 | notify(''); | |
1342 | } }); | |
1343 | ||
1344 | return false; | |
1345 | } | |
1346 | ||
1347 | function rescoreSelectedFeeds() { | |
1348 | ||
1349 | var sel_rows = getSelectedFeeds(); | |
1350 | ||
1351 | if (sel_rows.length > 0) { | |
1352 | ||
1353 | //var ok = confirm(__("Rescore last 100 articles in selected feeds?")); | |
1354 | var ok = confirm(__("Rescore articles in selected feeds?")); | |
1355 | ||
1356 | if (ok) { | |
1357 | notify_progress("Rescoring selected feeds...", true); | |
1358 | ||
1359 | var query = "?op=pref-feeds&method=rescore&quiet=1&ids="+ | |
1360 | param_escape(sel_rows.toString()); | |
1361 | ||
1362 | new Ajax.Request("backend.php", { | |
1363 | parameters: query, | |
1364 | onComplete: function(transport) { | |
1365 | notify_callback2(transport); | |
1366 | } }); | |
1367 | ||
1368 | } | |
1369 | } else { | |
1370 | alert(__("No feeds are selected.")); | |
1371 | } | |
1372 | ||
1373 | return false; | |
1374 | } | |
1375 | ||
1376 | function rescore_all_feeds() { | |
1377 | var ok = confirm(__("Rescore all articles? This operation may take a lot of time.")); | |
1378 | ||
1379 | if (ok) { | |
1380 | notify_progress("Rescoring feeds...", true); | |
1381 | ||
1382 | var query = "?op=pref-feeds&method=rescoreAll&quiet=1"; | |
1383 | ||
1384 | new Ajax.Request("backend.php", { | |
1385 | parameters: query, | |
1386 | onComplete: function(transport) { | |
1387 | notify_callback2(transport); | |
1388 | } }); | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | function labelColorReset() { | |
1393 | try { | |
1394 | var labels = getSelectedLabels(); | |
1395 | ||
1396 | if (labels.length > 0) { | |
1397 | var ok = confirm(__("Reset selected labels to default colors?")); | |
1398 | ||
1399 | if (ok) { | |
1400 | var query = "?op=pref-labels&method=colorreset&ids="+ | |
1401 | param_escape(labels.toString()); | |
1402 | ||
1403 | new Ajax.Request("backend.php", { | |
1404 | parameters: query, | |
1405 | onComplete: function(transport) { | |
1406 | updateLabelList(); | |
1407 | } }); | |
1408 | } | |
1409 | ||
1410 | } else { | |
1411 | alert(__("No labels are selected.")); | |
1412 | } | |
1413 | ||
1414 | } catch (e) { | |
1415 | exception_error("labelColorReset", e); | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | ||
1420 | function inPreferences() { | |
1421 | return true; | |
1422 | } | |
1423 | ||
1424 | function editProfiles() { | |
1425 | try { | |
1426 | ||
1427 | if (dijit.byId("profileEditDlg")) | |
1428 | dijit.byId("profileEditDlg").destroyRecursive(); | |
1429 | ||
1430 | var query = "backend.php?op=dlg&method=editPrefProfiles"; | |
1431 | ||
1432 | dialog = new dijit.Dialog({ | |
1433 | id: "profileEditDlg", | |
1434 | title: __("Settings Profiles"), | |
1435 | style: "width: 600px", | |
1436 | getSelectedProfiles: function() { | |
1437 | return getSelectedTableRowIds("prefFeedProfileList"); | |
1438 | }, | |
1439 | removeSelected: function() { | |
1440 | var sel_rows = this.getSelectedProfiles(); | |
1441 | ||
1442 | if (sel_rows.length > 0) { | |
1443 | var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed.")); | |
1444 | ||
1445 | if (ok) { | |
1446 | notify_progress("Removing selected profiles...", true); | |
1447 | ||
1448 | var query = "?op=rpc&method=remprofiles&ids="+ | |
1449 | param_escape(sel_rows.toString()); | |
1450 | ||
1451 | new Ajax.Request("backend.php", { | |
1452 | parameters: query, | |
1453 | onComplete: function(transport) { | |
1454 | notify(''); | |
1455 | editProfiles(); | |
1456 | } }); | |
1457 | ||
1458 | } | |
1459 | ||
1460 | } else { | |
1461 | alert(__("No profiles are selected.")); | |
1462 | } | |
1463 | }, | |
1464 | activateProfile: function() { | |
1465 | var sel_rows = this.getSelectedProfiles(); | |
1466 | ||
1467 | if (sel_rows.length == 1) { | |
1468 | ||
1469 | var ok = confirm(__("Activate selected profile?")); | |
1470 | ||
1471 | if (ok) { | |
1472 | notify_progress("Loading, please wait..."); | |
1473 | ||
1474 | var query = "?op=rpc&method=setprofile&id="+ | |
1475 | param_escape(sel_rows.toString()); | |
1476 | ||
1477 | new Ajax.Request("backend.php", { | |
1478 | parameters: query, | |
1479 | onComplete: function(transport) { | |
1480 | window.location.reload(); | |
1481 | } }); | |
1482 | } | |
1483 | ||
1484 | } else { | |
1485 | alert(__("Please choose a profile to activate.")); | |
1486 | } | |
1487 | }, | |
1488 | addProfile: function() { | |
1489 | if (this.validate()) { | |
1490 | notify_progress("Creating profile...", true); | |
1491 | ||
1492 | var query = "?op=rpc&method=addprofile&title=" + | |
1493 | param_escape(dialog.attr('value').newprofile); | |
1494 | ||
1495 | new Ajax.Request("backend.php", { | |
1496 | parameters: query, | |
1497 | onComplete: function(transport) { | |
1498 | notify(''); | |
1499 | editProfiles(); | |
1500 | } }); | |
1501 | ||
1502 | } | |
1503 | }, | |
1504 | execute: function() { | |
1505 | if (this.validate()) { | |
1506 | } | |
1507 | }, | |
1508 | href: query}); | |
1509 | ||
1510 | dialog.show(); | |
1511 | } catch (e) { | |
1512 | exception_error("editProfiles", e); | |
1513 | } | |
1514 | } | |
1515 | ||
1516 | function activatePrefProfile() { | |
1517 | ||
1518 | var sel_rows = getSelectedFeedCats(); | |
1519 | ||
1520 | if (sel_rows.length == 1) { | |
1521 | ||
1522 | var ok = confirm(__("Activate selected profile?")); | |
1523 | ||
1524 | if (ok) { | |
1525 | notify_progress("Loading, please wait..."); | |
1526 | ||
1527 | var query = "?op=rpc&method=setprofile&id="+ | |
1528 | param_escape(sel_rows.toString()); | |
1529 | ||
1530 | new Ajax.Request("backend.php", { | |
1531 | parameters: query, | |
1532 | onComplete: function(transport) { | |
1533 | window.location.reload(); | |
1534 | } }); | |
1535 | } | |
1536 | ||
1537 | } else { | |
1538 | alert(__("Please choose a profile to activate.")); | |
1539 | } | |
1540 | ||
1541 | return false; | |
1542 | } | |
1543 | ||
1544 | function clearFeedAccessKeys() { | |
1545 | ||
1546 | var ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?")); | |
1547 | ||
1548 | if (ok) { | |
1549 | notify_progress("Clearing URLs..."); | |
1550 | ||
1551 | var query = "?op=rpc&method=clearKeys"; | |
1552 | ||
1553 | new Ajax.Request("backend.php", { | |
1554 | parameters: query, | |
1555 | onComplete: function(transport) { | |
1556 | notify_info("Generated URLs cleared."); | |
1557 | } }); | |
1558 | } | |
1559 | ||
1560 | return false; | |
1561 | } | |
1562 | ||
1563 | function clearArticleAccessKeys() { | |
1564 | ||
1565 | var ok = confirm(__("This will invalidate all previously shared article URLs. Continue?")); | |
1566 | ||
1567 | if (ok) { | |
1568 | notify_progress("Clearing URLs..."); | |
1569 | ||
1570 | var query = "?op=rpc&method=clearArticleKeys"; | |
1571 | ||
1572 | new Ajax.Request("backend.php", { | |
1573 | parameters: query, | |
1574 | onComplete: function(transport) { | |
1575 | notify_info("Shared URLs cleared."); | |
1576 | } }); | |
1577 | } | |
1578 | ||
1579 | return false; | |
1580 | } | |
1581 | function resetFeedOrder() { | |
1582 | try { | |
1583 | notify_progress("Loading, please wait..."); | |
1584 | ||
1585 | new Ajax.Request("backend.php", { | |
1586 | parameters: "?op=pref-feeds&method=feedsortreset", | |
1587 | onComplete: function(transport) { | |
1588 | updateFeedList(); | |
1589 | } }); | |
1590 | ||
1591 | ||
1592 | } catch (e) { | |
1593 | exception_error("resetFeedOrder"); | |
1594 | } | |
1595 | } | |
1596 | ||
1597 | function resetCatOrder() { | |
1598 | try { | |
1599 | notify_progress("Loading, please wait..."); | |
1600 | ||
1601 | new Ajax.Request("backend.php", { | |
1602 | parameters: "?op=pref-feeds&method=catsortreset", | |
1603 | onComplete: function(transport) { | |
1604 | updateFeedList(); | |
1605 | } }); | |
1606 | ||
1607 | ||
1608 | } catch (e) { | |
1609 | exception_error("resetCatOrder"); | |
1610 | } | |
1611 | } | |
1612 | ||
1613 | function editCat(id, item, event) { | |
1614 | try { | |
1615 | var new_name = prompt(__('Rename category to:'), item.name); | |
1616 | ||
1617 | if (new_name && new_name != item.name) { | |
1618 | ||
1619 | notify_progress("Loading, please wait..."); | |
1620 | ||
1621 | new Ajax.Request("backend.php", { | |
1622 | parameters: { | |
1623 | op: 'pref-feeds', | |
1624 | method: 'renamecat', | |
1625 | id: id, | |
1626 | title: new_name, | |
1627 | }, | |
1628 | onComplete: function(transport) { | |
1629 | updateFeedList(); | |
1630 | } }); | |
1631 | } | |
1632 | ||
1633 | } catch (e) { | |
1634 | exception_error("editCat", e); | |
1635 | } | |
1636 | } | |
1637 | ||
1638 | function editLabel(id, event) { | |
1639 | try { | |
1640 | var query = "backend.php?op=pref-labels&method=edit&id=" + | |
1641 | param_escape(id); | |
1642 | ||
1643 | if (dijit.byId("labelEditDlg")) | |
1644 | dijit.byId("labelEditDlg").destroyRecursive(); | |
1645 | ||
1646 | dialog = new dijit.Dialog({ | |
1647 | id: "labelEditDlg", | |
1648 | title: __("Label Editor"), | |
1649 | style: "width: 600px", | |
1650 | setLabelColor: function(id, fg, bg) { | |
1651 | ||
1652 | var kind = ''; | |
1653 | var color = ''; | |
1654 | ||
1655 | if (fg && bg) { | |
1656 | kind = 'both'; | |
1657 | } else if (fg) { | |
1658 | kind = 'fg'; | |
1659 | color = fg; | |
1660 | } else if (bg) { | |
1661 | kind = 'bg'; | |
1662 | color = bg; | |
1663 | } | |
1664 | ||
1665 | var query = "?op=pref-labels&method=colorset&kind="+kind+ | |
1666 | "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) + | |
1667 | "&bg=" + param_escape(bg) + "&color=" + param_escape(color); | |
1668 | ||
1669 | // console.log(query); | |
1670 | ||
1671 | var e = $("LICID-" + id); | |
1672 | ||
1673 | if (e) { | |
1674 | if (fg) e.style.color = fg; | |
1675 | if (bg) e.style.backgroundColor = bg; | |
1676 | } | |
1677 | ||
1678 | new Ajax.Request("backend.php", { parameters: query }); | |
1679 | ||
1680 | updateFilterList(); | |
1681 | }, | |
1682 | execute: function() { | |
1683 | if (this.validate()) { | |
1684 | var caption = this.attr('value').caption; | |
1685 | var fg_color = this.attr('value').fg_color; | |
1686 | var bg_color = this.attr('value').bg_color; | |
1687 | var query = dojo.objectToQuery(this.attr('value')); | |
1688 | ||
1689 | dijit.byId('labelTree').setNameById(id, caption); | |
1690 | this.setLabelColor(id, fg_color, bg_color); | |
1691 | this.hide(); | |
1692 | ||
1693 | new Ajax.Request("backend.php", { | |
1694 | parameters: query, | |
1695 | onComplete: function(transport) { | |
1696 | updateFilterList(); | |
1697 | } }); | |
1698 | } | |
1699 | }, | |
1700 | href: query}); | |
1701 | ||
1702 | dialog.show(); | |
1703 | ||
1704 | } catch (e) { | |
1705 | exception_error("editLabel", e); | |
1706 | } | |
1707 | } | |
1708 | ||
1709 | function clearTwitterCredentials() { | |
1710 | try { | |
1711 | var ok = confirm(__("This will clear your stored authentication information for Twitter. Continue?")); | |
1712 | ||
1713 | if (ok) { | |
1714 | notify_progress("Clearing credentials..."); | |
1715 | ||
1716 | var query = "?op=pref-feeds&method=remtwitterinfo"; | |
1717 | ||
1718 | new Ajax.Request("backend.php", { | |
1719 | parameters: query, | |
1720 | onComplete: function(transport) { | |
1721 | notify_info("Twitter credentials have been cleared."); | |
1722 | updateFeedList(); | |
1723 | } }); | |
1724 | } | |
1725 | ||
1726 | } catch (e) { | |
1727 | exception_error("clearTwitterCredentials", e); | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | function customizeCSS() { | |
1732 | try { | |
1733 | var query = "backend.php?op=dlg&method=customizeCSS"; | |
1734 | ||
1735 | if (dijit.byId("cssEditDlg")) | |
1736 | dijit.byId("cssEditDlg").destroyRecursive(); | |
1737 | ||
1738 | dialog = new dijit.Dialog({ | |
1739 | id: "cssEditDlg", | |
1740 | title: __("Customize stylesheet"), | |
1741 | style: "width: 600px", | |
1742 | execute: function() { | |
1743 | notify_progress('Saving data...', true); | |
1744 | new Ajax.Request("backend.php", { | |
1745 | parameters: dojo.objectToQuery(this.attr('value')), | |
1746 | onComplete: function(transport) { | |
1747 | notify(''); | |
1748 | window.location.reload(); | |
1749 | } }); | |
1750 | ||
1751 | }, | |
1752 | href: query}); | |
1753 | ||
1754 | dialog.show(); | |
1755 | ||
1756 | } catch (e) { | |
1757 | exception_error("customizeCSS", e); | |
1758 | } | |
1759 | } | |
1760 | ||
1761 | function insertSSLserial(value) { | |
1762 | try { | |
1763 | dijit.byId("SSL_CERT_SERIAL").attr('value', value); | |
1764 | } catch (e) { | |
1765 | exception_error("insertSSLcerial", e); | |
1766 | } | |
1767 | } | |
1768 | ||
1769 | function getSelectedInstances() { | |
1770 | return getSelectedTableRowIds("prefInstanceList"); | |
1771 | } | |
1772 | ||
1773 | function addInstance() { | |
1774 | try { | |
1775 | var query = "backend.php?op=dlg&method=addInstance"; | |
1776 | ||
1777 | if (dijit.byId("instanceAddDlg")) | |
1778 | dijit.byId("instanceAddDlg").destroyRecursive(); | |
1779 | ||
1780 | dialog = new dijit.Dialog({ | |
1781 | id: "instanceAddDlg", | |
1782 | title: __("Link Instance"), | |
1783 | style: "width: 600px", | |
1784 | regenKey: function() { | |
1785 | new Ajax.Request("backend.php", { | |
1786 | parameters: "?op=rpc&method=genHash", | |
1787 | onComplete: function(transport) { | |
1788 | var reply = JSON.parse(transport.responseText); | |
1789 | if (reply) | |
1790 | dijit.byId('instance_add_key').attr('value', reply.hash); | |
1791 | ||
1792 | } }); | |
1793 | }, | |
1794 | execute: function() { | |
1795 | if (this.validate()) { | |
1796 | console.warn(dojo.objectToQuery(this.attr('value'))); | |
1797 | ||
1798 | notify_progress('Saving data...', true); | |
1799 | new Ajax.Request("backend.php", { | |
1800 | parameters: dojo.objectToQuery(this.attr('value')), | |
1801 | onComplete: function(transport) { | |
1802 | dialog.hide(); | |
1803 | notify(''); | |
1804 | updateInstanceList(); | |
1805 | } }); | |
1806 | } | |
1807 | }, | |
1808 | href: query, | |
1809 | }); | |
1810 | ||
1811 | dialog.show(); | |
1812 | ||
1813 | } catch (e) { | |
1814 | exception_error("addInstance", e); | |
1815 | } | |
1816 | } | |
1817 | ||
1818 | function editInstance(id, event) { | |
1819 | try { | |
1820 | if (!event || !event.ctrlKey) { | |
1821 | ||
1822 | selectTableRows('prefInstanceList', 'none'); | |
1823 | selectTableRowById('LIRR-'+id, 'LICHK-'+id, true); | |
1824 | ||
1825 | var query = "backend.php?op=pref-instances&method=edit&id=" + | |
1826 | param_escape(id); | |
1827 | ||
1828 | if (dijit.byId("instanceEditDlg")) | |
1829 | dijit.byId("instanceEditDlg").destroyRecursive(); | |
1830 | ||
1831 | dialog = new dijit.Dialog({ | |
1832 | id: "instanceEditDlg", | |
1833 | title: __("Edit Instance"), | |
1834 | style: "width: 600px", | |
1835 | regenKey: function() { | |
1836 | new Ajax.Request("backend.php", { | |
1837 | parameters: "?op=rpc&method=genHash", | |
1838 | onComplete: function(transport) { | |
1839 | var reply = JSON.parse(transport.responseText); | |
1840 | if (reply) | |
1841 | dijit.byId('instance_edit_key').attr('value', reply.hash); | |
1842 | ||
1843 | } }); | |
1844 | }, | |
1845 | execute: function() { | |
1846 | if (this.validate()) { | |
1847 | // console.warn(dojo.objectToQuery(this.attr('value'))); | |
1848 | ||
1849 | notify_progress('Saving data...', true); | |
1850 | new Ajax.Request("backend.php", { | |
1851 | parameters: dojo.objectToQuery(this.attr('value')), | |
1852 | onComplete: function(transport) { | |
1853 | dialog.hide(); | |
1854 | notify(''); | |
1855 | updateInstanceList(); | |
1856 | } }); | |
1857 | } | |
1858 | }, | |
1859 | href: query, | |
1860 | }); | |
1861 | ||
1862 | dialog.show(); | |
1863 | ||
1864 | } else if (event.ctrlKey) { | |
1865 | var cb = $('LICHK-' + id); | |
1866 | cb.checked = !cb.checked; | |
1867 | toggleSelectRow(cb); | |
1868 | } | |
1869 | ||
1870 | ||
1871 | } catch (e) { | |
1872 | exception_error("editInstance", e); | |
1873 | } | |
1874 | } | |
1875 | ||
1876 | function removeSelectedInstances() { | |
1877 | try { | |
1878 | var sel_rows = getSelectedInstances(); | |
1879 | ||
1880 | if (sel_rows.length > 0) { | |
1881 | ||
1882 | var ok = confirm(__("Remove selected instances?")); | |
1883 | ||
1884 | if (ok) { | |
1885 | notify_progress("Removing selected instances..."); | |
1886 | ||
1887 | var query = "?op=pref-instances&method=remove&ids="+ | |
1888 | param_escape(sel_rows.toString()); | |
1889 | ||
1890 | new Ajax.Request("backend.php", { | |
1891 | parameters: query, | |
1892 | onComplete: function(transport) { | |
1893 | notify(''); | |
1894 | updateInstanceList(); | |
1895 | } }); | |
1896 | } | |
1897 | ||
1898 | } else { | |
1899 | alert(__("No instances are selected.")); | |
1900 | } | |
1901 | ||
1902 | } catch (e) { | |
1903 | exception_error("removeInstance", e); | |
1904 | } | |
1905 | } | |
1906 | ||
1907 | function editSelectedInstance() { | |
1908 | var rows = getSelectedInstances(); | |
1909 | ||
1910 | if (rows.length == 0) { | |
1911 | alert(__("No instances are selected.")); | |
1912 | return; | |
1913 | } | |
1914 | ||
1915 | if (rows.length > 1) { | |
1916 | alert(__("Please select only one instance.")); | |
1917 | return; | |
1918 | } | |
1919 | ||
1920 | notify(""); | |
1921 | ||
1922 | editInstance(rows[0]); | |
1923 | } | |
1924 | ||
1925 | function showHelp() { | |
1926 | try { | |
1927 | new Ajax.Request("backend.php", { | |
1928 | parameters: "?op=backend&method=help&topic=prefs", | |
1929 | onComplete: function(transport) { | |
1930 | $("hotkey_help_overlay").innerHTML = transport.responseText; | |
1931 | Effect.Appear("hotkey_help_overlay", {duration : 0.3}); | |
1932 | } }); | |
1933 | ||
1934 | } catch (e) { | |
1935 | exception_error("showHelp", e); | |
1936 | } | |
1937 | } | |
1938 | ||
1939 | function exportData() { | |
1940 | try { | |
1941 | ||
1942 | var query = "backend.php?op=dlg&method=exportData"; | |
1943 | ||
1944 | if (dijit.byId("dataExportDlg")) | |
1945 | dijit.byId("dataExportDlg").destroyRecursive(); | |
1946 | ||
1947 | var exported = 0; | |
1948 | ||
1949 | dialog = new dijit.Dialog({ | |
1950 | id: "dataExportDlg", | |
1951 | title: __("Export Data"), | |
1952 | style: "width: 600px", | |
1953 | prepare: function() { | |
1954 | ||
1955 | notify_progress("Loading, please wait..."); | |
1956 | ||
1957 | new Ajax.Request("backend.php", { | |
1958 | parameters: "?op=rpc&method=exportrun&offset=" + exported, | |
1959 | onComplete: function(transport) { | |
1960 | try { | |
1961 | var rv = JSON.parse(transport.responseText); | |
1962 | ||
1963 | if (rv && rv.exported != undefined) { | |
1964 | if (rv.exported > 0) { | |
1965 | ||
1966 | exported += rv.exported; | |
1967 | ||
1968 | $("export_status_message").innerHTML = | |
1969 | "<img src='images/indicator_tiny.gif'> " + | |
1970 | "Exported %d articles, please wait...".replace("%d", | |
1971 | exported); | |
1972 | ||
1973 | setTimeout('dijit.byId("dataExportDlg").prepare()', 2000); | |
1974 | ||
1975 | } else { | |
1976 | ||
1977 | $("export_status_message").innerHTML = | |
1978 | __("Finished, exported %d articles. You can download the data <a class='visibleLink' href='%u'>here</a>.") | |
1979 | .replace("%d", exported) | |
1980 | .replace("%u", "backend.php?op=rpc&subop=exportget"); | |
1981 | ||
1982 | exported = 0; | |
1983 | ||
1984 | } | |
1985 | ||
1986 | } else { | |
1987 | $("export_status_message").innerHTML = | |
1988 | "Error occured, could not export data."; | |
1989 | } | |
1990 | } catch (e) { | |
1991 | exception_error("exportData", e, transport.responseText); | |
1992 | } | |
1993 | ||
1994 | notify(''); | |
1995 | ||
1996 | } }); | |
1997 | ||
1998 | }, | |
1999 | execute: function() { | |
2000 | if (this.validate()) { | |
2001 | ||
2002 | ||
2003 | ||
2004 | } | |
2005 | }, | |
2006 | href: query}); | |
2007 | ||
2008 | dialog.show(); | |
2009 | ||
2010 | ||
2011 | } catch (e) { | |
2012 | exception_error("exportData", e); | |
2013 | } | |
2014 | } | |
2015 |