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