]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
e9dcf3f3af1eb934f21861363ae9831d7ed6e423
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 closeInfoBox ( cleanup
) {
398 dialog
= dijit
. byId ( "infoBox" );
400 if ( dialog
) dialog
. hide ();
403 //exception_error("closeInfoBox", e);
409 function displayDlg ( id
, param
, callback
) {
411 notify_progress ( "Loading, please wait..." , true );
413 var query
= "?op=dlg&method=" +
414 param_escape ( id
) + "¶m=" + param_escape ( param
);
416 new Ajax
. Request ( "backend.php" , {
418 onComplete : function ( transport
) {
419 infobox_callback2 ( transport
);
420 if ( callback
) callback ( transport
);
426 function infobox_callback2 ( transport
) {
430 if ( dijit
. byId ( "infoBox" )) {
431 dialog
= dijit
. byId ( "infoBox" );
434 //console.log("infobox_callback2");
437 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
439 title
= title
. firstChild
. nodeValue
;
441 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
443 content
= content
. firstChild
. nodeValue
;
446 dialog
= new dijit
. Dialog ({
449 style
: "width: 600px" ,
450 onCancel : function () {
453 onExecute : function () {
456 onClose : function () {
461 dialog
. attr ( 'title' , title
);
462 dialog
. attr ( 'content' , content
);
469 exception_error ( "infobox_callback2" , e
);
473 function filterCR ( e
, f
)
478 key
= window
. event
. keyCode
; //IE
480 key
= e
. which
; //firefox
483 if ( typeof f
!= 'undefined' ) {
494 function getInitParam ( key
) {
495 return init_params
[ key
];
498 function setInitParam ( key
, value
) {
499 init_params
[ key
] = value
;
502 function fatalError ( code
, msg
, ext_info
) {
506 window
. location
. href
= "index.php" ;
507 } else if ( code
== 5 ) {
508 window
. location
. href
= "db-updater.php" ;
511 if ( msg
== "" ) msg
= "Unknown error" ;
514 if ( ext_info
. responseText
) {
515 ext_info
= ext_info
. responseText
;
519 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
523 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
524 "<p>" + msg
+ "</p>" ;
527 content
= content
+ "<div><b>Additional information:</b></div>" +
528 "<textarea style='width: 100%' readonly= \" 1 \" >" +
529 ext_info
+ "</textarea>" ;
532 var dialog
= new dijit
. Dialog ({
533 title
: "Fatal error" ,
534 style
: "width: 600px" ,
544 exception_error ( "fatalError" , e
);
548 /* function filterDlgCheckType(sender) {
552 var ftype = sender.value;
554 // if selected filter type is 5 (Date) enable the modifier dropbox
556 Element.show("filterDlg_dateModBox");
557 Element.show("filterDlg_dateChkBox");
559 Element.hide("filterDlg_dateModBox");
560 Element.hide("filterDlg_dateChkBox");
565 exception_error("filterDlgCheckType", e);
570 function filterDlgCheckAction ( sender
) {
574 var action
= sender
. value
;
576 var action_param
= $( "filterDlg_paramBox" );
579 console
. log ( "filterDlgCheckAction: can't find action param box!" );
583 // if selected action supports parameters, enable params field
584 if ( action
== 4 || action
== 6 || action
== 7 ) {
585 new Effect
. Appear ( action_param
, { duration
: 0.5 });
587 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
588 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
590 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
591 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
594 Element
. hide ( action_param
);
598 exception_error ( "filterDlgCheckAction" , e
);
603 function filterDlgCheckDate () {
605 var dialog
= dijit
. byId ( "filterEditDlg" );
607 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
609 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
611 new Ajax
. Request ( "backend.php" , {
613 onComplete : function ( transport
) {
615 var reply
= JSON
. parse ( transport
. responseText
);
617 if ( reply
[ 'result' ] == true ) {
618 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
621 alert ( __ ( "Date syntax is incorrect." ));
628 exception_error ( "filterDlgCheckDate" , e
);
632 function explainError ( code
) {
633 return displayDlg ( "explainError" , code
);
636 function loading_set_progress ( p
) {
638 loading_progress
+= p
;
640 if ( dijit
. byId ( "loading_bar" ))
641 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
643 if ( loading_progress
>= 90 )
647 exception_error ( "loading_set_progress" , e
);
651 function remove_splash () {
653 if ( Element
. visible ( "overlay" )) {
654 console
. log ( "about to remove splash, OMG!" );
655 Element
. hide ( "overlay" );
656 console
. log ( "removed splash!" );
660 function transport_error_check ( transport
) {
662 if ( transport
. responseXML
) {
663 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
666 var code
= error
. getAttribute ( "error-code" );
667 var msg
= error
. getAttribute ( "error-msg" );
669 fatalError ( code
, msg
);
675 exception_error ( "check_for_error_xml" , e
);
680 function strip_tags ( s
) {
681 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
684 function truncate_string ( s
, length
) {
685 if (! length
) length
= 30 ;
686 var tmp
= s
. substring ( 0 , length
);
687 if ( s
. length
> length
) tmp
+= "…" ;
691 function hotkey_prefix_timeout () {
694 var date
= new Date ();
695 var ts
= Math
. round ( date
. getTime () / 1000 );
697 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
698 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
699 hotkey_prefix_pressed
= false ;
700 hotkey_prefix
= false ;
701 Element
. hide ( 'cmdline' );
704 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
707 exception_error ( "hotkey_prefix_timeout" , e
);
711 function hideAuxDlg () {
713 Element
. hide ( 'auxDlg' );
715 exception_error ( "hideAuxDlg" , e
);
720 function uploadIconHandler ( rc
) {
724 notify_info ( "Upload complete." );
725 if ( inPreferences ()) {
728 setTimeout ( 'updateFeedList(false, false)' , 50 );
732 notify_error ( "Upload failed: icon is too big." );
735 notify_error ( "Upload failed." );
740 exception_error ( "uploadIconHandler" , e
);
744 function removeFeedIcon ( id
) {
748 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
749 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
753 notify_progress ( "Removing feed icon..." , true );
755 new Ajax
. Request ( "backend.php" , {
757 onComplete : function ( transport
) {
758 notify_info ( "Feed icon removed." );
759 if ( inPreferences ()) {
762 setTimeout ( 'updateFeedList(false, false)' , 50 );
769 exception_error ( "removeFeedIcon" , e
);
773 function uploadFeedIcon () {
777 var file
= $( "icon_file" );
779 if ( file
. value
. length
== 0 ) {
780 alert ( __ ( "Please select an image file to upload." ));
782 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
783 notify_progress ( "Uploading, please wait..." , true );
791 exception_error ( "uploadFeedIcon" , e
);
795 function addLabel ( select
, callback
) {
799 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
801 if ( caption
!= undefined ) {
804 alert ( __ ( "Can't create label: missing caption." ));
808 var query
= "?op=pref-labels&method=add&caption=" +
809 param_escape ( caption
);
812 query
+= "&output=select" ;
814 notify_progress ( "Loading, please wait..." , true );
816 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
818 new Ajax
. Request ( "backend.php" , {
820 onComplete : function ( transport
) {
823 } else if ( inPreferences ()) {
833 exception_error ( "addLabel" , e
);
837 function quickAddFeed () {
839 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
841 if ( dijit
. byId ( "feedAddDlg" ))
842 dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
844 var dialog
= new dijit
. Dialog ({
846 title
: __ ( "Subscribe to Feed" ),
847 style
: "width: 600px" ,
848 execute : function () {
849 if ( this . validate ()) {
850 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
852 var feed_url
= this . attr ( 'value' ). feed
;
854 Element
. show ( "feed_add_spinner" );
856 new Ajax
. Request ( "backend.php" , {
857 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
858 onComplete : function ( transport
) {
861 var reply
= JSON
. parse ( transport
. responseText
);
863 var rc
= reply
[ 'result' ];
866 Element
. hide ( "feed_add_spinner" );
868 console
. log ( "GOT RC: " + rc
);
870 switch ( parseInt ( rc
[ 'code' ])) {
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});
919 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
921 while ( select
. getOptions (). length
> 0 )
922 select
. removeOption ( 0 );
925 for ( var feedUrl
in feeds
) {
926 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
930 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
934 alert ( __ ( "Couldn't download the specified URL: %s" ).
935 replace ( "%s" , rc
[ 'message' ]));
938 alert ( __ ( "You are already subscribed to this feed." ));
943 exception_error ( "subscribeToFeed" , e
, transport
);
954 exception_error ( "quickAddFeed" , e
);
958 function createNewRuleElement ( parentNode
, replaceNode
) {
960 var form
= document
. forms
[ "filter_new_rule_form" ];
962 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
963 param_escape ( dojo
. formToJson ( form
));
967 new Ajax
. Request ( "backend.php" , {
969 onComplete : function ( transport
) {
971 var li
= dojo
. create ( "li" );
973 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
975 new dijit
. form
. CheckBox ({
976 onChange : function () {
977 toggleSelectListRow2 ( this ) },
980 dojo
. create ( "input" , { type
: "hidden" ,
982 value
: dojo
. formToJson ( form
) }, li
);
984 dojo
. create ( "span" , {
985 onclick : function () {
986 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
988 innerHTML
: transport
. responseText
}, li
);
991 parentNode
. replaceChild ( li
, replaceNode
);
993 parentNode
. appendChild ( li
);
996 exception_error ( "createNewRuleElement" , e
);
1000 exception_error ( "createNewRuleElement" , e
);
1004 function createNewActionElement ( parentNode
, replaceNode
) {
1006 var form
= document
. forms
[ "filter_new_action_form" ];
1008 if ( form
. action_id
. value
== 7 ) {
1009 form
. action_param
. value
= form
. action_param_label
. value
;
1012 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
1013 param_escape ( dojo
. formToJson ( form
));
1017 new Ajax
. Request ( "backend.php" , {
1019 onComplete : function ( transport
) {
1021 var li
= dojo
. create ( "li" );
1023 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
1025 new dijit
. form
. CheckBox ({
1026 onChange : function () {
1027 toggleSelectListRow2 ( this ) },
1030 dojo
. create ( "input" , { type
: "hidden" ,
1032 value
: dojo
. formToJson ( form
) }, li
);
1034 dojo
. create ( "span" , {
1035 onclick : function () {
1036 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
1038 innerHTML
: transport
. responseText
}, li
);
1041 parentNode
. replaceChild ( li
, replaceNode
);
1043 parentNode
. appendChild ( li
);
1047 exception_error ( "createNewActionElement" , e
);
1051 exception_error ( "createNewActionElement" , e
);
1056 function addFilterRule ( replaceNode
, ruleStr
) {
1058 if ( dijit
. byId ( "filterNewRuleDlg" ))
1059 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1061 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1062 param_escape ( ruleStr
);
1064 var rule_dlg
= new dijit
. Dialog ({
1065 id
: "filterNewRuleDlg" ,
1066 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1067 style
: "width: 600px" ,
1068 execute : function () {
1069 if ( this . validate ()) {
1070 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1078 exception_error ( "addFilterRule" , e
);
1082 function addFilterAction ( replaceNode
, actionStr
) {
1084 if ( dijit
. byId ( "filterNewActionDlg" ))
1085 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1087 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1088 param_escape ( actionStr
);
1090 var rule_dlg
= new dijit
. Dialog ({
1091 id
: "filterNewActionDlg" ,
1092 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1093 style
: "width: 600px" ,
1094 execute : function () {
1095 if ( this . validate ()) {
1096 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1104 exception_error ( "addFilterAction" , e
);
1108 function quickAddFilter () {
1111 if (! inPreferences ()) {
1112 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1113 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1114 param_escape ( activeFeedIsCat ());
1116 query
= "backend.php?op=pref-filters&method=newfilter" ;
1121 if ( dijit
. byId ( "feedEditDlg" ))
1122 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1124 if ( dijit
. byId ( "filterEditDlg" ))
1125 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1127 dialog
= new dijit
. Dialog ({
1128 id
: "filterEditDlg" ,
1129 title
: __ ( "Create Filter" ),
1130 style
: "width: 600px" ,
1132 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1134 if ( dijit
. byId ( "filterTestDlg" ))
1135 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1137 var test_dlg
= new dijit
. Dialog ({
1138 id
: "filterTestDlg" ,
1139 title
: "Test Filter" ,
1140 style
: "width: 600px" ,
1145 selectRules : function ( select
) {
1146 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1149 e
. parentNode
. addClassName ( "Selected" );
1151 e
. parentNode
. removeClassName ( "Selected" );
1154 selectActions : function ( select
) {
1155 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1159 e
. parentNode
. addClassName ( "Selected" );
1161 e
. parentNode
. removeClassName ( "Selected" );
1165 editRule : function ( e
) {
1166 var li
= e
. parentNode
;
1167 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1168 addFilterRule ( li
, rule
);
1170 editAction : function ( e
) {
1171 var li
= e
. parentNode
;
1172 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1173 addFilterAction ( li
, action
);
1175 addAction : function () { addFilterAction (); },
1176 addRule : function () { addFilterRule (); },
1177 deleteAction : function () {
1178 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1180 deleteRule : function () {
1181 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1183 execute : function () {
1184 if ( this . validate ()) {
1186 var query
= dojo
. formToQuery ( "filter_new_form" );
1190 new Ajax
. Request ( "backend.php" , {
1192 onComplete : function ( transport
) {
1193 if ( inPreferences ()) {
1203 if (! inPreferences ()) {
1204 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1205 dojo
. disconnect ( lh
);
1207 var title
= $( "PTITLE-FULL-" + active_post_id
);
1209 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1210 if ( title
) title
= title
. innerHTML
;
1212 console
. log ( title
+ " " + getActiveFeedId ());
1214 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1217 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1219 addFilterRule ( null , dojo
. toJson ( rule
));
1227 exception_error ( "quickAddFilter" , e
);
1231 function resetPubSub ( feed_id
, title
) {
1233 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1235 if ( title
== undefined || confirm ( msg
)) {
1236 notify_progress ( "Loading, please wait..." );
1238 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1240 new Ajax
. Request ( "backend.php" , {
1242 onComplete : function ( transport
) {
1243 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1244 notify_info ( "Subscription reset." );
1252 function unsubscribeFeed ( feed_id
, title
) {
1254 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1256 if ( title
== undefined || confirm ( msg
)) {
1257 notify_progress ( "Removing feed..." );
1259 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1261 new Ajax
. Request ( "backend.php" , {
1263 onComplete : function ( transport
) {
1265 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1267 if ( inPreferences ()) {
1270 if ( feed_id
== getActiveFeedId ())
1271 setTimeout ( "viewfeed(-5)" , 100 );
1281 function backend_sanity_check_callback ( transport
) {
1285 if ( sanity_check_done
) {
1286 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1287 "presence of Firebug or some other disrupting extension. " +
1288 "Please disable it and try again." );
1292 var reply
= JSON
. parse ( transport
. responseText
);
1295 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1299 var error_code
= reply
[ 'error' ][ 'code' ];
1301 if ( error_code
&& error_code
!= 0 ) {
1302 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1305 console
. log ( "sanity check ok" );
1307 var params
= reply
[ 'init-params' ];
1310 console
. log ( 'reading init-params...' );
1315 console
. log ( "IP: " + k
+ " => " + v
);
1319 init_params
= params
;
1322 sanity_check_done
= true ;
1324 init_second_stage ();
1327 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1331 /*function has_local_storage() {
1333 return 'sessionStorage' in window && window['sessionStorage'] != null;
1339 function catSelectOnChange ( elem
) {
1341 /* var value = elem[elem.selectedIndex].value;
1342 var def = elem.getAttribute('default');
1344 if (value == "ADD_CAT") {
1347 dropboxSelect(elem, def);
1349 elem.selectedIndex = 0;
1355 exception_error ( "catSelectOnChange" , e
);
1359 function quickAddCat ( elem
) {
1361 var cat
= prompt ( __ ( "Please enter category title:" ));
1365 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1367 notify_progress ( "Loading, please wait..." , true );
1369 new Ajax
. Request ( "backend.php" , {
1371 onComplete : function ( transport
) {
1372 var response
= transport
. responseXML
;
1373 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1374 var options
= select
. getElementsByTagName ( "option" );
1376 dropbox_replace_options ( elem
, options
);
1385 exception_error ( "quickAddCat" , e
);
1389 function genUrlChangeKey ( feed
, is_cat
) {
1392 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1396 notify_progress ( "Trying to change address..." , true );
1398 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1399 "&is_cat=" + param_escape ( is_cat
);
1401 new Ajax
. Request ( "backend.php" , {
1403 onComplete : function ( transport
) {
1404 var reply
= JSON
. parse ( transport
. responseText
);
1405 var new_link
= reply
. link
;
1407 var e
= $( 'gen_feed_url' );
1411 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1412 "&key=" + new_link
);
1414 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1415 "&key=" + new_link
);
1417 new Effect
. Highlight ( e
);
1422 notify_error ( "Could not change feed URL." );
1427 exception_error ( "genUrlChangeKey" , e
);
1432 function labelSelectOnChange ( elem
) {
1434 /* var value = elem[elem.selectedIndex].value;
1435 var def = elem.getAttribute('default');
1437 if (value == "ADD_LABEL") {
1440 dropboxSelect(elem, def);
1442 elem.selectedIndex = 0;
1444 addLabel(elem, function(transport) {
1448 var response = transport.responseXML;
1449 var select = response.getElementsByTagName("select")[0];
1450 var options = select.getElementsByTagName("option");
1452 dropbox_replace_options(elem, options);
1456 exception_error("addLabel", e);
1462 exception_error ( "labelSelectOnChange" , e
);
1466 function dropbox_replace_options ( elem
, options
) {
1469 while ( elem
. hasChildNodes ())
1470 elem
. removeChild ( elem
. firstChild
);
1474 for ( var i
= 0 ; i
< options
. length
; i
++) {
1475 var text
= options
[ i
]. firstChild
. nodeValue
;
1476 var value
= options
[ i
]. getAttribute ( "value" );
1478 if ( value
== undefined ) value
= text
;
1480 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1482 var option
= new Option ( text
, value
, issel
);
1484 if ( options
[ i
]. getAttribute ( "disabled" ))
1485 option
. setAttribute ( "disabled" , true );
1487 elem
. insert ( option
);
1489 if ( issel
) sel_idx
= i
;
1492 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1493 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1496 exception_error ( "dropbox_replace_options" , e
);
1500 // mode = all, none, invert
1501 function selectTableRows ( id
, mode
) {
1503 var rows
= $( id
). rows
;
1505 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1510 if ( row
. id
&& row
. className
) {
1511 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1512 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1514 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1515 var input
= inputs
[ j
];
1517 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1518 input
. id
. match ( bare_id
)) {
1521 dcb
= dijit
. getEnclosingWidget ( cb
);
1527 var issel
= row
. hasClassName ( "Selected" );
1529 if ( mode
== "all" && ! issel
) {
1530 row
. addClassName ( "Selected" );
1532 if ( dcb
) dcb
. set ( "checked" , true );
1533 } else if ( mode
== "none" && issel
) {
1534 row
. removeClassName ( "Selected" );
1536 if ( dcb
) dcb
. set ( "checked" , false );
1538 } else if ( mode
== "invert" ) {
1541 row
. removeClassName ( "Selected" );
1543 if ( dcb
) dcb
. set ( "checked" , false );
1545 row
. addClassName ( "Selected" );
1547 if ( dcb
) dcb
. set ( "checked" , true );
1555 exception_error ( "selectTableRows" , e
);
1560 function getSelectedTableRowIds ( id
) {
1564 var elem_rows
= $( id
). rows
;
1566 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1567 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1568 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1574 exception_error ( "getSelectedTableRowIds" , e
);
1580 function editFeed ( feed
, event
) {
1583 return alert ( __ ( "You can't edit this kind of feed." ));
1585 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1590 if ( dijit
. byId ( "filterEditDlg" ))
1591 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1593 if ( dijit
. byId ( "feedEditDlg" ))
1594 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1596 dialog
= new dijit
. Dialog ({
1598 title
: __ ( "Edit Feed" ),
1599 style
: "width: 600px" ,
1600 execute : function () {
1601 if ( this . validate ()) {
1602 // console.log(dojo.objectToQuery(this.attr('value')));
1604 notify_progress ( "Saving data..." , true );
1606 new Ajax
. Request ( "backend.php" , {
1607 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1608 onComplete : function ( transport
) {
1620 exception_error ( "editFeed" , e
);
1624 function feedBrowser () {
1626 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1628 if ( dijit
. byId ( "feedAddDlg" ))
1629 dijit
. byId ( "feedAddDlg" ). hide ();
1631 if ( dijit
. byId ( "feedBrowserDlg" ))
1632 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1634 var dialog
= new dijit
. Dialog ({
1635 id
: "feedBrowserDlg" ,
1636 title
: __ ( "More Feeds" ),
1637 style
: "width: 600px" ,
1638 getSelectedFeedIds : function () {
1639 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1640 var selected
= new Array ();
1642 list
. each ( function ( child
) {
1643 var id
= child
. id
. replace ( "FBROW-" , "" );
1645 if ( child
. hasClassName ( 'Selected' )) {
1652 getSelectedFeeds : function () {
1653 var list
= $$( "#browseFeedList li.Selected" );
1654 var selected
= new Array ();
1656 list
. each ( function ( child
) {
1657 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1658 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1660 selected
. push ([ title
, url
]);
1667 subscribe : function () {
1668 var mode
= this . attr ( 'value' ). mode
;
1672 selected
= this . getSelectedFeeds ();
1674 selected
= this . getSelectedFeedIds ();
1676 if ( selected
. length
> 0 ) {
1677 dijit
. byId ( "feedBrowserDlg" ). hide ();
1679 notify_progress ( "Loading, please wait..." , true );
1681 // we use dojo.toJson instead of JSON.stringify because
1682 // it somehow escapes everything TWICE, at least in Chrome 9
1684 var query
= "?op=rpc&method=massSubscribe&payload=" +
1685 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1689 new Ajax
. Request ( "backend.php" , {
1691 onComplete : function ( transport
) {
1697 alert ( __ ( "No feeds are selected." ));
1701 update : function () {
1702 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1704 Element
. show ( 'feed_browser_spinner' );
1706 new Ajax
. Request ( "backend.php" , {
1708 onComplete : function ( transport
) {
1711 Element
. hide ( 'feed_browser_spinner' );
1713 var c
= $( "browseFeedList" );
1715 var reply
= JSON
. parse ( transport
. responseText
);
1717 var r
= reply
[ 'content' ];
1718 var mode
= reply
[ 'mode' ];
1724 dojo
. parser
. parse ( "browseFeedList" );
1727 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1729 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1734 removeFromArchive : function () {
1735 var selected
= this . getSelectedFeeds ();
1737 if ( selected
. length
> 0 ) {
1739 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1742 Element
. show ( 'feed_browser_spinner' );
1744 var query
= "?op=rpc&method=remarchived&ids=" +
1745 param_escape ( selected
. toString ());;
1747 new Ajax
. Request ( "backend.php" , {
1749 onComplete : function ( transport
) {
1755 execute : function () {
1756 if ( this . validate ()) {
1765 exception_error ( "editFeed" , e
);
1769 function showFeedsWithErrors () {
1771 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1773 if ( dijit
. byId ( "errorFeedsDlg" ))
1774 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1776 dialog
= new dijit
. Dialog ({
1777 id
: "errorFeedsDlg" ,
1778 title
: __ ( "Feeds with update errors" ),
1779 style
: "width: 600px" ,
1780 getSelectedFeeds : function () {
1781 return getSelectedTableRowIds ( "prefErrorFeedList" );
1783 removeSelected : function () {
1784 var sel_rows
= this . getSelectedFeeds ();
1786 console
. log ( sel_rows
);
1788 if ( sel_rows
. length
> 0 ) {
1789 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1792 notify_progress ( "Removing selected feeds..." , true );
1794 var query
= "?op=pref-feeds&method=remove&ids=" +
1795 param_escape ( sel_rows
. toString ());
1797 new Ajax
. Request ( "backend.php" , {
1799 onComplete : function ( transport
) {
1807 alert ( __ ( "No feeds are selected." ));
1810 execute : function () {
1811 if ( this . validate ()) {
1819 exception_error ( "showFeedsWithErrors" , e
);
1824 /* new support functions for SelectByTag */
1826 function get_all_tags ( selObj
){
1828 if ( ! selObj
) return "" ;
1831 var len
= selObj
. options
. length
;
1833 for ( var i
= 0 ; i
< len
; i
++){
1834 if ( selObj
. options
[ i
]. selected
) {
1835 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1839 if ( result
. length
> 0 ){
1840 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1846 exception_error ( "get_all_tags" , e
);
1850 function get_radio_checked ( radioObj
) {
1852 if (! radioObj
) return "" ;
1854 var len
= radioObj
. length
;
1856 if ( len
== undefined ){
1857 if ( radioObj
. checked
){
1858 return ( radioObj
. value
);
1864 for ( var i
= 0 ; i
< len
; i
++ ){
1865 if ( radioObj
[ i
]. checked
){
1866 return ( radioObj
[ i
]. value
);
1871 exception_error ( "get_radio_checked" , e
);
1876 function get_timestamp () {
1877 var date
= new Date ();
1878 return Math
. round ( date
. getTime () / 1000 );