@ -1,10 +1,10 @@
var create _type = 0 ;
var interval = null ;
head ( function ( ) {
//Create new table
$ ( 'a.new_table' ) . click ( function ( ev ) {
ev . preventDefault ( ) ;
@ -13,8 +13,8 @@
$ ( 'div.mamufas' ) . fadeIn ( ) ;
bindESC ( ) ;
} ) ;
$ ( 'div.create_window ul li a' ) . click ( function ( ev ) {
ev . stopPropagation ( ) ;
ev . preventDefault ( ) ;
@ -24,8 +24,8 @@
( create _type == 0 ) ? create _type ++ : create _type -- ;
}
} ) ;
$ ( 'span.file input' ) . hover ( function ( ev ) {
$ ( 'span.file a' ) . addClass ( 'hover' ) ;
$ ( document ) . css ( 'cursor' , 'pointer' ) ;
@ -33,56 +33,30 @@
$ ( 'span.file a' ) . removeClass ( 'hover' ) ;
$ ( document ) . css ( 'cursor' , 'default' ) ;
} ) ;
$ ( 'input[type="file"]' ) . change ( function ( ev ) {
$ ( 'div.select_file p' ) . text ( $ ( this ) . attr ( 'value' ) . split ( '\\' ) [ 2 ] ) ;
if ( $ ( 'form input[type="file"]' ) . attr ( 'value' ) != '' && ! $ ( 'form input[type="submit"]' ) . hasClass ( 'disabled' ) ) {
$ ( 'div.create_window ul li:eq(0)' ) . addClass ( 'disabled' ) ;
$ ( 'form input[type="submit"]' ) . addClass ( 'disabled' ) ;
$ ( 'span.file' ) . addClass ( 'uploading' ) ;
var uuid = '' ;
for ( i = 0 ; i < 32 ; i ++ ) {
uuid += Math . floor ( Math . random ( ) * 16 ) . toString ( 16 ) ;
}
$ . ajax ( {
type : "POST" ,
url : '/api/json/tables/?X-Progress-ID=' + uuid ,
success : function ( data , textStatus , XMLHttpRequest ) {
var uploader = new qq . FileUploader ( {
element : document . getElementById ( 'uploader' ) ,
action : '/upload' ,
params : { } ,
allowedExtensions : [ 'csv' , 'xls' , 'zip' ] ,
sizeLimit : 0 , // max size
minSizeLimit : 0 , // min size
debug : false ,
function fetch ( uuid ) {
$ . ajax ( {
type : "GET" ,
headers : { 'cartodbclient' : true } ,
url : '/progress?X-Progress-ID=' + uuid ,
success : function ( result , textStatus , XMLHttpRequest ) {
var percentage = result . received / result . size ;
$ ( 'span.progress' ) . width ( ( 346 * percentage ) / 1 ) ;
if ( result . state == 'done' ) {
window . clearTimeout ( interval ) ;
georeferenceImport ( ) ;
}
} ,
error : function ( e ) {
console . debug ( e ) ;
}
} ) ;
}
interval = window . setInterval ( function ( ) { fetch ( uuid ) ; } , 200 ) ;
} ,
error : function ( e ) {
console . debug ( e ) ;
}
} ) ;
}
onSubmit : function ( id , fileName ) { } ,
onProgress : function ( id , fileName , loaded , total ) {
console . debug ( id , fileName , loaded , total ) ;
} ,
onComplete : function ( id , fileName , responseJSON ) {
console . debug ( responseJSON ) ;
} ,
onCancel : function ( id , fileName ) { } ,
messages : {
// error messages, see qq.FileUploaderBasic for content
} ,
showMessage : function ( message ) { alert ( message ) ; }
} ) ;
$ ( 'form#import_file' ) . submit ( function ( ev ) {
ev . stopPropagation ( ) ;
ev . preventDefault ( ) ;
@ -91,8 +65,8 @@
}
} ) ;
} ) ;
function resetUploadFile ( ) {
window . clearTimeout ( interval ) ;
create _type = 0 ;
@ -115,12 +89,12 @@
$ ( 'div.create_window ul li:eq(1)' ) . addClass ( 'finished' ) ;
$ ( 'form input[type="submit"]' ) . removeClass ( 'disabled' ) ;
$ ( 'span.file div.progress p' ) . html ( '<strong>69 rows</strong> correctly imported!' ) ;
}
function createNewToFinish ( ) {
$ ( 'div.create_window div.inner_' ) . animate ( { borderColor : '#FFC209' , height : '68px' } , 500 ) ;
$ ( 'div.create_window div.inner_ form' ) . animate ( { opacity : 0 } , 300 , function ( ) {