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