]>
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 displayHelpInfobox ( topic_id
) {
639 var url
= "backend.php?op=help&tid=" + param_escape ( topic_id
);
641 window
. open ( url
, "ttrss_help" ,
642 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0" );
646 function loading_set_progress ( p
) {
648 loading_progress
+= p
;
650 if ( dijit
. byId ( "loading_bar" ))
651 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
653 if ( loading_progress
>= 90 )
657 exception_error ( "loading_set_progress" , e
);
661 function remove_splash () {
663 if ( Element
. visible ( "overlay" )) {
664 console
. log ( "about to remove splash, OMG!" );
665 Element
. hide ( "overlay" );
666 console
. log ( "removed splash!" );
670 function transport_error_check ( transport
) {
672 if ( transport
. responseXML
) {
673 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
676 var code
= error
. getAttribute ( "error-code" );
677 var msg
= error
. getAttribute ( "error-msg" );
679 fatalError ( code
, msg
);
685 exception_error ( "check_for_error_xml" , e
);
690 function strip_tags ( s
) {
691 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
694 function truncate_string ( s
, length
) {
695 if (! length
) length
= 30 ;
696 var tmp
= s
. substring ( 0 , length
);
697 if ( s
. length
> length
) tmp
+= "…" ;
701 function hotkey_prefix_timeout () {
704 var date
= new Date ();
705 var ts
= Math
. round ( date
. getTime () / 1000 );
707 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
708 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
709 hotkey_prefix_pressed
= false ;
710 hotkey_prefix
= false ;
711 Element
. hide ( 'cmdline' );
714 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
717 exception_error ( "hotkey_prefix_timeout" , e
);
721 function hideAuxDlg () {
723 Element
. hide ( 'auxDlg' );
725 exception_error ( "hideAuxDlg" , e
);
730 function uploadIconHandler ( rc
) {
734 notify_info ( "Upload complete." );
735 if ( inPreferences ()) {
738 setTimeout ( 'updateFeedList(false, false)' , 50 );
742 notify_error ( "Upload failed: icon is too big." );
745 notify_error ( "Upload failed." );
750 exception_error ( "uploadIconHandler" , e
);
754 function removeFeedIcon ( id
) {
758 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
759 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
763 notify_progress ( "Removing feed icon..." , true );
765 new Ajax
. Request ( "backend.php" , {
767 onComplete : function ( transport
) {
768 notify_info ( "Feed icon removed." );
769 if ( inPreferences ()) {
772 setTimeout ( 'updateFeedList(false, false)' , 50 );
779 exception_error ( "uploadFeedIcon" , e
);
783 function uploadFeedIcon () {
787 var file
= $( "icon_file" );
789 if ( file
. value
. length
== 0 ) {
790 alert ( __ ( "Please select an image file to upload." ));
792 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
793 notify_progress ( "Uploading, please wait..." , true );
801 exception_error ( "uploadFeedIcon" , e
);
805 function addLabel ( select
, callback
) {
809 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
811 if ( caption
!= undefined ) {
814 alert ( __ ( "Can't create label: missing caption." ));
818 var query
= "?op=pref-labels&method=add&caption=" +
819 param_escape ( caption
);
822 query
+= "&output=select" ;
824 notify_progress ( "Loading, please wait..." , true );
826 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
828 new Ajax
. Request ( "backend.php" , {
830 onComplete : function ( transport
) {
833 } else if ( inPreferences ()) {
843 exception_error ( "addLabel" , e
);
847 function quickAddFeed () {
849 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
851 if ( dijit
. byId ( "feedAddDlg" ))
852 dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
854 var dialog
= new dijit
. Dialog ({
856 title
: __ ( "Subscribe to Feed" ),
857 style
: "width: 600px" ,
858 execute : function () {
859 if ( this . validate ()) {
860 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
862 var feed_url
= this . attr ( 'value' ). feed
;
864 notify_progress ( __ ( "Subscribing to feed..." ), true );
866 new Ajax
. Request ( "backend.php" , {
867 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
868 onComplete : function ( transport
) {
871 var reply
= JSON
. parse ( transport
. responseText
);
873 var rc
= parseInt ( reply
[ 'result' ]);
877 console
. log ( "GOT RC: " + rc
);
882 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
887 alert ( __ ( "Specified URL seems to be invalid." ));
890 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
893 notify_progress ( "Searching for feed urls..." , true );
895 new Ajax
. Request ( "backend.php" , {
896 parameters
: 'op=rpc&method=extractfeedurls&url=' + param_escape ( feed_url
),
897 onComplete : function ( transport
, dialog
, feed_url
) {
901 var reply
= JSON
. parse ( transport
. responseText
);
903 var feeds
= reply
[ 'urls' ];
905 console
. log ( transport
. responseText
);
907 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
909 while ( select
. getOptions (). length
> 0 )
910 select
. removeOption ( 0 );
913 for ( var feedUrl
in feeds
) {
914 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
918 // if (count > 5) count = 5;
919 // select.size = count;
921 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
926 alert ( __ ( "Couldn't download the specified URL." ));
929 alert ( __ ( "You are already subscribed to this feed." ));
934 exception_error ( "subscribeToFeed" , e
, transport
);
945 exception_error ( "quickAddFeed" , e
);
949 function quickAddFilter () {
951 var query
= "backend.php?op=dlg&method=quickAddFilter" ;
953 if ( dijit
. byId ( "filterEditDlg" ))
954 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
956 dialog
= new dijit
. Dialog ({
958 title
: __ ( "Create Filter" ),
959 style
: "width: 600px" ,
961 if ( this . validate ()) {
963 if ( dijit
. byId ( "filterTestDlg" ))
964 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
966 tdialog
= new dijit
. Dialog ({
968 title
: __ ( "Filter Test Results" ),
969 style
: "width: 600px" ,
970 href
: "backend.php?savemode=test&" +
971 dojo
. objectToQuery ( dialog
. attr ( 'value' )),
978 execute : function () {
979 if ( this . validate ()) {
981 var query
= "?op=rpc&method=verifyRegexp®_exp=" +
982 param_escape ( dialog
. attr ( 'value' ). reg_exp
);
984 notify_progress ( "Verifying regular expression..." );
986 new Ajax
. Request ( "backend.php" , {
988 onComplete : function ( transport
) {
989 var reply
= JSON
. parse ( transport
. responseText
);
994 if (! reply
[ 'status' ]) {
995 alert ( "Match regular expression seems to be invalid." );
998 notify_progress ( "Saving data..." , true );
1000 console
. log ( dojo
. objectToQuery ( dialog
. attr ( 'value' )));
1002 new Ajax
. Request ( "backend.php" , {
1003 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1004 onComplete : function ( transport
) {
1006 notify_info ( transport
. responseText
);
1007 if ( inPreferences ()) {
1020 exception_error ( "quickAddFilter" , e
);
1024 function resetPubSub ( feed_id
, title
) {
1026 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1028 if ( title
== undefined || confirm ( msg
)) {
1029 notify_progress ( "Loading, please wait..." );
1031 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1033 new Ajax
. Request ( "backend.php" , {
1035 onComplete : function ( transport
) {
1036 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1037 notify_info ( "Subscription reset." );
1045 function unsubscribeFeed ( feed_id
, title
) {
1047 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1049 if ( title
== undefined || confirm ( msg
)) {
1050 notify_progress ( "Removing feed..." );
1052 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1054 new Ajax
. Request ( "backend.php" , {
1056 onComplete : function ( transport
) {
1058 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1060 if ( inPreferences ()) {
1063 if ( feed_id
== getActiveFeedId ())
1064 setTimeout ( "viewfeed(-5)" , 100 );
1074 function backend_sanity_check_callback ( transport
) {
1078 if ( sanity_check_done
) {
1079 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1080 "presence of Firebug or some other disrupting extension. " +
1081 "Please disable it and try again." );
1085 var reply
= JSON
. parse ( transport
. responseText
);
1088 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1092 var error_code
= reply
[ 'error' ][ 'code' ];
1094 if ( error_code
&& error_code
!= 0 ) {
1095 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1098 console
. log ( "sanity check ok" );
1100 var params
= reply
[ 'init-params' ];
1103 console
. log ( 'reading init-params...' );
1108 console
. log ( "IP: " + k
+ " => " + v
);
1112 init_params
= params
;
1115 sanity_check_done
= true ;
1117 init_second_stage ();
1120 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1124 /*function has_local_storage() {
1126 return 'sessionStorage' in window && window['sessionStorage'] != null;
1132 function catSelectOnChange ( elem
) {
1134 /* var value = elem[elem.selectedIndex].value;
1135 var def = elem.getAttribute('default');
1137 if (value == "ADD_CAT") {
1140 dropboxSelect(elem, def);
1142 elem.selectedIndex = 0;
1148 exception_error ( "catSelectOnChange" , e
);
1152 function quickAddCat ( elem
) {
1154 var cat
= prompt ( __ ( "Please enter category title:" ));
1158 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1160 notify_progress ( "Loading, please wait..." , true );
1162 new Ajax
. Request ( "backend.php" , {
1164 onComplete : function ( transport
) {
1165 var response
= transport
. responseXML
;
1166 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1167 var options
= select
. getElementsByTagName ( "option" );
1169 dropbox_replace_options ( elem
, options
);
1178 exception_error ( "quickAddCat" , e
);
1182 function genUrlChangeKey ( feed
, is_cat
) {
1185 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1189 notify_progress ( "Trying to change address..." , true );
1191 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1192 "&is_cat=" + param_escape ( is_cat
);
1194 new Ajax
. Request ( "backend.php" , {
1196 onComplete : function ( transport
) {
1197 var reply
= JSON
. parse ( transport
. responseText
);
1198 var new_link
= reply
. link
;
1200 var e
= $( 'gen_feed_url' );
1204 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1205 "&key=" + new_link
);
1207 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1208 "&key=" + new_link
);
1210 new Effect
. Highlight ( e
);
1215 notify_error ( "Could not change feed URL." );
1220 exception_error ( "genUrlChangeKey" , e
);
1225 function labelSelectOnChange ( elem
) {
1227 /* var value = elem[elem.selectedIndex].value;
1228 var def = elem.getAttribute('default');
1230 if (value == "ADD_LABEL") {
1233 dropboxSelect(elem, def);
1235 elem.selectedIndex = 0;
1237 addLabel(elem, function(transport) {
1241 var response = transport.responseXML;
1242 var select = response.getElementsByTagName("select")[0];
1243 var options = select.getElementsByTagName("option");
1245 dropbox_replace_options(elem, options);
1249 exception_error("addLabel", e);
1255 exception_error ( "labelSelectOnChange" , e
);
1259 function dropbox_replace_options ( elem
, options
) {
1262 while ( elem
. hasChildNodes ())
1263 elem
. removeChild ( elem
. firstChild
);
1267 for ( var i
= 0 ; i
< options
. length
; i
++) {
1268 var text
= options
[ i
]. firstChild
. nodeValue
;
1269 var value
= options
[ i
]. getAttribute ( "value" );
1271 if ( value
== undefined ) value
= text
;
1273 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1275 var option
= new Option ( text
, value
, issel
);
1277 if ( options
[ i
]. getAttribute ( "disabled" ))
1278 option
. setAttribute ( "disabled" , true );
1280 elem
. insert ( option
);
1282 if ( issel
) sel_idx
= i
;
1285 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1286 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1289 exception_error ( "dropbox_replace_options" , e
);
1293 // mode = all, none, invert
1294 function selectTableRows ( id
, mode
) {
1296 var rows
= $( id
). rows
;
1298 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1302 if ( row
. id
&& row
. className
) {
1303 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1304 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1306 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1307 var input
= inputs
[ j
];
1309 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1310 input
. id
. match ( bare_id
)) {
1318 var issel
= row
. hasClassName ( "Selected" );
1320 if ( mode
== "all" && ! issel
) {
1321 row
. addClassName ( "Selected" );
1323 } else if ( mode
== "none" && issel
) {
1324 row
. removeClassName ( "Selected" );
1326 } else if ( mode
== "invert" ) {
1329 row
. removeClassName ( "Selected" );
1332 row
. addClassName ( "Selected" );
1341 exception_error ( "selectTableRows" , e
);
1346 function getSelectedTableRowIds ( id
) {
1350 var elem_rows
= $( id
). rows
;
1352 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1353 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1354 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1360 exception_error ( "getSelectedTableRowIds" , e
);
1366 function editFeed ( feed
, event
) {
1369 return alert ( __ ( "You can't edit this kind of feed." ));
1371 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1376 if ( dijit
. byId ( "feedEditDlg" ))
1377 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1379 dialog
= new dijit
. Dialog ({
1381 title
: __ ( "Edit Feed" ),
1382 style
: "width: 600px" ,
1383 execute : function () {
1384 if ( this . validate ()) {
1385 // console.log(dojo.objectToQuery(this.attr('value')));
1387 notify_progress ( "Saving data..." , true );
1389 new Ajax
. Request ( "backend.php" , {
1390 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1391 onComplete : function ( transport
) {
1403 exception_error ( "editFeed" , e
);
1407 function feedBrowser () {
1409 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1411 if ( dijit
. byId ( "feedAddDlg" ))
1412 dijit
. byId ( "feedAddDlg" ). hide ();
1414 if ( dijit
. byId ( "feedBrowserDlg" ))
1415 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1417 var dialog
= new dijit
. Dialog ({
1418 id
: "feedBrowserDlg" ,
1419 title
: __ ( "More Feeds" ),
1420 style
: "width: 600px" ,
1421 getSelectedFeedIds : function () {
1422 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1423 var selected
= new Array ();
1425 list
. each ( function ( child
) {
1426 var id
= child
. id
. replace ( "FBROW-" , "" );
1428 if ( child
. hasClassName ( 'Selected' )) {
1435 getSelectedFeeds : function () {
1436 var list
= $$( "#browseFeedList li.Selected" );
1437 var selected
= new Array ();
1439 list
. each ( function ( child
) {
1440 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1441 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1443 selected
. push ([ title
, url
]);
1450 subscribe : function () {
1451 var mode
= this . attr ( 'value' ). mode
;
1455 selected
= this . getSelectedFeeds ();
1457 selected
= this . getSelectedFeedIds ();
1459 if ( selected
. length
> 0 ) {
1460 dijit
. byId ( "feedBrowserDlg" ). hide ();
1462 notify_progress ( "Loading, please wait..." , true );
1464 // we use dojo.toJson instead of JSON.stringify because
1465 // it somehow escapes everything TWICE, at least in Chrome 9
1467 var query
= "?op=rpc&method=massSubscribe&payload=" +
1468 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1472 new Ajax
. Request ( "backend.php" , {
1474 onComplete : function ( transport
) {
1480 alert ( __ ( "No feeds are selected." ));
1484 update : function () {
1485 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1487 Element
. show ( 'feed_browser_spinner' );
1489 new Ajax
. Request ( "backend.php" , {
1491 onComplete : function ( transport
) {
1494 Element
. hide ( 'feed_browser_spinner' );
1496 var c
= $( "browseFeedList" );
1498 var reply
= JSON
. parse ( transport
. responseText
);
1500 var r
= reply
[ 'content' ];
1501 var mode
= reply
[ 'mode' ];
1507 dojo
. parser
. parse ( "browseFeedList" );
1510 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1512 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1517 removeFromArchive : function () {
1518 var selected
= this . getSelectedFeeds ();
1520 if ( selected
. length
> 0 ) {
1522 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1525 Element
. show ( 'feed_browser_spinner' );
1527 var query
= "?op=rpc&method=remarchived&ids=" +
1528 param_escape ( selected
. toString ());;
1530 new Ajax
. Request ( "backend.php" , {
1532 onComplete : function ( transport
) {
1538 execute : function () {
1539 if ( this . validate ()) {
1548 exception_error ( "editFeed" , e
);
1552 function showFeedsWithErrors () {
1554 var query
= "backend.php?op=dlg&method=feedsWithErrors" ;
1556 if ( dijit
. byId ( "errorFeedsDlg" ))
1557 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1559 dialog
= new dijit
. Dialog ({
1560 id
: "errorFeedsDlg" ,
1561 title
: __ ( "Feeds with update errors" ),
1562 style
: "width: 600px" ,
1563 getSelectedFeeds : function () {
1564 return getSelectedTableRowIds ( "prefErrorFeedList" );
1566 removeSelected : function () {
1567 var sel_rows
= this . getSelectedFeeds ();
1569 console
. log ( sel_rows
);
1571 if ( sel_rows
. length
> 0 ) {
1572 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1575 notify_progress ( "Removing selected feeds..." , true );
1577 var query
= "?op=pref-feeds&method=remove&ids=" +
1578 param_escape ( sel_rows
. toString ());
1580 new Ajax
. Request ( "backend.php" , {
1582 onComplete : function ( transport
) {
1590 alert ( __ ( "No feeds are selected." ));
1593 execute : function () {
1594 if ( this . validate ()) {
1602 exception_error ( "showFeedsWithErrors" , e
);
1607 /* new support functions for SelectByTag */
1609 function get_all_tags ( selObj
){
1611 if ( ! selObj
) return "" ;
1614 var len
= selObj
. options
. length
;
1616 for ( var i
= 0 ; i
< len
; i
++){
1617 if ( selObj
. options
[ i
]. selected
) {
1618 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1622 if ( result
. length
> 0 ){
1623 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1629 exception_error ( "get_all_tags" , e
);
1633 function get_radio_checked ( radioObj
) {
1635 if (! radioObj
) return "" ;
1637 var len
= radioObj
. length
;
1639 if ( len
== undefined ){
1640 if ( radioObj
. checked
){
1641 return ( radioObj
. value
);
1647 for ( var i
= 0 ; i
< len
; i
++ ){
1648 if ( radioObj
[ i
]. checked
){
1649 return ( radioObj
[ i
]. value
);
1654 exception_error ( "get_radio_checked" , e
);