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