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