2012-09-04 19:27:04 +00:00
var FileList = {
2012-04-15 13:48:02 +00:00
useUndo : true ,
2011-06-04 16:44:14 +00:00
update : function ( fileListHtml ) {
$ ( '#fileList' ) . empty ( ) . html ( fileListHtml ) ;
} ,
2013-02-09 13:42:03 +00:00
createRow : function ( type , name , iconurl , linktarget , size , lastModified , permissions ) {
var td , simpleSize , basename , extension ;
//containing tr
var tr = $ ( '<tr></tr>' ) . attr ( {
"data-type" : type ,
"data-size" : size ,
"data-file" : name ,
"data-permissions" : permissions
} ) ;
// filename td
td = $ ( '<td></td>' ) . attr ( {
"class" : "filename" ,
"style" : 'background-image:url(' + iconurl + ')'
} ) ;
td . append ( '<input type="checkbox" />' ) ;
var link _elem = $ ( '<a></a>' ) . attr ( {
"class" : "name" ,
"href" : linktarget
} ) ;
//split extension from filename for non dirs
if ( type != 'dir' && name . indexOf ( '.' ) != - 1 ) {
2012-09-23 01:16:52 +00:00
basename = name . substr ( 0 , name . lastIndexOf ( '.' ) ) ;
extension = name . substr ( name . lastIndexOf ( '.' ) ) ;
2013-02-09 13:42:03 +00:00
} else {
2012-09-23 01:16:52 +00:00
basename = name ;
extension = false ;
2011-07-28 21:52:49 +00:00
}
2013-02-09 13:42:03 +00:00
var name _span = $ ( '<span></span>' ) . addClass ( 'nametext' ) . text ( basename ) ;
link _elem . append ( name _span ) ;
2012-04-15 11:32:45 +00:00
if ( extension ) {
2013-02-09 13:42:03 +00:00
name _span . append ( $ ( '<span></span>' ) . addClass ( 'extension' ) . text ( extension ) ) ;
}
2013-02-22 16:21:57 +00:00
//dirs can show the number of uploaded files
2013-02-09 13:42:03 +00:00
if ( type == 'dir' ) {
link _elem . append ( $ ( '<span></span>' ) . attr ( {
'class' : 'uploadtext' ,
'currentUploads' : 0
} ) ) ;
2011-07-28 21:52:49 +00:00
}
2013-02-09 13:42:03 +00:00
td . append ( link _elem ) ;
tr . append ( td ) ;
2013-02-22 16:21:57 +00:00
2013-02-09 13:42:03 +00:00
//size column
if ( size != t ( 'files' , 'Pending' ) ) {
2011-07-28 21:52:49 +00:00
simpleSize = simpleFileSize ( size ) ;
} else {
2013-02-09 13:42:03 +00:00
simpleSize = t ( 'files' , 'Pending' ) ;
2011-07-28 21:52:49 +00:00
}
2013-02-09 13:42:03 +00:00
var sizeColor = Math . round ( 200 - Math . pow ( ( size / ( 1024 * 1024 ) ) , 2 ) ) ;
var lastModifiedTime = Math . round ( lastModified . getTime ( ) / 1000 ) ;
td = $ ( '<td></td>' ) . attr ( {
"class" : "filesize" ,
"title" : humanFileSize ( size ) ,
"style" : 'color:rgb(' + sizeColor + ',' + sizeColor + ',' + sizeColor + ')'
} ) . text ( simpleSize ) ;
tr . append ( td ) ;
2013-02-22 16:21:57 +00:00
2013-02-09 13:42:03 +00:00
// date column
var modifiedColor = Math . round ( ( Math . round ( ( new Date ( ) ) . getTime ( ) / 1000 ) - lastModifiedTime ) / 60 / 60 / 24 * 5 ) ;
td = $ ( '<td></td>' ) . attr ( { "class" : "date" } ) ;
td . append ( $ ( '<span></span>' ) . attr ( {
"class" : "modified" ,
"title" : formatDate ( lastModified ) ,
"style" : 'color:rgb(' + modifiedColor + ',' + modifiedColor + ',' + modifiedColor + ')'
} ) . text ( relative _modified _date ( lastModified . getTime ( ) / 1000 ) ) ) ;
tr . append ( td ) ;
return tr ;
} ,
addFile : function ( name , size , lastModified , loading , hidden ) {
var imgurl ;
if ( loading ) {
imgurl = OC . imagePath ( 'core' , 'loading.gif' ) ;
} else {
imgurl = OC . imagePath ( 'core' , 'filetypes/file.png' ) ;
}
var tr = this . createRow (
'file' ,
name ,
imgurl ,
OC . Router . generate ( 'download' , { file : $ ( '#dir' ) . val ( ) + '/' + name } ) ,
size ,
lastModified ,
$ ( '#permissions' ) . val ( )
) ;
2013-02-22 16:21:57 +00:00
2013-03-13 16:26:37 +00:00
FileList . insertElement ( name , 'file' , tr ) ;
2011-07-19 18:57:40 +00:00
if ( loading ) {
2013-03-13 16:26:37 +00:00
tr . data ( 'loading' , true ) ;
2011-07-19 18:57:40 +00:00
} else {
2013-03-13 16:26:37 +00:00
tr . find ( 'td.filename' ) . draggable ( dragOptions ) ;
2011-07-19 18:57:40 +00:00
}
2012-09-05 04:12:11 +00:00
if ( hidden ) {
2013-03-13 16:26:37 +00:00
tr . hide ( ) ;
2012-09-05 04:12:11 +00:00
}
2013-03-13 16:26:37 +00:00
FileActions . display ( tr . find ( 'td.filename' ) ) ;
return tr ;
2011-06-04 16:44:14 +00:00
} ,
2012-09-05 04:12:11 +00:00
addDir : function ( name , size , lastModified , hidden ) {
2013-02-22 16:21:57 +00:00
2013-02-09 13:42:03 +00:00
var tr = this . createRow (
'dir' ,
name ,
OC . imagePath ( 'core' , 'filetypes/folder.png' ) ,
OC . linkTo ( 'files' , 'index.php' ) + "?dir=" + encodeURIComponent ( $ ( '#dir' ) . val ( ) + '/' + name ) . replace ( /%2F/g , '/' ) ,
size ,
lastModified ,
$ ( '#permissions' ) . val ( )
) ;
2013-02-22 16:21:57 +00:00
2013-02-09 13:42:03 +00:00
FileList . insertElement ( name , 'dir' , tr ) ;
2013-03-13 16:26:37 +00:00
var td = tr . find ( 'td.filename' ) ;
td . draggable ( dragOptions ) ;
td . droppable ( folderDropOptions ) ;
2012-09-05 04:12:11 +00:00
if ( hidden ) {
2013-03-13 16:26:37 +00:00
tr . hide ( ) ;
2012-09-05 04:12:11 +00:00
}
2013-03-13 16:26:37 +00:00
FileActions . display ( tr . find ( 'td.filename' ) ) ;
return tr ;
2011-06-04 16:44:14 +00:00
} ,
refresh : function ( data ) {
2012-09-23 01:16:52 +00:00
var result = jQuery . parseJSON ( data . responseText ) ;
2011-06-04 16:44:14 +00:00
if ( typeof ( result . data . breadcrumb ) != 'undefined' ) {
updateBreadcrumb ( result . data . breadcrumb ) ;
}
FileList . update ( result . data . files ) ;
resetFileActionPanel ( ) ;
} ,
remove : function ( name ) {
2011-11-01 21:35:13 +00:00
$ ( 'tr' ) . filterAttr ( 'data-file' , name ) . find ( 'td.filename' ) . draggable ( 'destroy' ) ;
$ ( 'tr' ) . filterAttr ( 'data-file' , name ) . remove ( ) ;
2011-07-30 12:42:58 +00:00
if ( $ ( 'tr[data-file]' ) . length == 0 ) {
$ ( '#emptyfolder' ) . show ( ) ;
}
2011-06-04 16:44:14 +00:00
} ,
insertElement : function ( name , type , element ) {
//find the correct spot to insert the file or folder
2012-09-23 01:16:52 +00:00
var pos , fileElements = $ ( 'tr[data-file][data-type="' + type + '"]:visible' ) ;
2011-06-04 16:44:14 +00:00
if ( name . localeCompare ( $ ( fileElements [ 0 ] ) . attr ( 'data-file' ) ) < 0 ) {
2011-07-26 14:55:28 +00:00
pos = - 1 ;
2011-06-04 16:44:14 +00:00
} else if ( name . localeCompare ( $ ( fileElements [ fileElements . length - 1 ] ) . attr ( 'data-file' ) ) > 0 ) {
pos = fileElements . length - 1 ;
} else {
2012-09-23 01:16:52 +00:00
for ( pos = 0 ; pos < fileElements . length - 1 ; pos ++ ) {
2011-06-04 16:44:14 +00:00
if ( name . localeCompare ( $ ( fileElements [ pos ] ) . attr ( 'data-file' ) ) > 0 && name . localeCompare ( $ ( fileElements [ pos + 1 ] ) . attr ( 'data-file' ) ) < 0 ) {
break ;
}
}
}
2011-07-04 19:46:20 +00:00
if ( fileElements . length ) {
2011-07-26 14:55:28 +00:00
if ( pos == - 1 ) {
$ ( fileElements [ 0 ] ) . before ( element ) ;
} else {
$ ( fileElements [ pos ] ) . after ( element ) ;
}
} else if ( type == 'dir' && $ ( 'tr[data-file]' ) . length > 0 ) {
$ ( 'tr[data-file]' ) . first ( ) . before ( element ) ;
2011-07-04 19:46:20 +00:00
} else {
$ ( '#fileList' ) . append ( element ) ;
}
2011-07-30 12:42:58 +00:00
$ ( '#emptyfolder' ) . hide ( ) ;
2011-07-19 18:57:40 +00:00
} ,
2012-10-08 15:28:56 +00:00
loadingDone : function ( name , id ) {
2012-09-23 01:16:52 +00:00
var mime , tr = $ ( 'tr' ) . filterAttr ( 'data-file' , name ) ;
2011-10-08 19:18:47 +00:00
tr . data ( 'loading' , false ) ;
2012-09-23 01:16:52 +00:00
mime = tr . data ( 'mime' ) ;
2011-10-08 19:18:47 +00:00
tr . attr ( 'data-mime' , mime ) ;
2012-10-08 15:47:02 +00:00
if ( id != null ) {
tr . attr ( 'data-id' , id ) ;
}
2011-10-08 19:18:47 +00:00
getMimeIcon ( mime , function ( path ) {
tr . find ( 'td.filename' ) . attr ( 'style' , 'background-image:url(' + path + ')' ) ;
} ) ;
tr . find ( 'td.filename' ) . draggable ( dragOptions ) ;
2011-07-19 18:57:40 +00:00
} ,
isLoading : function ( name ) {
2011-11-01 21:35:13 +00:00
return $ ( 'tr' ) . filterAttr ( 'data-file' , name ) . data ( 'loading' ) ;
2011-07-28 21:04:34 +00:00
} ,
rename : function ( name ) {
2012-09-23 01:16:52 +00:00
var tr , td , input , form ;
tr = $ ( 'tr' ) . filterAttr ( 'data-file' , name ) ;
2011-07-29 00:26:20 +00:00
tr . data ( 'renaming' , true ) ;
2012-09-23 01:16:52 +00:00
td = tr . children ( 'td.filename' ) ;
2012-11-16 09:23:40 +00:00
input = $ ( '<input class="filename"/>' ) . val ( name ) ;
2012-09-23 01:16:52 +00:00
form = $ ( '<form></form>' ) ;
2011-07-28 21:04:34 +00:00
form . append ( input ) ;
2012-10-18 12:16:59 +00:00
td . children ( 'a.name' ) . hide ( ) ;
td . append ( form ) ;
2011-07-28 21:04:34 +00:00
input . focus ( ) ;
form . submit ( function ( event ) {
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
2011-07-29 15:51:17 +00:00
var newname = input . val ( ) ;
2013-01-06 11:52:00 +00:00
if ( ! Files . isFileNameValid ( newname ) ) {
2012-11-22 12:03:17 +00:00
return false ;
2013-01-07 09:39:35 +00:00
} else if ( newname != name ) {
2012-09-05 04:12:11 +00:00
if ( FileList . checkName ( name , newname , false ) ) {
2012-07-30 16:21:58 +00:00
newname = name ;
2012-10-14 19:04:08 +00:00
} else {
2012-07-30 16:21:58 +00:00
$ . get ( OC . filePath ( 'files' , 'ajax' , 'rename.php' ) , { dir : $ ( '#dir' ) . val ( ) , newname : newname , file : name } , function ( result ) {
if ( ! result || result . status == 'error' ) {
OC . dialogs . alert ( result . data . message , 'Error moving file' ) ;
newname = name ;
}
} ) ;
2012-10-14 19:04:08 +00:00
2012-09-19 12:05:09 +00:00
}
2012-10-02 16:38:17 +00:00
}
2012-11-15 16:16:18 +00:00
tr . data ( 'renaming' , false ) ;
2012-10-02 16:38:17 +00:00
tr . attr ( 'data-file' , newname ) ;
var path = td . children ( 'a.name' ) . attr ( 'href' ) ;
td . children ( 'a.name' ) . attr ( 'href' , path . replace ( encodeURIComponent ( name ) , encodeURIComponent ( newname ) ) ) ;
if ( newname . indexOf ( '.' ) > 0 && tr . data ( 'type' ) != 'dir' ) {
var basename = newname . substr ( 0 , newname . lastIndexOf ( '.' ) ) ;
} else {
var basename = newname ;
}
2012-10-18 12:16:59 +00:00
td . find ( 'a.name span.nametext' ) . text ( basename ) ;
2012-10-02 16:38:17 +00:00
if ( newname . indexOf ( '.' ) > 0 && tr . data ( 'type' ) != 'dir' ) {
2012-10-18 12:16:59 +00:00
if ( td . find ( 'a.name span.extension' ) . length == 0 ) {
td . find ( 'a.name span.nametext' ) . append ( '<span class="extension"></span>' ) ;
}
td . find ( 'a.name span.extension' ) . text ( newname . substr ( newname . lastIndexOf ( '.' ) ) ) ;
2012-07-30 16:21:58 +00:00
}
2012-10-18 12:16:59 +00:00
form . remove ( ) ;
td . children ( 'a.name' ) . show ( ) ;
2011-12-05 22:51:44 +00:00
return false ;
2011-07-28 21:04:34 +00:00
} ) ;
2012-12-18 15:39:01 +00:00
input . keyup ( function ( event ) {
if ( event . keyCode == 27 ) {
tr . data ( 'renaming' , false ) ;
form . remove ( ) ;
td . children ( 'a.name' ) . show ( ) ;
}
} ) ;
2011-12-05 22:51:44 +00:00
input . click ( function ( event ) {
2011-07-28 21:04:34 +00:00
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
} ) ;
input . blur ( function ( ) {
2011-07-29 15:51:17 +00:00
form . trigger ( 'submit' ) ;
2011-07-28 21:04:34 +00:00
} ) ;
2011-08-03 22:22:44 +00:00
} ,
2012-09-05 04:12:11 +00:00
checkName : function ( oldName , newName , isNewFile ) {
if ( isNewFile || $ ( 'tr' ) . filterAttr ( 'data-file' , newName ) . length > 0 ) {
2013-02-09 16:20:08 +00:00
var html ;
if ( isNewFile ) {
html = t ( 'files' , '{new_name} already exists' , { new _name : escapeHTML ( newName ) } ) + '<span class="replace">' + t ( 'files' , 'replace' ) + '</span><span class="suggest">' + t ( 'files' , 'suggest name' ) + '</span> <span class="cancel">' + t ( 'files' , 'cancel' ) + '</span>' ;
} else {
html = t ( 'files' , '{new_name} already exists' , { new _name : escapeHTML ( newName ) } ) + '<span class="replace">' + t ( 'files' , 'replace' ) + '</span><span class="cancel">' + t ( 'files' , 'cancel' ) + '</span>' ;
}
html = $ ( '<span>' + html + '</span>' ) ;
html . attr ( 'data-oldName' , oldName ) ;
html . attr ( 'data-newName' , newName ) ;
html . attr ( 'data-isNewFile' , isNewFile ) ;
OC . Notification . showHtml ( html ) ;
2012-09-05 04:12:11 +00:00
return true ;
} else {
return false ;
}
} ,
replace : function ( oldName , newName , isNewFile ) {
2012-07-30 16:21:58 +00:00
// Finish any existing actions
2012-09-05 04:12:11 +00:00
$ ( 'tr' ) . filterAttr ( 'data-file' , oldName ) . hide ( ) ;
$ ( 'tr' ) . filterAttr ( 'data-file' , newName ) . hide ( ) ;
var tr = $ ( 'tr' ) . filterAttr ( 'data-file' , oldName ) . clone ( ) ;
tr . attr ( 'data-replace' , 'true' ) ;
tr . attr ( 'data-file' , newName ) ;
var td = tr . children ( 'td.filename' ) ;
td . children ( 'a.name .span' ) . text ( newName ) ;
var path = td . children ( 'a.name' ) . attr ( 'href' ) ;
td . children ( 'a.name' ) . attr ( 'href' , path . replace ( encodeURIComponent ( oldName ) , encodeURIComponent ( newName ) ) ) ;
if ( newName . indexOf ( '.' ) > 0 ) {
var basename = newName . substr ( 0 , newName . lastIndexOf ( '.' ) ) ;
} else {
var basename = newName ;
}
td . children ( 'a.name' ) . empty ( ) ;
var span = $ ( '<span class="nametext"></span>' ) ;
span . text ( basename ) ;
td . children ( 'a.name' ) . append ( span ) ;
if ( newName . indexOf ( '.' ) > 0 ) {
span . append ( $ ( '<span class="extension">' + newName . substr ( newName . lastIndexOf ( '.' ) ) + '</span>' ) ) ;
}
FileList . insertElement ( newName , tr . data ( 'type' ) , tr ) ;
tr . show ( ) ;
2012-07-30 16:21:58 +00:00
FileList . replaceCanceled = false ;
FileList . replaceOldName = oldName ;
FileList . replaceNewName = newName ;
2012-09-05 04:12:11 +00:00
FileList . replaceIsNewFile = isNewFile ;
2012-08-20 15:24:10 +00:00
FileList . lastAction = function ( ) {
2012-07-30 16:21:58 +00:00
FileList . finishReplace ( ) ;
} ;
2013-02-09 16:20:08 +00:00
if ( ! isNewFile ) {
2013-01-04 22:34:09 +00:00
OC . Notification . showHtml ( t ( 'files' , 'replaced {new_name} with {old_name}' , { new _name : newName } , { old _name : oldName } ) + '<span class="undo">' + t ( 'files' , 'undo' ) + '</span>' ) ;
2012-09-05 04:12:11 +00:00
}
2012-07-30 16:21:58 +00:00
} ,
finishReplace : function ( ) {
if ( ! FileList . replaceCanceled && FileList . replaceOldName && FileList . replaceNewName ) {
2012-09-06 02:13:50 +00:00
$ . ajax ( { url : OC . filePath ( 'files' , 'ajax' , 'rename.php' ) , async : false , data : { dir : $ ( '#dir' ) . val ( ) , newname : FileList . replaceNewName , file : FileList . replaceOldName } , success : function ( result ) {
if ( result && result . status == 'success' ) {
$ ( 'tr' ) . filterAttr ( 'data-replace' , 'true' ) . removeAttr ( 'data-replace' ) ;
} else {
OC . dialogs . alert ( result . data . message , 'Error moving file' ) ;
}
FileList . replaceCanceled = true ;
FileList . replaceOldName = null ;
FileList . replaceNewName = null ;
FileList . lastAction = null ;
} } ) ;
2012-07-30 16:21:58 +00:00
}
} ,
2011-08-27 23:32:48 +00:00
do _delete : function ( files ) {
2013-01-30 13:32:20 +00:00
if ( files . substr ) {
files = [ files ] ;
2013-02-20 20:57:50 +00:00
}
for ( var i = 0 ; i < files . length ; i ++ ) {
2013-01-30 13:32:20 +00:00
var deleteAction = $ ( 'tr' ) . filterAttr ( 'data-file' , files [ i ] ) . children ( "td.date" ) . children ( ".action.delete" ) ;
var oldHTML = deleteAction [ 0 ] . outerHTML ;
2013-01-30 15:20:13 +00:00
var newHTML = '<img class="move2trash" data-action="Delete" title="' + t ( 'files' , 'perform delete operation' ) + '" src="' + OC . imagePath ( 'core' , 'loading.gif' ) + '"></a>' ;
2013-01-30 13:32:20 +00:00
deleteAction [ 0 ] . outerHTML = newHTML ;
}
2012-07-30 16:21:58 +00:00
// Finish any existing actions
2012-09-19 09:56:31 +00:00
if ( FileList . lastAction ) {
2012-07-30 16:21:58 +00:00
FileList . lastAction ( ) ;
2011-08-03 22:22:44 +00:00
}
2012-10-14 19:04:08 +00:00
2013-01-22 16:43:46 +00:00
var fileNames = JSON . stringify ( files ) ;
$ . post ( OC . filePath ( 'files' , 'ajax' , 'delete.php' ) ,
{ dir : $ ( '#dir' ) . val ( ) , files : fileNames } ,
function ( result ) {
if ( result . status == 'success' ) {
$ . each ( files , function ( index , file ) {
var files = $ ( 'tr' ) . filterAttr ( 'data-file' , file ) ;
2013-02-25 15:22:06 +00:00
files . remove ( ) ;
2013-01-22 16:43:46 +00:00
files . find ( 'input[type="checkbox"]' ) . removeAttr ( 'checked' ) ;
files . removeClass ( 'selected' ) ;
2011-08-03 22:22:44 +00:00
} ) ;
2013-01-22 16:43:46 +00:00
procesSelection ( ) ;
2013-01-30 13:32:20 +00:00
} else {
$ . each ( files , function ( index , file ) {
var deleteAction = $ ( 'tr' ) . filterAttr ( 'data-file' , file ) . children ( "td.date" ) . children ( ".move2trash" ) ;
deleteAction [ 0 ] . outerHTML = oldHTML ;
} ) ;
2013-02-22 16:21:57 +00:00
}
2013-01-22 16:43:46 +00:00
} ) ;
2011-06-04 16:44:14 +00:00
}
2012-09-23 01:16:52 +00:00
} ;
2011-08-03 22:22:44 +00:00
$ ( document ) . ready ( function ( ) {
2013-03-13 16:26:37 +00:00
// handle upload events
2013-03-27 14:55:44 +00:00
var file _upload _start = $ ( '#file_upload_start' ) ;
file _upload _start . on ( 'fileuploaddrop' , function ( e , data ) {
2013-03-13 16:26:37 +00:00
// only handle drop to dir if fileList exists
if ( $ ( '#fileList' ) . length > 0 ) {
var dropTarget = $ ( e . originalEvent . target ) . closest ( 'tr' ) ;
if ( dropTarget && dropTarget . data ( 'type' ) === 'dir' ) { // drag&drop upload to folder
var dirName = dropTarget . data ( 'file' ) ;
// update folder in form
data . formData = function ( form ) {
var formArray = form . serializeArray ( ) ;
// array index 0 contains the max files size
// array index 1 contains the request token
// array index 2 contains the directory
var parentDir = formArray [ 2 ] [ 'value' ] ;
if ( parentDir === '/' ) {
formArray [ 2 ] [ 'value' ] += dirName ;
} else {
formArray [ 2 ] [ 'value' ] += '/' + dirName ;
}
return formArray ;
}
}
}
} ) ;
2013-03-27 14:55:44 +00:00
file _upload _start . on ( 'fileuploadadd' , function ( e , data ) {
2013-03-13 16:26:37 +00:00
// only add to fileList if it exists
if ( $ ( '#fileList' ) . length > 0 ) {
if ( FileList . deleteFiles && FileList . deleteFiles . indexOf ( data . files [ 0 ] . name ) != - 1 ) { //finish delete if we are uploading a deleted file
FileList . finishDelete ( null , true ) ; //delete file before continuing
}
// add ui visualization to existing folder or as new stand-alone file?
var dropTarget = $ ( e . originalEvent . target ) . closest ( 'tr' ) ;
if ( dropTarget && dropTarget . data ( 'type' ) === 'dir' ) {
// add to existing folder
var dirName = dropTarget . data ( 'file' ) ;
// set dir context
data . context = $ ( 'tr' ) . filterAttr ( 'data-type' , 'dir' ) . filterAttr ( 'data-file' , dirName ) ;
// update upload counter ui
var uploadtext = data . context . find ( '.uploadtext' ) ;
var currentUploads = parseInt ( uploadtext . attr ( 'currentUploads' ) ) ;
currentUploads += 1 ;
uploadtext . attr ( 'currentUploads' , currentUploads ) ;
if ( currentUploads === 1 ) {
var img = OC . imagePath ( 'core' , 'loading.gif' ) ;
data . context . find ( 'td.filename' ) . attr ( 'style' , 'background-image:url(' + img + ')' ) ;
uploadtext . text ( t ( 'files' , '1 file uploading' ) ) ;
uploadtext . show ( ) ;
} else {
uploadtext . text ( currentUploads + ' ' + t ( 'files' , 'files uploading' ) ) ;
}
} else {
// add as stand-alone row to filelist
var uniqueName = getUniqueName ( data . files [ 0 ] . name ) ;
var size = t ( 'files' , 'Pending' ) ;
if ( data . files [ 0 ] . size >= 0 ) {
size = data . files [ 0 ] . size ;
}
var date = new Date ( ) ;
// create new file context
data . context = FileList . addFile ( uniqueName , size , date , true , false ) ;
}
}
} ) ;
2013-03-27 14:55:44 +00:00
file _upload _start . on ( 'fileuploaddone' , function ( e , data ) {
2013-03-13 16:26:37 +00:00
// only update the fileList if it exists
if ( $ ( '#fileList' ) . length > 0 ) {
var response ;
if ( typeof data . result === 'string' ) {
response = data . result ;
} else {
// fetch response from iframe
response = data . result [ 0 ] . body . innerText ;
}
var result = $ . parseJSON ( response ) ;
if ( typeof result [ 0 ] !== 'undefined' && result [ 0 ] . status === 'success' ) {
var file = result [ 0 ] ;
if ( data . context . data ( 'type' ) === 'file' ) {
// update file data
data . context . attr ( 'data-mime' , file . mime ) . attr ( 'data-id' , file . id ) ;
var size = data . context . data ( 'size' ) ;
if ( size != file . size ) {
data . context . attr ( 'data-size' , file . size ) ;
data . context . find ( 'td.filesize' ) . text ( humanFileSize ( file . size ) ) ;
}
if ( FileList . loadingDone ) {
FileList . loadingDone ( file . name , file . id ) ;
}
} else {
// update upload counter ui
var uploadtext = data . context . find ( '.uploadtext' ) ;
var currentUploads = parseInt ( uploadtext . attr ( 'currentUploads' ) ) ;
currentUploads -= 1 ;
uploadtext . attr ( 'currentUploads' , currentUploads ) ;
if ( currentUploads === 0 ) {
var img = OC . imagePath ( 'core' , 'filetypes/folder.png' ) ;
data . context . find ( 'td.filename' ) . attr ( 'style' , 'background-image:url(' + img + ')' ) ;
uploadtext . text ( '' ) ;
uploadtext . hide ( ) ;
} else {
uploadtext . text ( currentUploads + ' ' + t ( 'files' , 'files uploading' ) ) ;
}
// update folder size
var size = parseInt ( data . context . data ( 'size' ) ) ;
size += parseInt ( file . size ) ;
data . context . attr ( 'data-size' , size ) ;
data . context . find ( 'td.filesize' ) . text ( humanFileSize ( size ) ) ;
}
}
}
} ) ;
2013-03-27 14:55:44 +00:00
file _upload _start . on ( 'fileuploadfail' , function ( e , data ) {
2013-03-13 16:26:37 +00:00
// only update the fileList if it exists
// cleanup files, error notification has been shown by fileupload code
var tr = data . context ;
if ( typeof tr === 'undefined' ) {
tr = $ ( 'tr' ) . filterAttr ( 'data-file' , data . files [ 0 ] . name ) ;
}
if ( tr . attr ( 'data-type' ) === 'dir' ) {
//cleanup uploading to a dir
var uploadtext = tr . find ( '.uploadtext' ) ;
var img = OC . imagePath ( 'core' , 'filetypes/folder.png' ) ;
tr . find ( 'td.filename' ) . attr ( 'style' , 'background-image:url(' + img + ')' ) ;
uploadtext . text ( '' ) ;
uploadtext . hide ( ) ; //TODO really hide already
} else {
//remove file
tr . fadeOut ( ) ;
tr . remove ( ) ;
}
} ) ;
2011-08-05 05:37:08 +00:00
$ ( '#notification' ) . hide ( ) ;
2013-01-18 21:38:44 +00:00
$ ( '#notification' ) . on ( 'click' , '.undo' , function ( ) {
2012-07-30 16:21:58 +00:00
if ( FileList . deleteFiles ) {
2011-10-17 18:39:01 +00:00
$ . each ( FileList . deleteFiles , function ( index , file ) {
2011-11-01 21:35:13 +00:00
$ ( 'tr' ) . filterAttr ( 'data-file' , file ) . show ( ) ;
2011-10-17 18:39:01 +00:00
} ) ;
FileList . deleteCanceled = true ;
FileList . deleteFiles = null ;
2012-07-30 16:21:58 +00:00
} else if ( FileList . replaceOldName && FileList . replaceNewName ) {
2012-09-05 04:12:11 +00:00
if ( FileList . replaceIsNewFile ) {
// Delete the new uploaded file
FileList . deleteCanceled = false ;
FileList . deleteFiles = [ FileList . replaceOldName ] ;
} else {
$ ( 'tr' ) . filterAttr ( 'data-file' , FileList . replaceOldName ) . show ( ) ;
}
$ ( 'tr' ) . filterAttr ( 'data-replace' , 'true' ) . remove ( ) ;
$ ( 'tr' ) . filterAttr ( 'data-file' , FileList . replaceNewName ) . show ( ) ;
2012-07-30 16:21:58 +00:00
FileList . replaceCanceled = true ;
FileList . replaceOldName = null ;
FileList . replaceNewName = null ;
2012-09-05 04:12:11 +00:00
FileList . replaceIsNewFile = null ;
2011-10-17 18:39:01 +00:00
}
2012-08-22 21:08:10 +00:00
FileList . lastAction = null ;
2013-01-04 22:34:09 +00:00
OC . Notification . hide ( ) ;
2011-08-03 22:22:44 +00:00
} ) ;
2013-02-09 16:20:08 +00:00
$ ( '#notification:first-child' ) . on ( 'click' , '.replace' , function ( ) {
2013-01-04 22:34:09 +00:00
OC . Notification . hide ( function ( ) {
2013-02-09 16:20:08 +00:00
FileList . replace ( $ ( '#notification > span' ) . attr ( 'data-oldName' ) , $ ( '#notification > span' ) . attr ( 'data-newName' ) , $ ( '#notification > span' ) . attr ( 'data-isNewFile' ) ) ;
2013-01-02 14:09:40 +00:00
} ) ;
2012-07-30 16:21:58 +00:00
} ) ;
2013-02-09 16:20:08 +00:00
$ ( '#notification:first-child' ) . on ( 'click' , '.suggest' , function ( ) {
$ ( 'tr' ) . filterAttr ( 'data-file' , $ ( '#notification > span' ) . attr ( 'data-oldName' ) ) . show ( ) ;
2013-01-04 22:34:09 +00:00
OC . Notification . hide ( ) ;
2012-09-05 04:12:11 +00:00
} ) ;
2013-02-09 16:20:08 +00:00
$ ( '#notification:first-child' ) . on ( 'click' , '.cancel' , function ( ) {
if ( $ ( '#notification > span' ) . attr ( 'data-isNewFile' ) ) {
2012-09-05 04:12:11 +00:00
FileList . deleteCanceled = false ;
2013-02-09 16:20:08 +00:00
FileList . deleteFiles = [ $ ( '#notification > span' ) . attr ( 'data-oldName' ) ] ;
2012-09-05 04:12:11 +00:00
}
2012-07-30 16:21:58 +00:00
} ) ;
2012-09-23 01:16:52 +00:00
FileList . useUndo = ( window . onbeforeunload ) ? true : false ;
2011-08-03 22:22:44 +00:00
$ ( window ) . bind ( 'beforeunload' , function ( ) {
2012-07-30 16:21:58 +00:00
if ( FileList . lastAction ) {
FileList . lastAction ( ) ;
}
2011-08-03 22:22:44 +00:00
} ) ;
2012-11-05 17:42:44 +00:00
$ ( window ) . unload ( function ( ) {
$ ( window ) . trigger ( 'beforeunload' ) ;
} ) ;
2011-08-03 22:22:44 +00:00
} ) ;