]>
git.wh0rd.org - tt-rss.git/blob - js/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>" ;
36 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
37 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
39 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
40 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
43 content
+= "<div><b>Additional information:</b></div>" +
44 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
47 content
+= "<div><b>Stack trace:</b></div>" +
48 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
54 content
+= "<div class='dlgButtons'>" ;
56 content
+= "<button dojoType= \" dijit.form.Button \" " +
57 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
58 __ ( 'Report to tt-rss.org' ) + "</button> " ;
59 content
+= "<button dojoType= \" dijit.form.Button \" " +
60 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
61 __ ( 'Close' ) + "</button>" ;
64 if ( dijit
. byId ( "exceptionDlg" ))
65 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
67 var dialog
= new dijit
. Dialog ({
69 title
: "Unhandled exception" ,
70 style
: "width: 600px" ,
72 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." ))) {
74 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
75 browserName
: navigator
. appName
,
76 browserVersion
: navigator
. appVersion
,
77 browserPlatform
: navigator
. platform
,
78 browserCookies
: navigator
. cookieEnabled
,
81 document
. forms
[ 'exceptionForm' ]. submit ();
95 function format_exception_error ( location
, e
) {
99 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
101 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
102 " \n Function: " + location
+ "()" +
103 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
105 } else if ( e
. description
) {
106 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
108 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
111 console
. error ( "EXCEPTION: " + msg
);
116 function param_escape ( arg
) {
117 if ( typeof encodeURIComponent
!= 'undefined' )
118 return encodeURIComponent ( arg
);
123 function param_unescape ( arg
) {
124 if ( typeof decodeURIComponent
!= 'undefined' )
125 return decodeURIComponent ( arg
);
127 return unescape ( arg
);
130 var notify_hide_timerid
= false ;
132 function hide_notify () {
135 n
. style
. display
= "none" ;
139 function notify_silent_next () {
140 notify_silent
= true ;
143 function notify_real ( msg
, no_hide
, n_type
) {
146 notify_silent
= false ;
151 var nb
= $( "notify_body" );
153 if (! n
|| ! nb
) return ;
155 if ( notify_hide_timerid
) {
156 window
. clearTimeout ( notify_hide_timerid
);
160 if ( n
. style
. display
== "block" ) {
161 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
165 n
. style
. display
= "block" ;
177 if ( typeof __
!= 'undefined' ) {
182 n
. className
= "notify" ;
183 } else if ( n_type
== 2 ) {
184 n
. className
= "notifyProgress" ;
185 msg
= "<img src='" + getInitParam ( "sign_progress" )+ "'> " + msg
;
186 } else if ( n_type
== 3 ) {
187 n
. className
= "notifyError" ;
188 msg
= "<img src='" + getInitParam ( "sign_excl" )+ "'> " + msg
;
189 } else if ( n_type
== 4 ) {
190 n
. className
= "notifyInfo" ;
191 msg
= "<img src='" + getInitParam ( "sign_info" )+ "'> " + msg
;
194 // msg = "<img src='images/live_com_loading.gif'> " + msg;
199 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 3000 );
203 function notify ( msg
, no_hide
) {
204 notify_real ( msg
, no_hide
, 1 );
207 function notify_progress ( msg
, no_hide
) {
208 notify_real ( msg
, no_hide
, 2 );
211 function notify_error ( msg
, no_hide
) {
212 notify_real ( msg
, no_hide
, 3 );
216 function notify_info ( msg
, no_hide
) {
217 notify_real ( msg
, no_hide
, 4 );
220 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
226 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
229 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
231 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
235 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
236 document
. cookie
= name
+ "=" + escape ( value
) +
237 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
238 (( path
) ? "; path=" + path
: "" ) +
239 (( domain
) ? "; domain=" + domain
: "" ) +
240 (( secure
) ? "; secure" : "" );
243 function delCookie ( name
, path
, domain
) {
244 if ( getCookie ( name
)) {
245 document
. cookie
= name
+ "=" +
246 (( path
) ? ";path=" + path
: "" ) +
247 (( domain
) ? ";domain=" + domain
: "" ) +
248 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
253 function getCookie ( name
) {
255 var dc
= document
. cookie
;
256 var prefix
= name
+ "=" ;
257 var begin
= dc
. indexOf ( "; " + prefix
);
259 begin
= dc
. indexOf ( prefix
);
260 if ( begin
!= 0 ) return null ;
265 var end
= document
. cookie
. indexOf ( ";" , begin
);
269 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
272 function gotoPreferences () {
273 document
. location
. href
= "prefs.php" ;
276 function gotoMain () {
277 document
. location
. href
= "index.php" ;
280 function gotoExportOpml ( filename
, settings
) {
281 tmp
= settings
? 1 : 0 ;
282 document
. location
. href
= "opml.php?op=Export&filename=" + filename
+ "&settings=" + tmp
;
286 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
287 * * @author Sundar Dorai-Raj
288 * * Email: sdoraira@vt.edu
289 * * This program is free software; you can redistribute it and/or
290 * * modify it under the terms of the GNU General Public License
291 * * as published by the Free Software Foundation; either version 2
292 * * of the License, or (at your option) any later version,
293 * * provided that any use properly credits the author.
294 * * This program is distributed in the hope that it will be useful,
295 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
296 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297 * * GNU General Public License for more details at http://www.gnu.org * * */
299 var numbers
= ".0123456789" ;
300 function isNumeric ( x
) {
301 // is x a String or a character?
303 // remove negative sign
305 for ( var j
= 0 ; j
< x
. length
; j
++) {
306 // call isNumeric recursively for each character
307 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
308 if (! number
) return number
;
313 // if x is number return true
314 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
320 function toggleSelectRowById ( sender
, id
) {
322 return toggleSelectRow ( sender
, row
);
325 function toggleSelectListRow ( sender
) {
326 var row
= sender
. parentNode
;
327 return toggleSelectRow ( sender
, row
);
330 /* this is for dijit Checkbox */
331 function toggleSelectListRow2 ( sender
) {
332 var row
= sender
. domNode
. parentNode
;
333 return toggleSelectRow ( sender
, row
);
336 function tSR ( sender
, row
) {
337 return toggleSelectRow ( sender
, row
);
340 /* this is for dijit Checkbox */
341 function toggleSelectRow2 ( sender
, row
) {
343 if (! row
) row
= sender
. domNode
. parentNode
. parentNode
;
345 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
346 row
. addClassName ( 'Selected' );
348 row
. removeClassName ( 'Selected' );
352 function toggleSelectRow ( sender
, row
) {
354 if (! row
) row
= sender
. parentNode
. parentNode
;
356 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
357 row
. addClassName ( 'Selected' );
359 row
. removeClassName ( 'Selected' );
362 function checkboxToggleElement ( elem
, id
) {
364 Effect
. Appear ( id
, { duration
: 0.5 });
366 Effect
. Fade ( id
, { duration
: 0.5 });
370 function dropboxSelect ( e
, v
) {
371 for ( var i
= 0 ; i
< e
. length
; i
++) {
372 if ( e
[ i
]. value
== v
) {
379 function getURLParam ( param
){
380 return String ( window
. location
. href
). parseQuery ()[ param
];
383 function leading_zero ( p
) {
385 if ( s
. length
== 1 ) s
= "0" + s
;
389 function make_timestamp () {
392 return leading_zero ( d
. getHours ()) + ":" + leading_zero ( d
. getMinutes ()) +
393 ":" + leading_zero ( d
. getSeconds ());
397 function closeInfoBox ( cleanup
) {
399 dialog
= dijit
. byId ( "infoBox" );
401 if ( dialog
) dialog
. hide ();
404 //exception_error("closeInfoBox", e);
410 function displayDlg ( id
, param
, callback
) {
412 notify_progress ( "Loading, please wait..." , true );
414 var query
= "?op=dlg&method=" +
415 param_escape ( id
) + "¶m=" + param_escape ( param
);
417 new Ajax
. Request ( "backend.php" , {
419 onComplete : function ( transport
) {
420 infobox_callback2 ( transport
);
421 if ( callback
) callback ( transport
);
427 function infobox_callback2 ( transport
) {
431 if ( dijit
. byId ( "infoBox" )) {
432 dialog
= dijit
. byId ( "infoBox" );
435 //console.log("infobox_callback2");
438 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
440 title
= title
. firstChild
. nodeValue
;
442 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
444 content
= content
. firstChild
. nodeValue
;
447 dialog
= new dijit
. Dialog ({
450 style
: "width: 600px" ,
451 onCancel : function () {
454 onExecute : function () {
457 onClose : function () {
462 dialog
. attr ( 'title' , title
);
463 dialog
. attr ( 'content' , content
);
470 exception_error ( "infobox_callback2" , e
);
474 function filterCR ( e
, f
)
479 key
= window
. event
. keyCode
; //IE
481 key
= e
. which
; //firefox
484 if ( typeof f
!= 'undefined' ) {
495 function getInitParam ( key
) {
496 return init_params
[ key
];
499 function setInitParam ( key
, value
) {
500 init_params
[ key
] = value
;
503 function fatalError ( code
, msg
, ext_info
) {
507 window
. location
. href
= "index.php" ;
508 } else if ( code
== 5 ) {
509 window
. location
. href
= "db-updater.php" ;
512 if ( msg
== "" ) msg
= "Unknown error" ;
515 if ( ext_info
. responseText
) {
516 ext_info
= ext_info
. responseText
;
520 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
524 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
525 "<p>" + msg
+ "</p>" ;
528 content
= content
+ "<div><b>Additional information:</b></div>" +
529 "<textarea style='width: 100%' readonly= \" 1 \" >" +
530 ext_info
+ "</textarea>" ;
533 var dialog
= new dijit
. Dialog ({
534 title
: "Fatal error" ,
535 style
: "width: 600px" ,
545 exception_error ( "fatalError" , e
);
549 function filterDlgCheckType ( sender
) {
553 var ftype
= sender
. value
;
555 // if selected filter type is 5 (Date) enable the modifier dropbox
557 Element
. show ( "filterDlg_dateModBox" );
558 Element
. show ( "filterDlg_dateChkBox" );
560 Element
. hide ( "filterDlg_dateModBox" );
561 Element
. hide ( "filterDlg_dateChkBox" );
566 exception_error ( "filterDlgCheckType" , e
);
571 function filterDlgCheckAction ( sender
) {
575 var action
= sender
. value
;
577 var action_param
= $( "filterDlg_paramBox" );
580 console
. log ( "filterDlgCheckAction: can't find action param box!" );
584 // if selected action supports parameters, enable params field
585 if ( action
== 4 || action
== 6 || action
== 7 ) {
586 new Effect
. Appear ( action_param
, { duration
: 0.5 });
588 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
589 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
591 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
592 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
595 Element
. hide ( action_param
);
599 exception_error ( "filterDlgCheckAction" , e
);
604 function filterDlgCheckDate () {
606 var dialog
= dijit
. byId ( "filterEditDlg" );
608 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
610 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
612 new Ajax
. Request ( "backend.php" , {
614 onComplete : function ( transport
) {
616 var reply
= JSON
. parse ( transport
. responseText
);
618 if ( reply
[ 'result' ] == true ) {
619 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
622 alert ( __ ( "Date syntax is incorrect." ));
629 exception_error ( "filterDlgCheckDate" , e
);
633 function explainError ( code
) {
634 return displayDlg ( "explainError" , code
);
637 function loading_set_progress ( p
) {
639 loading_progress
+= p
;
641 if ( dijit
. byId ( "loading_bar" ))
642 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
644 if ( loading_progress
>= 90 )
648 exception_error ( "loading_set_progress" , e
);
652 function remove_splash () {
654 if ( Element
. visible ( "overlay" )) {
655 console
. log ( "about to remove splash, OMG!" );
656 Element
. hide ( "overlay" );
657 console
. log ( "removed splash!" );
661 function transport_error_check ( transport
) {
663 if ( transport
. responseXML
) {
664 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
667 var code
= error
. getAttribute ( "error-code" );
668 var msg
= error
. getAttribute ( "error-msg" );
670 fatalError ( code
, msg
);
676 exception_error ( "check_for_error_xml" , e
);
681 function strip_tags ( s
) {
682 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
685 function truncate_string ( s
, length
) {
686 if (! length
) length
= 30 ;
687 var tmp
= s
. substring ( 0 , length
);
688 if ( s
. length
> length
) tmp
+= "…" ;
692 function hotkey_prefix_timeout () {
695 var date
= new Date ();
696 var ts
= Math
. round ( date
. getTime () / 1000 );
698 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
699 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
700 hotkey_prefix_pressed
= false ;
701 hotkey_prefix
= false ;
702 Element
. hide ( 'cmdline' );
705 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
708 exception_error ( "hotkey_prefix_timeout" , e
);
712 function hideAuxDlg () {
714 Element
. hide ( 'auxDlg' );
716 exception_error ( "hideAuxDlg" , e
);
721 function uploadIconHandler ( rc
) {
725 notify_info ( "Upload complete." );
726 if ( inPreferences ()) {
729 setTimeout ( 'updateFeedList(false, false)' , 50 );
733 notify_error ( "Upload failed: icon is too big." );
736 notify_error ( "Upload failed." );
741 exception_error ( "uploadIconHandler" , e
);
745 function removeFeedIcon ( id
) {
749 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
750 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
754 notify_progress ( "Removing feed icon..." , true );
756 new Ajax
. Request ( "backend.php" , {
758 onComplete : function ( transport
) {
759 notify_info ( "Feed icon removed." );
760 if ( inPreferences ()) {
763 setTimeout ( 'updateFeedList(false, false)' , 50 );
770 exception_error ( "uploadFeedIcon" , e
);
774 function uploadFeedIcon () {
778 var file
= $( "icon_file" );
780 if ( file
. value
. length
== 0 ) {
781 alert ( __ ( "Please select an image file to upload." ));
783 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
784 notify_progress ( "Uploading, please wait..." , true );
792 exception_error ( "uploadFeedIcon" , e
);
796 function addLabel ( select
, callback
) {
800 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
802 if ( caption
!= undefined ) {
805 alert ( __ ( "Can't create label: missing caption." ));
809 var query
= "?op=pref-labels&method=add&caption=" +
810 param_escape ( caption
);
813 query
+= "&output=select" ;
815 notify_progress ( "Loading, please wait..." , true );
817 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
819 new Ajax
. Request ( "backend.php" , {
821 onComplete : function ( transport
) {
824 } else if ( inPreferences ()) {
834 exception_error ( "addLabel" , e
);
838 function quickAddFeed () {
840 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
842 if ( dijit
. byId ( "feedAddDlg" ))
843 dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
845 var dialog
= new dijit
. Dialog ({
847 title
: __ ( "Subscribe to Feed" ),
848 style
: "width: 600px" ,
849 execute : function () {
850 if ( this . validate ()) {
851 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
853 var feed_url
= this . attr ( 'value' ). feed
;
855 notify_progress ( __ ( "Subscribing to feed..." ), true );
857 new Ajax
. Request ( "backend.php" , {
858 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
859 onComplete : function ( transport
) {
862 var reply
= JSON
. parse ( transport
. responseText
);
864 var rc
= parseInt ( reply
[ 'result' ]);
868 console
. log ( "GOT RC: " + rc
);
873 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
878 alert ( __ ( "Specified URL seems to be invalid." ));
881 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
884 notify_progress ( "Searching for feed urls..." , true );
886 new Ajax
. Request ( "backend.php" , {
887 parameters
: 'op=rpc&method=extractfeedurls&url=' + param_escape ( feed_url
),
888 onComplete : function ( transport
, dialog
, feed_url
) {
892 var reply
= JSON
. parse ( transport
. responseText
);
894 var feeds
= reply
[ 'urls' ];
896 console
. log ( transport
. responseText
);
898 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
900 while ( select
. getOptions (). length
> 0 )
901 select
. removeOption ( 0 );
904 for ( var feedUrl
in feeds
) {
905 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
909 // if (count > 5) count = 5;
910 // select.size = count;
912 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
917 alert ( __ ( "Couldn't download the specified URL." ));
920 alert ( __ ( "You are already subscribed to this feed." ));
925 exception_error ( "subscribeToFeed" , e
, transport
);
936 exception_error ( "quickAddFeed" , e
);
940 function quickAddFilter () {
942 var query
= "backend.php?op=dlg&method=quickAddFilter" ;
944 if ( dijit
. byId ( "filterEditDlg" ))
945 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
947 dialog
= new dijit
. Dialog ({
949 title
: __ ( "Create Filter" ),
950 style
: "width: 600px" ,
952 if ( this . validate ()) {
954 if ( dijit
. byId ( "filterTestDlg" ))
955 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
957 tdialog
= new dijit
. Dialog ({
959 title
: __ ( "Filter Test Results" ),
960 style
: "width: 600px" ,
961 href
: "backend.php?savemode=test&" +
962 dojo
. objectToQuery ( dialog
. attr ( 'value' )),
969 execute : function () {
970 if ( this . validate ()) {
972 var query
= "?op=rpc&method=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 resetPubSub ( feed_id
, title
) {
1017 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1019 if ( title
== undefined || confirm ( msg
)) {
1020 notify_progress ( "Loading, please wait..." );
1022 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1024 new Ajax
. Request ( "backend.php" , {
1026 onComplete : function ( transport
) {
1027 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1028 notify_info ( "Subscription reset." );
1036 function unsubscribeFeed ( feed_id
, title
) {
1038 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1040 if ( title
== undefined || confirm ( msg
)) {
1041 notify_progress ( "Removing feed..." );
1043 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1045 new Ajax
. Request ( "backend.php" , {
1047 onComplete : function ( transport
) {
1049 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1051 if ( inPreferences ()) {
1054 if ( feed_id
== getActiveFeedId ())
1055 setTimeout ( "viewfeed(-5)" , 100 );
1065 function backend_sanity_check_callback ( transport
) {
1069 if ( sanity_check_done
) {
1070 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1071 "presence of Firebug or some other disrupting extension. " +
1072 "Please disable it and try again." );
1076 var reply
= JSON
. parse ( transport
. responseText
);
1079 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1083 var error_code
= reply
[ 'error' ][ 'code' ];
1085 if ( error_code
&& error_code
!= 0 ) {
1086 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1089 console
. log ( "sanity check ok" );
1091 var params
= reply
[ 'init-params' ];
1094 console
. log ( 'reading init-params...' );
1099 console
. log ( "IP: " + k
+ " => " + v
);
1103 init_params
= params
;
1106 sanity_check_done
= true ;
1108 init_second_stage ();
1111 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1115 /*function has_local_storage() {
1117 return 'sessionStorage' in window && window['sessionStorage'] != null;
1123 function catSelectOnChange ( elem
) {
1125 /* var value = elem[elem.selectedIndex].value;
1126 var def = elem.getAttribute('default');
1128 if (value == "ADD_CAT") {
1131 dropboxSelect(elem, def);
1133 elem.selectedIndex = 0;
1139 exception_error ( "catSelectOnChange" , e
);
1143 function quickAddCat ( elem
) {
1145 var cat
= prompt ( __ ( "Please enter category title:" ));
1149 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1151 notify_progress ( "Loading, please wait..." , true );
1153 new Ajax
. Request ( "backend.php" , {
1155 onComplete : function ( transport
) {
1156 var response
= transport
. responseXML
;
1157 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1158 var options
= select
. getElementsByTagName ( "option" );
1160 dropbox_replace_options ( elem
, options
);
1169 exception_error ( "quickAddCat" , e
);
1173 function genUrlChangeKey ( feed
, is_cat
) {
1176 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1180 notify_progress ( "Trying to change address..." , true );
1182 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1183 "&is_cat=" + param_escape ( is_cat
);
1185 new Ajax
. Request ( "backend.php" , {
1187 onComplete : function ( transport
) {
1188 var reply
= JSON
. parse ( transport
. responseText
);
1189 var new_link
= reply
. link
;
1191 var e
= $( 'gen_feed_url' );
1195 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1196 "&key=" + new_link
);
1198 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1199 "&key=" + new_link
);
1201 new Effect
. Highlight ( e
);
1206 notify_error ( "Could not change feed URL." );
1211 exception_error ( "genUrlChangeKey" , e
);
1216 function labelSelectOnChange ( elem
) {
1218 /* var value = elem[elem.selectedIndex].value;
1219 var def = elem.getAttribute('default');
1221 if (value == "ADD_LABEL") {
1224 dropboxSelect(elem, def);
1226 elem.selectedIndex = 0;
1228 addLabel(elem, function(transport) {
1232 var response = transport.responseXML;
1233 var select = response.getElementsByTagName("select")[0];
1234 var options = select.getElementsByTagName("option");
1236 dropbox_replace_options(elem, options);
1240 exception_error("addLabel", e);
1246 exception_error ( "labelSelectOnChange" , e
);
1250 function dropbox_replace_options ( elem
, options
) {
1253 while ( elem
. hasChildNodes ())
1254 elem
. removeChild ( elem
. firstChild
);
1258 for ( var i
= 0 ; i
< options
. length
; i
++) {
1259 var text
= options
[ i
]. firstChild
. nodeValue
;
1260 var value
= options
[ i
]. getAttribute ( "value" );
1262 if ( value
== undefined ) value
= text
;
1264 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1266 var option
= new Option ( text
, value
, issel
);
1268 if ( options
[ i
]. getAttribute ( "disabled" ))
1269 option
. setAttribute ( "disabled" , true );
1271 elem
. insert ( option
);
1273 if ( issel
) sel_idx
= i
;
1276 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1277 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1280 exception_error ( "dropbox_replace_options" , e
);
1284 // mode = all, none, invert
1285 function selectTableRows ( id
, mode
) {
1287 var rows
= $( id
). rows
;
1289 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1293 if ( row
. id
&& row
. className
) {
1294 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1295 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1297 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1298 var input
= inputs
[ j
];
1300 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1301 input
. id
. match ( bare_id
)) {
1309 var issel
= row
. hasClassName ( "Selected" );
1311 if ( mode
== "all" && ! issel
) {
1312 row
. addClassName ( "Selected" );
1314 } else if ( mode
== "none" && issel
) {
1315 row
. removeClassName ( "Selected" );
1317 } else if ( mode
== "invert" ) {
1320 row
. removeClassName ( "Selected" );
1323 row
. addClassName ( "Selected" );
1332 exception_error ( "selectTableRows" , e
);
1337 function getSelectedTableRowIds ( id
) {
1341 var elem_rows
= $( id
). rows
;
1343 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1344 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1345 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1351 exception_error ( "getSelectedTableRowIds" , e
);
1357 function editFeed ( feed
, event
) {
1360 return alert ( __ ( "You can't edit this kind of feed." ));
1362 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1367 if ( dijit
. byId ( "feedEditDlg" ))
1368 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1370 dialog
= new dijit
. Dialog ({
1372 title
: __ ( "Edit Feed" ),
1373 style
: "width: 600px" ,
1374 execute : function () {
1375 if ( this . validate ()) {
1376 // console.log(dojo.objectToQuery(this.attr('value')));
1378 notify_progress ( "Saving data..." , true );
1380 new Ajax
. Request ( "backend.php" , {
1381 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1382 onComplete : function ( transport
) {
1394 exception_error ( "editFeed" , e
);
1398 function feedBrowser () {
1400 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1402 if ( dijit
. byId ( "feedAddDlg" ))
1403 dijit
. byId ( "feedAddDlg" ). hide ();
1405 if ( dijit
. byId ( "feedBrowserDlg" ))
1406 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1408 var dialog
= new dijit
. Dialog ({
1409 id
: "feedBrowserDlg" ,
1410 title
: __ ( "More Feeds" ),
1411 style
: "width: 600px" ,
1412 getSelectedFeedIds : function () {
1413 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1414 var selected
= new Array ();
1416 list
. each ( function ( child
) {
1417 var id
= child
. id
. replace ( "FBROW-" , "" );
1419 if ( child
. hasClassName ( 'Selected' )) {
1426 getSelectedFeeds : function () {
1427 var list
= $$( "#browseFeedList li.Selected" );
1428 var selected
= new Array ();
1430 list
. each ( function ( child
) {
1431 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1432 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1434 selected
. push ([ title
, url
]);
1441 subscribe : function () {
1442 var mode
= this . attr ( 'value' ). mode
;
1446 selected
= this . getSelectedFeeds ();
1448 selected
= this . getSelectedFeedIds ();
1450 if ( selected
. length
> 0 ) {
1451 dijit
. byId ( "feedBrowserDlg" ). hide ();
1453 notify_progress ( "Loading, please wait..." , true );
1455 // we use dojo.toJson instead of JSON.stringify because
1456 // it somehow escapes everything TWICE, at least in Chrome 9
1458 var query
= "?op=rpc&method=massSubscribe&payload=" +
1459 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1463 new Ajax
. Request ( "backend.php" , {
1465 onComplete : function ( transport
) {
1471 alert ( __ ( "No feeds are selected." ));
1475 update : function () {
1476 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1478 Element
. show ( 'feed_browser_spinner' );
1480 new Ajax
. Request ( "backend.php" , {
1482 onComplete : function ( transport
) {
1485 Element
. hide ( 'feed_browser_spinner' );
1487 var c
= $( "browseFeedList" );
1489 var reply
= JSON
. parse ( transport
. responseText
);
1491 var r
= reply
[ 'content' ];
1492 var mode
= reply
[ 'mode' ];
1498 dojo
. parser
. parse ( "browseFeedList" );
1501 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1503 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1508 removeFromArchive : function () {
1509 var selected
= this . getSelectedFeeds ();
1511 if ( selected
. length
> 0 ) {
1513 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1516 Element
. show ( 'feed_browser_spinner' );
1518 var query
= "?op=rpc&method=remarchived&ids=" +
1519 param_escape ( selected
. toString ());;
1521 new Ajax
. Request ( "backend.php" , {
1523 onComplete : function ( transport
) {
1529 execute : function () {
1530 if ( this . validate ()) {
1539 exception_error ( "editFeed" , e
);
1543 function showFeedsWithErrors () {
1545 var query
= "backend.php?op=dlg&method=feedsWithErrors" ;
1547 if ( dijit
. byId ( "errorFeedsDlg" ))
1548 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1550 dialog
= new dijit
. Dialog ({
1551 id
: "errorFeedsDlg" ,
1552 title
: __ ( "Feeds with update errors" ),
1553 style
: "width: 600px" ,
1554 getSelectedFeeds : function () {
1555 return getSelectedTableRowIds ( "prefErrorFeedList" );
1557 removeSelected : function () {
1558 var sel_rows
= this . getSelectedFeeds ();
1560 console
. log ( sel_rows
);
1562 if ( sel_rows
. length
> 0 ) {
1563 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1566 notify_progress ( "Removing selected feeds..." , true );
1568 var query
= "?op=pref-feeds&method=remove&ids=" +
1569 param_escape ( sel_rows
. toString ());
1571 new Ajax
. Request ( "backend.php" , {
1573 onComplete : function ( transport
) {
1581 alert ( __ ( "No feeds are selected." ));
1584 execute : function () {
1585 if ( this . validate ()) {
1593 exception_error ( "showFeedsWithErrors" , e
);
1598 /* new support functions for SelectByTag */
1600 function get_all_tags ( selObj
){
1602 if ( ! selObj
) return "" ;
1605 var len
= selObj
. options
. length
;
1607 for ( var i
= 0 ; i
< len
; i
++){
1608 if ( selObj
. options
[ i
]. selected
) {
1609 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1613 if ( result
. length
> 0 ){
1614 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1620 exception_error ( "get_all_tags" , e
);
1624 function get_radio_checked ( radioObj
) {
1626 if (! radioObj
) return "" ;
1628 var len
= radioObj
. length
;
1630 if ( len
== undefined ){
1631 if ( radioObj
. checked
){
1632 return ( radioObj
. value
);
1638 for ( var i
= 0 ; i
< len
; i
++ ){
1639 if ( radioObj
[ i
]. checked
){
1640 return ( radioObj
[ i
]. value
);
1645 exception_error ( "get_radio_checked" , e
);