]>
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 ;
6 Ajax
. Base
. prototype . initialize
= Ajax
. Base
. prototype . initialize
. wrap (
7 function ( callOriginal
, options
) {
9 if ( getInitParam ( "csrf_token" ) != undefined ) {
10 Object
. extend ( options
, options
|| { });
12 if ( Object
. isString ( options
. parameters
))
13 options
. parameters
= options
. parameters
. toQueryParams ();
14 else if ( Object
. isHash ( options
. parameters
))
15 options
. parameters
= options
. parameters
. toObject ();
17 options
. parameters
[ "csrf_token" ] = getInitParam ( "csrf_token" );
20 return callOriginal ( options
);
24 /* add method to remove element from array */
26 Array
. prototype . remove = function ( s
) {
27 for ( var i
= 0 ; i
< this . length
; i
++) {
28 if ( s
== this [ i
]) this . splice ( i
, 1 );
32 /* create console.log if it doesn't exist */
34 if (! window
. console
) console
= {};
35 console
. log
= console
. log
|| function ( msg
) { };
36 console
. warn
= console
. warn
|| function ( msg
) { };
37 console
. error
= console
. error
|| function ( msg
) { };
39 function exception_error ( location
, e
, ext_info
) {
40 var msg
= format_exception_error ( location
, e
);
42 if (! ext_info
) ext_info
= false ;
47 if ( ext_info
. responseText
) {
48 ext_info
= ext_info
. responseText
;
52 var content
= "<div class= \" fatalError \" >" +
53 "<pre>" + msg
+ "</pre>" ;
55 content
+= "<form name= \" exceptionForm \" id= \" exceptionForm \" target= \" _blank \" " +
56 "action= \" http://tt-rss.org/report.php \" method= \" POST \" >" ;
58 content
+= "<textarea style= \" display : none \" name= \" message \" >" + msg
+ "</textarea>" ;
59 content
+= "<textarea style= \" display : none \" name= \" params \" >N/A</textarea>" ;
62 content
+= "<div><b>Additional information:</b></div>" +
63 "<textarea name= \" xinfo \" readonly= \" 1 \" >" + ext_info
+ "</textarea>" ;
66 content
+= "<div><b>Stack trace:</b></div>" +
67 "<textarea name= \" stack \" readonly= \" 1 \" >" + e
. stack
+ "</textarea>" ;
73 content
+= "<div class='dlgButtons'>" ;
75 content
+= "<button dojoType= \" dijit.form.Button \" " +
76 "onclick= \" dijit.byId('exceptionDlg').report() \" >" +
77 __ ( 'Report to tt-rss.org' ) + "</button> " ;
78 content
+= "<button dojoType= \" dijit.form.Button \" " +
79 "onclick= \" dijit.byId('exceptionDlg').hide() \" >" +
80 __ ( 'Close' ) + "</button>" ;
83 if ( dijit
. byId ( "exceptionDlg" ))
84 dijit
. byId ( "exceptionDlg" ). destroyRecursive ();
86 var dialog
= new dijit
. Dialog ({
88 title
: "Unhandled exception" ,
89 style
: "width: 600px" ,
91 if ( confirm ( __ ( "Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database." ))) {
93 document
. forms
[ 'exceptionForm' ]. params
. value
= $ H ({
94 browserName
: navigator
. appName
,
95 browserVersion
: navigator
. appVersion
,
96 browserPlatform
: navigator
. platform
,
97 browserCookies
: navigator
. cookieEnabled
,
100 document
. forms
[ 'exceptionForm' ]. submit ();
114 function format_exception_error ( location
, e
) {
118 var base_fname
= e
. fileName
. substring ( e
. fileName
. lastIndexOf ( "/" ) + 1 );
120 msg
= "Exception: " + e
. name
+ ", " + e
. message
+
121 " \n Function: " + location
+ "()" +
122 " \n Location: " + base_fname
+ ":" + e
. lineNumber
;
124 } else if ( e
. description
) {
125 msg
= "Exception: " + e
. description
+ " \n Function: " + location
+ "()" ;
127 msg
= "Exception: " + e
+ " \n Function: " + location
+ "()" ;
130 console
. error ( "EXCEPTION: " + msg
);
135 function param_escape ( arg
) {
136 if ( typeof encodeURIComponent
!= 'undefined' )
137 return encodeURIComponent ( arg
);
142 function param_unescape ( arg
) {
143 if ( typeof decodeURIComponent
!= 'undefined' )
144 return decodeURIComponent ( arg
);
146 return unescape ( arg
);
149 var notify_hide_timerid
= false ;
151 function hide_notify () {
154 n
. style
. display
= "none" ;
158 function notify_silent_next () {
159 notify_silent
= true ;
162 function notify_real ( msg
, no_hide
, n_type
) {
165 notify_silent
= false ;
170 var nb
= $( "notify_body" );
172 if (! n
|| ! nb
) return ;
174 if ( notify_hide_timerid
) {
175 window
. clearTimeout ( notify_hide_timerid
);
179 if ( n
. style
. display
== "block" ) {
180 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 0 );
184 n
. style
. display
= "block" ;
196 if ( typeof __
!= 'undefined' ) {
201 n
. className
= "notify" ;
202 } else if ( n_type
== 2 ) {
203 n
. className
= "notifyProgress" ;
204 msg
= "<img src='" + getInitParam ( "sign_progress" )+ "'> " + msg
;
205 } else if ( n_type
== 3 ) {
206 n
. className
= "notifyError" ;
207 msg
= "<img src='" + getInitParam ( "sign_excl" )+ "'> " + msg
;
208 } else if ( n_type
== 4 ) {
209 n
. className
= "notifyInfo" ;
210 msg
= "<img src='" + getInitParam ( "sign_info" )+ "'> " + msg
;
213 // msg = "<img src='images/live_com_loading.gif'> " + msg;
218 notify_hide_timerid
= window
. setTimeout ( "hide_notify()" , 3000 );
222 function notify ( msg
, no_hide
) {
223 notify_real ( msg
, no_hide
, 1 );
226 function notify_progress ( msg
, no_hide
) {
227 notify_real ( msg
, no_hide
, 2 );
230 function notify_error ( msg
, no_hide
) {
231 notify_real ( msg
, no_hide
, 3 );
235 function notify_info ( msg
, no_hide
) {
236 notify_real ( msg
, no_hide
, 4 );
239 function setCookie ( name
, value
, lifetime
, path
, domain
, secure
) {
245 d
. setTime ( d
. getTime () + ( lifetime
* 1000 ));
248 console
. log ( "setCookie: " + name
+ " => " + value
+ ": " + d
);
250 int_setCookie ( name
, value
, d
, path
, domain
, secure
);
254 function int_setCookie ( name
, value
, expires
, path
, domain
, secure
) {
255 document
. cookie
= name
+ "=" + escape ( value
) +
256 (( expires
) ? "; expires=" + expires
. toGMTString () : "" ) +
257 (( path
) ? "; path=" + path
: "" ) +
258 (( domain
) ? "; domain=" + domain
: "" ) +
259 (( secure
) ? "; secure" : "" );
262 function delCookie ( name
, path
, domain
) {
263 if ( getCookie ( name
)) {
264 document
. cookie
= name
+ "=" +
265 (( path
) ? ";path=" + path
: "" ) +
266 (( domain
) ? ";domain=" + domain
: "" ) +
267 ";expires=Thu, 01-Jan-1970 00:00:01 GMT" ;
272 function getCookie ( name
) {
274 var dc
= document
. cookie
;
275 var prefix
= name
+ "=" ;
276 var begin
= dc
. indexOf ( "; " + prefix
);
278 begin
= dc
. indexOf ( prefix
);
279 if ( begin
!= 0 ) return null ;
284 var end
= document
. cookie
. indexOf ( ";" , begin
);
288 return unescape ( dc
. substring ( begin
+ prefix
. length
, end
));
291 function gotoPreferences () {
292 document
. location
. href
= "prefs.php" ;
295 function gotoMain () {
296 document
. location
. href
= "index.php" ;
299 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
300 * * @author Sundar Dorai-Raj
301 * * Email: sdoraira@vt.edu
302 * * This program is free software; you can redistribute it and/or
303 * * modify it under the terms of the GNU General Public License
304 * * as published by the Free Software Foundation; either version 2
305 * * of the License, or (at your option) any later version,
306 * * provided that any use properly credits the author.
307 * * This program is distributed in the hope that it will be useful,
308 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
309 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
310 * * GNU General Public License for more details at http://www.gnu.org * * */
312 var numbers
= ".0123456789" ;
313 function isNumeric ( x
) {
314 // is x a String or a character?
316 // remove negative sign
318 for ( var j
= 0 ; j
< x
. length
; j
++) {
319 // call isNumeric recursively for each character
320 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
321 if (! number
) return number
;
326 // if x is number return true
327 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
333 function toggleSelectRowById ( sender
, id
) {
335 return toggleSelectRow ( sender
, row
);
338 function toggleSelectListRow ( sender
) {
339 var row
= sender
. parentNode
;
340 return toggleSelectRow ( sender
, row
);
343 /* this is for dijit Checkbox */
344 function toggleSelectListRow2 ( sender
) {
345 var row
= sender
. domNode
. parentNode
;
346 return toggleSelectRow ( sender
, row
);
349 function tSR ( sender
, row
) {
350 return toggleSelectRow ( sender
, row
);
353 /* this is for dijit Checkbox */
354 function toggleSelectRow2 ( sender
, row
) {
356 if (! row
) row
= sender
. domNode
. parentNode
. parentNode
;
358 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
359 row
. addClassName ( 'Selected' );
361 row
. removeClassName ( 'Selected' );
365 function toggleSelectRow ( sender
, row
) {
367 if (! row
) row
= sender
. parentNode
. parentNode
;
369 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
370 row
. addClassName ( 'Selected' );
372 row
. removeClassName ( 'Selected' );
375 function checkboxToggleElement ( elem
, id
) {
377 Effect
. Appear ( id
, { duration
: 0.5 });
379 Effect
. Fade ( id
, { duration
: 0.5 });
383 function dropboxSelect ( e
, v
) {
384 for ( var i
= 0 ; i
< e
. length
; i
++) {
385 if ( e
[ i
]. value
== v
) {
392 function getURLParam ( param
){
393 return String ( window
. location
. href
). parseQuery ()[ param
];
396 function leading_zero ( p
) {
398 if ( s
. length
== 1 ) s
= "0" + s
;
402 function make_timestamp () {
405 return leading_zero ( d
. getHours ()) + ":" + leading_zero ( d
. getMinutes ()) +
406 ":" + leading_zero ( d
. getSeconds ());
410 function closeInfoBox ( cleanup
) {
412 dialog
= dijit
. byId ( "infoBox" );
414 if ( dialog
) dialog
. hide ();
417 //exception_error("closeInfoBox", e);
423 function displayDlg ( id
, param
, callback
) {
425 notify_progress ( "Loading, please wait..." , true );
427 var query
= "?op=dlg&method=" +
428 param_escape ( id
) + "¶m=" + param_escape ( param
);
430 new Ajax
. Request ( "backend.php" , {
432 onComplete : function ( transport
) {
433 infobox_callback2 ( transport
);
434 if ( callback
) callback ( transport
);
440 function infobox_callback2 ( transport
) {
444 if ( dijit
. byId ( "infoBox" )) {
445 dialog
= dijit
. byId ( "infoBox" );
448 //console.log("infobox_callback2");
451 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
453 title
= title
. firstChild
. nodeValue
;
455 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
457 content
= content
. firstChild
. nodeValue
;
460 dialog
= new dijit
. Dialog ({
463 style
: "width: 600px" ,
464 onCancel : function () {
467 onExecute : function () {
470 onClose : function () {
475 dialog
. attr ( 'title' , title
);
476 dialog
. attr ( 'content' , content
);
483 exception_error ( "infobox_callback2" , e
);
487 function filterCR ( e
, f
)
492 key
= window
. event
. keyCode
; //IE
494 key
= e
. which
; //firefox
497 if ( typeof f
!= 'undefined' ) {
508 function getInitParam ( key
) {
509 return init_params
[ key
];
512 function setInitParam ( key
, value
) {
513 init_params
[ key
] = value
;
516 function fatalError ( code
, msg
, ext_info
) {
520 window
. location
. href
= "index.php" ;
521 } else if ( code
== 5 ) {
522 window
. location
. href
= "db-updater.php" ;
525 if ( msg
== "" ) msg
= "Unknown error" ;
528 if ( ext_info
. responseText
) {
529 ext_info
= ext_info
. responseText
;
533 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
537 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
538 "<p>" + msg
+ "</p>" ;
541 content
= content
+ "<div><b>Additional information:</b></div>" +
542 "<textarea style='width: 100%' readonly= \" 1 \" >" +
543 ext_info
+ "</textarea>" ;
546 var dialog
= new dijit
. Dialog ({
547 title
: "Fatal error" ,
548 style
: "width: 600px" ,
558 exception_error ( "fatalError" , e
);
562 function filterDlgCheckCat ( sender
) {
564 if ( sender
. checked
) {
565 Element
. show ( 'filterDlg_cats' );
566 Element
. hide ( 'filterDlg_feeds' );
568 Element
. show ( 'filterDlg_feeds' );
569 Element
. hide ( 'filterDlg_cats' );
573 exception_error ( "filterDlgCheckCat" , e
);
577 function filterDlgCheckType ( sender
) {
581 var ftype
= sender
. value
;
583 // if selected filter type is 5 (Date) enable the modifier dropbox
585 Element
. show ( "filterDlg_dateModBox" );
586 Element
. show ( "filterDlg_dateChkBox" );
588 Element
. hide ( "filterDlg_dateModBox" );
589 Element
. hide ( "filterDlg_dateChkBox" );
594 exception_error ( "filterDlgCheckType" , e
);
599 function filterDlgCheckAction ( sender
) {
603 var action
= sender
. value
;
605 var action_param
= $( "filterDlg_paramBox" );
608 console
. log ( "filterDlgCheckAction: can't find action param box!" );
612 // if selected action supports parameters, enable params field
613 if ( action
== 4 || action
== 6 || action
== 7 ) {
614 new Effect
. Appear ( action_param
, { duration
: 0.5 });
616 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
617 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
619 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
620 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
623 Element
. hide ( action_param
);
627 exception_error ( "filterDlgCheckAction" , e
);
632 function filterDlgCheckDate () {
634 var dialog
= dijit
. byId ( "filterEditDlg" );
636 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
638 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
640 new Ajax
. Request ( "backend.php" , {
642 onComplete : function ( transport
) {
644 var reply
= JSON
. parse ( transport
. responseText
);
646 if ( reply
[ 'result' ] == true ) {
647 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
650 alert ( __ ( "Date syntax is incorrect." ));
657 exception_error ( "filterDlgCheckDate" , e
);
661 function explainError ( code
) {
662 return displayDlg ( "explainError" , code
);
665 function loading_set_progress ( p
) {
667 loading_progress
+= p
;
669 if ( dijit
. byId ( "loading_bar" ))
670 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
672 if ( loading_progress
>= 90 )
676 exception_error ( "loading_set_progress" , e
);
680 function remove_splash () {
682 if ( Element
. visible ( "overlay" )) {
683 console
. log ( "about to remove splash, OMG!" );
684 Element
. hide ( "overlay" );
685 console
. log ( "removed splash!" );
689 function transport_error_check ( transport
) {
691 if ( transport
. responseXML
) {
692 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
695 var code
= error
. getAttribute ( "error-code" );
696 var msg
= error
. getAttribute ( "error-msg" );
698 fatalError ( code
, msg
);
704 exception_error ( "check_for_error_xml" , e
);
709 function strip_tags ( s
) {
710 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
713 function truncate_string ( s
, length
) {
714 if (! length
) length
= 30 ;
715 var tmp
= s
. substring ( 0 , length
);
716 if ( s
. length
> length
) tmp
+= "…" ;
720 function hotkey_prefix_timeout () {
723 var date
= new Date ();
724 var ts
= Math
. round ( date
. getTime () / 1000 );
726 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
727 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
728 hotkey_prefix_pressed
= false ;
729 hotkey_prefix
= false ;
730 Element
. hide ( 'cmdline' );
733 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
736 exception_error ( "hotkey_prefix_timeout" , e
);
740 function hideAuxDlg () {
742 Element
. hide ( 'auxDlg' );
744 exception_error ( "hideAuxDlg" , e
);
749 function uploadIconHandler ( rc
) {
753 notify_info ( "Upload complete." );
754 if ( inPreferences ()) {
757 setTimeout ( 'updateFeedList(false, false)' , 50 );
761 notify_error ( "Upload failed: icon is too big." );
764 notify_error ( "Upload failed." );
769 exception_error ( "uploadIconHandler" , e
);
773 function removeFeedIcon ( id
) {
777 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
778 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
782 notify_progress ( "Removing feed icon..." , true );
784 new Ajax
. Request ( "backend.php" , {
786 onComplete : function ( transport
) {
787 notify_info ( "Feed icon removed." );
788 if ( inPreferences ()) {
791 setTimeout ( 'updateFeedList(false, false)' , 50 );
798 exception_error ( "uploadFeedIcon" , e
);
802 function uploadFeedIcon () {
806 var file
= $( "icon_file" );
808 if ( file
. value
. length
== 0 ) {
809 alert ( __ ( "Please select an image file to upload." ));
811 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
812 notify_progress ( "Uploading, please wait..." , true );
820 exception_error ( "uploadFeedIcon" , e
);
824 function addLabel ( select
, callback
) {
828 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
830 if ( caption
!= undefined ) {
833 alert ( __ ( "Can't create label: missing caption." ));
837 var query
= "?op=pref-labels&method=add&caption=" +
838 param_escape ( caption
);
841 query
+= "&output=select" ;
843 notify_progress ( "Loading, please wait..." , true );
845 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
847 new Ajax
. Request ( "backend.php" , {
849 onComplete : function ( transport
) {
852 } else if ( inPreferences ()) {
862 exception_error ( "addLabel" , e
);
866 function quickAddFeed () {
868 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
870 if ( dijit
. byId ( "feedAddDlg" ))
871 dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
873 var dialog
= new dijit
. Dialog ({
875 title
: __ ( "Subscribe to Feed" ),
876 style
: "width: 600px" ,
877 execute : function () {
878 if ( this . validate ()) {
879 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
881 var feed_url
= this . attr ( 'value' ). feed
;
883 notify_progress ( __ ( "Subscribing to feed..." ), true );
885 new Ajax
. Request ( "backend.php" , {
886 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
887 onComplete : function ( transport
) {
890 var reply
= JSON
. parse ( transport
. responseText
);
892 var rc
= parseInt ( reply
[ 'result' ]);
896 console
. log ( "GOT RC: " + rc
);
901 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
906 alert ( __ ( "Specified URL seems to be invalid." ));
909 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
912 notify_progress ( "Searching for feed urls..." , true );
914 new Ajax
. Request ( "backend.php" , {
915 parameters
: 'op=rpc&method=extractfeedurls&url=' + param_escape ( feed_url
),
916 onComplete : function ( transport
, dialog
, feed_url
) {
920 var reply
= JSON
. parse ( transport
. responseText
);
922 var feeds
= reply
[ 'urls' ];
924 console
. log ( transport
. responseText
);
926 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
928 while ( select
. getOptions (). length
> 0 )
929 select
. removeOption ( 0 );
932 for ( var feedUrl
in feeds
) {
933 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
937 // if (count > 5) count = 5;
938 // select.size = count;
940 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
945 alert ( __ ( "Couldn't download the specified URL." ));
948 alert ( __ ( "You are already subscribed to this feed." ));
953 exception_error ( "subscribeToFeed" , e
, transport
);
964 exception_error ( "quickAddFeed" , e
);
968 function quickAddFilter () {
970 var query
= "backend.php?op=dlg&method=quickAddFilter" ;
972 if ( dijit
. byId ( "feedEditDlg" ))
973 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
975 if ( dijit
. byId ( "filterEditDlg" ))
976 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
978 dialog
= new dijit
. Dialog ({
980 title
: __ ( "Create Filter" ),
981 style
: "width: 600px" ,
983 if ( this . validate ()) {
985 if ( dijit
. byId ( "filterTestDlg" ))
986 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
988 tdialog
= new dijit
. Dialog ({
990 title
: __ ( "Filter Test Results" ),
991 style
: "width: 600px" ,
992 href
: "backend.php?savemode=test&" +
993 dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1000 execute : function () {
1001 if ( this . validate ()) {
1003 var query
= "?op=rpc&method=verifyRegexp®_exp=" +
1004 param_escape ( dialog
. attr ( 'value' ). reg_exp
);
1006 notify_progress ( "Verifying regular expression..." );
1008 new Ajax
. Request ( "backend.php" , {
1010 onComplete : function ( transport
) {
1011 var reply
= JSON
. parse ( transport
. responseText
);
1016 if (! reply
[ 'status' ]) {
1017 alert ( "Match regular expression seems to be invalid." );
1020 notify_progress ( "Saving data..." , true );
1022 console
. log ( dojo
. objectToQuery ( dialog
. attr ( 'value' )));
1024 new Ajax
. Request ( "backend.php" , {
1025 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1026 onComplete : function ( transport
) {
1028 notify_info ( transport
. responseText
);
1029 if ( inPreferences ()) {
1042 exception_error ( "quickAddFilter" , e
);
1046 function resetPubSub ( feed_id
, title
) {
1048 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1050 if ( title
== undefined || confirm ( msg
)) {
1051 notify_progress ( "Loading, please wait..." );
1053 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1055 new Ajax
. Request ( "backend.php" , {
1057 onComplete : function ( transport
) {
1058 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1059 notify_info ( "Subscription reset." );
1067 function unsubscribeFeed ( feed_id
, title
) {
1069 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1071 if ( title
== undefined || confirm ( msg
)) {
1072 notify_progress ( "Removing feed..." );
1074 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1076 new Ajax
. Request ( "backend.php" , {
1078 onComplete : function ( transport
) {
1080 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1082 if ( inPreferences ()) {
1085 if ( feed_id
== getActiveFeedId ())
1086 setTimeout ( "viewfeed(-5)" , 100 );
1096 function backend_sanity_check_callback ( transport
) {
1100 if ( sanity_check_done
) {
1101 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1102 "presence of Firebug or some other disrupting extension. " +
1103 "Please disable it and try again." );
1107 var reply
= JSON
. parse ( transport
. responseText
);
1110 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1114 var error_code
= reply
[ 'error' ][ 'code' ];
1116 if ( error_code
&& error_code
!= 0 ) {
1117 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1120 console
. log ( "sanity check ok" );
1122 var params
= reply
[ 'init-params' ];
1125 console
. log ( 'reading init-params...' );
1130 console
. log ( "IP: " + k
+ " => " + v
);
1134 init_params
= params
;
1137 sanity_check_done
= true ;
1139 init_second_stage ();
1142 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1146 /*function has_local_storage() {
1148 return 'sessionStorage' in window && window['sessionStorage'] != null;
1154 function catSelectOnChange ( elem
) {
1156 /* var value = elem[elem.selectedIndex].value;
1157 var def = elem.getAttribute('default');
1159 if (value == "ADD_CAT") {
1162 dropboxSelect(elem, def);
1164 elem.selectedIndex = 0;
1170 exception_error ( "catSelectOnChange" , e
);
1174 function quickAddCat ( elem
) {
1176 var cat
= prompt ( __ ( "Please enter category title:" ));
1180 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1182 notify_progress ( "Loading, please wait..." , true );
1184 new Ajax
. Request ( "backend.php" , {
1186 onComplete : function ( transport
) {
1187 var response
= transport
. responseXML
;
1188 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1189 var options
= select
. getElementsByTagName ( "option" );
1191 dropbox_replace_options ( elem
, options
);
1200 exception_error ( "quickAddCat" , e
);
1204 function genUrlChangeKey ( feed
, is_cat
) {
1207 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1211 notify_progress ( "Trying to change address..." , true );
1213 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1214 "&is_cat=" + param_escape ( is_cat
);
1216 new Ajax
. Request ( "backend.php" , {
1218 onComplete : function ( transport
) {
1219 var reply
= JSON
. parse ( transport
. responseText
);
1220 var new_link
= reply
. link
;
1222 var e
= $( 'gen_feed_url' );
1226 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1227 "&key=" + new_link
);
1229 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1230 "&key=" + new_link
);
1232 new Effect
. Highlight ( e
);
1237 notify_error ( "Could not change feed URL." );
1242 exception_error ( "genUrlChangeKey" , e
);
1247 function labelSelectOnChange ( elem
) {
1249 /* var value = elem[elem.selectedIndex].value;
1250 var def = elem.getAttribute('default');
1252 if (value == "ADD_LABEL") {
1255 dropboxSelect(elem, def);
1257 elem.selectedIndex = 0;
1259 addLabel(elem, function(transport) {
1263 var response = transport.responseXML;
1264 var select = response.getElementsByTagName("select")[0];
1265 var options = select.getElementsByTagName("option");
1267 dropbox_replace_options(elem, options);
1271 exception_error("addLabel", e);
1277 exception_error ( "labelSelectOnChange" , e
);
1281 function dropbox_replace_options ( elem
, options
) {
1284 while ( elem
. hasChildNodes ())
1285 elem
. removeChild ( elem
. firstChild
);
1289 for ( var i
= 0 ; i
< options
. length
; i
++) {
1290 var text
= options
[ i
]. firstChild
. nodeValue
;
1291 var value
= options
[ i
]. getAttribute ( "value" );
1293 if ( value
== undefined ) value
= text
;
1295 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1297 var option
= new Option ( text
, value
, issel
);
1299 if ( options
[ i
]. getAttribute ( "disabled" ))
1300 option
. setAttribute ( "disabled" , true );
1302 elem
. insert ( option
);
1304 if ( issel
) sel_idx
= i
;
1307 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1308 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1311 exception_error ( "dropbox_replace_options" , e
);
1315 // mode = all, none, invert
1316 function selectTableRows ( id
, mode
) {
1318 var rows
= $( id
). rows
;
1320 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1324 if ( row
. id
&& row
. className
) {
1325 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1326 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1328 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1329 var input
= inputs
[ j
];
1331 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1332 input
. id
. match ( bare_id
)) {
1340 var issel
= row
. hasClassName ( "Selected" );
1342 if ( mode
== "all" && ! issel
) {
1343 row
. addClassName ( "Selected" );
1345 } else if ( mode
== "none" && issel
) {
1346 row
. removeClassName ( "Selected" );
1348 } else if ( mode
== "invert" ) {
1351 row
. removeClassName ( "Selected" );
1354 row
. addClassName ( "Selected" );
1363 exception_error ( "selectTableRows" , e
);
1368 function getSelectedTableRowIds ( id
) {
1372 var elem_rows
= $( id
). rows
;
1374 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1375 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1376 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1382 exception_error ( "getSelectedTableRowIds" , e
);
1388 function editFeed ( feed
, event
) {
1391 return alert ( __ ( "You can't edit this kind of feed." ));
1393 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1398 if ( dijit
. byId ( "filterEditDlg" ))
1399 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1401 if ( dijit
. byId ( "feedEditDlg" ))
1402 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1404 dialog
= new dijit
. Dialog ({
1406 title
: __ ( "Edit Feed" ),
1407 style
: "width: 600px" ,
1408 execute : function () {
1409 if ( this . validate ()) {
1410 // console.log(dojo.objectToQuery(this.attr('value')));
1412 notify_progress ( "Saving data..." , true );
1414 new Ajax
. Request ( "backend.php" , {
1415 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1416 onComplete : function ( transport
) {
1428 exception_error ( "editFeed" , e
);
1432 function feedBrowser () {
1434 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1436 if ( dijit
. byId ( "feedAddDlg" ))
1437 dijit
. byId ( "feedAddDlg" ). hide ();
1439 if ( dijit
. byId ( "feedBrowserDlg" ))
1440 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1442 var dialog
= new dijit
. Dialog ({
1443 id
: "feedBrowserDlg" ,
1444 title
: __ ( "More Feeds" ),
1445 style
: "width: 600px" ,
1446 getSelectedFeedIds : function () {
1447 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1448 var selected
= new Array ();
1450 list
. each ( function ( child
) {
1451 var id
= child
. id
. replace ( "FBROW-" , "" );
1453 if ( child
. hasClassName ( 'Selected' )) {
1460 getSelectedFeeds : function () {
1461 var list
= $$( "#browseFeedList li.Selected" );
1462 var selected
= new Array ();
1464 list
. each ( function ( child
) {
1465 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1466 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1468 selected
. push ([ title
, url
]);
1475 subscribe : function () {
1476 var mode
= this . attr ( 'value' ). mode
;
1480 selected
= this . getSelectedFeeds ();
1482 selected
= this . getSelectedFeedIds ();
1484 if ( selected
. length
> 0 ) {
1485 dijit
. byId ( "feedBrowserDlg" ). hide ();
1487 notify_progress ( "Loading, please wait..." , true );
1489 // we use dojo.toJson instead of JSON.stringify because
1490 // it somehow escapes everything TWICE, at least in Chrome 9
1492 var query
= "?op=rpc&method=massSubscribe&payload=" +
1493 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1497 new Ajax
. Request ( "backend.php" , {
1499 onComplete : function ( transport
) {
1505 alert ( __ ( "No feeds are selected." ));
1509 update : function () {
1510 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1512 Element
. show ( 'feed_browser_spinner' );
1514 new Ajax
. Request ( "backend.php" , {
1516 onComplete : function ( transport
) {
1519 Element
. hide ( 'feed_browser_spinner' );
1521 var c
= $( "browseFeedList" );
1523 var reply
= JSON
. parse ( transport
. responseText
);
1525 var r
= reply
[ 'content' ];
1526 var mode
= reply
[ 'mode' ];
1532 dojo
. parser
. parse ( "browseFeedList" );
1535 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1537 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1542 removeFromArchive : function () {
1543 var selected
= this . getSelectedFeeds ();
1545 if ( selected
. length
> 0 ) {
1547 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1550 Element
. show ( 'feed_browser_spinner' );
1552 var query
= "?op=rpc&method=remarchived&ids=" +
1553 param_escape ( selected
. toString ());;
1555 new Ajax
. Request ( "backend.php" , {
1557 onComplete : function ( transport
) {
1563 execute : function () {
1564 if ( this . validate ()) {
1573 exception_error ( "editFeed" , e
);
1577 function showFeedsWithErrors () {
1579 var query
= "backend.php?op=dlg&method=feedsWithErrors" ;
1581 if ( dijit
. byId ( "errorFeedsDlg" ))
1582 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1584 dialog
= new dijit
. Dialog ({
1585 id
: "errorFeedsDlg" ,
1586 title
: __ ( "Feeds with update errors" ),
1587 style
: "width: 600px" ,
1588 getSelectedFeeds : function () {
1589 return getSelectedTableRowIds ( "prefErrorFeedList" );
1591 removeSelected : function () {
1592 var sel_rows
= this . getSelectedFeeds ();
1594 console
. log ( sel_rows
);
1596 if ( sel_rows
. length
> 0 ) {
1597 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1600 notify_progress ( "Removing selected feeds..." , true );
1602 var query
= "?op=pref-feeds&method=remove&ids=" +
1603 param_escape ( sel_rows
. toString ());
1605 new Ajax
. Request ( "backend.php" , {
1607 onComplete : function ( transport
) {
1615 alert ( __ ( "No feeds are selected." ));
1618 execute : function () {
1619 if ( this . validate ()) {
1627 exception_error ( "showFeedsWithErrors" , e
);
1632 /* new support functions for SelectByTag */
1634 function get_all_tags ( selObj
){
1636 if ( ! selObj
) return "" ;
1639 var len
= selObj
. options
. length
;
1641 for ( var i
= 0 ; i
< len
; i
++){
1642 if ( selObj
. options
[ i
]. selected
) {
1643 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1647 if ( result
. length
> 0 ){
1648 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1654 exception_error ( "get_all_tags" , e
);
1658 function get_radio_checked ( radioObj
) {
1660 if (! radioObj
) return "" ;
1662 var len
= radioObj
. length
;
1664 if ( len
== undefined ){
1665 if ( radioObj
. checked
){
1666 return ( radioObj
. value
);
1672 for ( var i
= 0 ; i
< len
; i
++ ){
1673 if ( radioObj
[ i
]. checked
){
1674 return ( radioObj
[ i
]. value
);
1679 exception_error ( "get_radio_checked" , e
);