]>
Commit | Line | Data |
---|---|---|
1 | var notify_silent = false; | |
2 | var loading_progress = 0; | |
3 | var sanity_check_done = false; | |
4 | ||
5 | /* add method to remove element from array */ | |
6 | ||
7 | Array.prototype.remove = function(s) { | |
8 | for (var i=0; i < this.length; i++) { | |
9 | if (s == this[i]) this.splice(i, 1); | |
10 | } | |
11 | } | |
12 | ||
13 | /* create console.log if it doesn't exist */ | |
14 | ||
15 | if (!window.console) console = {}; | |
16 | console.log = console.log || function(msg) { }; | |
17 | console.warn = console.warn || function(msg) { }; | |
18 | console.error = console.error || function(msg) { }; | |
19 | ||
20 | function exception_error(location, e, ext_info) { | |
21 | var msg = format_exception_error(location, e); | |
22 | ||
23 | if (!ext_info) ext_info = false; | |
24 | ||
25 | try { | |
26 | ||
27 | if (ext_info) { | |
28 | if (ext_info.responseText) { | |
29 | ext_info = ext_info.responseText; | |
30 | } | |
31 | } | |
32 | ||
33 | var content = "<div class=\"fatalError\">" + | |
34 | "<pre>" + msg + "</pre>"; | |
35 | ||
36 | content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+ | |
37 | "action=\"http://tt-rss.org/report.php\" method=\"POST\">"; | |
38 | ||
39 | content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>"; | |
40 | content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>"; | |
41 | ||
42 | if (ext_info) { | |
43 | content += "<div><b>Additional information:</b></div>" + | |
44 | "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>"; | |
45 | } | |
46 | ||
47 | content += "<div><b>Stack trace:</b></div>" + | |
48 | "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>"; | |
49 | ||
50 | content += "</form>"; | |
51 | ||
52 | content += "</div>"; | |
53 | ||
54 | content += "<div class='dlgButtons'>"; | |
55 | ||
56 | content += "<button dojoType=\"dijit.form.Button\""+ | |
57 | "onclick=\"dijit.byId('exceptionDlg').report()\">" + | |
58 | __('Report to tt-rss.org') + "</button> "; | |
59 | content += "<button dojoType=\"dijit.form.Button\" "+ | |
60 | "onclick=\"dijit.byId('exceptionDlg').hide()\">" + | |
61 | __('Close') + "</button>"; | |
62 | content += "</div>"; | |
63 | ||
64 | ||
65 | var dialog = new dijit.Dialog({ | |
66 | id: "exceptionDlg", | |
67 | title: "Unhandled exception", | |
68 | style: "width: 600px", | |
69 | report: function() { | |
70 | if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) { | |
71 | ||
72 | document.forms['exceptionForm'].params.value = $H({ | |
73 | browserName: navigator.appName, | |
74 | browserVersion: navigator.appVersion, | |
75 | browserPlatform: navigator.platform, | |
76 | browserCookies: navigator.cookieEnabled, | |
77 | }).toQueryString(); | |
78 | ||
79 | document.forms['exceptionForm'].submit(); | |
80 | ||
81 | } | |
82 | }, | |
83 | content: content}); | |
84 | ||
85 | dialog.show(); | |
86 | ||
87 | } catch (e) { | |
88 | alert(msg); | |
89 | } | |
90 | ||
91 | } | |
92 | ||
93 | function format_exception_error(location, e) { | |
94 | var msg; | |
95 | ||
96 | if (e.fileName) { | |
97 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
98 | ||
99 | msg = "Exception: " + e.name + ", " + e.message + | |
100 | "\nFunction: " + location + "()" + | |
101 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
102 | ||
103 | } else if (e.description) { | |
104 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
105 | } else { | |
106 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
107 | } | |
108 | ||
109 | console.error("EXCEPTION: " + msg); | |
110 | ||
111 | return msg; | |
112 | } | |
113 | ||
114 | function param_escape(arg) { | |
115 | if (typeof encodeURIComponent != 'undefined') | |
116 | return encodeURIComponent(arg); | |
117 | else | |
118 | return escape(arg); | |
119 | } | |
120 | ||
121 | function param_unescape(arg) { | |
122 | if (typeof decodeURIComponent != 'undefined') | |
123 | return decodeURIComponent(arg); | |
124 | else | |
125 | return unescape(arg); | |
126 | } | |
127 | ||
128 | var notify_hide_timerid = false; | |
129 | ||
130 | function hide_notify() { | |
131 | var n = $("notify"); | |
132 | if (n) { | |
133 | n.style.display = "none"; | |
134 | } | |
135 | } | |
136 | ||
137 | function notify_silent_next() { | |
138 | notify_silent = true; | |
139 | } | |
140 | ||
141 | function notify_real(msg, no_hide, n_type) { | |
142 | ||
143 | if (notify_silent) { | |
144 | notify_silent = false; | |
145 | return; | |
146 | } | |
147 | ||
148 | var n = $("notify"); | |
149 | var nb = $("notify_body"); | |
150 | ||
151 | if (!n || !nb) return; | |
152 | ||
153 | if (notify_hide_timerid) { | |
154 | window.clearTimeout(notify_hide_timerid); | |
155 | } | |
156 | ||
157 | if (msg == "") { | |
158 | if (n.style.display == "block") { | |
159 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
160 | } | |
161 | return; | |
162 | } else { | |
163 | n.style.display = "block"; | |
164 | } | |
165 | ||
166 | /* types: | |
167 | ||
168 | 1 - generic | |
169 | 2 - progress | |
170 | 3 - error | |
171 | 4 - info | |
172 | ||
173 | */ | |
174 | ||
175 | if (typeof __ != 'undefined') { | |
176 | msg = __(msg); | |
177 | } | |
178 | ||
179 | if (n_type == 1) { | |
180 | n.className = "notify"; | |
181 | } else if (n_type == 2) { | |
182 | n.className = "notifyProgress"; | |
183 | msg = "<img src='"+getInitParam("sign_progress")+"'> " + msg; | |
184 | } else if (n_type == 3) { | |
185 | n.className = "notifyError"; | |
186 | msg = "<img src='"+getInitParam("sign_excl")+"'> " + msg; | |
187 | } else if (n_type == 4) { | |
188 | n.className = "notifyInfo"; | |
189 | msg = "<img src='"+getInitParam("sign_info")+"'> " + msg; | |
190 | } | |
191 | ||
192 | // msg = "<img src='images/live_com_loading.gif'> " + msg; | |
193 | ||
194 | nb.innerHTML = msg; | |
195 | ||
196 | if (!no_hide) { | |
197 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); | |
198 | } | |
199 | } | |
200 | ||
201 | function notify(msg, no_hide) { | |
202 | notify_real(msg, no_hide, 1); | |
203 | } | |
204 | ||
205 | function notify_progress(msg, no_hide) { | |
206 | notify_real(msg, no_hide, 2); | |
207 | } | |
208 | ||
209 | function notify_error(msg, no_hide) { | |
210 | notify_real(msg, no_hide, 3); | |
211 | ||
212 | } | |
213 | ||
214 | function notify_info(msg, no_hide) { | |
215 | notify_real(msg, no_hide, 4); | |
216 | } | |
217 | ||
218 | function setCookie(name, value, lifetime, path, domain, secure) { | |
219 | ||
220 | var d = false; | |
221 | ||
222 | if (lifetime) { | |
223 | d = new Date(); | |
224 | d.setTime(d.getTime() + (lifetime * 1000)); | |
225 | } | |
226 | ||
227 | console.log("setCookie: " + name + " => " + value + ": " + d); | |
228 | ||
229 | int_setCookie(name, value, d, path, domain, secure); | |
230 | ||
231 | } | |
232 | ||
233 | function int_setCookie(name, value, expires, path, domain, secure) { | |
234 | document.cookie= name + "=" + escape(value) + | |
235 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
236 | ((path) ? "; path=" + path : "") + | |
237 | ((domain) ? "; domain=" + domain : "") + | |
238 | ((secure) ? "; secure" : ""); | |
239 | } | |
240 | ||
241 | function delCookie(name, path, domain) { | |
242 | if (getCookie(name)) { | |
243 | document.cookie = name + "=" + | |
244 | ((path) ? ";path=" + path : "") + | |
245 | ((domain) ? ";domain=" + domain : "" ) + | |
246 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
247 | } | |
248 | } | |
249 | ||
250 | ||
251 | function getCookie(name) { | |
252 | ||
253 | var dc = document.cookie; | |
254 | var prefix = name + "="; | |
255 | var begin = dc.indexOf("; " + prefix); | |
256 | if (begin == -1) { | |
257 | begin = dc.indexOf(prefix); | |
258 | if (begin != 0) return null; | |
259 | } | |
260 | else { | |
261 | begin += 2; | |
262 | } | |
263 | var end = document.cookie.indexOf(";", begin); | |
264 | if (end == -1) { | |
265 | end = dc.length; | |
266 | } | |
267 | return unescape(dc.substring(begin + prefix.length, end)); | |
268 | } | |
269 | ||
270 | function gotoPreferences() { | |
271 | document.location.href = "prefs.php"; | |
272 | } | |
273 | ||
274 | function gotoMain() { | |
275 | document.location.href = "tt-rss.php"; | |
276 | } | |
277 | ||
278 | function gotoExportOpml() { | |
279 | document.location.href = "opml.php?op=Export"; | |
280 | } | |
281 | ||
282 | ||
283 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
284 | * * @author Sundar Dorai-Raj | |
285 | * * Email: sdoraira@vt.edu | |
286 | * * This program is free software; you can redistribute it and/or | |
287 | * * modify it under the terms of the GNU General Public License | |
288 | * * as published by the Free Software Foundation; either version 2 | |
289 | * * of the License, or (at your option) any later version, | |
290 | * * provided that any use properly credits the author. | |
291 | * * This program is distributed in the hope that it will be useful, | |
292 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
293 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
294 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
295 | ||
296 | var numbers=".0123456789"; | |
297 | function isNumeric(x) { | |
298 | // is x a String or a character? | |
299 | if(x.length>1) { | |
300 | // remove negative sign | |
301 | x=Math.abs(x)+""; | |
302 | for(j=0;j<x.length;j++) { | |
303 | // call isNumeric recursively for each character | |
304 | number=isNumeric(x.substring(j,j+1)); | |
305 | if(!number) return number; | |
306 | } | |
307 | return number; | |
308 | } | |
309 | else { | |
310 | // if x is number return true | |
311 | if(numbers.indexOf(x)>=0) return true; | |
312 | return false; | |
313 | } | |
314 | } | |
315 | ||
316 | ||
317 | function toggleSelectRowById(sender, id) { | |
318 | var row = $(id); | |
319 | return toggleSelectRow(sender, row); | |
320 | } | |
321 | ||
322 | function toggleSelectListRow(sender) { | |
323 | var row = sender.parentNode; | |
324 | return toggleSelectRow(sender, row); | |
325 | } | |
326 | ||
327 | /* this is for dijit Checkbox */ | |
328 | function toggleSelectListRow2(sender) { | |
329 | var row = sender.domNode.parentNode; | |
330 | return toggleSelectRow(sender, row); | |
331 | } | |
332 | ||
333 | function tSR(sender, row) { | |
334 | return toggleSelectRow(sender, row); | |
335 | } | |
336 | ||
337 | /* this is for dijit Checkbox */ | |
338 | function toggleSelectRow2(sender, row) { | |
339 | ||
340 | if (!row) row = sender.domNode.parentNode.parentNode; | |
341 | ||
342 | if (sender.checked && !row.hasClassName('Selected')) | |
343 | row.addClassName('Selected'); | |
344 | else | |
345 | row.removeClassName('Selected'); | |
346 | } | |
347 | ||
348 | ||
349 | function toggleSelectRow(sender, row) { | |
350 | ||
351 | if (!row) row = sender.parentNode.parentNode; | |
352 | ||
353 | if (sender.checked && !row.hasClassName('Selected')) | |
354 | row.addClassName('Selected'); | |
355 | else | |
356 | row.removeClassName('Selected'); | |
357 | } | |
358 | ||
359 | function checkboxToggleElement(elem, id) { | |
360 | if (elem.checked) { | |
361 | Effect.Appear(id, {duration : 0.5}); | |
362 | } else { | |
363 | Effect.Fade(id, {duration : 0.5}); | |
364 | } | |
365 | } | |
366 | ||
367 | function dropboxSelect(e, v) { | |
368 | for (i = 0; i < e.length; i++) { | |
369 | if (e[i].value == v) { | |
370 | e.selectedIndex = i; | |
371 | break; | |
372 | } | |
373 | } | |
374 | } | |
375 | ||
376 | function getURLParam(param){ | |
377 | return String(window.location.href).parseQuery()[param]; | |
378 | } | |
379 | ||
380 | function leading_zero(p) { | |
381 | var s = String(p); | |
382 | if (s.length == 1) s = "0" + s; | |
383 | return s; | |
384 | } | |
385 | ||
386 | function make_timestamp() { | |
387 | var d = new Date(); | |
388 | ||
389 | return leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + | |
390 | ":" + leading_zero(d.getSeconds()); | |
391 | } | |
392 | ||
393 | ||
394 | function closeErrorBox() { | |
395 | ||
396 | if (Element.visible("errorBoxShadow")) { | |
397 | Element.hide("dialog_overlay"); | |
398 | Element.hide("errorBoxShadow"); | |
399 | } | |
400 | ||
401 | return false; | |
402 | } | |
403 | ||
404 | function closeInfoBox(cleanup) { | |
405 | try { | |
406 | dialog = dijit.byId("infoBox"); | |
407 | ||
408 | if (dialog) dialog.hide(); | |
409 | ||
410 | } catch (e) { | |
411 | //exception_error("closeInfoBox", e); | |
412 | } | |
413 | return false; | |
414 | } | |
415 | ||
416 | ||
417 | function displayDlg(id, param, callback) { | |
418 | ||
419 | notify_progress("Loading, please wait...", true); | |
420 | ||
421 | var query = "?op=dlg&id=" + | |
422 | param_escape(id) + "¶m=" + param_escape(param); | |
423 | ||
424 | new Ajax.Request("backend.php", { | |
425 | parameters: query, | |
426 | onComplete: function (transport) { | |
427 | infobox_callback2(transport); | |
428 | if (callback) callback(transport); | |
429 | } }); | |
430 | ||
431 | return false; | |
432 | } | |
433 | ||
434 | function infobox_callback2(transport) { | |
435 | try { | |
436 | var dialog = false; | |
437 | ||
438 | if (dijit.byId("infoBox")) { | |
439 | dialog = dijit.byId("infoBox"); | |
440 | } | |
441 | ||
442 | //console.log("infobox_callback2"); | |
443 | notify(''); | |
444 | ||
445 | var content; | |
446 | var dtitle = "Dialog"; | |
447 | ||
448 | var dlg = transport.responseXML.getElementsByTagName("dlg")[0]; | |
449 | ||
450 | var title = transport.responseXML.getElementsByTagName("title")[0]; | |
451 | if (title) | |
452 | title = title.firstChild.nodeValue; | |
453 | ||
454 | var content = transport.responseXML.getElementsByTagName("content")[0]; | |
455 | ||
456 | content = content.firstChild.nodeValue; | |
457 | ||
458 | if (!dialog) { | |
459 | dialog = new dijit.Dialog({ | |
460 | title: title, | |
461 | id: 'infoBox', | |
462 | style: "width: 600px", | |
463 | onCancel: function() { | |
464 | return true; | |
465 | }, | |
466 | onExecute: function() { | |
467 | return true; | |
468 | }, | |
469 | onClose: function() { | |
470 | return true; | |
471 | }, | |
472 | content: content}); | |
473 | } else { | |
474 | dialog.attr('title', title); | |
475 | dialog.attr('content', content); | |
476 | } | |
477 | ||
478 | dialog.show(); | |
479 | ||
480 | notify(""); | |
481 | } catch (e) { | |
482 | exception_error("infobox_callback2", e); | |
483 | } | |
484 | } | |
485 | ||
486 | function filterCR(e, f) | |
487 | { | |
488 | var key; | |
489 | ||
490 | if(window.event) | |
491 | key = window.event.keyCode; //IE | |
492 | else | |
493 | key = e.which; //firefox | |
494 | ||
495 | if (key == 13) { | |
496 | if (typeof f != 'undefined') { | |
497 | f(); | |
498 | return false; | |
499 | } else { | |
500 | return false; | |
501 | } | |
502 | } else { | |
503 | return true; | |
504 | } | |
505 | } | |
506 | ||
507 | function getInitParam(key) { | |
508 | return init_params[key]; | |
509 | } | |
510 | ||
511 | function setInitParam(key, value) { | |
512 | init_params[key] = value; | |
513 | } | |
514 | ||
515 | function fatalError(code, msg, ext_info) { | |
516 | try { | |
517 | ||
518 | if (code == 6) { | |
519 | window.location.href = "tt-rss.php"; | |
520 | } else if (code == 5) { | |
521 | window.location.href = "db-updater.php"; | |
522 | } else { | |
523 | ||
524 | if (msg == "") msg = "Unknown error"; | |
525 | ||
526 | if (ext_info) { | |
527 | if (ext_info.responseText) { | |
528 | ext_info = ext_info.responseText; | |
529 | } | |
530 | } | |
531 | ||
532 | if (ERRORS && ERRORS[code] && !msg) { | |
533 | msg = ERRORS[code]; | |
534 | } | |
535 | ||
536 | var content = "<div><b>Error code:</b> " + code + "</div>" + | |
537 | "<p>" + msg + "</p>"; | |
538 | ||
539 | if (ext_info) { | |
540 | content = content + "<div><b>Additional information:</b></div>" + | |
541 | "<textarea style='width: 100%' readonly=\"1\">" + | |
542 | ext_info + "</textarea>"; | |
543 | } | |
544 | ||
545 | var dialog = new dijit.Dialog({ | |
546 | title: "Fatal error", | |
547 | style: "width: 600px", | |
548 | content: content}); | |
549 | ||
550 | dialog.show(); | |
551 | ||
552 | } | |
553 | ||
554 | return false; | |
555 | ||
556 | } catch (e) { | |
557 | exception_error("fatalError", e); | |
558 | } | |
559 | } | |
560 | ||
561 | function filterDlgCheckType(sender) { | |
562 | ||
563 | try { | |
564 | ||
565 | var ftype = sender.value; | |
566 | ||
567 | // if selected filter type is 5 (Date) enable the modifier dropbox | |
568 | if (ftype == 5) { | |
569 | Element.show("filterDlg_dateModBox"); | |
570 | Element.show("filterDlg_dateChkBox"); | |
571 | } else { | |
572 | Element.hide("filterDlg_dateModBox"); | |
573 | Element.hide("filterDlg_dateChkBox"); | |
574 | ||
575 | } | |
576 | ||
577 | } catch (e) { | |
578 | exception_error("filterDlgCheckType", e); | |
579 | } | |
580 | ||
581 | } | |
582 | ||
583 | function filterDlgCheckAction(sender) { | |
584 | ||
585 | try { | |
586 | ||
587 | var action = sender.value; | |
588 | ||
589 | var action_param = $("filterDlg_paramBox"); | |
590 | ||
591 | if (!action_param) { | |
592 | console.log("filterDlgCheckAction: can't find action param box!"); | |
593 | return; | |
594 | } | |
595 | ||
596 | // if selected action supports parameters, enable params field | |
597 | if (action == 4 || action == 6 || action == 7) { | |
598 | new Effect.Appear(action_param, {duration : 0.5}); | |
599 | if (action != 7) { | |
600 | Element.show(dijit.byId("filterDlg_actionParam").domNode); | |
601 | Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); | |
602 | } else { | |
603 | Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); | |
604 | Element.hide(dijit.byId("filterDlg_actionParam").domNode); | |
605 | } | |
606 | } else { | |
607 | Element.hide(action_param); | |
608 | } | |
609 | ||
610 | } catch (e) { | |
611 | exception_error("filterDlgCheckAction", e); | |
612 | } | |
613 | ||
614 | } | |
615 | ||
616 | function filterDlgCheckDate() { | |
617 | try { | |
618 | var dialog = dijit.byId("filterEditDlg"); | |
619 | ||
620 | var reg_exp = dialog.attr('value').reg_exp; | |
621 | ||
622 | var query = "?op=rpc&subop=checkDate&date=" + reg_exp; | |
623 | ||
624 | new Ajax.Request("backend.php", { | |
625 | parameters: query, | |
626 | onComplete: function(transport) { | |
627 | ||
628 | var reply = JSON.parse(transport.responseText); | |
629 | ||
630 | if (reply['result'] == true) { | |
631 | alert(__("Date syntax appears to be correct:") + " " + reply['date']); | |
632 | return; | |
633 | } else { | |
634 | alert(__("Date syntax is incorrect.")); | |
635 | } | |
636 | ||
637 | } }); | |
638 | ||
639 | ||
640 | } catch (e) { | |
641 | exception_error("filterDlgCheckDate", e); | |
642 | } | |
643 | } | |
644 | ||
645 | function explainError(code) { | |
646 | return displayDlg("explainError", code); | |
647 | } | |
648 | ||
649 | function displayHelpInfobox(topic_id) { | |
650 | ||
651 | var url = "backend.php?op=help&tid=" + param_escape(topic_id); | |
652 | ||
653 | var w = window.open(url, "ttrss_help", | |
654 | "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0"); | |
655 | ||
656 | } | |
657 | ||
658 | function loading_set_progress(p) { | |
659 | try { | |
660 | loading_progress += p; | |
661 | ||
662 | if (dijit.byId("loading_bar")) | |
663 | dijit.byId("loading_bar").update({progress: loading_progress}); | |
664 | ||
665 | if (loading_progress >= 90) | |
666 | remove_splash(); | |
667 | ||
668 | } catch (e) { | |
669 | exception_error("loading_set_progress", e); | |
670 | } | |
671 | } | |
672 | ||
673 | function remove_splash() { | |
674 | ||
675 | if (Element.visible("overlay")) { | |
676 | console.log("about to remove splash, OMG!"); | |
677 | Element.hide("overlay"); | |
678 | console.log("removed splash!"); | |
679 | } | |
680 | } | |
681 | ||
682 | function transport_error_check(transport) { | |
683 | try { | |
684 | if (transport.responseXML) { | |
685 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
686 | ||
687 | if (error) { | |
688 | var code = error.getAttribute("error-code"); | |
689 | var msg = error.getAttribute("error-msg"); | |
690 | if (code != 0) { | |
691 | fatalError(code, msg); | |
692 | return false; | |
693 | } | |
694 | } | |
695 | } | |
696 | } catch (e) { | |
697 | exception_error("check_for_error_xml", e); | |
698 | } | |
699 | return true; | |
700 | } | |
701 | ||
702 | function strip_tags(s) { | |
703 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
704 | } | |
705 | ||
706 | function truncate_string(s, length) { | |
707 | if (!length) length = 30; | |
708 | var tmp = s.substring(0, length); | |
709 | if (s.length > length) tmp += "…"; | |
710 | return tmp; | |
711 | } | |
712 | ||
713 | function hotkey_prefix_timeout() { | |
714 | try { | |
715 | ||
716 | var date = new Date(); | |
717 | var ts = Math.round(date.getTime() / 1000); | |
718 | ||
719 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
720 | console.log("hotkey_prefix seems to be stuck, aborting"); | |
721 | hotkey_prefix_pressed = false; | |
722 | hotkey_prefix = false; | |
723 | Element.hide('cmdline'); | |
724 | } | |
725 | ||
726 | setTimeout("hotkey_prefix_timeout()", 1000); | |
727 | ||
728 | } catch (e) { | |
729 | exception_error("hotkey_prefix_timeout", e); | |
730 | } | |
731 | } | |
732 | ||
733 | function hideAuxDlg() { | |
734 | try { | |
735 | Element.hide('auxDlg'); | |
736 | } catch (e) { | |
737 | exception_error("hideAuxDlg", e); | |
738 | } | |
739 | } | |
740 | ||
741 | ||
742 | function uploadIconHandler(rc) { | |
743 | try { | |
744 | switch (rc) { | |
745 | case 0: | |
746 | notify_info("Upload complete."); | |
747 | if (inPreferences()) { | |
748 | updateFeedList(); | |
749 | } else { | |
750 | setTimeout('updateFeedList(false, false)', 50); | |
751 | } | |
752 | break; | |
753 | case 1: | |
754 | notify_error("Upload failed: icon is too big."); | |
755 | break; | |
756 | case 2: | |
757 | notify_error("Upload failed."); | |
758 | break; | |
759 | } | |
760 | ||
761 | } catch (e) { | |
762 | exception_error("uploadIconHandler", e); | |
763 | } | |
764 | } | |
765 | ||
766 | function removeFeedIcon(id) { | |
767 | ||
768 | try { | |
769 | ||
770 | if (confirm(__("Remove stored feed icon?"))) { | |
771 | var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id); | |
772 | ||
773 | console.log(query); | |
774 | ||
775 | notify_progress("Removing feed icon...", true); | |
776 | ||
777 | new Ajax.Request("backend.php", { | |
778 | parameters: query, | |
779 | onComplete: function(transport) { | |
780 | notify_info("Feed icon removed."); | |
781 | if (inPreferences()) { | |
782 | updateFeedList(); | |
783 | } else { | |
784 | setTimeout('updateFeedList(false, false)', 50); | |
785 | } | |
786 | } }); | |
787 | } | |
788 | ||
789 | return false; | |
790 | } catch (e) { | |
791 | exception_error("uploadFeedIcon", e); | |
792 | } | |
793 | } | |
794 | ||
795 | function uploadFeedIcon() { | |
796 | ||
797 | try { | |
798 | ||
799 | var file = $("icon_file"); | |
800 | ||
801 | if (file.value.length == 0) { | |
802 | alert(__("Please select an image file to upload.")); | |
803 | } else { | |
804 | if (confirm(__("Upload new icon for this feed?"))) { | |
805 | notify_progress("Uploading, please wait...", true); | |
806 | return true; | |
807 | } | |
808 | } | |
809 | ||
810 | return false; | |
811 | ||
812 | } catch (e) { | |
813 | exception_error("uploadFeedIcon", e); | |
814 | } | |
815 | } | |
816 | ||
817 | function addLabel(select, callback) { | |
818 | ||
819 | try { | |
820 | ||
821 | var caption = prompt(__("Please enter label caption:"), ""); | |
822 | ||
823 | if (caption != undefined) { | |
824 | ||
825 | if (caption == "") { | |
826 | alert(__("Can't create label: missing caption.")); | |
827 | return false; | |
828 | } | |
829 | ||
830 | var query = "?op=pref-labels&subop=add&caption=" + | |
831 | param_escape(caption); | |
832 | ||
833 | if (select) | |
834 | query += "&output=select"; | |
835 | ||
836 | notify_progress("Loading, please wait...", true); | |
837 | ||
838 | if (inPreferences() && !select) active_tab = "labelConfig"; | |
839 | ||
840 | new Ajax.Request("backend.php", { | |
841 | parameters: query, | |
842 | onComplete: function(transport) { | |
843 | if (callback) { | |
844 | callback(transport); | |
845 | } else if (inPreferences()) { | |
846 | updateLabelList(); | |
847 | } else { | |
848 | updateFeedList(); | |
849 | } | |
850 | } }); | |
851 | ||
852 | } | |
853 | ||
854 | } catch (e) { | |
855 | exception_error("addLabel", e); | |
856 | } | |
857 | } | |
858 | ||
859 | function quickAddFeed() { | |
860 | try { | |
861 | var query = "backend.php?op=dlg&id=quickAddFeed"; | |
862 | ||
863 | if (dijit.byId("feedAddDlg")) | |
864 | dijit.byId("feedAddDlg").destroyRecursive(); | |
865 | ||
866 | var dialog = new dijit.Dialog({ | |
867 | id: "feedAddDlg", | |
868 | title: __("Subscribe to Feed"), | |
869 | style: "width: 600px", | |
870 | execute: function() { | |
871 | if (this.validate()) { | |
872 | console.log(dojo.objectToQuery(this.attr('value'))); | |
873 | ||
874 | var feed_url = this.attr('value').feed; | |
875 | ||
876 | notify_progress(__("Subscribing to feed..."), true); | |
877 | ||
878 | new Ajax.Request("backend.php", { | |
879 | parameters: dojo.objectToQuery(this.attr('value')), | |
880 | onComplete: function(transport) { | |
881 | try { | |
882 | ||
883 | var reply = JSON.parse(transport.responseText); | |
884 | ||
885 | var rc = parseInt(reply['result']); | |
886 | ||
887 | notify(''); | |
888 | ||
889 | console.log("GOT RC: " + rc); | |
890 | ||
891 | switch (rc) { | |
892 | case 1: | |
893 | dialog.hide(); | |
894 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
895 | ||
896 | updateFeedList(); | |
897 | break; | |
898 | case 2: | |
899 | alert(__("Specified URL seems to be invalid.")); | |
900 | break; | |
901 | case 3: | |
902 | alert(__("Specified URL doesn't seem to contain any feeds.")); | |
903 | break; | |
904 | case 4: | |
905 | notify_progress("Searching for feed urls...", true); | |
906 | ||
907 | new Ajax.Request("backend.php", { | |
908 | parameters: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url), | |
909 | onComplete: function(transport, dialog, feed_url) { | |
910 | ||
911 | notify(''); | |
912 | ||
913 | var reply = JSON.parse(transport.responseText); | |
914 | ||
915 | var feeds = reply['urls']; | |
916 | ||
917 | console.log(transport.responseText); | |
918 | ||
919 | var select = dijit.byId("feedDlg_feedContainerSelect"); | |
920 | ||
921 | while (select.getOptions().length > 0) | |
922 | select.removeOption(0); | |
923 | ||
924 | var count = 0; | |
925 | for (var feedUrl in feeds) { | |
926 | select.addOption({value: feedUrl, label: feeds[feedUrl]}); | |
927 | count++; | |
928 | } | |
929 | ||
930 | // if (count > 5) count = 5; | |
931 | // select.size = count; | |
932 | ||
933 | Effect.Appear('feedDlg_feedsContainer', {duration : 0.5}); | |
934 | } | |
935 | }); | |
936 | break; | |
937 | case 5: | |
938 | alert(__("Couldn't download the specified URL.")); | |
939 | break; | |
940 | case 0: | |
941 | alert(__("You are already subscribed to this feed.")); | |
942 | break; | |
943 | } | |
944 | ||
945 | } catch (e) { | |
946 | exception_error("subscribeToFeed", e, transport); | |
947 | } | |
948 | ||
949 | } }); | |
950 | ||
951 | } | |
952 | }, | |
953 | href: query}); | |
954 | ||
955 | dialog.show(); | |
956 | } catch (e) { | |
957 | exception_error("quickAddFeed", e); | |
958 | } | |
959 | } | |
960 | ||
961 | function quickAddFilter() { | |
962 | try { | |
963 | var query = "backend.php?op=dlg&id=quickAddFilter"; | |
964 | ||
965 | if (dijit.byId("filterEditDlg")) | |
966 | dijit.byId("filterEditDlg").destroyRecursive(); | |
967 | ||
968 | dialog = new dijit.Dialog({ | |
969 | id: "filterEditDlg", | |
970 | title: __("Create Filter"), | |
971 | style: "width: 600px", | |
972 | test: function() { | |
973 | if (this.validate()) { | |
974 | ||
975 | if (dijit.byId("filterTestDlg")) | |
976 | dijit.byId("filterTestDlg").destroyRecursive(); | |
977 | ||
978 | tdialog = new dijit.Dialog({ | |
979 | id: "filterTestDlg", | |
980 | title: __("Filter Test Results"), | |
981 | style: "width: 600px", | |
982 | href: "backend.php?savemode=test&" + | |
983 | dojo.objectToQuery(dialog.attr('value')), | |
984 | }); | |
985 | ||
986 | tdialog.show(); | |
987 | ||
988 | } | |
989 | }, | |
990 | execute: function() { | |
991 | if (this.validate()) { | |
992 | ||
993 | var query = "?op=rpc&subop=verifyRegexp®_exp=" + | |
994 | param_escape(dialog.attr('value').reg_exp); | |
995 | ||
996 | notify_progress("Verifying regular expression..."); | |
997 | ||
998 | new Ajax.Request("backend.php", { | |
999 | parameters: query, | |
1000 | onComplete: function(transport) { | |
1001 | var reply = JSON.parse(transport.responseText); | |
1002 | ||
1003 | if (reply) { | |
1004 | notify(''); | |
1005 | ||
1006 | if (!reply['status']) { | |
1007 | alert("Match regular expression seems to be invalid."); | |
1008 | return; | |
1009 | } else { | |
1010 | notify_progress("Saving data...", true); | |
1011 | ||
1012 | console.log(dojo.objectToQuery(dialog.attr('value'))); | |
1013 | ||
1014 | new Ajax.Request("backend.php", { | |
1015 | parameters: dojo.objectToQuery(dialog.attr('value')), | |
1016 | onComplete: function(transport) { | |
1017 | dialog.hide(); | |
1018 | notify_info(transport.responseText); | |
1019 | if (inPreferences()) { | |
1020 | updateFilterList(); | |
1021 | } | |
1022 | }}) | |
1023 | } | |
1024 | } | |
1025 | }}); | |
1026 | } | |
1027 | }, | |
1028 | href: query}); | |
1029 | ||
1030 | dialog.show(); | |
1031 | } catch (e) { | |
1032 | exception_error("quickAddFilter", e); | |
1033 | } | |
1034 | } | |
1035 | ||
1036 | function resetPubSub(feed_id, title) { | |
1037 | ||
1038 | var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title); | |
1039 | ||
1040 | if (title == undefined || confirm(msg)) { | |
1041 | notify_progress("Loading, please wait..."); | |
1042 | ||
1043 | var query = "?op=pref-feeds&quiet=1&subop=resetPubSub&ids=" + feed_id; | |
1044 | ||
1045 | new Ajax.Request("backend.php", { | |
1046 | parameters: query, | |
1047 | onComplete: function(transport) { | |
1048 | dijit.byId("pubsubReset_Btn").attr('disabled', true); | |
1049 | notify_info("Subscription reset."); | |
1050 | } }); | |
1051 | } | |
1052 | ||
1053 | return false; | |
1054 | } | |
1055 | ||
1056 | ||
1057 | function unsubscribeFeed(feed_id, title) { | |
1058 | ||
1059 | var msg = __("Unsubscribe from %s?").replace("%s", title); | |
1060 | ||
1061 | if (title == undefined || confirm(msg)) { | |
1062 | notify_progress("Removing feed..."); | |
1063 | ||
1064 | var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; | |
1065 | ||
1066 | new Ajax.Request("backend.php", { | |
1067 | parameters: query, | |
1068 | onComplete: function(transport) { | |
1069 | ||
1070 | if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); | |
1071 | ||
1072 | if (inPreferences()) { | |
1073 | updateFeedList(); | |
1074 | } else { | |
1075 | if (feed_id == getActiveFeedId()) | |
1076 | setTimeout("viewfeed(-5)", 100); | |
1077 | } | |
1078 | ||
1079 | } }); | |
1080 | } | |
1081 | ||
1082 | return false; | |
1083 | } | |
1084 | ||
1085 | ||
1086 | function backend_sanity_check_callback(transport) { | |
1087 | ||
1088 | try { | |
1089 | ||
1090 | if (sanity_check_done) { | |
1091 | fatalError(11, "Sanity check request received twice. This can indicate "+ | |
1092 | "presence of Firebug or some other disrupting extension. "+ | |
1093 | "Please disable it and try again."); | |
1094 | return; | |
1095 | } | |
1096 | ||
1097 | var reply = JSON.parse(transport.responseText); | |
1098 | ||
1099 | if (!reply) { | |
1100 | fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); | |
1101 | return; | |
1102 | } | |
1103 | ||
1104 | var error_code = reply['error']['code']; | |
1105 | ||
1106 | if (error_code && error_code != 0) { | |
1107 | return fatalError(error_code, reply['error']['message']); | |
1108 | } | |
1109 | ||
1110 | console.log("sanity check ok"); | |
1111 | ||
1112 | var params = reply['init-params']; | |
1113 | ||
1114 | if (params) { | |
1115 | console.log('reading init-params...'); | |
1116 | ||
1117 | if (params) { | |
1118 | for (k in params) { | |
1119 | var v = params[k]; | |
1120 | console.log("IP: " + k + " => " + v); | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | init_params = params; | |
1125 | } | |
1126 | ||
1127 | sanity_check_done = true; | |
1128 | ||
1129 | init_second_stage(); | |
1130 | ||
1131 | } catch (e) { | |
1132 | exception_error("backend_sanity_check_callback", e, transport); | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | function has_local_storage() { | |
1137 | try { | |
1138 | return 'sessionStorage' in window && window['sessionStorage'] != null; | |
1139 | } catch (e) { | |
1140 | return false; | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | function catSelectOnChange(elem) { | |
1145 | try { | |
1146 | /* var value = elem[elem.selectedIndex].value; | |
1147 | var def = elem.getAttribute('default'); | |
1148 | ||
1149 | if (value == "ADD_CAT") { | |
1150 | ||
1151 | if (def) | |
1152 | dropboxSelect(elem, def); | |
1153 | else | |
1154 | elem.selectedIndex = 0; | |
1155 | ||
1156 | quickAddCat(elem); | |
1157 | } */ | |
1158 | ||
1159 | } catch (e) { | |
1160 | exception_error("catSelectOnChange", e); | |
1161 | } | |
1162 | } | |
1163 | ||
1164 | function quickAddCat(elem) { | |
1165 | try { | |
1166 | var cat = prompt(__("Please enter category title:")); | |
1167 | ||
1168 | if (cat) { | |
1169 | ||
1170 | var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat); | |
1171 | ||
1172 | notify_progress("Loading, please wait...", true); | |
1173 | ||
1174 | new Ajax.Request("backend.php", { | |
1175 | parameters: query, | |
1176 | onComplete: function (transport) { | |
1177 | var response = transport.responseXML; | |
1178 | var select = response.getElementsByTagName("select")[0]; | |
1179 | var options = select.getElementsByTagName("option"); | |
1180 | ||
1181 | dropbox_replace_options(elem, options); | |
1182 | ||
1183 | notify(''); | |
1184 | ||
1185 | } }); | |
1186 | ||
1187 | } | |
1188 | ||
1189 | } catch (e) { | |
1190 | exception_error("quickAddCat", e); | |
1191 | } | |
1192 | } | |
1193 | ||
1194 | function genUrlChangeKey(feed, is_cat) { | |
1195 | ||
1196 | try { | |
1197 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
1198 | ||
1199 | if (ok) { | |
1200 | ||
1201 | notify_progress("Trying to change address...", true); | |
1202 | ||
1203 | var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + | |
1204 | "&is_cat=" + param_escape(is_cat); | |
1205 | ||
1206 | new Ajax.Request("backend.php", { | |
1207 | parameters: query, | |
1208 | onComplete: function(transport) { | |
1209 | var reply = JSON.parse(transport.responseText); | |
1210 | var new_link = reply.link; | |
1211 | ||
1212 | var e = $('gen_feed_url'); | |
1213 | ||
1214 | if (new_link) { | |
1215 | ||
1216 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
1217 | "&key=" + new_link); | |
1218 | ||
1219 | e.href = e.href.replace(/\&key=.*$/, | |
1220 | "&key=" + new_link); | |
1221 | ||
1222 | new Effect.Highlight(e); | |
1223 | ||
1224 | notify(''); | |
1225 | ||
1226 | } else { | |
1227 | notify_error("Could not change feed URL."); | |
1228 | } | |
1229 | } }); | |
1230 | } | |
1231 | } catch (e) { | |
1232 | exception_error("genUrlChangeKey", e); | |
1233 | } | |
1234 | return false; | |
1235 | } | |
1236 | ||
1237 | function labelSelectOnChange(elem) { | |
1238 | try { | |
1239 | /* var value = elem[elem.selectedIndex].value; | |
1240 | var def = elem.getAttribute('default'); | |
1241 | ||
1242 | if (value == "ADD_LABEL") { | |
1243 | ||
1244 | if (def) | |
1245 | dropboxSelect(elem, def); | |
1246 | else | |
1247 | elem.selectedIndex = 0; | |
1248 | ||
1249 | addLabel(elem, function(transport) { | |
1250 | ||
1251 | try { | |
1252 | ||
1253 | var response = transport.responseXML; | |
1254 | var select = response.getElementsByTagName("select")[0]; | |
1255 | var options = select.getElementsByTagName("option"); | |
1256 | ||
1257 | dropbox_replace_options(elem, options); | |
1258 | ||
1259 | notify(''); | |
1260 | } catch (e) { | |
1261 | exception_error("addLabel", e); | |
1262 | } | |
1263 | }); | |
1264 | } */ | |
1265 | ||
1266 | } catch (e) { | |
1267 | exception_error("labelSelectOnChange", e); | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | function dropbox_replace_options(elem, options) { | |
1272 | ||
1273 | try { | |
1274 | while (elem.hasChildNodes()) | |
1275 | elem.removeChild(elem.firstChild); | |
1276 | ||
1277 | var sel_idx = -1; | |
1278 | ||
1279 | for (var i = 0; i < options.length; i++) { | |
1280 | var text = options[i].firstChild.nodeValue; | |
1281 | var value = options[i].getAttribute("value"); | |
1282 | ||
1283 | if (value == undefined) value = text; | |
1284 | ||
1285 | var issel = options[i].getAttribute("selected") == "1"; | |
1286 | ||
1287 | var option = new Option(text, value, issel); | |
1288 | ||
1289 | if (options[i].getAttribute("disabled")) | |
1290 | option.setAttribute("disabled", true); | |
1291 | ||
1292 | elem.insert(option); | |
1293 | ||
1294 | if (issel) sel_idx = i; | |
1295 | } | |
1296 | ||
1297 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) | |
1298 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1299 | ||
1300 | } catch (e) { | |
1301 | exception_error("dropbox_replace_options", e); | |
1302 | } | |
1303 | } | |
1304 | ||
1305 | // mode = all, none, invert | |
1306 | function selectTableRows(id, mode) { | |
1307 | try { | |
1308 | var rows = $(id).rows; | |
1309 | ||
1310 | for (var i = 0; i < rows.length; i++) { | |
1311 | var row = rows[i]; | |
1312 | var cb = false; | |
1313 | ||
1314 | if (row.id && row.className) { | |
1315 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1316 | var inputs = rows[i].getElementsByTagName("input"); | |
1317 | ||
1318 | for (var j = 0; j < inputs.length; j++) { | |
1319 | var input = inputs[j]; | |
1320 | ||
1321 | if (input.getAttribute("type") == "checkbox" && | |
1322 | input.id.match(bare_id)) { | |
1323 | ||
1324 | cb = input; | |
1325 | break; | |
1326 | } | |
1327 | } | |
1328 | ||
1329 | if (cb) { | |
1330 | var issel = row.hasClassName("Selected"); | |
1331 | ||
1332 | if (mode == "all" && !issel) { | |
1333 | row.addClassName("Selected"); | |
1334 | cb.checked = true; | |
1335 | } else if (mode == "none" && issel) { | |
1336 | row.removeClassName("Selected"); | |
1337 | cb.checked = false; | |
1338 | } else if (mode == "invert") { | |
1339 | ||
1340 | if (issel) { | |
1341 | row.removeClassName("Selected"); | |
1342 | cb.checked = false; | |
1343 | } else { | |
1344 | row.addClassName("Selected"); | |
1345 | cb.checked = true; | |
1346 | } | |
1347 | } | |
1348 | } | |
1349 | } | |
1350 | } | |
1351 | ||
1352 | } catch (e) { | |
1353 | exception_error("selectTableRows", e); | |
1354 | ||
1355 | } | |
1356 | } | |
1357 | ||
1358 | function getSelectedTableRowIds(id) { | |
1359 | var rows = []; | |
1360 | ||
1361 | try { | |
1362 | var elem_rows = $(id).rows; | |
1363 | ||
1364 | for (i = 0; i < elem_rows.length; i++) { | |
1365 | if (elem_rows[i].hasClassName("Selected")) { | |
1366 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); | |
1367 | rows.push(bare_id); | |
1368 | } | |
1369 | } | |
1370 | ||
1371 | } catch (e) { | |
1372 | exception_error("getSelectedTableRowIds", e); | |
1373 | } | |
1374 | ||
1375 | return rows; | |
1376 | } | |
1377 | ||
1378 | function editFeed(feed, event) { | |
1379 | try { | |
1380 | if (feed <= 0) | |
1381 | return alert(__("You can't edit this kind of feed.")); | |
1382 | ||
1383 | var query = "backend.php?op=pref-feeds&subop=editfeed&id=" + | |
1384 | param_escape(feed); | |
1385 | ||
1386 | console.log(query); | |
1387 | ||
1388 | if (dijit.byId("feedEditDlg")) | |
1389 | dijit.byId("feedEditDlg").destroyRecursive(); | |
1390 | ||
1391 | dialog = new dijit.Dialog({ | |
1392 | id: "feedEditDlg", | |
1393 | title: __("Edit Feed"), | |
1394 | style: "width: 600px", | |
1395 | execute: function() { | |
1396 | if (this.validate()) { | |
1397 | // console.log(dojo.objectToQuery(this.attr('value'))); | |
1398 | ||
1399 | notify_progress("Saving data...", true); | |
1400 | ||
1401 | new Ajax.Request("backend.php", { | |
1402 | parameters: dojo.objectToQuery(dialog.attr('value')), | |
1403 | onComplete: function(transport) { | |
1404 | dialog.hide(); | |
1405 | notify(''); | |
1406 | updateFeedList(); | |
1407 | }}) | |
1408 | } | |
1409 | }, | |
1410 | href: query}); | |
1411 | ||
1412 | dialog.show(); | |
1413 | ||
1414 | } catch (e) { | |
1415 | exception_error("editFeed", e); | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | function feedBrowser() { | |
1420 | try { | |
1421 | var query = "backend.php?op=dlg&id=feedBrowser"; | |
1422 | ||
1423 | if (dijit.byId("feedAddDlg")) | |
1424 | dijit.byId("feedAddDlg").hide(); | |
1425 | ||
1426 | if (dijit.byId("feedBrowserDlg")) | |
1427 | dijit.byId("feedBrowserDlg").destroyRecursive(); | |
1428 | ||
1429 | var dialog = new dijit.Dialog({ | |
1430 | id: "feedBrowserDlg", | |
1431 | title: __("More Feeds"), | |
1432 | style: "width: 600px", | |
1433 | getSelectedFeedIds: function() { | |
1434 | var list = $$("#browseFeedList li[id*=FBROW]"); | |
1435 | var selected = new Array(); | |
1436 | ||
1437 | list.each(function(child) { | |
1438 | var id = child.id.replace("FBROW-", ""); | |
1439 | ||
1440 | if (child.hasClassName('Selected')) { | |
1441 | selected.push(id); | |
1442 | } | |
1443 | }); | |
1444 | ||
1445 | return selected; | |
1446 | }, | |
1447 | getSelectedFeeds: function() { | |
1448 | var list = $$("#browseFeedList li.Selected"); | |
1449 | var selected = new Array(); | |
1450 | ||
1451 | list.each(function(child) { | |
1452 | var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; | |
1453 | var url = child.getElementsBySelector("a.fb_feedUrl")[0].href; | |
1454 | ||
1455 | selected.push([title,url]); | |
1456 | ||
1457 | }); | |
1458 | ||
1459 | return selected; | |
1460 | }, | |
1461 | ||
1462 | subscribe: function() { | |
1463 | var mode = this.attr('value').mode; | |
1464 | var selected = []; | |
1465 | ||
1466 | if (mode == "1") | |
1467 | selected = this.getSelectedFeeds(); | |
1468 | else | |
1469 | selected = this.getSelectedFeedIds(); | |
1470 | ||
1471 | if (selected.length > 0) { | |
1472 | dijit.byId("feedBrowserDlg").hide(); | |
1473 | ||
1474 | notify_progress("Loading, please wait...", true); | |
1475 | ||
1476 | // we use dojo.toJson instead of JSON.stringify because | |
1477 | // it somehow escapes everything TWICE, at least in Chrome 9 | |
1478 | ||
1479 | var query = "?op=rpc&subop=massSubscribe&payload="+ | |
1480 | param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode); | |
1481 | ||
1482 | console.log(query); | |
1483 | ||
1484 | new Ajax.Request("backend.php", { | |
1485 | parameters: query, | |
1486 | onComplete: function(transport) { | |
1487 | notify(''); | |
1488 | updateFeedList(); | |
1489 | } }); | |
1490 | ||
1491 | } else { | |
1492 | alert(__("No feeds are selected.")); | |
1493 | } | |
1494 | ||
1495 | }, | |
1496 | update: function() { | |
1497 | var query = dojo.objectToQuery(dialog.attr('value')); | |
1498 | ||
1499 | Element.show('feed_browser_spinner'); | |
1500 | ||
1501 | new Ajax.Request("backend.php", { | |
1502 | parameters: query, | |
1503 | onComplete: function(transport) { | |
1504 | notify(''); | |
1505 | ||
1506 | Element.hide('feed_browser_spinner'); | |
1507 | ||
1508 | var c = $("browseFeedList"); | |
1509 | ||
1510 | var reply = JSON.parse(transport.responseText); | |
1511 | ||
1512 | var r = reply['content']; | |
1513 | var mode = reply['mode']; | |
1514 | ||
1515 | if (c && r) { | |
1516 | c.innerHTML = r; | |
1517 | } | |
1518 | ||
1519 | dojo.parser.parse("browseFeedList"); | |
1520 | ||
1521 | if (mode == 2) { | |
1522 | Element.show(dijit.byId('feed_archive_remove').domNode); | |
1523 | } else { | |
1524 | Element.hide(dijit.byId('feed_archive_remove').domNode); | |
1525 | } | |
1526 | ||
1527 | } }); | |
1528 | }, | |
1529 | removeFromArchive: function() { | |
1530 | var selected = this.getSelectedFeeds(); | |
1531 | ||
1532 | if (selected.length > 0) { | |
1533 | ||
1534 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); | |
1535 | ||
1536 | if (confirm(pr)) { | |
1537 | Element.show('feed_browser_spinner'); | |
1538 | ||
1539 | var query = "?op=rpc&subop=remarchived&ids=" + | |
1540 | param_escape(selected.toString());; | |
1541 | ||
1542 | new Ajax.Request("backend.php", { | |
1543 | parameters: query, | |
1544 | onComplete: function(transport) { | |
1545 | dialog.update(); | |
1546 | } }); | |
1547 | } | |
1548 | } | |
1549 | }, | |
1550 | execute: function() { | |
1551 | if (this.validate()) { | |
1552 | this.subscribe(); | |
1553 | } | |
1554 | }, | |
1555 | href: query}); | |
1556 | ||
1557 | dialog.show(); | |
1558 | ||
1559 | } catch (e) { | |
1560 | exception_error("editFeed", e); | |
1561 | } | |
1562 | } | |
1563 | ||
1564 | function showFeedsWithErrors() { | |
1565 | try { | |
1566 | var query = "backend.php?op=dlg&id=feedsWithErrors"; | |
1567 | ||
1568 | if (dijit.byId("errorFeedsDlg")) | |
1569 | dijit.byId("errorFeedsDlg").destroyRecursive(); | |
1570 | ||
1571 | dialog = new dijit.Dialog({ | |
1572 | id: "errorFeedsDlg", | |
1573 | title: __("Feeds with update errors"), | |
1574 | style: "width: 600px", | |
1575 | getSelectedFeeds: function() { | |
1576 | return getSelectedTableRowIds("prefErrorFeedList"); | |
1577 | }, | |
1578 | removeSelected: function() { | |
1579 | var sel_rows = this.getSelectedFeeds(); | |
1580 | ||
1581 | console.log(sel_rows); | |
1582 | ||
1583 | if (sel_rows.length > 0) { | |
1584 | var ok = confirm(__("Remove selected feeds?")); | |
1585 | ||
1586 | if (ok) { | |
1587 | notify_progress("Removing selected feeds...", true); | |
1588 | ||
1589 | var query = "?op=pref-feeds&subop=remove&ids="+ | |
1590 | param_escape(sel_rows.toString()); | |
1591 | ||
1592 | new Ajax.Request("backend.php", { | |
1593 | parameters: query, | |
1594 | onComplete: function(transport) { | |
1595 | notify(''); | |
1596 | dialog.hide(); | |
1597 | updateFeedList(); | |
1598 | } }); | |
1599 | } | |
1600 | ||
1601 | } else { | |
1602 | alert(__("No feeds are selected.")); | |
1603 | } | |
1604 | }, | |
1605 | execute: function() { | |
1606 | if (this.validate()) { | |
1607 | } | |
1608 | }, | |
1609 | href: query}); | |
1610 | ||
1611 | dialog.show(); | |
1612 | ||
1613 | } catch (e) { | |
1614 | exception_error("showFeedsWithErrors", e); | |
1615 | } | |
1616 | ||
1617 | } | |
1618 | ||
1619 |