@@ -611,41 +611,67 @@ QueryBuilder = {
611611 } ,
612612 convert : {
613613 configured : {
614+ check_validity_of_file_content : function ( file_data ) {
615+ var result = { valid : true , description : "" } ;
616+ return result ;
617+ } ,
618+ handle_error_output : function ( valid , error_description ) {
619+ if ( valid == true ) {
620+ $ ( ".configured-download-file-ok" ) . show ( "fast" ) ;
621+ }
622+ else {
623+ $ ( "#configured_download_error_message" ) . html ( error_description ) ;
624+ $ ( ".configured-download-file-error" ) . show ( "fast" ) ;
625+ }
626+ } ,
614627 handle_file_upload : function ( evt ) {
615- var files = evt . target . files ; // FileList object
616-
617- // files is a FileList of File objects. List some properties.
618- var output = [ ] ;
619- for ( var i = 0 , f ; f = files [ i ] ; i ++ ) {
628+ $ ( ".configured-download-file-ok" ) . hide ( ) ;
629+ $ ( ".configured-download-file-error" ) . hide ( ) ;
630+ var files = evt . target . files ; // FileList object
631+ var valid_file = false ;
632+ var error_description = "" ;
633+ var output = [ ] ;
634+ var f = files [ 0 ] ;
620635
621- output . push ( '<li><strong>' , escape ( f . name ) , '</strong> (' , f . type || 'n/a' , ') - ' ,
636+ if ( get_file_extension ( f . name ) != "txt" ) {
637+ QueryBuilder . convert . configured . handle_error_output ( false , "The file uploaded is not <strong>.txt</strong> file" ) ;
638+ }
639+ else {
640+ output . push ( '<li><strong>' , escape ( f . name ) , '</strong> (' , f . type || 'n/a' , ') - ' ,
622641 f . size , ' bytes, last modified: ' ,
623642 f . lastModifiedDate ? f . lastModifiedDate . toLocaleDateString ( ) : 'n/a' ,
624643 '</li>' ) ;
625644 var reader = new FileReader ( ) ;
626645 var file_data = "" ;
627646 reader . onload = function ( e ) {
628- var blocks = QueryBuilder . convert . configured . get_string_blocks ( reader . result ) ;
629- configured_convert . header = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "header" ) ;
630- configured_convert . body = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "body" ) ;
631- configured_convert . footer = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "footer" ) ;
632- str_variable_dictionary = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "variable_dictionary" ) ;
633- arr_variable_dictionary = str_variable_dictionary . split ( "\n" ) ;
634- configured_convert . variable_dictionary = [ ] ;
635- for ( i = 0 ; i < arr_variable_dictionary . length ; i ++ ) {
636- arr_var = arr_variable_dictionary [ i ] . split ( "=" ) ;
637- if ( arr_var . length == 2 ) {
638- configured_convert . variable_dictionary . push ( { variable : arr_var [ 0 ] . trim ( ) , value : arr_var [ 1 ] . trim ( ) } ) ;
647+ var file_validity = QueryBuilder . convert . configured . check_validity_of_file_content ( reader . result ) ;
648+ if ( file_validity . valid == true ) {
649+ var blocks = QueryBuilder . convert . configured . get_string_blocks ( reader . result ) ;
650+ configured_convert . header = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "header" ) ;
651+ configured_convert . body = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "body" ) ;
652+ configured_convert . footer = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "footer" ) ;
653+ str_variable_dictionary = QueryBuilder . convert . configured . get_block_string_from_blocks ( blocks , "variable_dictionary" ) ;
654+ arr_variable_dictionary = str_variable_dictionary . split ( "\n" ) ;
655+ configured_convert . variable_dictionary = [ ] ;
656+ for ( i = 0 ; i < arr_variable_dictionary . length ; i ++ ) {
657+ arr_var = arr_variable_dictionary [ i ] . split ( "=" ) ;
658+ if ( arr_var . length == 2 ) {
659+ configured_convert . variable_dictionary . push ( { variable : arr_var [ 0 ] . trim ( ) , value : arr_var [ 1 ] . trim ( ) } ) ;
660+ }
639661 }
640662 }
663+ QueryBuilder . convert . configured . handle_error_output ( file_validity . valid , file_validity . description ) ;
641664 } ;
642665 reader . readAsText ( f ) ;
643- }
666+ }
667+
644668
645669 //document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
646- $ ( ".configured-download-file-ok" ) . show ( "fast" ) ;
670+
647671
648672 } ,
673+
674+
649675
650676 get_block_string_from_blocks : function ( blocks , block_type ) {
651677 var result = "" ;
@@ -711,6 +737,7 @@ QueryBuilder = {
711737 $ ( "#btn_group_download" ) . hide ( "fast" ) ;
712738 $ ( "#btn_download_configured_convert_template" ) . attr ( "href" , "/query/configured_convert_template?selected_properties=" + QueryBuilder . properties . get_checked_properties ( ) ) ;
713739 $ ( ".configured-download-file-ok" ) . hide ( ) ;
740+ $ ( ".configured-download-file-error" ) . hide ( ) ;
714741 } ,
715742 hide_download : function ( motion ) {
716743 if ( motion != undefined && motion != "" ) {
0 commit comments