2010-12-07 20:19:27 +01:00
$ ( document ) . ready ( function ( ) {
2012-10-19 17:09:34 +02:00
2011-02-24 00:28:51 +01:00
var uploader ;
2010-12-07 20:19:27 +01:00
2011-07-29 23:13:32 +02:00
$ ( "#plupload_files" ) . pluploadQueue ( {
2010-12-07 20:19:27 +01:00
// General settings
2012-09-12 20:54:11 +02:00
runtimes : 'gears, html5, html4' ,
2013-01-14 22:00:38 +01:00
url : baseUrl + 'Plupload/upload/format/json' ,
2012-09-12 20:54:11 +02:00
chunk _size : '5mb' ,
unique _names : 'true' ,
2011-04-28 00:33:32 +02:00
multiple _queues : 'true' ,
2010-12-07 20:19:27 +01:00
filters : [
2012-09-13 16:35:13 +02:00
{ title : "Audio Files" , extensions : "ogg,mp3,oga,flac,wav,m4a,mp4" }
2010-12-07 20:19:27 +01:00
]
} ) ;
2011-02-24 00:28:51 +01:00
uploader = $ ( "#plupload_files" ) . pluploadQueue ( ) ;
2010-12-07 20:19:27 +01:00
uploader . bind ( 'FileUploaded' , function ( up , file , json ) {
var j = jQuery . parseJSON ( json . response ) ;
2011-11-23 20:12:14 +01:00
if ( j . error !== undefined ) {
2010-12-07 20:19:27 +01:00
var row = $ ( "<tr/>" )
. append ( '<td>' + file . name + '</td>' )
. append ( '<td>' + j . error . message + '</td>' ) ;
$ ( "#plupload_error" ) . find ( "table" ) . append ( row ) ;
2012-05-30 00:38:34 +02:00
$ ( "#plupload_error table" ) . css ( "display" , "inline-table" ) ;
2011-08-02 20:20:28 +02:00
} else {
2011-11-23 20:12:14 +01:00
var tempFileName = j . tempfilepath ;
2013-01-14 22:00:38 +01:00
$ . get ( baseUrl + 'Plupload/copyfile/format/json/name/' +
2012-10-19 17:09:34 +02:00
encodeURIComponent ( file . name ) + '/tempname/' +
2013-02-07 21:41:47 +01:00
encodeURIComponent ( tempFileName ) , function ( jr ) {
2011-08-02 20:20:28 +02:00
if ( jr . error !== undefined ) {
var row = $ ( "<tr/>" )
. append ( '<td>' + file . name + '</td>' )
. append ( '<td>' + jr . error . message + '</td>' ) ;
$ ( "#plupload_error" ) . find ( "table" ) . append ( row ) ;
2012-05-30 00:38:34 +02:00
$ ( "#plupload_error table" ) . css ( "display" , "inline-table" ) ;
2011-08-02 20:20:28 +02:00
}
} ) ;
2010-12-07 20:19:27 +01:00
}
} ) ;
2011-05-31 17:23:48 +02:00
var uploadProgress = false ;
uploader . bind ( 'QueueChanged' , function ( ) {
2012-08-30 17:43:11 +02:00
uploadProgress = ( uploader . files . length > 0 )
} ) ;
2011-05-31 17:23:48 +02:00
uploader . bind ( 'UploadComplete' , function ( ) {
uploadProgress = false ;
} ) ;
$ ( window ) . bind ( 'beforeunload' , function ( ) {
if ( uploadProgress ) {
2012-11-22 20:37:54 +01:00
return sprintf ( $ . i18n . _ ( "You are currently uploading files. %sGoing to another screen will cancel the upload process. %sAre you sure you want to leave the page?" ) ,
"\n" , "\n" ) ;
2011-05-31 17:23:48 +02:00
}
} ) ;
2010-12-07 20:19:27 +01:00
} ) ;