]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var notify_silent
= false;
2 var loading_progress
= 0;
3 var sanity_check_done
= false;
5 /* add method to remove element from array */
7 Array
.prototype.remove = function(s
) {
8 for (var i
=0; i
< this.length
; i
++) {
9 if (s
== this[i
]) this.splice(i
, 1);
13 /* create console.log if it doesn't exist */
15 if (!window
.console
) console
= {};
16 console
.log
= console
.log
|| function(msg
) { };
17 console
.warn
= console
.warn
|| function(msg
) { };
18 console
.error
= console
.error
|| function(msg
) { };
20 function exception_error(location
, e
, ext_info
) {
21 var msg
= format_exception_error(location
, e
);
23 if (!ext_info
) ext_info
= false;
28 if (ext_info
.responseText
) {
29 ext_info
= ext_info
.responseText
;
33 var content
= "<div class=\"fatalError\">" +
34 "<pre>" + msg
+ "</pre>";
37 content
+= "<div><b>Additional information:</b></div>" +
38 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
41 content
+= "<div><b>Stack trace:</b></div>" +
42 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
44 // content += "<div style='text-align : center'>" +
45 // "<button onclick=\"closeInfoBox()\">" +
46 // "Close this window" + "</button></div>";
50 // TODO: add code to automatically report errors to tt-rss.org
52 var dialog
= new dijit
.Dialog({
53 title
: "Unhandled exception",
54 style
: "width: 600px",
65 function format_exception_error(location
, e
) {
69 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
71 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
72 "\nFunction: " + location
+ "()" +
73 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
75 } else if (e
.description
) {
76 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
78 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
81 console
.error("EXCEPTION: " + msg
);
86 function param_escape(arg
) {
87 if (typeof encodeURIComponent
!= 'undefined')
88 return encodeURIComponent(arg
);
93 function param_unescape(arg
) {
94 if (typeof decodeURIComponent
!= 'undefined')
95 return decodeURIComponent(arg
);
100 var notify_hide_timerid
= false;
102 function hide_notify() {
105 n
.style
.display
= "none";
109 function notify_silent_next() {
110 notify_silent
= true;
113 function notify_real(msg
, no_hide
, n_type
) {
116 notify_silent
= false;
121 var nb
= $("notify_body");
123 if (!n
|| !nb
) return;
125 if (notify_hide_timerid
) {
126 window
.clearTimeout(notify_hide_timerid
);
130 if (n
.style
.display
== "block") {
131 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
135 n
.style
.display
= "block";
147 if (typeof __
!= 'undefined') {
152 n
.className
= "notify";
153 } else if (n_type
== 2) {
154 n
.className
= "notifyProgress";
155 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
156 } else if (n_type
== 3) {
157 n
.className
= "notifyError";
158 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
159 } else if (n_type
== 4) {
160 n
.className
= "notifyInfo";
161 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
164 // msg = "<img src='images/live_com_loading.gif'> " + msg;
169 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
173 function notify(msg
, no_hide
) {
174 notify_real(msg
, no_hide
, 1);
177 function notify_progress(msg
, no_hide
) {
178 notify_real(msg
, no_hide
, 2);
181 function notify_error(msg
, no_hide
) {
182 notify_real(msg
, no_hide
, 3);
186 function notify_info(msg
, no_hide
) {
187 notify_real(msg
, no_hide
, 4);
190 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
196 d
.setTime(d
.getTime() + (lifetime
* 1000));
199 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
201 int_setCookie(name
, value
, d
, path
, domain
, secure
);
205 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
206 document
.cookie
= name
+ "=" + escape(value
) +
207 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
208 ((path
) ? "; path=" + path
: "") +
209 ((domain
) ? "; domain=" + domain
: "") +
210 ((secure
) ? "; secure" : "");
213 function delCookie(name
, path
, domain
) {
214 if (getCookie(name
)) {
215 document
.cookie
= name
+ "=" +
216 ((path
) ? ";path=" + path
: "") +
217 ((domain
) ? ";domain=" + domain
: "" ) +
218 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
223 function getCookie(name
) {
225 var dc
= document
.cookie
;
226 var prefix
= name
+ "=";
227 var begin
= dc
.indexOf("; " + prefix
);
229 begin
= dc
.indexOf(prefix
);
230 if (begin
!= 0) return null;
235 var end
= document
.cookie
.indexOf(";", begin
);
239 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
242 function gotoPreferences() {
243 document
.location
.href
= "prefs.php";
246 function gotoMain() {
247 document
.location
.href
= "tt-rss.php";
250 function gotoExportOpml() {
251 document
.location
.href
= "opml.php?op=Export";
255 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
256 * * @author Sundar Dorai-Raj
257 * * Email: sdoraira@vt.edu
258 * * This program is free software; you can redistribute it and/or
259 * * modify it under the terms of the GNU General Public License
260 * * as published by the Free Software Foundation; either version 2
261 * * of the License, or (at your option) any later version,
262 * * provided that any use properly credits the author.
263 * * This program is distributed in the hope that it will be useful,
264 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
265 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
266 * * GNU General Public License for more details at http://www.gnu.org * * */
268 var numbers
=".0123456789";
269 function isNumeric(x
) {
270 // is x a String or a character?
272 // remove negative sign
274 for(j
=0;j
<x
.length
;j
++) {
275 // call isNumeric recursively for each character
276 number
=isNumeric(x
.substring(j
,j
+1));
277 if(!number
) return number
;
282 // if x is number return true
283 if(numbers
.indexOf(x
)>=0) return true;
289 function toggleSelectRowById(sender
, id
) {
291 return toggleSelectRow(sender
, row
);
294 function toggleSelectListRow(sender
) {
295 var row
= sender
.parentNode
;
296 return toggleSelectRow(sender
, row
);
299 /* this is for dijit Checkbox */
300 function toggleSelectListRow2(sender
) {
301 var row
= sender
.domNode
.parentNode
;
302 return toggleSelectRow(sender
, row
);
305 function tSR(sender
, row
) {
306 return toggleSelectRow(sender
, row
);
309 /* this is for dijit Checkbox */
310 function toggleSelectRow2(sender
, row
) {
312 if (!row
) row
= sender
.domNode
.parentNode
.parentNode
;
314 if (sender
.checked
&& !row
.hasClassName('Selected'))
315 row
.addClassName('Selected');
317 row
.removeClassName('Selected');
321 function toggleSelectRow(sender
, row
) {
323 if (!row
) row
= sender
.parentNode
.parentNode
;
325 if (sender
.checked
&& !row
.hasClassName('Selected'))
326 row
.addClassName('Selected');
328 row
.removeClassName('Selected');
331 function checkboxToggleElement(elem
, id
) {
333 Effect
.Appear(id
, {duration
: 0.5});
335 Effect
.Fade(id
, {duration
: 0.5});
339 function dropboxSelect(e
, v
) {
340 for (i
= 0; i
< e
.length
; i
++) {
341 if (e
[i
].value
== v
) {
348 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
349 // bugfixed just a little bit :-)
350 function getURLParam(strParamName
){
352 var strHref
= window
.location
.href
;
354 if (strHref
.indexOf("#") == strHref
.length
-1) {
355 strHref
= strHref
.substring(0, strHref
.length
-1);
358 if ( strHref
.indexOf("?") > -1 ){
359 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
360 var aQueryString
= strQueryString
.split("&");
361 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
362 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
363 var aParam
= aQueryString
[iParam
].split("=");
364 strReturn
= aParam
[1];
372 function leading_zero(p
) {
374 if (s
.length
== 1) s
= "0" + s
;
378 function make_timestamp() {
381 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
382 ":" + leading_zero(d
.getSeconds());
386 function closeErrorBox() {
388 if (Element
.visible("errorBoxShadow")) {
389 Element
.hide("dialog_overlay");
390 Element
.hide("errorBoxShadow");
396 function closeInfoBox(cleanup
) {
398 dialog
= dijit
.byId("infoBox");
400 if (dialog
) dialog
.hide();
403 //exception_error("closeInfoBox", e);
409 function displayDlg(id
, param
, callback
) {
411 notify_progress("Loading, please wait...", true);
413 var query
= "?op=dlg&id=" +
414 param_escape(id
) + "¶m=" + param_escape(param
);
416 new Ajax
.Request("backend.php", {
418 onComplete: function (transport
) {
419 infobox_callback2(transport
);
420 if (callback
) callback(transport
);
426 function infobox_submit_callback2(transport
) {
430 // called from prefs, reload tab
431 if (typeof active_tab
!= 'undefined' && active_tab
) {
432 selectTab(active_tab
, false);
436 if (transport
.responseText
) {
437 notify_info(transport
.responseText
);
441 function infobox_callback2(transport
) {
445 if (dijit
.byId("infoBox")) {
446 dialog
= dijit
.byId("infoBox");
449 //console.log("infobox_callback2");
453 var dtitle
= "Dialog";
455 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
457 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
459 title
= title
.firstChild
.nodeValue
;
461 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
463 content
= content
.firstChild
.nodeValue
;
466 dialog
= new dijit
.Dialog({
469 style
: "width: 600px",
470 onCancel: function() {
473 onExecute: function() {
476 onClose: function() {
481 dialog
.attr('title', title
);
482 dialog
.attr('content', content
);
489 exception_error("infobox_callback2", e
);
493 function createFilter() {
497 var form
= document
.forms
['filter_add_form'];
498 var reg_exp
= form
.reg_exp
.value
;
501 alert(__("Can't add filter: nothing to match on."));
505 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
507 notify_progress("Verifying regular expression...");
509 new Ajax
.Request("backend.php", {
511 onComplete: function(transport
) {
512 handle_rpc_reply(transport
);
514 var response
= transport
.responseXML
;
517 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
521 if (s
== "INVALID") {
522 alert("Match regular expression seems to be invalid.");
526 var query
= Form
.serialize("filter_add_form");
528 // we can be called from some other tab in Prefs
529 if (typeof active_tab
!= 'undefined' && active_tab
) {
530 active_tab
= "filterConfig";
533 new Ajax
.Request("backend.php?" + query
, {
534 onComplete: function (transport
) {
535 infobox_submit_callback2(transport
);
545 exception_error("createFilter", e
);
549 function filterCR(e
, f
)
554 key
= window
.event
.keyCode
; //IE
556 key
= e
.which
; //firefox
559 if (typeof f
!= 'undefined') {
570 function getInitParam(key
) {
571 return init_params
[key
];
574 function setInitParam(key
, value
) {
575 init_params
[key
] = value
;
578 function fatalError(code
, msg
, ext_info
) {
581 if (!ext_info
) ext_info
= "N/A";
584 window
.location
.href
= "tt-rss.php";
585 } else if (code
== 5) {
586 window
.location
.href
= "db-updater.php";
589 if (msg
== "") msg
= "Unknown error";
591 var ebc
= $("xebContent");
595 Element
.show("dialog_overlay");
596 Element
.show("errorBoxShadow");
597 Element
.hide("xebBtn");
600 if (ext_info
.responseText
) {
601 ext_info
= ext_info
.responseText
;
606 "<div><b>Error message:</b></div>" +
607 "<pre>" + msg
+ "</pre>" +
608 "<div><b>Additional information:</b></div>" +
609 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
614 exception_error("fatalError", e
);
618 function filterDlgCheckType(sender
) {
622 var ftype
= sender
.value
;
624 // if selected filter type is 5 (Date) enable the modifier dropbox
626 Element
.show("filterDlg_dateModBox");
627 Element
.show("filterDlg_dateChkBox");
629 Element
.hide("filterDlg_dateModBox");
630 Element
.hide("filterDlg_dateChkBox");
635 exception_error("filterDlgCheckType", e
);
640 function filterDlgCheckAction(sender
) {
644 var action
= sender
.value
;
646 var action_param
= $("filterDlg_paramBox");
649 console
.log("filterDlgCheckAction: can't find action param box!");
653 // if selected action supports parameters, enable params field
654 if (action
== 4 || action
== 6 || action
== 7) {
655 new Effect
.Appear(action_param
, {duration
: 0.5});
657 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
658 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
660 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
661 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
664 Element
.hide(action_param
);
668 exception_error("filterDlgCheckAction", e
);
673 function filterDlgCheckDate() {
675 var dialog
= dijit
.byId("filterEditDlg");
677 var reg_exp
= dialog
.attr('value').reg_exp
;
679 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
681 new Ajax
.Request("backend.php", {
683 onComplete: function(transport
) {
685 if (transport
.responseXML
) {
686 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
688 if (result
&& result
.firstChild
) {
689 if (result
.firstChild
.nodeValue
== "1") {
690 alert(__("Date syntax appears to be correct."));
696 alert(__("Date syntax is incorrect."));
702 exception_error("filterDlgCheckDate", e
);
706 function explainError(code
) {
707 return displayDlg("explainError", code
);
710 function displayHelpInfobox(topic_id
) {
712 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
714 var w
= window
.open(url
, "ttrss_help",
715 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
719 function loading_set_progress(p
) {
721 loading_progress
+= p
;
723 if (dijit
.byId("loading_bar"))
724 dijit
.byId("loading_bar").update({progress
: loading_progress
});
726 if (loading_progress
>= 90)
730 exception_error("loading_set_progress", e
);
734 function remove_splash() {
736 if (Element
.visible("overlay")) {
737 console
.log("about to remove splash, OMG!");
738 Element
.hide("overlay");
739 console
.log("removed splash!");
743 /* function getSelectedFeedsFromBrowser() {
745 var list = $$("#browseFeedList li[id*=FBROW]");
747 var selected = new Array();
749 list.each(function(child) {
750 var id = child.id.replace("FBROW-", "");
752 if (child.hasClassName('Selected')) {
761 function transport_error_check(transport
) {
763 if (transport
.responseXML
) {
764 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
767 var code
= error
.getAttribute("error-code");
768 var msg
= error
.getAttribute("error-msg");
770 fatalError(code
, msg
);
776 exception_error("check_for_error_xml", e
);
781 function strip_tags(s
) {
782 return s
.replace(/<\/?[^>]+(>|$)/g, "");
785 function truncate_string(s
, length
) {
786 if (!length
) length
= 30;
787 var tmp
= s
.substring(0, length
);
788 if (s
.length
> length
) tmp
+= "…";
792 function hotkey_prefix_timeout() {
795 var date
= new Date();
796 var ts
= Math
.round(date
.getTime() / 1000);
798 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
799 console
.log("hotkey_prefix seems to be stuck, aborting");
800 hotkey_prefix_pressed
= false;
801 hotkey_prefix
= false;
802 Element
.hide('cmdline');
805 setTimeout("hotkey_prefix_timeout()", 1000);
808 exception_error("hotkey_prefix_timeout", e
);
812 function hideAuxDlg() {
814 Element
.hide('auxDlg');
816 exception_error("hideAuxDlg", e
);
821 function uploadIconHandler(rc
) {
825 notify_info("Upload complete.");
826 if (inPreferences()) {
829 setTimeout('updateFeedList(false, false)', 50);
833 notify_error("Upload failed: icon is too big.");
836 notify_error("Upload failed.");
841 exception_error("uploadIconHandler", e
);
845 function removeFeedIcon(id
) {
849 if (confirm(__("Remove stored feed icon?"))) {
850 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
854 notify_progress("Removing feed icon...", true);
856 new Ajax
.Request("backend.php", {
858 onComplete: function(transport
) {
859 notify_info("Feed icon removed.");
860 if (inPreferences()) {
863 setTimeout('updateFeedList(false, false)', 50);
870 exception_error("uploadFeedIcon", e
);
874 function uploadFeedIcon() {
878 var file
= $("icon_file");
880 if (file
.value
.length
== 0) {
881 alert(__("Please select an image file to upload."));
883 if (confirm(__("Upload new icon for this feed?"))) {
884 notify_progress("Uploading, please wait...", true);
892 exception_error("uploadFeedIcon", e
);
896 function addLabel(select
, callback
) {
900 var caption
= prompt(__("Please enter label caption:"), "");
902 if (caption
!= undefined) {
905 alert(__("Can't create label: missing caption."));
909 var query
= "?op=pref-labels&subop=add&caption=" +
910 param_escape(caption
);
913 query
+= "&output=select";
915 notify_progress("Loading, please wait...", true);
917 if (inPreferences() && !select
) active_tab
= "labelConfig";
919 new Ajax
.Request("backend.php", {
921 onComplete: function(transport
) {
924 } else if (inPreferences()) {
925 infobox_submit_callback2(transport
);
934 exception_error("addLabel", e
);
938 function quickAddFeed() {
940 var query
= "backend.php?op=dlg&id=quickAddFeed";
942 if (dijit
.byId("feedAddDlg"))
943 dijit
.byId("feedAddDlg").destroyRecursive();
945 var dialog
= new dijit
.Dialog({
947 title
: __("Subscribe to Feed"),
948 style
: "width: 600px",
949 execute: function() {
950 if (this.validate()) {
951 console
.log(dojo
.objectToQuery(this.attr('value')));
953 var feed_url
= this.attr('value').feed
;
955 notify_progress(__("Subscribing to feed..."), true);
957 new Ajax
.Request("backend.php", {
958 parameters
: dojo
.objectToQuery(this.attr('value')),
959 onComplete: function(transport
) {
962 if (!transport
.responseXML
) {
963 console
.log(transport
.responseText
);
964 alert(__("Server error while trying to subscribe to specified feed."));
968 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
969 var rc
= parseInt(result
.getAttribute('code'));
973 console
.log("GOT RC: " + rc
);
978 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
980 if (inPreferences()) {
983 setTimeout('updateFeedList(false, false)', 50);
987 alert(__("Specified URL seems to be invalid."));
990 alert(__("Specified URL doesn't seem to contain any feeds."));
993 notify_progress("Searching for feed urls...", true);
995 new Ajax
.Request("backend.php", {
996 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url
),
997 onComplete: function(transport
, dialog
, feed_url
) {
999 if (!transport
.responseXML
) {
1000 console
.log(transport
.responseText
);
1001 alert(__("Server error while trying to query feed URLs."));
1007 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
1008 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
1010 console
.log(transport
.responseText
);
1012 var select
= dijit
.byId("feedDlg_feedContainerSelect");
1014 while (select
.getOptions().length
> 0)
1015 select
.removeOption(0);
1018 for (var feedUrl
in feeds
) {
1019 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
1023 // if (count > 5) count = 5;
1024 // select.size = count;
1026 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
1031 alert(__("Couldn't download the specified URL."));
1034 alert(__("You are already subscribed to this feed."));
1039 exception_error("subscribeToFeed", e
);
1050 exception_error("quickAddFeed", e
);
1054 function quickAddFilter() {
1056 var query
= "backend.php?op=dlg&id=quickAddFilter";
1058 if (dijit
.byId("filterEditDlg"))
1059 dijit
.byId("filterEditDlg").destroyRecursive();
1061 dialog
= new dijit
.Dialog({
1062 id
: "filterEditDlg",
1063 title
: __("Create Filter"),
1064 style
: "width: 600px",
1065 execute: function() {
1066 if (this.validate()) {
1068 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
1069 param_escape(dialog
.attr('value').reg_exp
);
1071 notify_progress("Verifying regular expression...");
1073 new Ajax
.Request("backend.php", {
1075 onComplete: function(transport
) {
1076 handle_rpc_reply(transport
);
1077 var response
= transport
.responseXML
;
1080 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
1084 if (s
== "INVALID") {
1085 alert("Match regular expression seems to be invalid.");
1088 notify_progress("Saving data...", true);
1090 console
.log(dojo
.objectToQuery(dialog
.attr('value')));
1092 new Ajax
.Request("backend.php", {
1093 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1094 onComplete: function(transport
) {
1096 notify_info(transport
.responseText
);
1097 if (inPreferences()) {
1110 exception_error("quickAddFilter", e
);
1114 function unsubscribeFeed(feed_id
, title
) {
1116 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1118 if (title
== undefined || confirm(msg
)) {
1119 notify_progress("Removing feed...");
1121 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1123 new Ajax
.Request("backend.php", {
1125 onComplete: function(transport
) {
1127 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1129 if (inPreferences()) {
1132 dlg_frefresh_callback(transport
, feed_id
);
1142 function backend_sanity_check_callback(transport
) {
1146 if (sanity_check_done
) {
1147 fatalError(11, "Sanity check request received twice. This can indicate "+
1148 "presence of Firebug or some other disrupting extension. "+
1149 "Please disable it and try again.");
1153 if (!transport
.responseXML
) {
1155 fatalError(3, "Sanity check: Received reply is not XML",
1156 transport
.responseText
);
1161 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1164 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1168 var error_code
= reply
.getAttribute("error-code");
1170 if (error_code
&& error_code
!= 0) {
1171 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1174 console
.log("sanity check ok");
1176 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1179 console
.log('reading init-params...');
1181 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1186 console
.log("IP: " + k
+ " => " + v
);
1190 init_params
= params
;
1193 sanity_check_done
= true;
1195 init_second_stage();
1198 exception_error("backend_sanity_check_callback", e
, transport
);
1202 function has_local_storage() {
1204 return 'sessionStorage' in window
&& window
['sessionStorage'] != null;
1210 function catSelectOnChange(elem
) {
1212 /* var value = elem[elem.selectedIndex].value;
1213 var def = elem.getAttribute('default');
1215 if (value == "ADD_CAT") {
1218 dropboxSelect(elem, def);
1220 elem.selectedIndex = 0;
1226 exception_error("catSelectOnChange", e
);
1230 function quickAddCat(elem
) {
1232 var cat
= prompt(__("Please enter category title:"));
1236 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1238 notify_progress("Loading, please wait...", true);
1240 new Ajax
.Request("backend.php", {
1242 onComplete: function (transport
) {
1243 var response
= transport
.responseXML
;
1244 var select
= response
.getElementsByTagName("select")[0];
1245 var options
= select
.getElementsByTagName("option");
1247 dropbox_replace_options(elem
, options
);
1256 exception_error("quickAddCat", e
);
1260 function genUrlChangeKey(feed
, is_cat
) {
1263 var ok
= confirm(__("Generate new syndication address for this feed?"));
1267 notify_progress("Trying to change address...", true);
1269 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1270 "&is_cat=" + param_escape(is_cat
);
1272 new Ajax
.Request("backend.php", {
1274 onComplete: function(transport
) {
1275 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1277 var e
= $('gen_feed_url');
1281 new_link
= new_link
.firstChild
.nodeValue
;
1283 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1284 "&key=" + new_link
);
1286 e
.href
= e
.href
.replace(/\&key=.*$/,
1287 "&key=" + new_link
);
1289 new Effect
.Highlight(e
);
1294 notify_error("Could not change feed URL.");
1299 exception_error("genUrlChangeKey", e
);
1304 function labelSelectOnChange(elem
) {
1306 /* var value = elem[elem.selectedIndex].value;
1307 var def = elem.getAttribute('default');
1309 if (value == "ADD_LABEL") {
1312 dropboxSelect(elem, def);
1314 elem.selectedIndex = 0;
1316 addLabel(elem, function(transport) {
1320 var response = transport.responseXML;
1321 var select = response.getElementsByTagName("select")[0];
1322 var options = select.getElementsByTagName("option");
1324 dropbox_replace_options(elem, options);
1328 exception_error("addLabel", e);
1334 exception_error("labelSelectOnChange", e
);
1338 function dropbox_replace_options(elem
, options
) {
1341 while (elem
.hasChildNodes())
1342 elem
.removeChild(elem
.firstChild
);
1346 for (var i
= 0; i
< options
.length
; i
++) {
1347 var text
= options
[i
].firstChild
.nodeValue
;
1348 var value
= options
[i
].getAttribute("value");
1350 if (value
== undefined) value
= text
;
1352 var issel
= options
[i
].getAttribute("selected") == "1";
1354 var option
= new Option(text
, value
, issel
);
1356 if (options
[i
].getAttribute("disabled"))
1357 option
.setAttribute("disabled", true);
1359 elem
.insert(option
);
1361 if (issel
) sel_idx
= i
;
1364 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1365 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1368 exception_error("dropbox_replace_options", e
);
1372 // mode = all, none, invert
1373 function selectTableRows(id
, mode
) {
1375 var rows
= $(id
).rows
;
1377 for (var i
= 0; i
< rows
.length
; i
++) {
1381 if (row
.id
&& row
.className
) {
1382 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1383 var inputs
= rows
[i
].getElementsByTagName("input");
1385 for (var j
= 0; j
< inputs
.length
; j
++) {
1386 var input
= inputs
[j
];
1388 if (input
.getAttribute("type") == "checkbox" &&
1389 input
.id
.match(bare_id
)) {
1397 var issel
= row
.hasClassName("Selected");
1399 if (mode
== "all" && !issel
) {
1400 row
.addClassName("Selected");
1402 } else if (mode
== "none" && issel
) {
1403 row
.removeClassName("Selected");
1405 } else if (mode
== "invert") {
1408 row
.removeClassName("Selected");
1411 row
.addClassName("Selected");
1420 exception_error("selectTableRows", e
);
1425 function getSelectedTableRowIds(id
) {
1429 var elem_rows
= $(id
).rows
;
1431 for (i
= 0; i
< elem_rows
.length
; i
++) {
1432 if (elem_rows
[i
].hasClassName("Selected")) {
1433 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1439 exception_error("getSelectedTableRowIds", e
);
1445 function editFeed(feed
, event
) {
1448 return alert(__("You can't edit this kind of feed."));
1450 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1455 if (dijit
.byId("feedEditDlg"))
1456 dijit
.byId("feedEditDlg").destroyRecursive();
1458 dialog
= new dijit
.Dialog({
1460 title
: __("Edit Feed"),
1461 style
: "width: 600px",
1462 execute: function() {
1463 if (this.validate()) {
1464 // console.log(dojo.objectToQuery(this.attr('value')));
1466 notify_progress("Saving data...", true);
1468 new Ajax
.Request("backend.php", {
1469 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1470 onComplete: function(transport
) {
1472 if (inPreferences()) {
1476 dlg_frefresh_callback(transport
);
1486 exception_error("editFeed", e
);
1490 function feedBrowser() {
1492 var query
= "backend.php?op=dlg&id=feedBrowser";
1494 if (dijit
.byId("feedAddDlg"))
1495 dijit
.byId("feedAddDlg").hide();
1497 if (dijit
.byId("feedBrowserDlg"))
1498 dijit
.byId("feedBrowserDlg").destroyRecursive();
1500 var dialog
= new dijit
.Dialog({
1501 id
: "feedBrowserDlg",
1502 title
: __("More Feeds"),
1503 style
: "width: 600px",
1504 getSelectedFeeds: function() {
1505 var list
= $$("#browseFeedList li[id*=FBROW]");
1506 var selected
= new Array();
1508 list
.each(function(child
) {
1509 var id
= child
.id
.replace("FBROW-", "");
1511 if (child
.hasClassName('Selected')) {
1518 subscribe: function() {
1519 var selected
= this.getSelectedFeeds();
1520 var mode
= this.attr('value').mode
;
1522 if (selected
.length
> 0) {
1523 dijit
.byId("feedBrowserDlg").hide();
1525 notify_progress("Loading, please wait...", true);
1527 var query
= "?op=rpc&subop=massSubscribe&ids="+
1528 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1532 new Ajax
.Request("backend.php", {
1534 onComplete: function(transport
) {
1536 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1537 var nf_value
= nf
.getAttribute("value");
1539 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1541 if (inPreferences()) {
1544 setTimeout('updateFeedList(false, false)', 50);
1549 alert(__("No feeds are selected."));
1553 update: function() {
1554 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1556 Element
.show('feed_browser_spinner');
1558 new Ajax
.Request("backend.php", {
1560 onComplete: function(transport
) {
1563 Element
.hide('feed_browser_spinner');
1565 var c
= $("browseFeedList");
1566 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
1567 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
1568 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
1571 c
.innerHTML
= r
.firstChild
.nodeValue
;
1574 dojo
.parser
.parse("browseFeedList");
1576 if (parseInt(mode
.getAttribute("value")) == 2) {
1577 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1579 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1584 removeFromArchive: function() {
1585 var selected
= this.getSelectedFeeds();
1587 if (selected
.length
> 0) {
1589 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1592 Element
.show('feed_browser_spinner');
1594 var query
= "?op=rpc&subop=remarchived&ids=" +
1595 param_escape(selected
.toString());;
1597 new Ajax
.Request("backend.php", {
1599 onComplete: function(transport
) {
1605 execute: function() {
1606 if (this.validate()) {
1615 exception_error("editFeed", e
);