]>
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 gotoLogout () {
296 document
. location
. href
= "backend.php?op=logout" ;
299 function gotoMain () {
300 document
. location
. href
= "index.php" ;
303 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
304 * * @author Sundar Dorai-Raj
305 * * Email: sdoraira@vt.edu
306 * * This program is free software; you can redistribute it and/or
307 * * modify it under the terms of the GNU General Public License
308 * * as published by the Free Software Foundation; either version 2
309 * * of the License, or (at your option) any later version,
310 * * provided that any use properly credits the author.
311 * * This program is distributed in the hope that it will be useful,
312 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
313 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
314 * * GNU General Public License for more details at http://www.gnu.org * * */
316 var numbers
= ".0123456789" ;
317 function isNumeric ( x
) {
318 // is x a String or a character?
320 // remove negative sign
322 for ( var j
= 0 ; j
< x
. length
; j
++) {
323 // call isNumeric recursively for each character
324 number
= isNumeric ( x
. substring ( j
, j
+ 1 ));
325 if (! number
) return number
;
330 // if x is number return true
331 if ( numbers
. indexOf ( x
)>= 0 ) return true ;
337 function toggleSelectRowById ( sender
, id
) {
339 return toggleSelectRow ( sender
, row
);
342 function toggleSelectListRow ( sender
) {
343 var row
= sender
. parentNode
;
344 return toggleSelectRow ( sender
, row
);
347 /* this is for dijit Checkbox */
348 function toggleSelectListRow2 ( sender
) {
349 var row
= sender
. domNode
. parentNode
;
350 return toggleSelectRow ( sender
, row
);
353 /* this is for dijit Checkbox */
354 function toggleSelectRow2 ( sender
, row
, is_cdm
) {
358 row
= sender
. domNode
. parentNode
. parentNode
;
360 row
= sender
. domNode
. parentNode
. parentNode
. parentNode
; // oh ffs
362 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
363 row
. addClassName ( 'Selected' );
365 row
. removeClassName ( 'Selected' );
369 function toggleSelectRow ( sender
, row
) {
371 if (! row
) row
= sender
. parentNode
. parentNode
;
373 if ( sender
. checked
&& ! row
. hasClassName ( 'Selected' ))
374 row
. addClassName ( 'Selected' );
376 row
. removeClassName ( 'Selected' );
379 function checkboxToggleElement ( elem
, id
) {
381 Effect
. Appear ( id
, { duration
: 0.5 });
383 Effect
. Fade ( id
, { duration
: 0.5 });
387 function dropboxSelect ( e
, v
) {
388 for ( var i
= 0 ; i
< e
. length
; i
++) {
389 if ( e
[ i
]. value
== v
) {
396 function getURLParam ( param
){
397 return String ( window
. location
. href
). parseQuery ()[ param
];
400 function closeInfoBox ( cleanup
) {
402 dialog
= dijit
. byId ( "infoBox" );
404 if ( dialog
) dialog
. hide ();
407 //exception_error("closeInfoBox", e);
413 function displayDlg ( id
, param
, callback
) {
415 notify_progress ( "Loading, please wait..." , true );
417 var query
= "?op=dlg&method=" +
418 param_escape ( id
) + "¶m=" + param_escape ( param
);
420 new Ajax
. Request ( "backend.php" , {
422 onComplete : function ( transport
) {
423 infobox_callback2 ( transport
);
424 if ( callback
) callback ( transport
);
430 function infobox_callback2 ( transport
) {
434 if ( dijit
. byId ( "infoBox" )) {
435 dialog
= dijit
. byId ( "infoBox" );
438 //console.log("infobox_callback2");
441 var title
= transport
. responseXML
. getElementsByTagName ( "title" )[ 0 ];
443 title
= title
. firstChild
. nodeValue
;
445 var content
= transport
. responseXML
. getElementsByTagName ( "content" )[ 0 ];
447 content
= content
. firstChild
. nodeValue
;
450 dialog
= new dijit
. Dialog ({
453 style
: "width: 600px" ,
454 onCancel : function () {
457 onExecute : function () {
460 onClose : function () {
465 dialog
. attr ( 'title' , title
);
466 dialog
. attr ( 'content' , content
);
473 exception_error ( "infobox_callback2" , e
);
477 function filterCR ( e
, f
)
482 key
= window
. event
. keyCode
; //IE
484 key
= e
. which
; //firefox
487 if ( typeof f
!= 'undefined' ) {
498 function getInitParam ( key
) {
499 return init_params
[ key
];
502 function setInitParam ( key
, value
) {
503 init_params
[ key
] = value
;
506 function fatalError ( code
, msg
, ext_info
) {
510 window
. location
. href
= "index.php" ;
511 } else if ( code
== 5 ) {
512 window
. location
. href
= "db-updater.php" ;
515 if ( msg
== "" ) msg
= "Unknown error" ;
518 if ( ext_info
. responseText
) {
519 ext_info
= ext_info
. responseText
;
523 if ( ERRORS
&& ERRORS
[ code
] && ! msg
) {
527 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
528 "<p>" + msg
+ "</p>" ;
531 content
= content
+ "<div><b>Additional information:</b></div>" +
532 "<textarea style='width: 100%' readonly= \" 1 \" >" +
533 ext_info
+ "</textarea>" ;
536 var dialog
= new dijit
. Dialog ({
537 title
: "Fatal error" ,
538 style
: "width: 600px" ,
548 exception_error ( "fatalError" , e
);
552 /* function filterDlgCheckType(sender) {
556 var ftype = sender.value;
558 // if selected filter type is 5 (Date) enable the modifier dropbox
560 Element.show("filterDlg_dateModBox");
561 Element.show("filterDlg_dateChkBox");
563 Element.hide("filterDlg_dateModBox");
564 Element.hide("filterDlg_dateChkBox");
569 exception_error("filterDlgCheckType", e);
574 function filterDlgCheckAction ( sender
) {
578 var action
= sender
. value
;
580 var action_param
= $( "filterDlg_paramBox" );
583 console
. log ( "filterDlgCheckAction: can't find action param box!" );
587 // if selected action supports parameters, enable params field
588 if ( action
== 4 || action
== 6 || action
== 7 ) {
589 new Effect
. Appear ( action_param
, { duration
: 0.5 });
591 Element
. show ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
592 Element
. hide ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
594 Element
. show ( dijit
. byId ( "filterDlg_actionParamLabel" ). domNode
);
595 Element
. hide ( dijit
. byId ( "filterDlg_actionParam" ). domNode
);
598 Element
. hide ( action_param
);
602 exception_error ( "filterDlgCheckAction" , e
);
607 function filterDlgCheckDate () {
609 var dialog
= dijit
. byId ( "filterEditDlg" );
611 var reg_exp
= dialog
. attr ( 'value' ). reg_exp
;
613 var query
= "?op=rpc&method=checkDate&date=" + reg_exp
;
615 new Ajax
. Request ( "backend.php" , {
617 onComplete : function ( transport
) {
619 var reply
= JSON
. parse ( transport
. responseText
);
621 if ( reply
[ 'result' ] == true ) {
622 alert ( __ ( "Date syntax appears to be correct:" ) + " " + reply
[ 'date' ]);
625 alert ( __ ( "Date syntax is incorrect." ));
632 exception_error ( "filterDlgCheckDate" , e
);
636 function explainError ( code
) {
637 return displayDlg ( "explainError" , code
);
640 function loading_set_progress ( p
) {
642 loading_progress
+= p
;
644 if ( dijit
. byId ( "loading_bar" ))
645 dijit
. byId ( "loading_bar" ). update ({ progress
: loading_progress
});
647 if ( loading_progress
>= 90 )
651 exception_error ( "loading_set_progress" , e
);
655 function remove_splash () {
657 if ( Element
. visible ( "overlay" )) {
658 console
. log ( "about to remove splash, OMG!" );
659 Element
. hide ( "overlay" );
660 console
. log ( "removed splash!" );
664 function transport_error_check ( transport
) {
666 if ( transport
. responseXML
) {
667 var error
= transport
. responseXML
. getElementsByTagName ( "error" )[ 0 ];
670 var code
= error
. getAttribute ( "error-code" );
671 var msg
= error
. getAttribute ( "error-msg" );
673 fatalError ( code
, msg
);
679 exception_error ( "check_for_error_xml" , e
);
684 function strip_tags ( s
) {
685 return s
. replace ( /<\/?[^>]+(>|$)/g , "" );
688 function truncate_string ( s
, length
) {
689 if (! length
) length
= 30 ;
690 var tmp
= s
. substring ( 0 , length
);
691 if ( s
. length
> length
) tmp
+= "…" ;
695 function hotkey_prefix_timeout () {
698 var date
= new Date ();
699 var ts
= Math
. round ( date
. getTime () / 1000 );
701 if ( hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5 ) {
702 console
. log ( "hotkey_prefix seems to be stuck, aborting" );
703 hotkey_prefix_pressed
= false ;
704 hotkey_prefix
= false ;
705 Element
. hide ( 'cmdline' );
708 setTimeout ( "hotkey_prefix_timeout()" , 1000 );
711 exception_error ( "hotkey_prefix_timeout" , e
);
715 function hideAuxDlg () {
717 Element
. hide ( 'auxDlg' );
719 exception_error ( "hideAuxDlg" , e
);
724 function uploadIconHandler ( rc
) {
728 notify_info ( "Upload complete." );
729 if ( inPreferences ()) {
732 setTimeout ( 'updateFeedList(false, false)' , 50 );
736 notify_error ( "Upload failed: icon is too big." );
739 notify_error ( "Upload failed." );
744 exception_error ( "uploadIconHandler" , e
);
748 function removeFeedIcon ( id
) {
752 if ( confirm ( __ ( "Remove stored feed icon?" ))) {
753 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape ( id
);
757 notify_progress ( "Removing feed icon..." , true );
759 new Ajax
. Request ( "backend.php" , {
761 onComplete : function ( transport
) {
762 notify_info ( "Feed icon removed." );
763 if ( inPreferences ()) {
766 setTimeout ( 'updateFeedList(false, false)' , 50 );
773 exception_error ( "removeFeedIcon" , e
);
777 function uploadFeedIcon () {
781 var file
= $( "icon_file" );
783 if ( file
. value
. length
== 0 ) {
784 alert ( __ ( "Please select an image file to upload." ));
786 if ( confirm ( __ ( "Upload new icon for this feed?" ))) {
787 notify_progress ( "Uploading, please wait..." , true );
795 exception_error ( "uploadFeedIcon" , e
);
799 function addLabel ( select
, callback
) {
803 var caption
= prompt ( __ ( "Please enter label caption:" ), "" );
805 if ( caption
!= undefined ) {
808 alert ( __ ( "Can't create label: missing caption." ));
812 var query
= "?op=pref-labels&method=add&caption=" +
813 param_escape ( caption
);
816 query
+= "&output=select" ;
818 notify_progress ( "Loading, please wait..." , true );
820 if ( inPreferences () && ! select
) active_tab
= "labelConfig" ;
822 new Ajax
. Request ( "backend.php" , {
824 onComplete : function ( transport
) {
827 } else if ( inPreferences ()) {
837 exception_error ( "addLabel" , e
);
841 function quickAddFeed () {
843 var query
= "backend.php?op=dlg&method=quickAddFeed" ;
845 // overlapping widgets
846 if ( dijit
. byId ( "batchSubDlg" )) dijit
. byId ( "batchSubDlg" ). destroyRecursive ();
847 if ( dijit
. byId ( "feedAddDlg" )) dijit
. byId ( "feedAddDlg" ). destroyRecursive ();
849 var dialog
= new dijit
. Dialog ({
851 title
: __ ( "Subscribe to Feed" ),
852 style
: "width: 600px" ,
853 execute : function () {
854 if ( this . validate ()) {
855 console
. log ( dojo
. objectToQuery ( this . attr ( 'value' )));
857 var feed_url
= this . attr ( 'value' ). feed
;
859 Element
. show ( "feed_add_spinner" );
861 new Ajax
. Request ( "backend.php" , {
862 parameters
: dojo
. objectToQuery ( this . attr ( 'value' )),
863 onComplete : function ( transport
) {
866 var reply
= JSON
. parse ( transport
. responseText
);
868 var rc
= reply
[ 'result' ];
871 Element
. hide ( "feed_add_spinner" );
873 console
. log ( "GOT RC: " + rc
);
875 switch ( parseInt ( rc
[ 'code' ])) {
878 notify_info ( __ ( "Subscribed to %s" ). replace ( "%s" , feed_url
));
883 alert ( __ ( "Specified URL seems to be invalid." ));
886 alert ( __ ( "Specified URL doesn't seem to contain any feeds." ));
889 /* notify_progress("Searching for feed urls...", true);
891 new Ajax.Request("backend.php", {
892 parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url),
893 onComplete: function(transport, dialog, feed_url) {
897 var reply = JSON.parse(transport.responseText);
899 var feeds = reply['urls'];
901 console.log(transport.responseText);
903 var select = dijit.byId("feedDlg_feedContainerSelect");
905 while (select.getOptions().length > 0)
906 select.removeOption(0);
909 for (var feedUrl in feeds) {
910 select.addOption({value: feedUrl, label: feeds[feedUrl]});
914 // if (count > 5) count = 5;
915 // select.size = count;
917 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
924 var select
= dijit
. byId ( "feedDlg_feedContainerSelect" );
926 while ( select
. getOptions (). length
> 0 )
927 select
. removeOption ( 0 );
930 for ( var feedUrl
in feeds
) {
931 select
. addOption ({ value
: feedUrl
, label
: feeds
[ feedUrl
]});
935 Effect
. Appear ( 'feedDlg_feedsContainer' , { duration
: 0.5 });
939 alert ( __ ( "Couldn't download the specified URL: %s" ).
940 replace ( "%s" , rc
[ 'message' ]));
943 alert ( __ ( "You are already subscribed to this feed." ));
948 exception_error ( "subscribeToFeed" , e
, transport
);
959 exception_error ( "quickAddFeed" , e
);
963 function createNewRuleElement ( parentNode
, replaceNode
) {
965 var form
= document
. forms
[ "filter_new_rule_form" ];
967 form
. reg_exp
. value
= form
. reg_exp
. value
. replace ( /(<([^>]+)>)/ig , "" );
969 var query
= "backend.php?op=pref-filters&method=printrulename&rule=" +
970 param_escape ( dojo
. formToJson ( form
));
974 new Ajax
. Request ( "backend.php" , {
976 onComplete : function ( transport
) {
978 var li
= dojo
. create ( "li" );
980 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
982 new dijit
. form
. CheckBox ({
983 onChange : function () {
984 toggleSelectListRow2 ( this ) },
987 dojo
. create ( "input" , { type
: "hidden" ,
989 value
: dojo
. formToJson ( form
) }, li
);
991 dojo
. create ( "span" , {
992 onclick : function () {
993 dijit
. byId ( 'filterEditDlg' ). editRule ( this );
995 innerHTML
: transport
. responseText
}, li
);
998 parentNode
. replaceChild ( li
, replaceNode
);
1000 parentNode
. appendChild ( li
);
1003 exception_error ( "createNewRuleElement" , e
);
1007 exception_error ( "createNewRuleElement" , e
);
1011 function createNewActionElement ( parentNode
, replaceNode
) {
1013 var form
= document
. forms
[ "filter_new_action_form" ];
1015 if ( form
. action_id
. value
== 7 ) {
1016 form
. action_param
. value
= form
. action_param_label
. value
;
1019 var query
= "backend.php?op=pref-filters&method=printactionname&action=" +
1020 param_escape ( dojo
. formToJson ( form
));
1024 new Ajax
. Request ( "backend.php" , {
1026 onComplete : function ( transport
) {
1028 var li
= dojo
. create ( "li" );
1030 var cb
= dojo
. create ( "input" , { type
: "checkbox" }, li
);
1032 new dijit
. form
. CheckBox ({
1033 onChange : function () {
1034 toggleSelectListRow2 ( this ) },
1037 dojo
. create ( "input" , { type
: "hidden" ,
1039 value
: dojo
. formToJson ( form
) }, li
);
1041 dojo
. create ( "span" , {
1042 onclick : function () {
1043 dijit
. byId ( 'filterEditDlg' ). editAction ( this );
1045 innerHTML
: transport
. responseText
}, li
);
1048 parentNode
. replaceChild ( li
, replaceNode
);
1050 parentNode
. appendChild ( li
);
1054 exception_error ( "createNewActionElement" , e
);
1058 exception_error ( "createNewActionElement" , e
);
1063 function addFilterRule ( replaceNode
, ruleStr
) {
1065 if ( dijit
. byId ( "filterNewRuleDlg" ))
1066 dijit
. byId ( "filterNewRuleDlg" ). destroyRecursive ();
1068 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
1069 param_escape ( ruleStr
);
1071 var rule_dlg
= new dijit
. Dialog ({
1072 id
: "filterNewRuleDlg" ,
1073 title
: ruleStr
? __ ( "Edit rule" ) : __ ( "Add rule" ),
1074 style
: "width: 600px" ,
1075 execute : function () {
1076 if ( this . validate ()) {
1077 createNewRuleElement ($( "filterDlg_Matches" ), replaceNode
);
1085 exception_error ( "addFilterRule" , e
);
1089 function addFilterAction ( replaceNode
, actionStr
) {
1091 if ( dijit
. byId ( "filterNewActionDlg" ))
1092 dijit
. byId ( "filterNewActionDlg" ). destroyRecursive ();
1094 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
1095 param_escape ( actionStr
);
1097 var rule_dlg
= new dijit
. Dialog ({
1098 id
: "filterNewActionDlg" ,
1099 title
: actionStr
? __ ( "Edit action" ) : __ ( "Add action" ),
1100 style
: "width: 600px" ,
1101 execute : function () {
1102 if ( this . validate ()) {
1103 createNewActionElement ($( "filterDlg_Actions" ), replaceNode
);
1111 exception_error ( "addFilterAction" , e
);
1115 function quickAddFilter () {
1118 if (! inPreferences ()) {
1119 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
1120 param_escape ( getActiveFeedId ()) + "&is_cat=" +
1121 param_escape ( activeFeedIsCat ());
1123 query
= "backend.php?op=pref-filters&method=newfilter" ;
1128 if ( dijit
. byId ( "feedEditDlg" ))
1129 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1131 if ( dijit
. byId ( "filterEditDlg" ))
1132 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1134 dialog
= new dijit
. Dialog ({
1135 id
: "filterEditDlg" ,
1136 title
: __ ( "Create Filter" ),
1137 style
: "width: 600px" ,
1139 var query
= "backend.php?" + dojo
. formToQuery ( "filter_new_form" ) + "&savemode=test" ;
1141 if ( dijit
. byId ( "filterTestDlg" ))
1142 dijit
. byId ( "filterTestDlg" ). destroyRecursive ();
1144 var test_dlg
= new dijit
. Dialog ({
1145 id
: "filterTestDlg" ,
1146 title
: "Test Filter" ,
1147 style
: "width: 600px" ,
1152 selectRules : function ( select
) {
1153 $$( "#filterDlg_Matches input[type=checkbox]" ). each ( function ( e
) {
1156 e
. parentNode
. addClassName ( "Selected" );
1158 e
. parentNode
. removeClassName ( "Selected" );
1161 selectActions : function ( select
) {
1162 $$( "#filterDlg_Actions input[type=checkbox]" ). each ( function ( e
) {
1166 e
. parentNode
. addClassName ( "Selected" );
1168 e
. parentNode
. removeClassName ( "Selected" );
1172 editRule : function ( e
) {
1173 var li
= e
. parentNode
;
1174 var rule
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1175 addFilterRule ( li
, rule
);
1177 editAction : function ( e
) {
1178 var li
= e
. parentNode
;
1179 var action
= li
. getElementsByTagName ( "INPUT" )[ 1 ]. value
;
1180 addFilterAction ( li
, action
);
1182 addAction : function () { addFilterAction (); },
1183 addRule : function () { addFilterRule (); },
1184 deleteAction : function () {
1185 $$( "#filterDlg_Actions li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1187 deleteRule : function () {
1188 $$( "#filterDlg_Matches li.[class*=Selected]" ). each ( function ( e
) { e
. parentNode
. removeChild ( e
) });
1190 execute : function () {
1191 if ( this . validate ()) {
1193 var query
= dojo
. formToQuery ( "filter_new_form" );
1197 new Ajax
. Request ( "backend.php" , {
1199 onComplete : function ( transport
) {
1200 if ( inPreferences ()) {
1210 if (! inPreferences ()) {
1211 var lh
= dojo
. connect ( dialog
, "onLoad" , function (){
1212 dojo
. disconnect ( lh
);
1214 var title
= $( "PTITLE-FULL-" + getActiveArticleId ());
1216 if ( title
|| getActiveFeedId () || activeFeedIsCat ()) {
1217 if ( title
) title
= title
. innerHTML
;
1219 console
. log ( title
+ " " + getActiveFeedId ());
1221 var feed_id
= activeFeedIsCat () ? 'CAT:' + parseInt ( getActiveFeedId ()) :
1224 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1226 addFilterRule ( null , dojo
. toJson ( rule
));
1234 exception_error ( "quickAddFilter" , e
);
1238 function resetPubSub ( feed_id
, title
) {
1240 var msg
= __ ( "Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update." ). replace ( "%s" , title
);
1242 if ( title
== undefined || confirm ( msg
)) {
1243 notify_progress ( "Loading, please wait..." );
1245 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1247 new Ajax
. Request ( "backend.php" , {
1249 onComplete : function ( transport
) {
1250 dijit
. byId ( "pubsubReset_Btn" ). attr ( 'disabled' , true );
1251 notify_info ( "Subscription reset." );
1259 function unsubscribeFeed ( feed_id
, title
) {
1261 var msg
= __ ( "Unsubscribe from %s?" ). replace ( "%s" , title
);
1263 if ( title
== undefined || confirm ( msg
)) {
1264 notify_progress ( "Removing feed..." );
1266 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1268 new Ajax
. Request ( "backend.php" , {
1270 onComplete : function ( transport
) {
1272 if ( dijit
. byId ( "feedEditDlg" )) dijit
. byId ( "feedEditDlg" ). hide ();
1274 if ( inPreferences ()) {
1277 if ( feed_id
== getActiveFeedId ())
1278 setTimeout ( "viewfeed(-5)" , 100 );
1280 if ( feed_id
< 0 ) updateFeedList ();
1290 function backend_sanity_check_callback ( transport
) {
1294 if ( sanity_check_done
) {
1295 fatalError ( 11 , "Sanity check request received twice. This can indicate " +
1296 "presence of Firebug or some other disrupting extension. " +
1297 "Please disable it and try again." );
1301 var reply
= JSON
. parse ( transport
. responseText
);
1304 fatalError ( 3 , "Sanity check: invalid RPC reply" , transport
. responseText
);
1308 var error_code
= reply
[ 'error' ][ 'code' ];
1310 if ( error_code
&& error_code
!= 0 ) {
1311 return fatalError ( error_code
, reply
[ 'error' ][ 'message' ]);
1314 console
. log ( "sanity check ok" );
1316 var params
= reply
[ 'init-params' ];
1319 console
. log ( 'reading init-params...' );
1324 console
. log ( "IP: " + k
+ " => " + v
);
1328 init_params
= params
;
1331 sanity_check_done
= true ;
1333 init_second_stage ();
1336 exception_error ( "backend_sanity_check_callback" , e
, transport
);
1340 /*function has_local_storage() {
1342 return 'sessionStorage' in window && window['sessionStorage'] != null;
1348 function catSelectOnChange ( elem
) {
1350 /* var value = elem[elem.selectedIndex].value;
1351 var def = elem.getAttribute('default');
1353 if (value == "ADD_CAT") {
1356 dropboxSelect(elem, def);
1358 elem.selectedIndex = 0;
1364 exception_error ( "catSelectOnChange" , e
);
1368 function quickAddCat ( elem
) {
1370 var cat
= prompt ( __ ( "Please enter category title:" ));
1374 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape ( cat
);
1376 notify_progress ( "Loading, please wait..." , true );
1378 new Ajax
. Request ( "backend.php" , {
1380 onComplete : function ( transport
) {
1381 var response
= transport
. responseXML
;
1382 var select
= response
. getElementsByTagName ( "select" )[ 0 ];
1383 var options
= select
. getElementsByTagName ( "option" );
1385 dropbox_replace_options ( elem
, options
);
1394 exception_error ( "quickAddCat" , e
);
1398 function genUrlChangeKey ( feed
, is_cat
) {
1401 var ok
= confirm ( __ ( "Generate new syndication address for this feed?" ));
1405 notify_progress ( "Trying to change address..." , true );
1407 var query
= "?op=rpc&method=regenFeedKey&id=" + param_escape ( feed
) +
1408 "&is_cat=" + param_escape ( is_cat
);
1410 new Ajax
. Request ( "backend.php" , {
1412 onComplete : function ( transport
) {
1413 var reply
= JSON
. parse ( transport
. responseText
);
1414 var new_link
= reply
. link
;
1416 var e
= $( 'gen_feed_url' );
1420 e
. innerHTML
= e
. innerHTML
. replace ( /\&key=.*$/ ,
1421 "&key=" + new_link
);
1423 e
. href
= e
. href
. replace ( /\&key=.*$/ ,
1424 "&key=" + new_link
);
1426 new Effect
. Highlight ( e
);
1431 notify_error ( "Could not change feed URL." );
1436 exception_error ( "genUrlChangeKey" , e
);
1441 function labelSelectOnChange ( elem
) {
1443 /* var value = elem[elem.selectedIndex].value;
1444 var def = elem.getAttribute('default');
1446 if (value == "ADD_LABEL") {
1449 dropboxSelect(elem, def);
1451 elem.selectedIndex = 0;
1453 addLabel(elem, function(transport) {
1457 var response = transport.responseXML;
1458 var select = response.getElementsByTagName("select")[0];
1459 var options = select.getElementsByTagName("option");
1461 dropbox_replace_options(elem, options);
1465 exception_error("addLabel", e);
1471 exception_error ( "labelSelectOnChange" , e
);
1475 function dropbox_replace_options ( elem
, options
) {
1478 while ( elem
. hasChildNodes ())
1479 elem
. removeChild ( elem
. firstChild
);
1483 for ( var i
= 0 ; i
< options
. length
; i
++) {
1484 var text
= options
[ i
]. firstChild
. nodeValue
;
1485 var value
= options
[ i
]. getAttribute ( "value" );
1487 if ( value
== undefined ) value
= text
;
1489 var issel
= options
[ i
]. getAttribute ( "selected" ) == "1" ;
1491 var option
= new Option ( text
, value
, issel
);
1493 if ( options
[ i
]. getAttribute ( "disabled" ))
1494 option
. setAttribute ( "disabled" , true );
1496 elem
. insert ( option
);
1498 if ( issel
) sel_idx
= i
;
1501 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1502 if ( sel_idx
>= 0 ) elem
. selectedIndex
= sel_idx
;
1505 exception_error ( "dropbox_replace_options" , e
);
1509 // mode = all, none, invert
1510 function selectTableRows ( id
, mode
) {
1512 var rows
= $( id
). rows
;
1514 for ( var i
= 0 ; i
< rows
. length
; i
++) {
1519 if ( row
. id
&& row
. className
) {
1520 var bare_id
= row
. id
. replace ( /^[A-Z]*?-/ , "" );
1521 var inputs
= rows
[ i
]. getElementsByTagName ( "input" );
1523 for ( var j
= 0 ; j
< inputs
. length
; j
++) {
1524 var input
= inputs
[ j
];
1526 if ( input
. getAttribute ( "type" ) == "checkbox" &&
1527 input
. id
. match ( bare_id
)) {
1530 dcb
= dijit
. getEnclosingWidget ( cb
);
1536 var issel
= row
. hasClassName ( "Selected" );
1538 if ( mode
== "all" && ! issel
) {
1539 row
. addClassName ( "Selected" );
1541 if ( dcb
) dcb
. set ( "checked" , true );
1542 } else if ( mode
== "none" && issel
) {
1543 row
. removeClassName ( "Selected" );
1545 if ( dcb
) dcb
. set ( "checked" , false );
1547 } else if ( mode
== "invert" ) {
1550 row
. removeClassName ( "Selected" );
1552 if ( dcb
) dcb
. set ( "checked" , false );
1554 row
. addClassName ( "Selected" );
1556 if ( dcb
) dcb
. set ( "checked" , true );
1564 exception_error ( "selectTableRows" , e
);
1569 function getSelectedTableRowIds ( id
) {
1573 var elem_rows
= $( id
). rows
;
1575 for ( var i
= 0 ; i
< elem_rows
. length
; i
++) {
1576 if ( elem_rows
[ i
]. hasClassName ( "Selected" )) {
1577 var bare_id
= elem_rows
[ i
]. id
. replace ( /^[A-Z]*?-/ , "" );
1583 exception_error ( "getSelectedTableRowIds" , e
);
1589 function editFeed ( feed
, event
) {
1592 return alert ( __ ( "You can't edit this kind of feed." ));
1594 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1599 if ( dijit
. byId ( "filterEditDlg" ))
1600 dijit
. byId ( "filterEditDlg" ). destroyRecursive ();
1602 if ( dijit
. byId ( "feedEditDlg" ))
1603 dijit
. byId ( "feedEditDlg" ). destroyRecursive ();
1605 dialog
= new dijit
. Dialog ({
1607 title
: __ ( "Edit Feed" ),
1608 style
: "width: 600px" ,
1609 execute : function () {
1610 if ( this . validate ()) {
1611 // console.log(dojo.objectToQuery(this.attr('value')));
1613 notify_progress ( "Saving data..." , true );
1615 new Ajax
. Request ( "backend.php" , {
1616 parameters
: dojo
. objectToQuery ( dialog
. attr ( 'value' )),
1617 onComplete : function ( transport
) {
1629 exception_error ( "editFeed" , e
);
1633 function feedBrowser () {
1635 var query
= "backend.php?op=dlg&method=feedBrowser" ;
1637 if ( dijit
. byId ( "feedAddDlg" ))
1638 dijit
. byId ( "feedAddDlg" ). hide ();
1640 if ( dijit
. byId ( "feedBrowserDlg" ))
1641 dijit
. byId ( "feedBrowserDlg" ). destroyRecursive ();
1643 var dialog
= new dijit
. Dialog ({
1644 id
: "feedBrowserDlg" ,
1645 title
: __ ( "More Feeds" ),
1646 style
: "width: 600px" ,
1647 getSelectedFeedIds : function () {
1648 var list
= $$( "#browseFeedList li[id*=FBROW]" );
1649 var selected
= new Array ();
1651 list
. each ( function ( child
) {
1652 var id
= child
. id
. replace ( "FBROW-" , "" );
1654 if ( child
. hasClassName ( 'Selected' )) {
1661 getSelectedFeeds : function () {
1662 var list
= $$( "#browseFeedList li.Selected" );
1663 var selected
= new Array ();
1665 list
. each ( function ( child
) {
1666 var title
= child
. getElementsBySelector ( "span.fb_feedTitle" )[ 0 ]. innerHTML
;
1667 var url
= child
. getElementsBySelector ( "a.fb_feedUrl" )[ 0 ]. href
;
1669 selected
. push ([ title
, url
]);
1676 subscribe : function () {
1677 var mode
= this . attr ( 'value' ). mode
;
1681 selected
= this . getSelectedFeeds ();
1683 selected
= this . getSelectedFeedIds ();
1685 if ( selected
. length
> 0 ) {
1686 dijit
. byId ( "feedBrowserDlg" ). hide ();
1688 notify_progress ( "Loading, please wait..." , true );
1690 // we use dojo.toJson instead of JSON.stringify because
1691 // it somehow escapes everything TWICE, at least in Chrome 9
1693 var query
= "?op=rpc&method=massSubscribe&payload=" +
1694 param_escape ( dojo
. toJson ( selected
)) + "&mode=" + param_escape ( mode
);
1698 new Ajax
. Request ( "backend.php" , {
1700 onComplete : function ( transport
) {
1706 alert ( __ ( "No feeds are selected." ));
1710 update : function () {
1711 var query
= dojo
. objectToQuery ( dialog
. attr ( 'value' ));
1713 Element
. show ( 'feed_browser_spinner' );
1715 new Ajax
. Request ( "backend.php" , {
1717 onComplete : function ( transport
) {
1720 Element
. hide ( 'feed_browser_spinner' );
1722 var c
= $( "browseFeedList" );
1724 var reply
= JSON
. parse ( transport
. responseText
);
1726 var r
= reply
[ 'content' ];
1727 var mode
= reply
[ 'mode' ];
1733 dojo
. parser
. parse ( "browseFeedList" );
1736 Element
. show ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1738 Element
. hide ( dijit
. byId ( 'feed_archive_remove' ). domNode
);
1743 removeFromArchive : function () {
1744 var selected
= this . getSelectedFeeds ();
1746 if ( selected
. length
> 0 ) {
1748 var pr
= __ ( "Remove selected feeds from the archive? Feeds with stored articles will not be removed." );
1751 Element
. show ( 'feed_browser_spinner' );
1753 var query
= "?op=rpc&method=remarchived&ids=" +
1754 param_escape ( selected
. toString ());;
1756 new Ajax
. Request ( "backend.php" , {
1758 onComplete : function ( transport
) {
1764 execute : function () {
1765 if ( this . validate ()) {
1774 exception_error ( "editFeed" , e
);
1778 function showFeedsWithErrors () {
1780 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors" ;
1782 if ( dijit
. byId ( "errorFeedsDlg" ))
1783 dijit
. byId ( "errorFeedsDlg" ). destroyRecursive ();
1785 dialog
= new dijit
. Dialog ({
1786 id
: "errorFeedsDlg" ,
1787 title
: __ ( "Feeds with update errors" ),
1788 style
: "width: 600px" ,
1789 getSelectedFeeds : function () {
1790 return getSelectedTableRowIds ( "prefErrorFeedList" );
1792 removeSelected : function () {
1793 var sel_rows
= this . getSelectedFeeds ();
1795 console
. log ( sel_rows
);
1797 if ( sel_rows
. length
> 0 ) {
1798 var ok
= confirm ( __ ( "Remove selected feeds?" ));
1801 notify_progress ( "Removing selected feeds..." , true );
1803 var query
= "?op=pref-feeds&method=remove&ids=" +
1804 param_escape ( sel_rows
. toString ());
1806 new Ajax
. Request ( "backend.php" , {
1808 onComplete : function ( transport
) {
1816 alert ( __ ( "No feeds are selected." ));
1819 execute : function () {
1820 if ( this . validate ()) {
1828 exception_error ( "showFeedsWithErrors" , e
);
1833 /* new support functions for SelectByTag */
1835 function get_all_tags ( selObj
){
1837 if ( ! selObj
) return "" ;
1840 var len
= selObj
. options
. length
;
1842 for ( var i
= 0 ; i
< len
; i
++){
1843 if ( selObj
. options
[ i
]. selected
) {
1844 result
+= selObj
[ i
]. value
+ "%2C" ; // is really a comma
1848 if ( result
. length
> 0 ){
1849 result
= result
. substr ( 0 , result
. length
- 3 ); // remove trailing %2C
1855 exception_error ( "get_all_tags" , e
);
1859 function get_radio_checked ( radioObj
) {
1861 if (! radioObj
) return "" ;
1863 var len
= radioObj
. length
;
1865 if ( len
== undefined ){
1866 if ( radioObj
. checked
){
1867 return ( radioObj
. value
);
1873 for ( var i
= 0 ; i
< len
; i
++ ){
1874 if ( radioObj
[ i
]. checked
){
1875 return ( radioObj
[ i
]. value
);
1880 exception_error ( "get_radio_checked" , e
);
1885 function get_timestamp () {
1886 var date
= new Date ();
1887 return Math
. round ( date
. getTime () / 1000 );
1890 function helpDialog ( topic
) {
1892 var query
= "backend.php?op=backend&method=help&topic=" + param_escape ( topic
);
1894 if ( dijit
. byId ( "helpDlg" ))
1895 dijit
. byId ( "helpDlg" ). destroyRecursive ();
1897 dialog
= new dijit
. Dialog ({
1900 style
: "width: 600px" ,
1907 exception_error ( "helpDialog" , e
);