]>
Commit | Line | Data |
---|---|---|
730dbf19 | 1 | var notify_silent = false; |
fcc36744 | 2 | var loading_progress = 0; |
4a3da1c8 | 3 | var sanity_check_done = false; |
8484ce22 | 4 | var init_params = {}; |
f822a8e5 | 5 | var _label_base_index = -1024; |
8484ce22 AD |
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 | ); | |
61992f57 | 24 | |
b07b61da AD |
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 | } | |
e331188f | 31 | }; |
b07b61da | 32 | |
84c7b824 AD |
33 | /* create console.log if it doesn't exist */ |
34 | ||
35 | if (!window.console) console = {}; | |
f3f67c1b AD |
36 | console.log = console.log || function(msg) { }; |
37 | console.warn = console.warn || function(msg) { }; | |
38 | console.error = console.error || function(msg) { }; | |
583c58b8 | 39 | |
273d1e29 | 40 | function exception_error(location, e, ext_info) { |
e8a429e3 | 41 | var msg = format_exception_error(location, e); |
e8a429e3 | 42 | |
84c7b824 | 43 | if (!ext_info) ext_info = false; |
91743a49 | 44 | |
273d1e29 | 45 | try { |
e8a429e3 | 46 | |
951906dc AD |
47 | if (ext_info) { |
48 | if (ext_info.responseText) { | |
49 | ext_info = ext_info.responseText; | |
e8a429e3 | 50 | } |
951906dc | 51 | } |
84c7b824 | 52 | |
951906dc AD |
53 | var content = "<div class=\"fatalError\">" + |
54 | "<pre>" + msg + "</pre>"; | |
84c7b824 | 55 | |
be2f5e1a AD |
56 | content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+ |
57 | "action=\"http://tt-rss.org/report.php\" method=\"POST\">"; | |
58 | ||
59 | content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>"; | |
60 | content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>"; | |
61 | ||
951906dc AD |
62 | if (ext_info) { |
63 | content += "<div><b>Additional information:</b></div>" + | |
be2f5e1a | 64 | "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>"; |
e8a429e3 AD |
65 | } |
66 | ||
951906dc | 67 | content += "<div><b>Stack trace:</b></div>" + |
be2f5e1a AD |
68 | "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>"; |
69 | ||
70 | content += "</form>"; | |
951906dc | 71 | |
6e4f4ce1 AD |
72 | content += "</div>"; |
73 | ||
ba083651 AD |
74 | content += "<div class='dlgButtons'>"; |
75 | ||
76 | content += "<button dojoType=\"dijit.form.Button\""+ | |
77 | "onclick=\"dijit.byId('exceptionDlg').report()\">" + | |
78 | __('Report to tt-rss.org') + "</button> "; | |
79 | content += "<button dojoType=\"dijit.form.Button\" "+ | |
be2f5e1a | 80 | "onclick=\"dijit.byId('exceptionDlg').hide()\">" + |
ba083651 AD |
81 | __('Close') + "</button>"; |
82 | content += "</div>"; | |
83 | ||
6d1aacbb AD |
84 | if (dijit.byId("exceptionDlg")) |
85 | dijit.byId("exceptionDlg").destroyRecursive(); | |
951906dc | 86 | |
6e4f4ce1 | 87 | var dialog = new dijit.Dialog({ |
ba083651 | 88 | id: "exceptionDlg", |
6e4f4ce1 AD |
89 | title: "Unhandled exception", |
90 | style: "width: 600px", | |
ba083651 AD |
91 | report: function() { |
92 | 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."))) { | |
93 | ||
be2f5e1a | 94 | document.forms['exceptionForm'].params.value = $H({ |
ba083651 AD |
95 | browserName: navigator.appName, |
96 | browserVersion: navigator.appVersion, | |
97 | browserPlatform: navigator.platform, | |
98 | browserCookies: navigator.cookieEnabled, | |
be2f5e1a | 99 | }).toQueryString(); |
ba083651 | 100 | |
be2f5e1a | 101 | document.forms['exceptionForm'].submit(); |
ba083651 AD |
102 | |
103 | } | |
104 | }, | |
6e4f4ce1 AD |
105 | content: content}); |
106 | ||
107 | dialog.show(); | |
951906dc | 108 | |
273d1e29 | 109 | } catch (e) { |
e8a429e3 | 110 | alert(msg); |
e8a429e3 | 111 | } |
273d1e29 | 112 | |
e8a429e3 AD |
113 | } |
114 | ||
115 | function format_exception_error(location, e) { | |
83f043bb AD |
116 | var msg; |
117 | ||
118 | if (e.fileName) { | |
119 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
be2f5e1a AD |
120 | |
121 | msg = "Exception: " + e.name + ", " + e.message + | |
83f043bb AD |
122 | "\nFunction: " + location + "()" + |
123 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
f74cfded AD |
124 | |
125 | } else if (e.description) { | |
126 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
83f043bb AD |
127 | } else { |
128 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
129 | } | |
130 | ||
84c7b824 | 131 | console.error("EXCEPTION: " + msg); |
ee1f45f4 | 132 | |
e8a429e3 | 133 | return msg; |
7719618b AD |
134 | } |
135 | ||
7726fa02 AD |
136 | function param_escape(arg) { |
137 | if (typeof encodeURIComponent != 'undefined') | |
be2f5e1a | 138 | return encodeURIComponent(arg); |
7726fa02 AD |
139 | else |
140 | return escape(arg); | |
141 | } | |
142 | ||
143 | function param_unescape(arg) { | |
144 | if (typeof decodeURIComponent != 'undefined') | |
be2f5e1a | 145 | return decodeURIComponent(arg); |
7726fa02 AD |
146 | else |
147 | return unescape(arg); | |
148 | } | |
149 | ||
ce3bf408 | 150 | var notify_hide_timerid = false; |
59a543f0 | 151 | |
ce3bf408 | 152 | function hide_notify() { |
acac8448 | 153 | var n = $("notify"); |
42c32916 | 154 | if (n) { |
d05514a4 | 155 | n.style.display = "none"; |
8dcfffd0 | 156 | } |
be2f5e1a | 157 | } |
c05608c2 | 158 | |
730dbf19 AD |
159 | function notify_silent_next() { |
160 | notify_silent = true; | |
161 | } | |
162 | ||
42c32916 | 163 | function notify_real(msg, no_hide, n_type) { |
7726fa02 | 164 | |
730dbf19 AD |
165 | if (notify_silent) { |
166 | notify_silent = false; | |
167 | return; | |
168 | } | |
169 | ||
acac8448 AD |
170 | var n = $("notify"); |
171 | var nb = $("notify_body"); | |
7726fa02 | 172 | |
c05608c2 | 173 | if (!n || !nb) return; |
f0601b87 | 174 | |
0655a1d5 AD |
175 | if (notify_hide_timerid) { |
176 | window.clearTimeout(notify_hide_timerid); | |
177 | } | |
178 | ||
8dcfffd0 | 179 | if (msg == "") { |
0655a1d5 AD |
180 | if (n.style.display == "block") { |
181 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
182 | } | |
183 | return; | |
7726fa02 | 184 | } else { |
0ceded7a | 185 | n.style.display = "block"; |
8dcfffd0 | 186 | } |
7726fa02 | 187 | |
42c32916 AD |
188 | /* types: |
189 | ||
190 | 1 - generic | |
191 | 2 - progress | |
192 | 3 - error | |
193 | 4 - info | |
194 | ||
195 | */ | |
196 | ||
f3977cf5 AD |
197 | if (typeof __ != 'undefined') { |
198 | msg = __(msg); | |
199 | } | |
200 | ||
42c32916 AD |
201 | if (n_type == 1) { |
202 | n.className = "notify"; | |
203 | } else if (n_type == 2) { | |
204 | n.className = "notifyProgress"; | |
a60446be | 205 | msg = "<img src='images/indicator_white.gif'> " + msg; |
42c32916 | 206 | } else if (n_type == 3) { |
f407c086 | 207 | n.className = "notifyError"; |
a60446be | 208 | msg = "<img src='images/sign_excl.svg'> " + msg; |
42c32916 AD |
209 | } else if (n_type == 4) { |
210 | n.className = "notifyInfo"; | |
a60446be | 211 | msg = "<img src='images/sign_info.svg'> " + msg; |
0530ddd8 AD |
212 | } |
213 | ||
106689b0 AD |
214 | // msg = "<img src='images/live_com_loading.gif'> " + msg; |
215 | ||
478d4067 AD |
216 | if (no_hide) { |
217 | msg += " (<a href='#' onclick=\"notify('')\">X</a>)"; | |
218 | } | |
219 | ||
220 | ||
0ceded7a AD |
221 | nb.innerHTML = msg; |
222 | ||
4d4200a8 | 223 | if (!no_hide) { |
292a8a12 | 224 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); |
4d4200a8 | 225 | } |
ce3bf408 AD |
226 | } |
227 | ||
42c32916 AD |
228 | function notify(msg, no_hide) { |
229 | notify_real(msg, no_hide, 1); | |
ce3bf408 AD |
230 | } |
231 | ||
42c32916 AD |
232 | function notify_progress(msg, no_hide) { |
233 | notify_real(msg, no_hide, 2); | |
234 | } | |
235 | ||
236 | function notify_error(msg, no_hide) { | |
237 | notify_real(msg, no_hide, 3); | |
238 | ||
239 | } | |
240 | ||
241 | function notify_info(msg, no_hide) { | |
242 | notify_real(msg, no_hide, 4); | |
7726fa02 AD |
243 | } |
244 | ||
76b4eae1 | 245 | function setCookie(name, value, lifetime, path, domain, secure) { |
be2f5e1a | 246 | |
76b4eae1 | 247 | var d = false; |
be2f5e1a | 248 | |
76b4eae1 AD |
249 | if (lifetime) { |
250 | d = new Date(); | |
be0801a1 | 251 | d.setTime(d.getTime() + (lifetime * 1000)); |
76b4eae1 | 252 | } |
cdbb6dc6 | 253 | |
84c7b824 | 254 | console.log("setCookie: " + name + " => " + value + ": " + d); |
be2f5e1a | 255 | |
76b4eae1 AD |
256 | int_setCookie(name, value, d, path, domain, secure); |
257 | ||
258 | } | |
259 | ||
260 | function int_setCookie(name, value, expires, path, domain, secure) { | |
ac43eba1 AD |
261 | document.cookie= name + "=" + escape(value) + |
262 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
263 | ((path) ? "; path=" + path : "") + | |
264 | ((domain) ? "; domain=" + domain : "") + | |
265 | ((secure) ? "; secure" : ""); | |
266 | } | |
267 | ||
76b4eae1 AD |
268 | function delCookie(name, path, domain) { |
269 | if (getCookie(name)) { | |
270 | document.cookie = name + "=" + | |
271 | ((path) ? ";path=" + path : "") + | |
272 | ((domain) ? ";domain=" + domain : "" ) + | |
273 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
274 | } | |
275 | } | |
be2f5e1a | 276 | |
76b4eae1 | 277 | |
ac43eba1 AD |
278 | function getCookie(name) { |
279 | ||
280 | var dc = document.cookie; | |
281 | var prefix = name + "="; | |
282 | var begin = dc.indexOf("; " + prefix); | |
283 | if (begin == -1) { | |
284 | begin = dc.indexOf(prefix); | |
285 | if (begin != 0) return null; | |
286 | } | |
287 | else { | |
288 | begin += 2; | |
289 | } | |
290 | var end = document.cookie.indexOf(";", begin); | |
291 | if (end == -1) { | |
292 | end = dc.length; | |
293 | } | |
294 | return unescape(dc.substring(begin + prefix.length, end)); | |
295 | } | |
296 | ||
e828e31e AD |
297 | function gotoPreferences() { |
298 | document.location.href = "prefs.php"; | |
299 | } | |
300 | ||
2d1282d4 AD |
301 | function gotoLogout() { |
302 | document.location.href = "backend.php?op=logout"; | |
303 | } | |
304 | ||
e828e31e | 305 | function gotoMain() { |
107d0cf3 | 306 | document.location.href = "index.php"; |
e828e31e AD |
307 | } |
308 | ||
b6644d29 AD |
309 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj |
310 | * * @author Sundar Dorai-Raj | |
311 | * * Email: sdoraira@vt.edu | |
312 | * * This program is free software; you can redistribute it and/or | |
be2f5e1a AD |
313 | * * modify it under the terms of the GNU General Public License |
314 | * * as published by the Free Software Foundation; either version 2 | |
315 | * * of the License, or (at your option) any later version, | |
316 | * * provided that any use properly credits the author. | |
b6644d29 AD |
317 | * * This program is distributed in the hope that it will be useful, |
318 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
319 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
320 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
321 | ||
322 | var numbers=".0123456789"; | |
323 | function isNumeric(x) { | |
324 | // is x a String or a character? | |
325 | if(x.length>1) { | |
326 | // remove negative sign | |
327 | x=Math.abs(x)+""; | |
e331188f | 328 | for(var j=0;j<x.length;j++) { |
b6644d29 AD |
329 | // call isNumeric recursively for each character |
330 | number=isNumeric(x.substring(j,j+1)); | |
331 | if(!number) return number; | |
332 | } | |
333 | return number; | |
334 | } | |
335 | else { | |
336 | // if x is number return true | |
337 | if(numbers.indexOf(x)>=0) return true; | |
338 | return false; | |
339 | } | |
340 | } | |
341 | ||
3745788e | 342 | |
386cbf27 | 343 | function toggleSelectRowById(sender, id) { |
acac8448 | 344 | var row = $(id); |
ca8e3d75 | 345 | return toggleSelectRow(sender, row); |
386cbf27 AD |
346 | } |
347 | ||
b92e6209 | 348 | function toggleSelectListRow(sender) { |
ca8e3d75 AD |
349 | var row = sender.parentNode; |
350 | return toggleSelectRow(sender, row); | |
b92e6209 AD |
351 | } |
352 | ||
a8328019 AD |
353 | /* this is for dijit Checkbox */ |
354 | function toggleSelectListRow2(sender) { | |
355 | var row = sender.domNode.parentNode; | |
356 | return toggleSelectRow(sender, row); | |
357 | } | |
358 | ||
a8328019 | 359 | /* this is for dijit Checkbox */ |
831408f0 | 360 | function toggleSelectRow2(sender, row, is_cdm) { |
a8328019 | 361 | |
831408f0 AD |
362 | if (!row) |
363 | if (!is_cdm) | |
364 | row = sender.domNode.parentNode.parentNode; | |
365 | else | |
366 | row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs | |
a8328019 AD |
367 | |
368 | if (sender.checked && !row.hasClassName('Selected')) | |
369 | row.addClassName('Selected'); | |
370 | else | |
371 | row.removeClassName('Selected'); | |
372 | } | |
373 | ||
374 | ||
524de8dc | 375 | function toggleSelectRow(sender, row) { |
1572afe5 | 376 | |
524de8dc | 377 | if (!row) row = sender.parentNode.parentNode; |
ca8e3d75 AD |
378 | |
379 | if (sender.checked && !row.hasClassName('Selected')) | |
380 | row.addClassName('Selected'); | |
381 | else | |
382 | row.removeClassName('Selected'); | |
1572afe5 AD |
383 | } |
384 | ||
b9073cd9 AD |
385 | function checkboxToggleElement(elem, id) { |
386 | if (elem.checked) { | |
6e4f4ce1 | 387 | Effect.Appear(id, {duration : 0.5}); |
b9073cd9 | 388 | } else { |
ecace165 | 389 | Effect.Fade(id, {duration : 0.5}); |
b9073cd9 AD |
390 | } |
391 | } | |
392 | ||
1b0809ae | 393 | function dropboxSelect(e, v) { |
e331188f | 394 | for (var i = 0; i < e.length; i++) { |
1b0809ae AD |
395 | if (e[i].value == v) { |
396 | e.selectedIndex = i; | |
397 | break; | |
398 | } | |
399 | } | |
400 | } | |
0ee1d1a0 | 401 | |
ec320224 AD |
402 | function getURLParam(param){ |
403 | return String(window.location.href).parseQuery()[param]; | |
be2f5e1a | 404 | } |
0ee1d1a0 | 405 | |
e8a429e3 | 406 | function closeInfoBox(cleanup) { |
588e4dc3 | 407 | try { |
439caa8b | 408 | dialog = dijit.byId("infoBox"); |
6e4f4ce1 | 409 | |
439caa8b | 410 | if (dialog) dialog.hide(); |
e8a429e3 | 411 | |
588e4dc3 | 412 | } catch (e) { |
951906dc | 413 | //exception_error("closeInfoBox", e); |
e8a429e3 | 414 | } |
90ac84df | 415 | return false; |
e5d758e3 AD |
416 | } |
417 | ||
418 | ||
542aebac | 419 | function displayDlg(id, param, callback) { |
7b5c6012 | 420 | |
951906dc | 421 | notify_progress("Loading, please wait...", true); |
2371c520 | 422 | |
3f363052 | 423 | var query = "?op=dlg&method=" + |
288487e4 AD |
424 | param_escape(id) + "¶m=" + param_escape(param); |
425 | ||
b4e75b2a AD |
426 | new Ajax.Request("backend.php", { |
427 | parameters: query, | |
288487e4 AD |
428 | onComplete: function (transport) { |
429 | infobox_callback2(transport); | |
542aebac | 430 | if (callback) callback(transport); |
288487e4 AD |
431 | } }); |
432 | ||
90ac84df | 433 | return false; |
7b5c6012 AD |
434 | } |
435 | ||
d395a942 AD |
436 | function infobox_callback2(transport) { |
437 | try { | |
439caa8b AD |
438 | var dialog = false; |
439 | ||
457d4849 | 440 | if (dijit.byId("infoBox")) { |
439caa8b | 441 | dialog = dijit.byId("infoBox"); |
457d4849 | 442 | } |
5ede560f | 443 | |
951906dc AD |
444 | //console.log("infobox_callback2"); |
445 | notify(''); | |
5ede560f | 446 | |
0a836593 AD |
447 | var title = transport.responseXML.getElementsByTagName("title")[0]; |
448 | if (title) | |
449 | title = title.firstChild.nodeValue; | |
de85cac2 | 450 | |
0a836593 | 451 | var content = transport.responseXML.getElementsByTagName("content")[0]; |
be2f5e1a | 452 | |
0a836593 | 453 | content = content.firstChild.nodeValue; |
05fcdf52 | 454 | |
439caa8b AD |
455 | if (!dialog) { |
456 | dialog = new dijit.Dialog({ | |
457 | title: title, | |
458 | id: 'infoBox', | |
459 | style: "width: 600px", | |
460 | onCancel: function() { | |
461 | return true; | |
462 | }, | |
463 | onExecute: function() { | |
464 | return true; | |
465 | }, | |
466 | onClose: function() { | |
467 | return true; | |
468 | }, | |
469 | content: content}); | |
470 | } else { | |
471 | dialog.attr('title', title); | |
472 | dialog.attr('content', content); | |
473 | } | |
6e4f4ce1 AD |
474 | |
475 | dialog.show(); | |
476 | ||
d395a942 AD |
477 | notify(""); |
478 | } catch (e) { | |
479 | exception_error("infobox_callback2", e); | |
442d77f1 AD |
480 | } |
481 | } | |
482 | ||
6e6504bc | 483 | function filterCR(e, f) |
86b682ce AD |
484 | { |
485 | var key; | |
486 | ||
487 | if(window.event) | |
488 | key = window.event.keyCode; //IE | |
489 | else | |
490 | key = e.which; //firefox | |
491 | ||
6e6504bc AD |
492 | if (key == 13) { |
493 | if (typeof f != 'undefined') { | |
494 | f(); | |
495 | return false; | |
496 | } else { | |
497 | return false; | |
498 | } | |
499 | } else { | |
500 | return true; | |
501 | } | |
86b682ce AD |
502 | } |
503 | ||
33d13e72 | 504 | function getInitParam(key) { |
40496720 | 505 | return init_params[key]; |
33d13e72 | 506 | } |
3ac2b520 | 507 | |
dbfc9522 | 508 | function setInitParam(key, value) { |
5158ced9 | 509 | init_params[key] = value; |
be0801a1 AD |
510 | } |
511 | ||
273d1e29 | 512 | function fatalError(code, msg, ext_info) { |
be2f5e1a | 513 | try { |
a7565293 | 514 | |
b4c27af7 | 515 | if (code == 6) { |
107d0cf3 | 516 | window.location.href = "index.php"; |
b4c27af7 | 517 | } else if (code == 5) { |
661135c7 | 518 | window.location.href = "db-updater.php"; |
b4c27af7 | 519 | } else { |
be2f5e1a | 520 | |
273d1e29 | 521 | if (msg == "") msg = "Unknown error"; |
42c32916 | 522 | |
68535211 AD |
523 | if (ext_info) { |
524 | if (ext_info.responseText) { | |
525 | ext_info = ext_info.responseText; | |
273d1e29 | 526 | } |
68535211 AD |
527 | } |
528 | ||
529 | if (ERRORS && ERRORS[code] && !msg) { | |
530 | msg = ERRORS[code]; | |
531 | } | |
be2f5e1a | 532 | |
68535211 AD |
533 | var content = "<div><b>Error code:</b> " + code + "</div>" + |
534 | "<p>" + msg + "</p>"; | |
535 | ||
536 | if (ext_info) { | |
537 | content = content + "<div><b>Additional information:</b></div>" + | |
be2f5e1a | 538 | "<textarea style='width: 100%' readonly=\"1\">" + |
68535211 | 539 | ext_info + "</textarea>"; |
273d1e29 | 540 | } |
68535211 AD |
541 | |
542 | var dialog = new dijit.Dialog({ | |
543 | title: "Fatal error", | |
544 | style: "width: 600px", | |
545 | content: content}); | |
546 | ||
547 | dialog.show(); | |
548 | ||
4724a093 | 549 | } |
a7565293 | 550 | |
68535211 AD |
551 | return false; |
552 | ||
a7565293 AD |
553 | } catch (e) { |
554 | exception_error("fatalError", e); | |
555 | } | |
556 | } | |
557 | ||
6aff7845 | 558 | /* function filterDlgCheckType(sender) { |
d0da85c2 AD |
559 | |
560 | try { | |
561 | ||
d90868d7 | 562 | var ftype = sender.value; |
d0da85c2 AD |
563 | |
564 | // if selected filter type is 5 (Date) enable the modifier dropbox | |
565 | if (ftype == 5) { | |
d90868d7 AD |
566 | Element.show("filterDlg_dateModBox"); |
567 | Element.show("filterDlg_dateChkBox"); | |
d0da85c2 | 568 | } else { |
d90868d7 AD |
569 | Element.hide("filterDlg_dateModBox"); |
570 | Element.hide("filterDlg_dateChkBox"); | |
d0da85c2 AD |
571 | |
572 | } | |
573 | ||
574 | } catch (e) { | |
575 | exception_error("filterDlgCheckType", e); | |
576 | } | |
577 | ||
6aff7845 | 578 | } */ |
d0da85c2 | 579 | |
350f0ad1 AD |
580 | function filterDlgCheckAction(sender) { |
581 | ||
582 | try { | |
583 | ||
d90868d7 | 584 | var action = sender.value; |
350f0ad1 | 585 | |
d90868d7 | 586 | var action_param = $("filterDlg_paramBox"); |
350f0ad1 AD |
587 | |
588 | if (!action_param) { | |
84c7b824 | 589 | console.log("filterDlgCheckAction: can't find action param box!"); |
350f0ad1 AD |
590 | return; |
591 | } | |
592 | ||
593 | // if selected action supports parameters, enable params field | |
ceb30ba4 | 594 | if (action == 4 || action == 6 || action == 7) { |
d90868d7 | 595 | new Effect.Appear(action_param, {duration : 0.5}); |
ceb30ba4 | 596 | if (action != 7) { |
d90868d7 AD |
597 | Element.show(dijit.byId("filterDlg_actionParam").domNode); |
598 | Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); | |
ceb30ba4 | 599 | } else { |
d90868d7 AD |
600 | Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); |
601 | Element.hide(dijit.byId("filterDlg_actionParam").domNode); | |
ceb30ba4 | 602 | } |
350f0ad1 | 603 | } else { |
143a4973 | 604 | Element.hide(action_param); |
350f0ad1 AD |
605 | } |
606 | ||
607 | } catch (e) { | |
438f2ce9 | 608 | exception_error("filterDlgCheckAction", e); |
350f0ad1 AD |
609 | } |
610 | ||
611 | } | |
ef16ae37 | 612 | |
d0da85c2 AD |
613 | function filterDlgCheckDate() { |
614 | try { | |
d90868d7 | 615 | var dialog = dijit.byId("filterEditDlg"); |
d0da85c2 | 616 | |
d90868d7 | 617 | var reg_exp = dialog.attr('value').reg_exp; |
d0da85c2 | 618 | |
f30ef1fa | 619 | var query = "?op=rpc&method=checkDate&date=" + reg_exp; |
d0da85c2 | 620 | |
b4e75b2a AD |
621 | new Ajax.Request("backend.php", { |
622 | parameters: query, | |
be2f5e1a | 623 | onComplete: function(transport) { |
d0da85c2 | 624 | |
da661d71 | 625 | var reply = JSON.parse(transport.responseText); |
d0da85c2 | 626 | |
da661d71 | 627 | if (reply['result'] == true) { |
aaba2225 | 628 | alert(__("Date syntax appears to be correct:") + " " + reply['date']); |
da661d71 AD |
629 | return; |
630 | } else { | |
631 | alert(__("Date syntax is incorrect.")); | |
632 | } | |
d0da85c2 AD |
633 | |
634 | } }); | |
635 | ||
636 | ||
637 | } catch (e) { | |
638 | exception_error("filterDlgCheckDate", e); | |
639 | } | |
640 | } | |
641 | ||
ef16ae37 AD |
642 | function explainError(code) { |
643 | return displayDlg("explainError", code); | |
644 | } | |
01a87dff | 645 | |
99509451 | 646 | function loading_set_progress(p) { |
730dbf19 | 647 | try { |
fcc36744 | 648 | loading_progress += p; |
fca95d5f | 649 | |
fcc36744 AD |
650 | if (dijit.byId("loading_bar")) |
651 | dijit.byId("loading_bar").update({progress: loading_progress}); | |
99509451 | 652 | |
fcc36744 AD |
653 | if (loading_progress >= 90) |
654 | remove_splash(); | |
730dbf19 AD |
655 | |
656 | } catch (e) { | |
657 | exception_error("loading_set_progress", e); | |
658 | } | |
659 | } | |
08827aaf AD |
660 | |
661 | function remove_splash() { | |
fcc36744 | 662 | |
08827aaf | 663 | if (Element.visible("overlay")) { |
84c7b824 | 664 | console.log("about to remove splash, OMG!"); |
08827aaf | 665 | Element.hide("overlay"); |
84c7b824 | 666 | console.log("removed splash!"); |
08827aaf AD |
667 | } |
668 | } | |
071ec48f | 669 | |
2184738a AD |
670 | function transport_error_check(transport) { |
671 | try { | |
672 | if (transport.responseXML) { | |
673 | var error = transport.responseXML.getElementsByTagName("error")[0]; | |
674 | ||
675 | if (error) { | |
676 | var code = error.getAttribute("error-code"); | |
677 | var msg = error.getAttribute("error-msg"); | |
678 | if (code != 0) { | |
679 | fatalError(code, msg); | |
680 | return false; | |
681 | } | |
682 | } | |
683 | } | |
684 | } catch (e) { | |
685 | exception_error("check_for_error_xml", e); | |
686 | } | |
687 | return true; | |
688 | } | |
2bab8824 | 689 | |
261b88b3 AD |
690 | function strip_tags(s) { |
691 | return s.replace(/<\/?[^>]+(>|$)/g, ""); | |
692 | } | |
693 | ||
694 | function truncate_string(s, length) { | |
695 | if (!length) length = 30; | |
696 | var tmp = s.substring(0, length); | |
697 | if (s.length > length) tmp += "…"; | |
698 | return tmp; | |
699 | } | |
ab553f9a | 700 | |
78935092 AD |
701 | function hotkey_prefix_timeout() { |
702 | try { | |
703 | ||
704 | var date = new Date(); | |
705 | var ts = Math.round(date.getTime() / 1000); | |
706 | ||
707 | if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { | |
84c7b824 | 708 | console.log("hotkey_prefix seems to be stuck, aborting"); |
78935092 AD |
709 | hotkey_prefix_pressed = false; |
710 | hotkey_prefix = false; | |
711 | Element.hide('cmdline'); | |
712 | } | |
713 | ||
714 | setTimeout("hotkey_prefix_timeout()", 1000); | |
715 | ||
716 | } catch (e) { | |
717 | exception_error("hotkey_prefix_timeout", e); | |
718 | } | |
719 | } | |
720 | ||
37e93d6c AD |
721 | function hideAuxDlg() { |
722 | try { | |
723 | Element.hide('auxDlg'); | |
724 | } catch (e) { | |
725 | exception_error("hideAuxDlg", e); | |
726 | } | |
727 | } | |
728 | ||
ef88b1cc | 729 | |
7abf159d | 730 | function uploadIconHandler(rc) { |
c3b7b797 | 731 | try { |
7abf159d AD |
732 | switch (rc) { |
733 | case 0: | |
734 | notify_info("Upload complete."); | |
735 | if (inPreferences()) { | |
736 | updateFeedList(); | |
737 | } else { | |
738 | setTimeout('updateFeedList(false, false)', 50); | |
739 | } | |
740 | break; | |
741 | case 1: | |
742 | notify_error("Upload failed: icon is too big."); | |
743 | break; | |
744 | case 2: | |
745 | notify_error("Upload failed."); | |
746 | break; | |
747 | } | |
748 | ||
749 | } catch (e) { | |
750 | exception_error("uploadIconHandler", e); | |
751 | } | |
752 | } | |
753 | ||
754 | function removeFeedIcon(id) { | |
755 | ||
756 | try { | |
757 | ||
758 | if (confirm(__("Remove stored feed icon?"))) { | |
f30ef1fa | 759 | var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id); |
c3b7b797 | 760 | |
84c7b824 | 761 | console.log(query); |
c3b7b797 | 762 | |
7abf159d | 763 | notify_progress("Removing feed icon...", true); |
c3b7b797 | 764 | |
7abf159d AD |
765 | new Ajax.Request("backend.php", { |
766 | parameters: query, | |
be2f5e1a | 767 | onComplete: function(transport) { |
7abf159d AD |
768 | notify_info("Feed icon removed."); |
769 | if (inPreferences()) { | |
770 | updateFeedList(); | |
771 | } else { | |
772 | setTimeout('updateFeedList(false, false)', 50); | |
773 | } | |
be2f5e1a | 774 | } }); |
7abf159d AD |
775 | } |
776 | ||
777 | return false; | |
c3b7b797 | 778 | } catch (e) { |
35b9844b | 779 | exception_error("removeFeedIcon", e); |
c3b7b797 AD |
780 | } |
781 | } | |
782 | ||
783 | function uploadFeedIcon() { | |
784 | ||
785 | try { | |
786 | ||
787 | var file = $("icon_file"); | |
788 | ||
789 | if (file.value.length == 0) { | |
790 | alert(__("Please select an image file to upload.")); | |
c3b7b797 | 791 | } else { |
7abf159d AD |
792 | if (confirm(__("Upload new icon for this feed?"))) { |
793 | notify_progress("Uploading, please wait...", true); | |
794 | return true; | |
795 | } | |
c3b7b797 AD |
796 | } |
797 | ||
7abf159d AD |
798 | return false; |
799 | ||
c3b7b797 AD |
800 | } catch (e) { |
801 | exception_error("uploadFeedIcon", e); | |
802 | } | |
803 | } | |
804 | ||
1c31e190 | 805 | function addLabel(select, callback) { |
d002edc7 AD |
806 | |
807 | try { | |
808 | ||
809 | var caption = prompt(__("Please enter label caption:"), ""); | |
810 | ||
811 | if (caption != undefined) { | |
be2f5e1a | 812 | |
d002edc7 AD |
813 | if (caption == "") { |
814 | alert(__("Can't create label: missing caption.")); | |
815 | return false; | |
816 | } | |
817 | ||
f30ef1fa | 818 | var query = "?op=pref-labels&method=add&caption=" + |
d002edc7 AD |
819 | param_escape(caption); |
820 | ||
1c31e190 AD |
821 | if (select) |
822 | query += "&output=select"; | |
823 | ||
d002edc7 AD |
824 | notify_progress("Loading, please wait...", true); |
825 | ||
1c31e190 | 826 | if (inPreferences() && !select) active_tab = "labelConfig"; |
d002edc7 AD |
827 | |
828 | new Ajax.Request("backend.php", { | |
829 | parameters: query, | |
be2f5e1a | 830 | onComplete: function(transport) { |
1c31e190 AD |
831 | if (callback) { |
832 | callback(transport); | |
833 | } else if (inPreferences()) { | |
36146ae5 | 834 | updateLabelList(); |
d002edc7 AD |
835 | } else { |
836 | updateFeedList(); | |
837 | } | |
838 | } }); | |
839 | ||
840 | } | |
841 | ||
842 | } catch (e) { | |
843 | exception_error("addLabel", e); | |
844 | } | |
845 | } | |
846 | ||
3393238d | 847 | function quickAddFeed() { |
11b9d0be | 848 | try { |
3f363052 | 849 | var query = "backend.php?op=dlg&method=quickAddFeed"; |
11b9d0be | 850 | |
c714cee7 AD |
851 | // overlapping widgets |
852 | if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); | |
853 | if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); | |
11b9d0be AD |
854 | |
855 | var dialog = new dijit.Dialog({ | |
856 | id: "feedAddDlg", | |
857 | title: __("Subscribe to Feed"), | |
858 | style: "width: 600px", | |
859 | execute: function() { | |
860 | if (this.validate()) { | |
861 | console.log(dojo.objectToQuery(this.attr('value'))); | |
862 | ||
863 | var feed_url = this.attr('value').feed; | |
864 | ||
23d2471c | 865 | Element.show("feed_add_spinner"); |
11b9d0be AD |
866 | |
867 | new Ajax.Request("backend.php", { | |
868 | parameters: dojo.objectToQuery(this.attr('value')), | |
be2f5e1a | 869 | onComplete: function(transport) { |
11b9d0be | 870 | try { |
e9175d13 AD |
871 | |
872 | var reply = JSON.parse(transport.responseText); | |
be2f5e1a | 873 | |
23d2471c | 874 | var rc = reply['result']; |
be2f5e1a | 875 | |
11b9d0be | 876 | notify(''); |
23d2471c | 877 | Element.hide("feed_add_spinner"); |
11b9d0be AD |
878 | |
879 | console.log("GOT RC: " + rc); | |
be2f5e1a | 880 | |
23d2471c | 881 | switch (parseInt(rc['code'])) { |
11b9d0be AD |
882 | case 1: |
883 | dialog.hide(); | |
884 | notify_info(__("Subscribed to %s").replace("%s", feed_url)); | |
be2f5e1a | 885 | |
36146ae5 | 886 | updateFeedList(); |
11b9d0be AD |
887 | break; |
888 | case 2: | |
889 | alert(__("Specified URL seems to be invalid.")); | |
890 | break; | |
891 | case 3: | |
892 | alert(__("Specified URL doesn't seem to contain any feeds.")); | |
893 | break; | |
894 | case 4: | |
759e5132 | 895 | /* notify_progress("Searching for feed urls...", true); |
11b9d0be AD |
896 | |
897 | new Ajax.Request("backend.php", { | |
f30ef1fa | 898 | parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url), |
11b9d0be AD |
899 | onComplete: function(transport, dialog, feed_url) { |
900 | ||
11b9d0be AD |
901 | notify(''); |
902 | ||
e9175d13 AD |
903 | var reply = JSON.parse(transport.responseText); |
904 | ||
905 | var feeds = reply['urls']; | |
11b9d0be AD |
906 | |
907 | console.log(transport.responseText); | |
908 | ||
909 | var select = dijit.byId("feedDlg_feedContainerSelect"); | |
910 | ||
911 | while (select.getOptions().length > 0) | |
912 | select.removeOption(0); | |
913 | ||
914 | var count = 0; | |
915 | for (var feedUrl in feeds) { | |
916 | select.addOption({value: feedUrl, label: feeds[feedUrl]}); | |
917 | count++; | |
918 | } | |
919 | ||
920 | // if (count > 5) count = 5; | |
be2f5e1a AD |
921 | // select.size = count; |
922 | ||
923 | Effect.Appear('feedDlg_feedsContainer', {duration : 0.5}); | |
11b9d0be AD |
924 | } |
925 | }); | |
759e5132 AD |
926 | break; */ |
927 | ||
928 | feeds = rc['feeds']; | |
929 | ||
930 | var select = dijit.byId("feedDlg_feedContainerSelect"); | |
931 | ||
932 | while (select.getOptions().length > 0) | |
933 | select.removeOption(0); | |
934 | ||
935 | var count = 0; | |
936 | for (var feedUrl in feeds) { | |
937 | select.addOption({value: feedUrl, label: feeds[feedUrl]}); | |
938 | count++; | |
939 | } | |
940 | ||
941 | Effect.Appear('feedDlg_feedsContainer', {duration : 0.5}); | |
942 | ||
11b9d0be AD |
943 | break; |
944 | case 5: | |
23d2471c AD |
945 | alert(__("Couldn't download the specified URL: %s"). |
946 | replace("%s", rc['message'])); | |
11b9d0be AD |
947 | break; |
948 | case 0: | |
949 | alert(__("You are already subscribed to this feed.")); | |
950 | break; | |
951 | } | |
be2f5e1a | 952 | |
11b9d0be | 953 | } catch (e) { |
592f0339 | 954 | exception_error("subscribeToFeed", e, transport); |
11b9d0be | 955 | } |
be2f5e1a | 956 | |
11b9d0be AD |
957 | } }); |
958 | ||
959 | } | |
960 | }, | |
961 | href: query}); | |
962 | ||
963 | dialog.show(); | |
964 | } catch (e) { | |
965 | exception_error("quickAddFeed", e); | |
966 | } | |
3393238d AD |
967 | } |
968 | ||
6aff7845 AD |
969 | function createNewRuleElement(parentNode, replaceNode) { |
970 | try { | |
971 | var form = document.forms["filter_new_rule_form"]; | |
972 | ||
f01c8ec4 AD |
973 | form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,""); |
974 | ||
6aff7845 AD |
975 | var query = "backend.php?op=pref-filters&method=printrulename&rule="+ |
976 | param_escape(dojo.formToJson(form)); | |
977 | ||
978 | console.log(query); | |
979 | ||
980 | new Ajax.Request("backend.php", { | |
981 | parameters: query, | |
982 | onComplete: function (transport) { | |
983 | try { | |
984 | var li = dojo.create("li"); | |
985 | ||
04e41840 AD |
986 | var cb = dojo.create("input", { type: "checkbox" }, li); |
987 | ||
988 | new dijit.form.CheckBox({ | |
989 | onChange: function() { | |
990 | toggleSelectListRow2(this) }, | |
991 | }, cb); | |
6aff7845 AD |
992 | |
993 | dojo.create("input", { type: "hidden", | |
994 | name: "rule[]", | |
995 | value: dojo.formToJson(form) }, li); | |
996 | ||
997 | dojo.create("span", { | |
998 | onclick: function() { | |
999 | dijit.byId('filterEditDlg').editRule(this); | |
1000 | }, | |
1001 | innerHTML: transport.responseText }, li); | |
1002 | ||
1003 | if (replaceNode) { | |
1004 | parentNode.replaceChild(li, replaceNode); | |
1005 | } else { | |
1006 | parentNode.appendChild(li); | |
1007 | } | |
1008 | } catch (e) { | |
1009 | exception_error("createNewRuleElement", e); | |
1010 | } | |
1011 | } }); | |
1012 | } catch (e) { | |
1013 | exception_error("createNewRuleElement", e); | |
1014 | } | |
1015 | } | |
1016 | ||
1017 | function createNewActionElement(parentNode, replaceNode) { | |
1018 | try { | |
1019 | var form = document.forms["filter_new_action_form"]; | |
1020 | ||
1021 | if (form.action_id.value == 7) { | |
1022 | form.action_param.value = form.action_param_label.value; | |
1023 | } | |
1024 | ||
1025 | var query = "backend.php?op=pref-filters&method=printactionname&action="+ | |
1026 | param_escape(dojo.formToJson(form)); | |
1027 | ||
1028 | console.log(query); | |
1029 | ||
1030 | new Ajax.Request("backend.php", { | |
1031 | parameters: query, | |
1032 | onComplete: function (transport) { | |
1033 | try { | |
1034 | var li = dojo.create("li"); | |
1035 | ||
04e41840 AD |
1036 | var cb = dojo.create("input", { type: "checkbox" }, li); |
1037 | ||
1038 | new dijit.form.CheckBox({ | |
1039 | onChange: function() { | |
1040 | toggleSelectListRow2(this) }, | |
1041 | }, cb); | |
6aff7845 AD |
1042 | |
1043 | dojo.create("input", { type: "hidden", | |
1044 | name: "action[]", | |
1045 | value: dojo.formToJson(form) }, li); | |
1046 | ||
1047 | dojo.create("span", { | |
1048 | onclick: function() { | |
1049 | dijit.byId('filterEditDlg').editAction(this); | |
1050 | }, | |
1051 | innerHTML: transport.responseText }, li); | |
1052 | ||
1053 | if (replaceNode) { | |
1054 | parentNode.replaceChild(li, replaceNode); | |
1055 | } else { | |
1056 | parentNode.appendChild(li); | |
1057 | } | |
1058 | ||
1059 | } catch (e) { | |
1060 | exception_error("createNewActionElement", e); | |
1061 | } | |
1062 | } }); | |
1063 | } catch (e) { | |
1064 | exception_error("createNewActionElement", e); | |
1065 | } | |
1066 | } | |
1067 | ||
1068 | ||
1069 | function addFilterRule(replaceNode, ruleStr) { | |
1070 | try { | |
1071 | if (dijit.byId("filterNewRuleDlg")) | |
1072 | dijit.byId("filterNewRuleDlg").destroyRecursive(); | |
1073 | ||
1074 | var query = "backend.php?op=pref-filters&method=newrule&rule=" + | |
1075 | param_escape(ruleStr); | |
1076 | ||
1077 | var rule_dlg = new dijit.Dialog({ | |
1078 | id: "filterNewRuleDlg", | |
1079 | title: ruleStr ? __("Edit rule") : __("Add rule"), | |
1080 | style: "width: 600px", | |
1081 | execute: function() { | |
1082 | if (this.validate()) { | |
1083 | createNewRuleElement($("filterDlg_Matches"), replaceNode); | |
1084 | this.hide(); | |
1085 | } | |
1086 | }, | |
1087 | href: query}); | |
1088 | ||
1089 | rule_dlg.show(); | |
1090 | } catch (e) { | |
1091 | exception_error("addFilterRule", e); | |
1092 | } | |
1093 | } | |
1094 | ||
1095 | function addFilterAction(replaceNode, actionStr) { | |
1096 | try { | |
1097 | if (dijit.byId("filterNewActionDlg")) | |
1098 | dijit.byId("filterNewActionDlg").destroyRecursive(); | |
1099 | ||
1100 | var query = "backend.php?op=pref-filters&method=newaction&action=" + | |
1101 | param_escape(actionStr); | |
1102 | ||
1103 | var rule_dlg = new dijit.Dialog({ | |
1104 | id: "filterNewActionDlg", | |
1105 | title: actionStr ? __("Edit action") : __("Add action"), | |
1106 | style: "width: 600px", | |
1107 | execute: function() { | |
1108 | if (this.validate()) { | |
1109 | createNewActionElement($("filterDlg_Actions"), replaceNode); | |
1110 | this.hide(); | |
1111 | } | |
1112 | }, | |
1113 | href: query}); | |
1114 | ||
1115 | rule_dlg.show(); | |
1116 | } catch (e) { | |
1117 | exception_error("addFilterAction", e); | |
1118 | } | |
1119 | } | |
1120 | ||
3393238d | 1121 | function quickAddFilter() { |
d90868d7 | 1122 | try { |
da1da2e4 AD |
1123 | var query = ""; |
1124 | if (!inPreferences()) { | |
6aff7845 | 1125 | query = "backend.php?op=pref-filters&method=newfilter&feed=" + |
da1da2e4 AD |
1126 | param_escape(getActiveFeedId()) + "&is_cat=" + |
1127 | param_escape(activeFeedIsCat()); | |
1128 | } else { | |
6aff7845 | 1129 | query = "backend.php?op=pref-filters&method=newfilter"; |
da1da2e4 | 1130 | } |
d90868d7 | 1131 | |
6aff7845 AD |
1132 | console.log(query); |
1133 | ||
4cd30111 AD |
1134 | if (dijit.byId("feedEditDlg")) |
1135 | dijit.byId("feedEditDlg").destroyRecursive(); | |
1136 | ||
d90868d7 AD |
1137 | if (dijit.byId("filterEditDlg")) |
1138 | dijit.byId("filterEditDlg").destroyRecursive(); | |
1139 | ||
1140 | dialog = new dijit.Dialog({ | |
1141 | id: "filterEditDlg", | |
1142 | title: __("Create Filter"), | |
1143 | style: "width: 600px", | |
4e02f582 AD |
1144 | test: function() { |
1145 | var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; | |
1146 | ||
1147 | if (dijit.byId("filterTestDlg")) | |
1148 | dijit.byId("filterTestDlg").destroyRecursive(); | |
1149 | ||
1150 | var test_dlg = new dijit.Dialog({ | |
1151 | id: "filterTestDlg", | |
1152 | title: "Test Filter", | |
1153 | style: "width: 600px", | |
1154 | href: query}); | |
1155 | ||
1156 | test_dlg.show(); | |
1157 | }, | |
ec630524 AD |
1158 | selectRules: function(select) { |
1159 | $$("#filterDlg_Matches input[type=checkbox]").each(function(e) { | |
1160 | e.checked = select; | |
1161 | if (select) | |
1162 | e.parentNode.addClassName("Selected"); | |
1163 | else | |
1164 | e.parentNode.removeClassName("Selected"); | |
1165 | }); | |
1166 | }, | |
1167 | selectActions: function(select) { | |
1168 | $$("#filterDlg_Actions input[type=checkbox]").each(function(e) { | |
1169 | e.checked = select; | |
1170 | ||
1171 | if (select) | |
1172 | e.parentNode.addClassName("Selected"); | |
1173 | else | |
1174 | e.parentNode.removeClassName("Selected"); | |
1175 | ||
1176 | }); | |
1177 | }, | |
6aff7845 AD |
1178 | editRule: function(e) { |
1179 | var li = e.parentNode; | |
1180 | var rule = li.getElementsByTagName("INPUT")[1].value; | |
1181 | addFilterRule(li, rule); | |
1182 | }, | |
1183 | editAction: function(e) { | |
1184 | var li = e.parentNode; | |
1185 | var action = li.getElementsByTagName("INPUT")[1].value; | |
1186 | addFilterAction(li, action); | |
1187 | }, | |
1188 | addAction: function() { addFilterAction(); }, | |
1189 | addRule: function() { addFilterRule(); }, | |
1190 | deleteAction: function() { | |
1191 | $$("#filterDlg_Actions li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) }); | |
1192 | }, | |
1193 | deleteRule: function() { | |
1194 | $$("#filterDlg_Matches li.[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) }); | |
5593784a | 1195 | }, |
d90868d7 AD |
1196 | execute: function() { |
1197 | if (this.validate()) { | |
141fb6e3 | 1198 | |
6aff7845 | 1199 | var query = dojo.formToQuery("filter_new_form"); |
141fb6e3 | 1200 | |
6aff7845 | 1201 | console.log(query); |
141fb6e3 | 1202 | |
6aff7845 | 1203 | new Ajax.Request("backend.php", { |
141fb6e3 | 1204 | parameters: query, |
6aff7845 AD |
1205 | onComplete: function (transport) { |
1206 | if (inPreferences()) { | |
1207 | updateFilterList(); | |
d90868d7 | 1208 | } |
6aff7845 AD |
1209 | |
1210 | dialog.hide(); | |
1211 | } }); | |
d90868d7 AD |
1212 | } |
1213 | }, | |
1214 | href: query}); | |
1215 | ||
ab564aef AD |
1216 | if (!inPreferences()) { |
1217 | var lh = dojo.connect(dialog, "onLoad", function(){ | |
1218 | dojo.disconnect(lh); | |
1219 | ||
5defc29f | 1220 | var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId(); |
ab564aef | 1221 | |
5defc29f AD |
1222 | new Ajax.Request("backend.php", { |
1223 | parameters: query, | |
1224 | onComplete: function(transport) { | |
1225 | var reply = JSON.parse(transport.responseText); | |
ab564aef | 1226 | |
5defc29f | 1227 | var title = false; |
ab564aef | 1228 | |
5defc29f | 1229 | if (reply && reply) title = reply.title; |
ab564aef | 1230 | |
5defc29f AD |
1231 | if (title || getActiveFeedId() || activeFeedIsCat()) { |
1232 | ||
1233 | console.log(title + " " + getActiveFeedId()); | |
1234 | ||
1235 | var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : | |
1236 | getActiveFeedId(); | |
1237 | ||
1238 | var rule = { reg_exp: title, feed_id: feed_id, filter_type: 1 }; | |
1239 | ||
1240 | addFilterRule(null, dojo.toJson(rule)); | |
1241 | } | |
1242 | ||
1243 | } }); | |
ab564aef | 1244 | |
ab564aef AD |
1245 | }); |
1246 | } | |
1247 | ||
d90868d7 | 1248 | dialog.show(); |
e54dbacb | 1249 | |
d90868d7 AD |
1250 | } catch (e) { |
1251 | exception_error("quickAddFilter", e); | |
1252 | } | |
3393238d | 1253 | } |
78bcd2c4 | 1254 | |
5de27114 AD |
1255 | function resetPubSub(feed_id, title) { |
1256 | ||
1257 | var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title); | |
1258 | ||
1259 | if (title == undefined || confirm(msg)) { | |
1260 | notify_progress("Loading, please wait..."); | |
1261 | ||
f30ef1fa | 1262 | var query = "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id; |
5de27114 AD |
1263 | |
1264 | new Ajax.Request("backend.php", { | |
1265 | parameters: query, | |
1266 | onComplete: function(transport) { | |
1267 | dijit.byId("pubsubReset_Btn").attr('disabled', true); | |
1268 | notify_info("Subscription reset."); | |
1269 | } }); | |
1270 | } | |
1271 | ||
1272 | return false; | |
1273 | } | |
1274 | ||
1275 | ||
78bcd2c4 AD |
1276 | function unsubscribeFeed(feed_id, title) { |
1277 | ||
1278 | var msg = __("Unsubscribe from %s?").replace("%s", title); | |
1279 | ||
1280 | if (title == undefined || confirm(msg)) { | |
1281 | notify_progress("Removing feed..."); | |
1282 | ||
f30ef1fa | 1283 | var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id; |
78bcd2c4 AD |
1284 | |
1285 | new Ajax.Request("backend.php", { | |
1286 | parameters: query, | |
1287 | onComplete: function(transport) { | |
1288 | ||
11b9d0be | 1289 | if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); |
be2f5e1a | 1290 | |
78bcd2c4 | 1291 | if (inPreferences()) { |
be2f5e1a | 1292 | updateFeedList(); |
78bcd2c4 | 1293 | } else { |
8cd576a1 AD |
1294 | if (feed_id == getActiveFeedId()) |
1295 | setTimeout("viewfeed(-5)", 100); | |
8a775535 AD |
1296 | |
1297 | if (feed_id < 0) updateFeedList(); | |
78bcd2c4 AD |
1298 | } |
1299 | ||
1300 | } }); | |
1301 | } | |
1302 | ||
1303 | return false; | |
1304 | } | |
1305 | ||
1306 | ||
4a3da1c8 AD |
1307 | function backend_sanity_check_callback(transport) { |
1308 | ||
1309 | try { | |
1310 | ||
1311 | if (sanity_check_done) { | |
1312 | fatalError(11, "Sanity check request received twice. This can indicate "+ | |
1313 | "presence of Firebug or some other disrupting extension. "+ | |
1314 | "Please disable it and try again."); | |
1315 | return; | |
1316 | } | |
1317 | ||
ebb948c2 | 1318 | var reply = JSON.parse(transport.responseText); |
4a3da1c8 AD |
1319 | |
1320 | if (!reply) { | |
1321 | fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); | |
1322 | return; | |
1323 | } | |
1324 | ||
ebb948c2 | 1325 | var error_code = reply['error']['code']; |
be2f5e1a | 1326 | |
4a3da1c8 | 1327 | if (error_code && error_code != 0) { |
ebb948c2 | 1328 | return fatalError(error_code, reply['error']['message']); |
4a3da1c8 AD |
1329 | } |
1330 | ||
1331 | console.log("sanity check ok"); | |
1332 | ||
ebb948c2 | 1333 | var params = reply['init-params']; |
4a3da1c8 AD |
1334 | |
1335 | if (params) { | |
1336 | console.log('reading init-params...'); | |
f1f3a642 | 1337 | |
f1f3a642 | 1338 | if (params) { |
c4f7ba80 | 1339 | for (k in params) { |
c4f7ba80 | 1340 | var v = params[k]; |
c4f7ba80 | 1341 | console.log("IP: " + k + " => " + v); |
88a41b64 AD |
1342 | |
1343 | if (k == "label_base_index") _label_base_index = parseInt(v); | |
f1f3a642 | 1344 | } |
4a3da1c8 | 1345 | } |
c4f7ba80 AD |
1346 | |
1347 | init_params = params; | |
4a3da1c8 AD |
1348 | } |
1349 | ||
1350 | sanity_check_done = true; | |
1351 | ||
1352 | init_second_stage(); | |
1353 | ||
1354 | } catch (e) { | |
be2f5e1a AD |
1355 | exception_error("backend_sanity_check_callback", e, transport); |
1356 | } | |
4a3da1c8 AD |
1357 | } |
1358 | ||
78b2c6ce | 1359 | /*function has_local_storage() { |
dbf8845e AD |
1360 | try { |
1361 | return 'sessionStorage' in window && window['sessionStorage'] != null; | |
ff0010c1 AD |
1362 | } catch (e) { |
1363 | return false; | |
be2f5e1a | 1364 | } |
78b2c6ce | 1365 | } */ |
5c7c7da9 AD |
1366 | |
1367 | function catSelectOnChange(elem) { | |
1368 | try { | |
f9c388f5 | 1369 | /* var value = elem[elem.selectedIndex].value; |
5c7c7da9 AD |
1370 | var def = elem.getAttribute('default'); |
1371 | ||
1372 | if (value == "ADD_CAT") { | |
1373 | ||
1374 | if (def) | |
1375 | dropboxSelect(elem, def); | |
1376 | else | |
1377 | elem.selectedIndex = 0; | |
1378 | ||
1379 | quickAddCat(elem); | |
f9c388f5 | 1380 | } */ |
5c7c7da9 AD |
1381 | |
1382 | } catch (e) { | |
1383 | exception_error("catSelectOnChange", e); | |
1384 | } | |
1385 | } | |
1386 | ||
c00907f2 | 1387 | function quickAddCat(elem) { |
5c7c7da9 AD |
1388 | try { |
1389 | var cat = prompt(__("Please enter category title:")); | |
1390 | ||
1391 | if (cat) { | |
1392 | ||
f30ef1fa | 1393 | var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat); |
5c7c7da9 | 1394 | |
c00907f2 AD |
1395 | notify_progress("Loading, please wait...", true); |
1396 | ||
5c7c7da9 AD |
1397 | new Ajax.Request("backend.php", { |
1398 | parameters: query, | |
1399 | onComplete: function (transport) { | |
1400 | var response = transport.responseXML; | |
c00907f2 AD |
1401 | var select = response.getElementsByTagName("select")[0]; |
1402 | var options = select.getElementsByTagName("option"); | |
5c7c7da9 | 1403 | |
c00907f2 | 1404 | dropbox_replace_options(elem, options); |
5c7c7da9 | 1405 | |
c00907f2 | 1406 | notify(''); |
5c7c7da9 AD |
1407 | |
1408 | } }); | |
1409 | ||
1410 | } | |
1411 | ||
1412 | } catch (e) { | |
1413 | exception_error("quickAddCat", e); | |
1414 | } | |
1415 | } | |
8801fb01 AD |
1416 | |
1417 | function genUrlChangeKey(feed, is_cat) { | |
1418 | ||
1419 | try { | |
1420 | var ok = confirm(__("Generate new syndication address for this feed?")); | |
be2f5e1a | 1421 | |
8801fb01 | 1422 | if (ok) { |
be2f5e1a | 1423 | |
8801fb01 | 1424 | notify_progress("Trying to change address...", true); |
be2f5e1a | 1425 | |
f30ef1fa | 1426 | var query = "?op=rpc&method=regenFeedKey&id=" + param_escape(feed) + |
8801fb01 AD |
1427 | "&is_cat=" + param_escape(is_cat); |
1428 | ||
1429 | new Ajax.Request("backend.php", { | |
1430 | parameters: query, | |
1431 | onComplete: function(transport) { | |
91d16ff1 AD |
1432 | var reply = JSON.parse(transport.responseText); |
1433 | var new_link = reply.link; | |
be2f5e1a | 1434 | |
8801fb01 | 1435 | var e = $('gen_feed_url'); |
be2f5e1a | 1436 | |
8801fb01 | 1437 | if (new_link) { |
be2f5e1a AD |
1438 | |
1439 | e.innerHTML = e.innerHTML.replace(/\&key=.*$/, | |
8801fb01 AD |
1440 | "&key=" + new_link); |
1441 | ||
6c0ba5b6 AD |
1442 | e.href = e.href.replace(/\&key=.*$/, |
1443 | "&key=" + new_link); | |
8801fb01 AD |
1444 | |
1445 | new Effect.Highlight(e); | |
1446 | ||
1447 | notify(''); | |
be2f5e1a | 1448 | |
8801fb01 AD |
1449 | } else { |
1450 | notify_error("Could not change feed URL."); | |
1451 | } | |
1452 | } }); | |
1453 | } | |
1454 | } catch (e) { | |
1455 | exception_error("genUrlChangeKey", e); | |
1456 | } | |
1457 | return false; | |
1458 | } | |
1459 | ||
1c31e190 AD |
1460 | function labelSelectOnChange(elem) { |
1461 | try { | |
d90868d7 | 1462 | /* var value = elem[elem.selectedIndex].value; |
1c31e190 AD |
1463 | var def = elem.getAttribute('default'); |
1464 | ||
1465 | if (value == "ADD_LABEL") { | |
1466 | ||
1467 | if (def) | |
1468 | dropboxSelect(elem, def); | |
1469 | else | |
1470 | elem.selectedIndex = 0; | |
1471 | ||
1472 | addLabel(elem, function(transport) { | |
1c31e190 | 1473 | |
10249c41 | 1474 | try { |
1c31e190 | 1475 | |
10249c41 AD |
1476 | var response = transport.responseXML; |
1477 | var select = response.getElementsByTagName("select")[0]; | |
1478 | var options = select.getElementsByTagName("option"); | |
1479 | ||
1480 | dropbox_replace_options(elem, options); | |
1481 | ||
1482 | notify(''); | |
1483 | } catch (e) { | |
1484 | exception_error("addLabel", e); | |
1485 | } | |
1c31e190 | 1486 | }); |
d90868d7 | 1487 | } */ |
1c31e190 AD |
1488 | |
1489 | } catch (e) { | |
10249c41 | 1490 | exception_error("labelSelectOnChange", e); |
1c31e190 AD |
1491 | } |
1492 | } | |
1493 | ||
10249c41 AD |
1494 | function dropbox_replace_options(elem, options) { |
1495 | ||
1496 | try { | |
1497 | while (elem.hasChildNodes()) | |
1498 | elem.removeChild(elem.firstChild); | |
1499 | ||
1500 | var sel_idx = -1; | |
1501 | ||
1502 | for (var i = 0; i < options.length; i++) { | |
1503 | var text = options[i].firstChild.nodeValue; | |
1504 | var value = options[i].getAttribute("value"); | |
11eb3f4e AD |
1505 | |
1506 | if (value == undefined) value = text; | |
1507 | ||
10249c41 | 1508 | var issel = options[i].getAttribute("selected") == "1"; |
c00907f2 AD |
1509 | |
1510 | var option = new Option(text, value, issel); | |
1511 | ||
1512 | if (options[i].getAttribute("disabled")) | |
1513 | option.setAttribute("disabled", true); | |
1514 | ||
1515 | elem.insert(option); | |
1516 | ||
10249c41 AD |
1517 | if (issel) sel_idx = i; |
1518 | } | |
1c31e190 | 1519 | |
10249c41 AD |
1520 | // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true) |
1521 | if (sel_idx >= 0) elem.selectedIndex = sel_idx; | |
1522 | ||
1523 | } catch (e) { | |
1524 | exception_error("dropbox_replace_options", e); | |
1525 | } | |
1526 | } | |
e69fb880 AD |
1527 | |
1528 | // mode = all, none, invert | |
1529 | function selectTableRows(id, mode) { | |
1530 | try { | |
1531 | var rows = $(id).rows; | |
1532 | ||
1533 | for (var i = 0; i < rows.length; i++) { | |
1534 | var row = rows[i]; | |
1535 | var cb = false; | |
ddb575c7 | 1536 | var dcb = false; |
e69fb880 AD |
1537 | |
1538 | if (row.id && row.className) { | |
1539 | var bare_id = row.id.replace(/^[A-Z]*?-/, ""); | |
1540 | var inputs = rows[i].getElementsByTagName("input"); | |
1541 | ||
1542 | for (var j = 0; j < inputs.length; j++) { | |
1543 | var input = inputs[j]; | |
1544 | ||
be2f5e1a | 1545 | if (input.getAttribute("type") == "checkbox" && |
e69fb880 AD |
1546 | input.id.match(bare_id)) { |
1547 | ||
1548 | cb = input; | |
ddb575c7 | 1549 | dcb = dijit.getEnclosingWidget(cb); |
e69fb880 AD |
1550 | break; |
1551 | } | |
1552 | } | |
1553 | ||
ddb575c7 | 1554 | if (cb || dcb) { |
ca8e3d75 | 1555 | var issel = row.hasClassName("Selected"); |
e69fb880 AD |
1556 | |
1557 | if (mode == "all" && !issel) { | |
ca8e3d75 | 1558 | row.addClassName("Selected"); |
e69fb880 | 1559 | cb.checked = true; |
ddb575c7 | 1560 | if (dcb) dcb.set("checked", true); |
e69fb880 | 1561 | } else if (mode == "none" && issel) { |
ca8e3d75 | 1562 | row.removeClassName("Selected"); |
e69fb880 | 1563 | cb.checked = false; |
ddb575c7 AD |
1564 | if (dcb) dcb.set("checked", false); |
1565 | ||
e69fb880 AD |
1566 | } else if (mode == "invert") { |
1567 | ||
1568 | if (issel) { | |
ca8e3d75 | 1569 | row.removeClassName("Selected"); |
e69fb880 | 1570 | cb.checked = false; |
ddb575c7 | 1571 | if (dcb) dcb.set("checked", false); |
e69fb880 | 1572 | } else { |
ca8e3d75 | 1573 | row.addClassName("Selected"); |
e69fb880 | 1574 | cb.checked = true; |
ddb575c7 | 1575 | if (dcb) dcb.set("checked", true); |
e69fb880 AD |
1576 | } |
1577 | } | |
1578 | } | |
1579 | } | |
1580 | } | |
1581 | ||
1582 | } catch (e) { | |
1583 | exception_error("selectTableRows", e); | |
1584 | ||
1585 | } | |
1586 | } | |
1587 | ||
1588 | function getSelectedTableRowIds(id) { | |
1589 | var rows = []; | |
1590 | ||
1591 | try { | |
1592 | var elem_rows = $(id).rows; | |
1593 | ||
e331188f | 1594 | for (var i = 0; i < elem_rows.length; i++) { |
ca8e3d75 | 1595 | if (elem_rows[i].hasClassName("Selected")) { |
e69fb880 AD |
1596 | var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); |
1597 | rows.push(bare_id); | |
1598 | } | |
1599 | } | |
1600 | ||
1601 | } catch (e) { | |
1602 | exception_error("getSelectedTableRowIds", e); | |
1603 | } | |
1604 | ||
1605 | return rows; | |
1606 | } | |
1607 | ||
f9c388f5 | 1608 | function editFeed(feed, event) { |
f9c388f5 | 1609 | try { |
33f31dfd AD |
1610 | if (feed <= 0) |
1611 | return alert(__("You can't edit this kind of feed.")); | |
1612 | ||
f30ef1fa | 1613 | var query = "backend.php?op=pref-feeds&method=editfeed&id=" + |
f9c388f5 AD |
1614 | param_escape(feed); |
1615 | ||
1616 | console.log(query); | |
1617 | ||
4cd30111 AD |
1618 | if (dijit.byId("filterEditDlg")) |
1619 | dijit.byId("filterEditDlg").destroyRecursive(); | |
1620 | ||
f9c388f5 AD |
1621 | if (dijit.byId("feedEditDlg")) |
1622 | dijit.byId("feedEditDlg").destroyRecursive(); | |
1623 | ||
1624 | dialog = new dijit.Dialog({ | |
1625 | id: "feedEditDlg", | |
1626 | title: __("Edit Feed"), | |
1627 | style: "width: 600px", | |
1628 | execute: function() { | |
1629 | if (this.validate()) { | |
05acc0d6 | 1630 | // console.log(dojo.objectToQuery(this.attr('value'))); |
f9c388f5 AD |
1631 | |
1632 | notify_progress("Saving data...", true); | |
1633 | ||
1634 | new Ajax.Request("backend.php", { | |
1635 | parameters: dojo.objectToQuery(dialog.attr('value')), | |
1636 | onComplete: function(transport) { | |
1637 | dialog.hide(); | |
7d8eca88 | 1638 | notify(''); |
8cd576a1 | 1639 | updateFeedList(); |
e331188f | 1640 | }}); |
f9c388f5 AD |
1641 | } |
1642 | }, | |
1643 | href: query}); | |
1644 | ||
1645 | dialog.show(); | |
1646 | ||
1647 | } catch (e) { | |
1648 | exception_error("editFeed", e); | |
1649 | } | |
1650 | } | |
1651 | ||
11b9d0be AD |
1652 | function feedBrowser() { |
1653 | try { | |
3f363052 | 1654 | var query = "backend.php?op=dlg&method=feedBrowser"; |
11b9d0be AD |
1655 | |
1656 | if (dijit.byId("feedAddDlg")) | |
1657 | dijit.byId("feedAddDlg").hide(); | |
1658 | ||
1659 | if (dijit.byId("feedBrowserDlg")) | |
1660 | dijit.byId("feedBrowserDlg").destroyRecursive(); | |
1661 | ||
1662 | var dialog = new dijit.Dialog({ | |
1663 | id: "feedBrowserDlg", | |
1664 | title: __("More Feeds"), | |
1665 | style: "width: 600px", | |
6f907113 | 1666 | getSelectedFeedIds: function() { |
11b9d0be AD |
1667 | var list = $$("#browseFeedList li[id*=FBROW]"); |
1668 | var selected = new Array(); | |
be2f5e1a AD |
1669 | |
1670 | list.each(function(child) { | |
11b9d0be | 1671 | var id = child.id.replace("FBROW-", ""); |
be2f5e1a | 1672 | |
11b9d0be AD |
1673 | if (child.hasClassName('Selected')) { |
1674 | selected.push(id); | |
be2f5e1a | 1675 | } |
11b9d0be | 1676 | }); |
be2f5e1a | 1677 | |
11b9d0be AD |
1678 | return selected; |
1679 | }, | |
6f907113 AD |
1680 | getSelectedFeeds: function() { |
1681 | var list = $$("#browseFeedList li.Selected"); | |
1682 | var selected = new Array(); | |
1683 | ||
1684 | list.each(function(child) { | |
1685 | var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; | |
1686 | var url = child.getElementsBySelector("a.fb_feedUrl")[0].href; | |
1687 | ||
1688 | selected.push([title,url]); | |
1689 | ||
1690 | }); | |
1691 | ||
1692 | return selected; | |
1693 | }, | |
1694 | ||
11b9d0be | 1695 | subscribe: function() { |
11b9d0be | 1696 | var mode = this.attr('value').mode; |
6f907113 AD |
1697 | var selected = []; |
1698 | ||
1699 | if (mode == "1") | |
1700 | selected = this.getSelectedFeeds(); | |
1701 | else | |
1702 | selected = this.getSelectedFeedIds(); | |
be2f5e1a | 1703 | |
11b9d0be AD |
1704 | if (selected.length > 0) { |
1705 | dijit.byId("feedBrowserDlg").hide(); | |
be2f5e1a | 1706 | |
11b9d0be | 1707 | notify_progress("Loading, please wait...", true); |
be2f5e1a | 1708 | |
6f907113 AD |
1709 | // we use dojo.toJson instead of JSON.stringify because |
1710 | // it somehow escapes everything TWICE, at least in Chrome 9 | |
1711 | ||
f30ef1fa | 1712 | var query = "?op=rpc&method=massSubscribe&payload="+ |
6f907113 | 1713 | param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode); |
11b9d0be AD |
1714 | |
1715 | console.log(query); | |
be2f5e1a | 1716 | |
11b9d0be AD |
1717 | new Ajax.Request("backend.php", { |
1718 | parameters: query, | |
be2f5e1a | 1719 | onComplete: function(transport) { |
6f907113 AD |
1720 | notify(''); |
1721 | updateFeedList(); | |
11b9d0be | 1722 | } }); |
be2f5e1a | 1723 | |
11b9d0be AD |
1724 | } else { |
1725 | alert(__("No feeds are selected.")); | |
1726 | } | |
be2f5e1a | 1727 | |
11b9d0be AD |
1728 | }, |
1729 | update: function() { | |
1730 | var query = dojo.objectToQuery(dialog.attr('value')); | |
be2f5e1a | 1731 | |
11b9d0be | 1732 | Element.show('feed_browser_spinner'); |
be2f5e1a | 1733 | |
11b9d0be AD |
1734 | new Ajax.Request("backend.php", { |
1735 | parameters: query, | |
be2f5e1a | 1736 | onComplete: function(transport) { |
11b9d0be | 1737 | notify(''); |
be2f5e1a | 1738 | |
11b9d0be | 1739 | Element.hide('feed_browser_spinner'); |
be2f5e1a | 1740 | |
11b9d0be | 1741 | var c = $("browseFeedList"); |
4a16bda3 AD |
1742 | |
1743 | var reply = JSON.parse(transport.responseText); | |
1744 | ||
1745 | var r = reply['content']; | |
1746 | var mode = reply['mode']; | |
be2f5e1a | 1747 | |
11b9d0be | 1748 | if (c && r) { |
4a16bda3 | 1749 | c.innerHTML = r; |
11b9d0be | 1750 | } |
be2f5e1a | 1751 | |
11b9d0be | 1752 | dojo.parser.parse("browseFeedList"); |
be2f5e1a | 1753 | |
4a16bda3 | 1754 | if (mode == 2) { |
11b9d0be AD |
1755 | Element.show(dijit.byId('feed_archive_remove').domNode); |
1756 | } else { | |
1757 | Element.hide(dijit.byId('feed_archive_remove').domNode); | |
1758 | } | |
be2f5e1a | 1759 | |
11b9d0be AD |
1760 | } }); |
1761 | }, | |
1762 | removeFromArchive: function() { | |
943de334 | 1763 | var selected = this.getSelectedFeedIds(); |
be2f5e1a | 1764 | |
11b9d0be | 1765 | if (selected.length > 0) { |
be2f5e1a | 1766 | |
11b9d0be | 1767 | var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); |
be2f5e1a | 1768 | |
11b9d0be AD |
1769 | if (confirm(pr)) { |
1770 | Element.show('feed_browser_spinner'); | |
be2f5e1a | 1771 | |
10534e86 | 1772 | var query = "?op=rpc&method=remarchive&ids=" + |
11b9d0be | 1773 | param_escape(selected.toString());; |
be2f5e1a | 1774 | |
11b9d0be AD |
1775 | new Ajax.Request("backend.php", { |
1776 | parameters: query, | |
be2f5e1a | 1777 | onComplete: function(transport) { |
11b9d0be | 1778 | dialog.update(); |
be2f5e1a | 1779 | } }); |
11b9d0be AD |
1780 | } |
1781 | } | |
1782 | }, | |
1783 | execute: function() { | |
1784 | if (this.validate()) { | |
1785 | this.subscribe(); | |
1786 | } | |
1787 | }, | |
1788 | href: query}); | |
1789 | ||
1790 | dialog.show(); | |
1791 | ||
1792 | } catch (e) { | |
1793 | exception_error("editFeed", e); | |
1794 | } | |
1795 | } | |
1796 | ||
e57e73ef AD |
1797 | function showFeedsWithErrors() { |
1798 | try { | |
bc6fa236 | 1799 | var query = "backend.php?op=pref-feeds&method=feedsWithErrors"; |
e57e73ef AD |
1800 | |
1801 | if (dijit.byId("errorFeedsDlg")) | |
1802 | dijit.byId("errorFeedsDlg").destroyRecursive(); | |
1803 | ||
1804 | dialog = new dijit.Dialog({ | |
1805 | id: "errorFeedsDlg", | |
1806 | title: __("Feeds with update errors"), | |
1807 | style: "width: 600px", | |
1808 | getSelectedFeeds: function() { | |
1809 | return getSelectedTableRowIds("prefErrorFeedList"); | |
1810 | }, | |
1811 | removeSelected: function() { | |
1812 | var sel_rows = this.getSelectedFeeds(); | |
1813 | ||
1814 | console.log(sel_rows); | |
1815 | ||
1816 | if (sel_rows.length > 0) { | |
1817 | var ok = confirm(__("Remove selected feeds?")); | |
1818 | ||
1819 | if (ok) { | |
1820 | notify_progress("Removing selected feeds...", true); | |
1821 | ||
f30ef1fa | 1822 | var query = "?op=pref-feeds&method=remove&ids="+ |
e57e73ef AD |
1823 | param_escape(sel_rows.toString()); |
1824 | ||
1825 | new Ajax.Request("backend.php", { | |
1826 | parameters: query, | |
1827 | onComplete: function(transport) { | |
1828 | notify(''); | |
1829 | dialog.hide(); | |
1830 | updateFeedList(); | |
1831 | } }); | |
1832 | } | |
1833 | ||
1834 | } else { | |
1835 | alert(__("No feeds are selected.")); | |
1836 | } | |
1837 | }, | |
1838 | execute: function() { | |
1839 | if (this.validate()) { | |
1840 | } | |
1841 | }, | |
1842 | href: query}); | |
1843 | ||
1844 | dialog.show(); | |
1845 | ||
1846 | } catch (e) { | |
1847 | exception_error("showFeedsWithErrors", e); | |
1848 | } | |
1849 | ||
1850 | } | |
1851 | ||
147f5632 | 1852 | /* new support functions for SelectByTag */ |
f9c388f5 | 1853 | |
147f5632 CM |
1854 | function get_all_tags(selObj){ |
1855 | try { | |
1856 | if( !selObj ) return ""; | |
1857 | ||
1858 | var result = ""; | |
1859 | var len = selObj.options.length; | |
1860 | ||
1861 | for (var i=0; i < len; i++){ | |
1862 | if (selObj.options[i].selected) { | |
1863 | result += selObj[i].value + "%2C"; // is really a comma | |
1864 | } | |
1865 | } | |
1866 | ||
1867 | if (result.length > 0){ | |
1868 | result = result.substr(0, result.length-3); // remove trailing %2C | |
1869 | } | |
1870 | ||
1871 | return(result); | |
1872 | ||
1873 | } catch (e) { | |
1874 | exception_error("get_all_tags", e); | |
1875 | } | |
1876 | } | |
1877 | ||
1878 | function get_radio_checked(radioObj) { | |
1879 | try { | |
1880 | if (!radioObj) return ""; | |
1881 | ||
1882 | var len = radioObj.length; | |
1883 | ||
1884 | if (len == undefined){ | |
1885 | if(radioObj.checked){ | |
1886 | return(radioObj.value); | |
1887 | } else { | |
1888 | return(""); | |
1889 | } | |
1890 | } | |
1891 | ||
1892 | for( var i=0; i < len; i++ ){ | |
1893 | if( radioObj[i].checked ){ | |
1894 | return( radioObj[i].value); | |
1895 | } | |
1896 | } | |
1897 | ||
1898 | } catch (e) { | |
1899 | exception_error("get_radio_checked", e); | |
1900 | } | |
1901 | return(""); | |
1902 | } | |
4d5eed55 AD |
1903 | |
1904 | function get_timestamp() { | |
1905 | var date = new Date(); | |
1906 | return Math.round(date.getTime() / 1000); | |
1907 | } | |
b8cb4d08 AD |
1908 | |
1909 | function helpDialog(topic) { | |
1910 | try { | |
1911 | var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); | |
1912 | ||
1913 | if (dijit.byId("helpDlg")) | |
1914 | dijit.byId("helpDlg").destroyRecursive(); | |
1915 | ||
1916 | dialog = new dijit.Dialog({ | |
1917 | id: "helpDlg", | |
1918 | title: __("Help"), | |
1919 | style: "width: 600px", | |
1920 | href: query, | |
1921 | }); | |
1922 | ||
1923 | dialog.show(); | |
1924 | ||
1925 | } catch (e) { | |
1926 | exception_error("helpDialog", e); | |
1927 | } | |
1928 | } | |
1929 | ||
f0540b59 AD |
1930 | function htmlspecialchars_decode (string, quote_style) { |
1931 | // http://kevin.vanzonneveld.net | |
1932 | // + original by: Mirek Slugen | |
1933 | // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
1934 | // + bugfixed by: Mateusz "loonquawl" Zalega | |
1935 | // + input by: ReverseSyntax | |
1936 | // + input by: Slawomir Kaniecki | |
1937 | // + input by: Scott Cariss | |
1938 | // + input by: Francois | |
1939 | // + bugfixed by: Onno Marsman | |
1940 | // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
1941 | // + bugfixed by: Brett Zamir (http://brett-zamir.me) | |
1942 | // + input by: Ratheous | |
1943 | // + input by: Mailfaker (http://www.weedem.fr/) | |
1944 | // + reimplemented by: Brett Zamir (http://brett-zamir.me) | |
1945 | // + bugfixed by: Brett Zamir (http://brett-zamir.me) | |
1946 | // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES'); | |
1947 | // * returns 1: '<p>this -> "</p>' | |
1948 | // * example 2: htmlspecialchars_decode("&quot;"); | |
1949 | // * returns 2: '"' | |
1950 | var optTemp = 0, | |
1951 | i = 0, | |
1952 | noquotes = false; | |
1953 | if (typeof quote_style === 'undefined') { | |
1954 | quote_style = 2; | |
1955 | } | |
1956 | string = string.toString().replace(/</g, '<').replace(/>/g, '>'); | |
1957 | var OPTS = { | |
1958 | 'ENT_NOQUOTES': 0, | |
1959 | 'ENT_HTML_QUOTE_SINGLE': 1, | |
1960 | 'ENT_HTML_QUOTE_DOUBLE': 2, | |
1961 | 'ENT_COMPAT': 2, | |
1962 | 'ENT_QUOTES': 3, | |
1963 | 'ENT_IGNORE': 4 | |
1964 | }; | |
1965 | if (quote_style === 0) { | |
1966 | noquotes = true; | |
1967 | } | |
1968 | if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags | |
1969 | quote_style = [].concat(quote_style); | |
1970 | for (i = 0; i < quote_style.length; i++) { | |
1971 | // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4 | |
1972 | if (OPTS[quote_style[i]] === 0) { | |
1973 | noquotes = true; | |
1974 | } else if (OPTS[quote_style[i]]) { | |
1975 | optTemp = optTemp | OPTS[quote_style[i]]; | |
1976 | } | |
1977 | } | |
1978 | quote_style = optTemp; | |
1979 | } | |
1980 | if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) { | |
1981 | string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should | |
1982 | // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP | |
1983 | } | |
1984 | if (!noquotes) { | |
1985 | string = string.replace(/"/g, '"'); | |
1986 | } | |
1987 | // Put this in last place to avoid escape being double-decoded | |
1988 | string = string.replace(/&/g, '&'); | |
1989 | ||
1990 | return string; | |
1991 | } | |
f822a8e5 AD |
1992 | |
1993 | ||
1994 | function label_to_feed_id(label) { | |
1995 | return _label_base_index - 1 - Math.abs(label); | |
1996 | } | |
1997 | ||
1998 | function feed_to_label_id(feed) { | |
1999 | return _label_base_index - 1 + Math.abs(feed); | |
2000 | } | |
2001 |