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