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