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