]>
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>" ;
46 content
+= "<div class='dlgButtons'>" ;
48 content
+= "<button dojoType= \" dijit.form.Button \" " +
49 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
50 __ ( 'Report to tt-rss.org' ) + "</button> " ;
51 content
+= "<button dojoType= \" dijit.form.Button \" " +
52 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
53 __ ( 'Close' ) + "</button>" ;
57 var dialog
= new dijit
. Dialog ({
59 title
: "Unhandled exception" ,
60 style
: "width: 600px" ,
62 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." ))) {
68 browserName
: navigator
. appName
,
69 browserVersion
: navigator
. appVersion
,
70 browserPlatform
: navigator
. platform
,
71 browserCookies
: navigator
. cookieEnabled
,
74 var url
= "http://tt-rss.org/report.php?" + params
. toQueryString ();
90 function format_exception_error ( location
, e
) {
94 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
96 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
97 " \n Function: " + location
+ "()" +
98 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
100 } else if ( e
. description
) {
101 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
103 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
106 console
. error ( "EXCEPTION: " + msg
);
111 function param_escape ( arg
) {
112 if ( typeof encodeURIComponent
!= 'undefined' )
113 return encodeURIComponent ( arg
);
118 function param_unescape ( arg
) {
119 if ( typeof decodeURIComponent
!= 'undefined' )
120 return decodeURIComponent ( arg
);
122 return unescape ( arg
);
125 var notify_hide_timerid
= false ;
127 function hide_notify () {
130 n
. style
. display
= "none" ;
134 function notify_silent_next () {
135 notify_silent
= true ;
138 function notify_real ( msg
, no_hide
, n_type
) {
141 notify_silent
= false ;
146 var nb
= $( "notify_body" );
148 if (! n
|| ! nb
) return ;
150 if ( notify_hide_timerid
) {
151 window
. clearTimeout ( notify_hide_timerid
);
155 if ( n
. style
. display
== "block" ) {
156 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
160 n
. style
. display
= "block" ;
172 if ( typeof __
!= 'undefined' ) {
177 n
. className
= "notify" ;
178 } else if ( n_type
== 2 ) {
179 n
. className
= "notifyProgress" ;
180 msg
= "<img src='" + getInitParam ( "sign_progress" )+ "'> " + msg
;
181 } else if ( n_type
== 3 ) {
182 n
. className
= "notifyError" ;
183 msg
= "<img src='" + getInitParam ( "sign_excl" )+ "'> " + msg
;
184 } else if ( n_type
== 4 ) {
185 n
. className
= "notifyInfo" ;
186 msg
= "<img src='" + getInitParam ( "sign_info" )+ "'> " + msg
;
189 // msg = "<img src='images/live_com_loading.gif'> " + msg;
194 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 3000 );
198 function notify ( msg
, no_hide
) {
199 notify_real ( msg
, no_hide
, 1 );
202 function notify_progress ( msg
, no_hide
) {
203 notify_real ( msg
, no_hide
, 2 );
206 function notify_error ( msg
, no_hide
) {
207 notify_real ( msg
, no_hide
, 3 );
211 function notify_info ( msg
, no_hide
) {
212 notify_real ( msg
, no_hide
, 4 );
215 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
221 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
224 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
226 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
230 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
231 document
. cookie
= name
+ "=" + escape ( value
) +
232 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
233 (( path
) ? "; path=" + path
: "" ) +
234 (( domain
) ? "; domain=" + domain
: "" ) +
235 (( secure
) ? "; secure" : "" );
238 function delCookie ( name
, path
, domain
) {
239 if ( getCookie ( name
)) {
240 document
. cookie
= name
+ "=" +
241 (( path
) ? ";path=" + path
: "" ) +
242 (( domain
) ? ";domain=" + domain
: "" ) +
243 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
248 function getCookie ( name
) {
250 var dc
= document
. cookie
;
251 var prefix
= name
+ "=" ;
252 var begin
= dc
. indexOf ( "; " + prefix
);
254 begin
= dc
. indexOf ( prefix
);
255 if ( begin
!= 0 ) return null ;
260 var end
= document
. cookie
. indexOf ( ";" , begin
);
264 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
267 function gotoPreferences () {
268 document
. location
. href
= "prefs.php" ;
271 function gotoMain () {
272 document
. location
. href
= "tt-rss.php" ;
275 function gotoExportOpml () {
276 document
. location
. href
= "opml.php?op=Export" ;
280 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
281 * * @author Sundar Dorai-Raj
282 * * Email: sdoraira@vt.edu
283 * * This program is free software; you can redistribute it and/or
284 * * modify it under the terms of the GNU General Public License
285 * * as published by the Free Software Foundation; either version 2
286 * * of the License, or (at your option) any later version,
287 * * provided that any use properly credits the author.
288 * * This program is distributed in the hope that it will be useful,
289 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
290 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
291 * * GNU General Public License for more details at http://www.gnu.org * * */
293 var numbers
= ".0123456789" ;
294 function isNumeric ( x
) {
295 // is x a String or a character?
297 // remove negative sign
299 for ( j
= 0 ; j
< x
. length
; j
++) {
300 // call isNumeric recursively for each character
301 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
302 if (! number
) return number
;
307 // if x is number return true
308 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
314 function toggleSelectRowById ( sender
, id
) {
316 return toggleSelectRow ( sender
, row
);
319 function toggleSelectListRow ( sender
) {
320 var row
= sender
. parentNode
;
321 return toggleSelectRow ( sender
, row
);
324 /* this is for dijit Checkbox */
325 function toggleSelectListRow2 ( sender
) {
326 var row
= sender
. domNode
. parentNode
;
327 return toggleSelectRow ( sender
, row
);
330 function tSR ( sender
, row
) {
331 return toggleSelectRow ( sender
, row
);
334 /* this is for dijit Checkbox */
335 function toggleSelectRow2 ( sender
, row
) {
337 if (! row
) row
= sender
. domNode
. parentNode
. parentNode
;
339 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
340 row
. addClassName ( 'Selected' );
342 row
. removeClassName ( 'Selected' );
346 function toggleSelectRow ( sender
, row
) {
348 if (! row
) row
= sender
. parentNode
. parentNode
;
350 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
351 row
. addClassName ( 'Selected' );
353 row
. removeClassName ( 'Selected' );
356 function checkboxToggleElement ( elem
, id
) {
358 Effect
. Appear ( id
, { duration
: 0.5 });
360 Effect
. Fade ( id
, { duration
: 0.5 });
364 function dropboxSelect ( e
, v
) {
365 for ( i
= 0 ; i
< e
. length
; i
++) {
366 if ( e
[ i
]. value
== v
) {
373 function getURLParam ( param
){
374 return String ( window
. location
. href
). parseQuery ()[ param
];
377 function leading_zero ( p
) {
379 if ( s
. length
== 1 ) s
= "0" + s
;
383 function make_timestamp () {
386 return leading_zero ( d
. getHours ()) + ":" + leading_zero ( d
. getMinutes ()) +
387 ":" + leading_zero ( d
. getSeconds ());
391 function closeErrorBox () {
393 if ( Element
. visible ( "errorBoxShadow" )) {
394 Element
. hide ( "dialog_overlay" );
395 Element
. hide ( "errorBoxShadow" );
401 function closeInfoBox ( cleanup
) {
403 dialog
= dijit
. byId ( "infoBox" );
405 if ( dialog
) dialog
. hide ();
408 //exception_error("closeInfoBox", e);
414 function displayDlg ( id
, param
, callback
) {
416 notify_progress ( "Loading, please wait..." , true );
418 var query
= "?op=dlg&id=" +
419 param_escape ( id
) + "¶m=" + param_escape ( param
);
421 new Ajax
. Request ( "backend.php" , {
423 onComplete : function ( transport
) {
424 infobox_callback2 ( transport
);
425 if ( callback
) callback ( transport
);
431 function infobox_callback2 ( transport
) {
435 if ( dijit
. byId ( "infoBox" )) {
436 dialog
= dijit
. byId ( "infoBox" );
439 //console.log("infobox_callback2");
443 var dtitle
= "Dialog" ;
445 var dlg
= transport
. responseXML
. getElementsByTagName ( "dlg" )[ 0 ];
447 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
449 title
= title
. firstChild
. nodeValue
;
451 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
453 content
= content
. firstChild
. nodeValue
;
456 dialog
= new dijit
. Dialog ({
459 style
: "width: 600px" ,
460 onCancel : function () {
463 onExecute : function () {
466 onClose : function () {
471 dialog
. attr ( 'title' , title
);
472 dialog
. attr ( 'content' , content
);
479 exception_error ( "infobox_callback2" , e
);
483 function filterCR ( e
, f
)
488 key
= window
. event
. keyCode
; //IE
490 key
= e
. which
; //firefox
493 if ( typeof f
!= 'undefined' ) {
504 function getInitParam ( key
) {
505 return init_params
[ key
];
508 function setInitParam ( key
, value
) {
509 init_params
[ key
] = value
;
512 function fatalError ( code
, msg
, ext_info
) {
516 window
. location
. href
= "tt-rss.php" ;
517 } else if ( code
== 5 ) {
518 window
. location
. href
= "db-updater.php" ;
521 if ( msg
== "" ) msg
= "Unknown error" ;
524 if ( ext_info
. responseText
) {
525 ext_info
= ext_info
. responseText
;
529 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
533 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
534 "<p>" + msg
+ "</p>" ;
537 content
= content
+ "<div><b>Additional information:</b></div>" +
538 "<textarea style='width: 100%' readonly= \" 1 \" >" +
539 ext_info
+ "</textarea>" ;
542 var dialog
= new dijit
. Dialog ({
543 title
: "Fatal error" ,
544 style
: "width: 600px" ,
554 exception_error ( "fatalError" , e
);
558 function filterDlgCheckType ( sender
) {
562 var ftype
= sender
. value
;
564 // if selected filter type is 5 (Date) enable the modifier dropbox
566 Element
. show ( "filterDlg_dateModBox" );
567 Element
. show ( "filterDlg_dateChkBox" );
569 Element
. hide ( "filterDlg_dateModBox" );
570 Element
. hide ( "filterDlg_dateChkBox" );
575 exception_error ( "filterDlgCheckType" , e
);
580 function filterDlgCheckAction ( sender
) {
584 var action
= sender
. value
;
586 var action_param
= $( "filterDlg_paramBox" );
589 console
. log ( "filterDlgCheckAction: can't find action param box!" );
593 // if selected action supports parameters, enable params field
594 if ( action
== 4 || action
== 6 || action
== 7 ) {
595 new Effect
. Appear ( action_param
, { duration
: 0.5 });
597 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
598 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
600 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
601 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
604 Element
. hide ( action_param
);
608 exception_error ( "filterDlgCheckAction" , e
);
613 function filterDlgCheckDate () {
615 var dialog
= dijit
. byId ( "filterEditDlg" );
617 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
619 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
621 new Ajax
. Request ( "backend.php" , {
623 onComplete : function ( transport
) {
625 var reply
= JSON
. parse ( transport
. responseText
);
627 if ( reply
[ 'result' ] == true ) {
628 alert ( __ ( "Date syntax appears to be correct." ));
631 alert ( __ ( "Date syntax is incorrect." ));
638 exception_error ( "filterDlgCheckDate" , e
);
642 function explainError ( code
) {
643 return displayDlg ( "explainError" , code
);
646 function displayHelpInfobox ( topic_id
) {
648 var url
= "backend.php?op=help&tid=" + param_escape ( topic_id
);
650 var w
= window
. open ( url
, "ttrss_help" ,
651 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0" );
655 function loading_set_progress ( p
) {
657 loading_progress
+= p
;
659 if ( dijit
. byId ( "loading_bar" ))
660 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
662 if ( loading_progress
>= 90 )
666 exception_error ( "loading_set_progress" , e
);
670 function remove_splash () {
672 if ( Element
. visible ( "overlay" )) {
673 console
. log ( "about to remove splash, OMG!" );
674 Element
. hide ( "overlay" );
675 console
. log ( "removed splash!" );
679 function transport_error_check ( transport
) {
681 if ( transport
. responseXML
) {
682 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
685 var code
= error
. getAttribute ( "error-code" );
686 var msg
= error
. getAttribute ( "error-msg" );
688 fatalError ( code
, msg
);
694 exception_error ( "check_for_error_xml" , e
);
699 function strip_tags ( s
) {
700 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
703 function truncate_string ( s
, length
) {
704 if (! length
) length
= 30 ;
705 var tmp
= s
. substring ( 0 , length
);
706 if ( s
. length
> length
) tmp
+= "…" ;
710 function hotkey_prefix_timeout () {
713 var date
= new Date ();
714 var ts
= Math
. round ( date
. getTime () / 1000 );
716 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
717 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
718 hotkey_prefix_pressed
= false ;
719 hotkey_prefix
= false ;
720 Element
. hide ( 'cmdline' );
723 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
726 exception_error ( "hotkey_prefix_timeout" , e
);
730 function hideAuxDlg () {
732 Element
. hide ( 'auxDlg' );
734 exception_error ( "hideAuxDlg" , e
);
739 function uploadIconHandler ( rc
) {
743 notify_info ( "Upload complete." );
744 if ( inPreferences ()) {
747 setTimeout ( 'updateFeedList(false, false)' , 50 );
751 notify_error ( "Upload failed: icon is too big." );
754 notify_error ( "Upload failed." );
759 exception_error ( "uploadIconHandler" , e
);
763 function removeFeedIcon ( id
) {
767 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
768 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape ( id
);
772 notify_progress ( "Removing feed icon..." , true );
774 new Ajax
. Request ( "backend.php" , {
776 onComplete : function ( transport
) {
777 notify_info ( "Feed icon removed." );
778 if ( inPreferences ()) {
781 setTimeout ( 'updateFeedList(false, false)' , 50 );
788 exception_error ( "uploadFeedIcon" , e
);
792 function uploadFeedIcon () {
796 var file
= $( "icon_file" );
798 if ( file
. value
. length
== 0 ) {
799 alert ( __ ( "Please select an image file to upload." ));
801 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
802 notify_progress ( "Uploading, please wait..." , true );
810 exception_error ( "uploadFeedIcon" , e
);
814 function addLabel ( select
, callback
) {
818 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
820 if ( caption
!= undefined ) {
823 alert ( __ ( "Can't create label: missing caption." ));
827 var query
= "?op=pref-labels&subop=add&caption=" +
828 param_escape ( caption
);
831 query
+= "&output=select" ;
833 notify_progress ( "Loading, please wait..." , true );
835 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
837 new Ajax
. Request ( "backend.php" , {
839 onComplete : function ( transport
) {
842 } else if ( inPreferences ()) {
852 exception_error ( "addLabel" , e
);
856 function quickAddFeed () {
858 var query
= "backend.php?op=dlg&id=quickAddFeed" ;
860 if ( dijit
. byId ( "feedAddDlg" ))
861 dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
863 var dialog
= new dijit
. Dialog ({
865 title
: __ ( "Subscribe to Feed" ),
866 style
: "width: 600px" ,
867 execute : function () {
868 if ( this . validate ()) {
869 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
871 var feed_url
= this . attr ( 'value' ). feed
;
873 notify_progress ( __ ( "Subscribing to feed..." ), true );
875 new Ajax
. Request ( "backend.php" , {
876 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
877 onComplete : function ( transport
) {
880 var reply
= JSON
. parse ( transport
. responseText
);
882 var rc
= parseInt ( reply
[ 'result' ]);
886 console
. log ( "GOT RC: " + rc
);
891 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
896 alert ( __ ( "Specified URL seems to be invalid." ));
899 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
902 notify_progress ( "Searching for feed urls..." , true );
904 new Ajax
. Request ( "backend.php" , {
905 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape ( feed_url
),
906 onComplete : function ( transport
, dialog
, feed_url
) {
910 var reply
= JSON
. parse ( transport
. responseText
);
912 var feeds
= reply
[ 'urls' ];
914 console
. log ( transport
. responseText
);
916 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
918 while ( select
. getOptions (). length
> 0 )
919 select
. removeOption ( 0 );
922 for ( var feedUrl
in feeds
) {
923 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
927 // if (count > 5) count = 5;
928 // select.size = count;
930 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
935 alert ( __ ( "Couldn't download the specified URL." ));
938 alert ( __ ( "You are already subscribed to this feed." ));
943 exception_error ( "subscribeToFeed" , e
);
954 exception_error ( "quickAddFeed" , e
);
958 function quickAddFilter () {
960 var query
= "backend.php?op=dlg&id=quickAddFilter" ;
962 if ( dijit
. byId ( "filterEditDlg" ))
963 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
965 dialog
= new dijit
. Dialog ({
967 title
: __ ( "Create Filter" ),
968 style
: "width: 600px" ,
969 execute : function () {
970 if ( this . validate ()) {
972 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
973 param_escape ( dialog
. attr ( 'value' ). reg_exp
);
975 notify_progress ( "Verifying regular expression..." );
977 new Ajax
. Request ( "backend.php" , {
979 onComplete : function ( transport
) {
980 var reply
= JSON
. parse ( transport
. responseText
);
985 if (! reply
[ 'status' ]) {
986 alert ( "Match regular expression seems to be invalid." );
989 notify_progress ( "Saving data..." , true );
991 console
. log ( dojo
. objectToQuery ( dialog
. attr ( 'value' )));
993 new Ajax
. Request ( "backend.php" , {
994 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
995 onComplete : function ( transport
) {
997 notify_info ( transport
. responseText
);
998 if ( inPreferences ()) {
1011 exception_error ( "quickAddFilter" , e
);
1015 function unsubscribeFeed ( feed_id
, title
) {
1017 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1019 if ( title
== undefined || confirm ( msg
)) {
1020 notify_progress ( "Removing feed..." );
1022 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1024 new Ajax
. Request ( "backend.php" , {
1026 onComplete : function ( transport
) {
1028 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1030 if ( inPreferences ()) {
1033 if ( feed_id
== getActiveFeedId ())
1034 setTimeout ( "viewfeed(-5)" , 100 );
1044 function backend_sanity_check_callback ( transport
) {
1048 if ( sanity_check_done
) {
1049 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1050 "presence of Firebug or some other disrupting extension. " +
1051 "Please disable it and try again." );
1055 if (! transport
. responseXML
) {
1057 fatalError ( 3 , "Sanity check: Received reply is not XML" ,
1058 transport
. responseText
);
1063 var reply
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
1066 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1070 var error_code
= reply
. getAttribute ( "error-code" );
1072 if ( error_code
&& error_code
!= 0 ) {
1073 return fatalError ( error_code
, reply
. getAttribute ( "error-msg" ));
1076 console
. log ( "sanity check ok" );
1078 var params
= transport
. responseXML
. getElementsByTagName ( "init-params" )[ 0 ];
1081 console
. log ( 'reading init-params...' );
1083 params
= JSON
. parse ( params
. firstChild
. nodeValue
);
1088 console
. log ( "IP: " + k
+ " => " + v
);
1092 init_params
= params
;
1095 sanity_check_done
= true ;
1097 init_second_stage ();
1100 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1104 function has_local_storage () {
1106 return 'sessionStorage' in window
&& window
[ 'sessionStorage' ] != null ;
1112 function catSelectOnChange ( elem
) {
1114 /* var value = elem[elem.selectedIndex].value;
1115 var def = elem.getAttribute('default');
1117 if (value == "ADD_CAT") {
1120 dropboxSelect(elem, def);
1122 elem.selectedIndex = 0;
1128 exception_error ( "catSelectOnChange" , e
);
1132 function quickAddCat ( elem
) {
1134 var cat
= prompt ( __ ( "Please enter category title:" ));
1138 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape ( cat
);
1140 notify_progress ( "Loading, please wait..." , true );
1142 new Ajax
. Request ( "backend.php" , {
1144 onComplete : function ( transport
) {
1145 var response
= transport
. responseXML
;
1146 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1147 var options
= select
. getElementsByTagName ( "option" );
1149 dropbox_replace_options ( elem
, options
);
1158 exception_error ( "quickAddCat" , e
);
1162 function genUrlChangeKey ( feed
, is_cat
) {
1165 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1169 notify_progress ( "Trying to change address..." , true );
1171 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape ( feed
) +
1172 "&is_cat=" + param_escape ( is_cat
);
1174 new Ajax
. Request ( "backend.php" , {
1176 onComplete : function ( transport
) {
1177 var reply
= JSON
. parse ( transport
. responseText
);
1178 var new_link
= reply
. link
;
1180 var e
= $( 'gen_feed_url' );
1184 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1185 "&key=" + new_link
);
1187 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1188 "&key=" + new_link
);
1190 new Effect
. Highlight ( e
);
1195 notify_error ( "Could not change feed URL." );
1200 exception_error ( "genUrlChangeKey" , e
);
1205 function labelSelectOnChange ( elem
) {
1207 /* var value = elem[elem.selectedIndex].value;
1208 var def = elem.getAttribute('default');
1210 if (value == "ADD_LABEL") {
1213 dropboxSelect(elem, def);
1215 elem.selectedIndex = 0;
1217 addLabel(elem, function(transport) {
1221 var response = transport.responseXML;
1222 var select = response.getElementsByTagName("select")[0];
1223 var options = select.getElementsByTagName("option");
1225 dropbox_replace_options(elem, options);
1229 exception_error("addLabel", e);
1235 exception_error ( "labelSelectOnChange" , e
);
1239 function dropbox_replace_options ( elem
, options
) {
1242 while ( elem
. hasChildNodes ())
1243 elem
. removeChild ( elem
. firstChild
);
1247 for ( var i
= 0 ; i
< options
. length
; i
++) {
1248 var text
= options
[ i
]. firstChild
. nodeValue
;
1249 var value
= options
[ i
]. getAttribute ( "value" );
1251 if ( value
== undefined ) value
= text
;
1253 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1255 var option
= new Option ( text
, value
, issel
);
1257 if ( options
[ i
]. getAttribute ( "disabled" ))
1258 option
. setAttribute ( "disabled" , true );
1260 elem
. insert ( option
);
1262 if ( issel
) sel_idx
= i
;
1265 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1266 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1269 exception_error ( "dropbox_replace_options" , e
);
1273 // mode = all, none, invert
1274 function selectTableRows ( id
, mode
) {
1276 var rows
= $( id
). rows
;
1278 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1282 if ( row
. id
&& row
. className
) {
1283 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1284 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1286 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1287 var input
= inputs
[ j
];
1289 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1290 input
. id
. match ( bare_id
)) {
1298 var issel
= row
. hasClassName ( "Selected" );
1300 if ( mode
== "all" && ! issel
) {
1301 row
. addClassName ( "Selected" );
1303 } else if ( mode
== "none" && issel
) {
1304 row
. removeClassName ( "Selected" );
1306 } else if ( mode
== "invert" ) {
1309 row
. removeClassName ( "Selected" );
1312 row
. addClassName ( "Selected" );
1321 exception_error ( "selectTableRows" , e
);
1326 function getSelectedTableRowIds ( id
) {
1330 var elem_rows
= $( id
). rows
;
1332 for ( i
= 0 ; i
< elem_rows
. length
; i
++) {
1333 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1334 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1340 exception_error ( "getSelectedTableRowIds" , e
);
1346 function editFeed ( feed
, event
) {
1349 return alert ( __ ( "You can't edit this kind of feed." ));
1351 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1356 if ( dijit
. byId ( "feedEditDlg" ))
1357 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1359 dialog
= new dijit
. Dialog ({
1361 title
: __ ( "Edit Feed" ),
1362 style
: "width: 600px" ,
1363 execute : function () {
1364 if ( this . validate ()) {
1365 // console.log(dojo.objectToQuery(this.attr('value')));
1367 notify_progress ( "Saving data..." , true );
1369 new Ajax
. Request ( "backend.php" , {
1370 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1371 onComplete : function ( transport
) {
1383 exception_error ( "editFeed" , e
);
1387 function feedBrowser () {
1389 var query
= "backend.php?op=dlg&id=feedBrowser" ;
1391 if ( dijit
. byId ( "feedAddDlg" ))
1392 dijit
. byId ( "feedAddDlg" ). hide ();
1394 if ( dijit
. byId ( "feedBrowserDlg" ))
1395 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1397 var dialog
= new dijit
. Dialog ({
1398 id
: "feedBrowserDlg" ,
1399 title
: __ ( "More Feeds" ),
1400 style
: "width: 600px" ,
1401 getSelectedFeeds : function () {
1402 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1403 var selected
= new Array ();
1405 list
. each ( function ( child
) {
1406 var id
= child
. id
. replace ( "FBROW-" , "" );
1408 if ( child
. hasClassName ( 'Selected' )) {
1415 subscribe : function () {
1416 var selected
= this . getSelectedFeeds ();
1417 var mode
= this . attr ( 'value' ). mode
;
1419 if ( selected
. length
> 0 ) {
1420 dijit
. byId ( "feedBrowserDlg" ). hide ();
1422 notify_progress ( "Loading, please wait..." , true );
1424 var query
= "?op=rpc&subop=massSubscribe&ids=" +
1425 param_escape ( selected
. toString ()) + "&mode=" + param_escape ( mode
);
1429 new Ajax
. Request ( "backend.php" , {
1431 onComplete : function ( transport
) {
1432 if ( inPreferences ()) {
1438 alert ( __ ( "No feeds are selected." ));
1442 update : function () {
1443 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1445 Element
. show ( 'feed_browser_spinner' );
1447 new Ajax
. Request ( "backend.php" , {
1449 onComplete : function ( transport
) {
1452 Element
. hide ( 'feed_browser_spinner' );
1454 var c
= $( "browseFeedList" );
1456 var reply
= JSON
. parse ( transport
. responseText
);
1458 var r
= reply
[ 'content' ];
1459 var mode
= reply
[ 'mode' ];
1465 dojo
. parser
. parse ( "browseFeedList" );
1468 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1470 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1475 removeFromArchive : function () {
1476 var selected
= this . getSelectedFeeds ();
1478 if ( selected
. length
> 0 ) {
1480 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1483 Element
. show ( 'feed_browser_spinner' );
1485 var query
= "?op=rpc&subop=remarchived&ids=" +
1486 param_escape ( selected
. toString ());;
1488 new Ajax
. Request ( "backend.php" , {
1490 onComplete : function ( transport
) {
1496 execute : function () {
1497 if ( this . validate ()) {
1506 exception_error ( "editFeed" , e
);