progress fixes
This commit is contained in:
parent
4588efc44b
commit
f94e603698
|
@ -99,8 +99,8 @@ if (strpos($dir, '..') === false) {
|
||||||
$fileCount = count($files['name']);
|
$fileCount = count($files['name']);
|
||||||
for ($i = 0; $i < $fileCount; $i++) {
|
for ($i = 0; $i < $fileCount; $i++) {
|
||||||
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
|
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
|
||||||
if (isset($_POST['new_name'])) {
|
if (isset($_POST['newname'])) {
|
||||||
$newName = $_POST['new_name'];
|
$newName = $_POST['newname'];
|
||||||
} else {
|
} else {
|
||||||
$newName = $files['name'][$i];
|
$newName = $files['name'][$i];
|
||||||
}
|
}
|
||||||
|
@ -109,11 +109,12 @@ if (strpos($dir, '..') === false) {
|
||||||
} else {
|
} else {
|
||||||
$replace = false;
|
$replace = false;
|
||||||
}
|
}
|
||||||
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).$newName);
|
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$newName);
|
||||||
if ( ! $replace && \OC\Files\Filesystem::file_exists($target)) {
|
if ( ! $replace && \OC\Files\Filesystem::file_exists($target)) {
|
||||||
$meta = \OC\Files\Filesystem::getFileInfo($target);
|
$meta = \OC\Files\Filesystem::getFileInfo($target);
|
||||||
$result[] = array('status' => 'existserror',
|
$result[] = array('status' => 'existserror',
|
||||||
'mime' => $meta['mimetype'],
|
'type' => $meta['mimetype'],
|
||||||
|
'mtime' => $meta['mtime'],
|
||||||
'size' => $meta['size'],
|
'size' => $meta['size'],
|
||||||
'id' => $meta['fileid'],
|
'id' => $meta['fileid'],
|
||||||
'name' => basename($target),
|
'name' => basename($target),
|
||||||
|
|
|
@ -190,6 +190,9 @@ table.dragshadow td.size {
|
||||||
margin-left: -200px;
|
margin-left: -200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.oc-dialog .fileexists table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
.oc-dialog .fileexists .original .icon {
|
.oc-dialog .fileexists .original .icon {
|
||||||
width: 64px;
|
width: 64px;
|
||||||
height: 64px;
|
height: 64px;
|
||||||
|
@ -201,6 +204,7 @@ table.dragshadow td.size {
|
||||||
|
|
||||||
.oc-dialog .fileexists .replacement {
|
.oc-dialog .fileexists .replacement {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.oc-dialog .fileexists .replacement .icon {
|
.oc-dialog .fileexists .replacement .icon {
|
||||||
|
@ -213,10 +217,23 @@ table.dragshadow td.size {
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
.oc-dialog .fileexists label[for="new-name"] {
|
.oc-dialog .fileexists .toggle {
|
||||||
margin-top: 20px;
|
background-image: url('%webroot%/core/img/actions/triangle-e.png');
|
||||||
display: block;
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
}
|
}
|
||||||
|
.oc-dialog .fileexists #allfileslabel {
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists #allfiles {
|
||||||
|
vertical-align: bottom;
|
||||||
|
position: relative;
|
||||||
|
top: -3px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists #allfiles + span{
|
||||||
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
|
||||||
.oc-dialog .fileexists h3 {
|
.oc-dialog .fileexists h3 {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,30 @@
|
||||||
/**
|
/**
|
||||||
|
* 1. tracking which file to upload next -> upload queue with data elements added whenever add is called
|
||||||
|
* 2. tracking progress for each folder individually -> track progress in a progress[dirname] object
|
||||||
|
* - every new selection increases the total size and number of files for a directory
|
||||||
|
* - add increases, successful done decreases, skip decreases, cancel decreases
|
||||||
|
* 3. track selections -> the general skip / overwrite decision is selection based and can change
|
||||||
|
* - server might send already exists error -> show dialog & remember decision for selection again
|
||||||
|
* - server sends error, how do we find collection?
|
||||||
|
* 4. track jqXHR object to prevent browser from navigationg away -> track in a uploads[dirname][filename] object [x]
|
||||||
|
*
|
||||||
|
* selections can progress in parrallel but each selection progresses sequentially
|
||||||
|
*
|
||||||
|
* -> store everything in context?
|
||||||
|
* context.folder
|
||||||
|
* context.element?
|
||||||
|
* context.progressui?
|
||||||
|
* context.jqXHR
|
||||||
|
* context.selection
|
||||||
|
* context.selection.onExistsAction?
|
||||||
|
*
|
||||||
|
* context available in what events?
|
||||||
|
* build in drop() add dir
|
||||||
|
* latest in add() add file? add selection!
|
||||||
|
* progress? -> update progress?
|
||||||
|
* onsubmit -> context.jqXHR?
|
||||||
|
* fail() ->
|
||||||
|
* done()
|
||||||
*
|
*
|
||||||
* when versioning app is active -> always overwrite
|
* when versioning app is active -> always overwrite
|
||||||
*
|
*
|
||||||
|
@ -22,24 +48,74 @@
|
||||||
* dialoge:
|
* dialoge:
|
||||||
* -> skip, replace, choose (or abort) ()
|
* -> skip, replace, choose (or abort) ()
|
||||||
* -> choose left or right (with skip) (when only one file in list also show rename option and remember for all option)
|
* -> choose left or right (with skip) (when only one file in list also show rename option and remember for all option)
|
||||||
|
*
|
||||||
|
* progress always based on filesize
|
||||||
|
* number of files as text, bytes as bar
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
OC.upload = {
|
|
||||||
|
//TODO clean uploads when all progress has completed
|
||||||
|
OC.Upload = {
|
||||||
|
/**
|
||||||
|
* map to lookup the selections for a given directory.
|
||||||
|
* @type Array
|
||||||
|
*/
|
||||||
|
_selections: {},
|
||||||
|
/*
|
||||||
|
* queue which progress tracker to use for the next upload
|
||||||
|
* @type Array
|
||||||
|
*/
|
||||||
|
_queue: [],
|
||||||
|
queueUpload:function(data) {
|
||||||
|
// add to queue
|
||||||
|
this._queue.push(data); //remember what to upload next
|
||||||
|
if ( ! this.isProcessing() ) {
|
||||||
|
this.startUpload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getSelection:function(originalFiles) {
|
||||||
|
if (!originalFiles.selectionKey) {
|
||||||
|
originalFiles.selectionKey = 'selection-' + $.assocArraySize(this._selections);
|
||||||
|
this._selections[originalFiles.selectionKey] = {
|
||||||
|
selectionKey:originalFiles.selectionKey,
|
||||||
|
files:{},
|
||||||
|
totalBytes:0,
|
||||||
|
loadedBytes:0,
|
||||||
|
currentFile:0,
|
||||||
|
uploads:{},
|
||||||
|
checked:false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this._selections[originalFiles.selectionKey];
|
||||||
|
},
|
||||||
|
cancelUpload:function(dir, filename) {
|
||||||
|
var deleted = false;
|
||||||
|
jQuery.each(this._selections, function(i, selection) {
|
||||||
|
if (selection.dir === dir && selection.uploads[filename]) {
|
||||||
|
delete selection.uploads[filename];
|
||||||
|
deleted = true;
|
||||||
|
return false; // end searching through selections
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deleted;
|
||||||
|
},
|
||||||
|
cancelUploads:function() {
|
||||||
|
jQuery.each(this._selections,function(i,selection){
|
||||||
|
jQuery.each(selection.uploads, function (j, jqXHR) {
|
||||||
|
delete jqXHR;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this._queue = [];
|
||||||
|
this._isProcessing = false;
|
||||||
|
},
|
||||||
_isProcessing:false,
|
_isProcessing:false,
|
||||||
isProcessing:function(){
|
isProcessing:function(){
|
||||||
return this._isProcessing;
|
return this._isProcessing;
|
||||||
},
|
},
|
||||||
_uploadQueue:[],
|
|
||||||
addUpload:function(data){
|
|
||||||
this._uploadQueue.push(data);
|
|
||||||
|
|
||||||
if ( ! OC.upload.isProcessing() ) {
|
|
||||||
OC.upload.startUpload();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
startUpload:function(){
|
startUpload:function(){
|
||||||
if (this._uploadQueue.length > 0) {
|
if (this._queue.length > 0) {
|
||||||
this._isProcessing = true;
|
this._isProcessing = true;
|
||||||
this.nextUpload();
|
this.nextUpload();
|
||||||
return true;
|
return true;
|
||||||
|
@ -48,32 +124,50 @@ OC.upload = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nextUpload:function(){
|
nextUpload:function(){
|
||||||
if (this._uploadQueue.length > 0) {
|
if (this._queue.length > 0) {
|
||||||
var data = this._uploadQueue.pop();
|
var data = this._queue.pop();
|
||||||
var jqXHR = data.submit();
|
var selection = this.getSelection(data.originalFiles);
|
||||||
|
selection.uploads[data.files[0]] = data.submit();
|
||||||
|
|
||||||
// remember jqXHR to show warning to user when he navigates away but an upload is still in progress
|
|
||||||
if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') {
|
|
||||||
var dirName = data.context.data('file');
|
|
||||||
if(typeof uploadingFiles[dirName] === 'undefined') {
|
|
||||||
uploadingFiles[dirName] = {};
|
|
||||||
}
|
|
||||||
uploadingFiles[dirName][data.files[0].name] = jqXHR;
|
|
||||||
} else {
|
|
||||||
uploadingFiles[data.files[0].name] = jqXHR;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//queue is empty, we are done
|
//queue is empty, we are done
|
||||||
this._isProcessing = false;
|
this._isProcessing = false;
|
||||||
|
//TODO free data
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
progressBytes: function() {
|
||||||
|
var total = 0;
|
||||||
|
var loaded = 0;
|
||||||
|
jQuery.each(this._selections, function (i, selection) {
|
||||||
|
total += selection.totalBytes;
|
||||||
|
loaded += selection.loadedBytes;
|
||||||
|
});
|
||||||
|
return (loaded/total)*100;
|
||||||
|
},
|
||||||
|
loadedBytes: function() {
|
||||||
|
var loaded = 0;
|
||||||
|
jQuery.each(this._selections, function (i, selection) {
|
||||||
|
loaded += selection.loadedBytes;
|
||||||
|
});
|
||||||
|
return loaded;
|
||||||
|
},
|
||||||
|
totalBytes: function() {
|
||||||
|
var total = 0;
|
||||||
|
jQuery.each(this._selections, function (i, selection) {
|
||||||
|
total += selection.totalBytes;
|
||||||
|
});
|
||||||
|
return total;
|
||||||
|
},
|
||||||
|
handleExists:function(data) {
|
||||||
|
|
||||||
},
|
},
|
||||||
onCancel:function(data){
|
onCancel:function(data){
|
||||||
//TODO cancel all uploads
|
//TODO cancel all uploads
|
||||||
Files.cancelUploads();
|
OC.Upload.cancelUploads();
|
||||||
this._uploadQueue = [];
|
|
||||||
this._isProcessing = false;
|
|
||||||
},
|
},
|
||||||
onSkip:function(data){
|
onSkip:function(data){
|
||||||
|
var selection = this.getSelection(data.originalFiles);
|
||||||
|
selection.loadedBytes += data.loaded;
|
||||||
this.nextUpload();
|
this.nextUpload();
|
||||||
},
|
},
|
||||||
onReplace:function(data){
|
onReplace:function(data){
|
||||||
|
@ -83,8 +177,14 @@ OC.upload = {
|
||||||
},
|
},
|
||||||
onRename:function(data, newName){
|
onRename:function(data, newName){
|
||||||
//TODO rename file in filelist, stop spinner
|
//TODO rename file in filelist, stop spinner
|
||||||
data.data.append('new_name', newName);
|
data.data.append('newname', newName);
|
||||||
data.submit();
|
data.submit();
|
||||||
|
},
|
||||||
|
setAction:function(data, action) {
|
||||||
|
|
||||||
|
},
|
||||||
|
setDefaultAction:function(action) {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,15 +192,23 @@ $(document).ready(function() {
|
||||||
|
|
||||||
var file_upload_param = {
|
var file_upload_param = {
|
||||||
dropZone: $('#content'), // restrict dropZone to content div
|
dropZone: $('#content'), // restrict dropZone to content div
|
||||||
|
|
||||||
//singleFileUploads is on by default, so the data.files array will always have length 1
|
//singleFileUploads is on by default, so the data.files array will always have length 1
|
||||||
add: function(e, data) {
|
add: function(e, data) {
|
||||||
var that = $(this);
|
var that = $(this);
|
||||||
|
|
||||||
if (typeof data.originalFiles.checked === 'undefined') {
|
// lookup selection for dir
|
||||||
|
var selection = OC.Upload.getSelection(data.originalFiles);
|
||||||
|
|
||||||
var totalSize = 0;
|
if (!selection.dir) {
|
||||||
|
selection.dir = $('#dir').val();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! selection.checked ) {
|
||||||
|
|
||||||
|
selection.totalBytes = 0;
|
||||||
$.each(data.originalFiles, function(i, file) {
|
$.each(data.originalFiles, function(i, file) {
|
||||||
totalSize += file.size;
|
selection.totalBytes += file.size;
|
||||||
|
|
||||||
if (file.type === '' && file.size === 4096) {
|
if (file.type === '' && file.size === 4096) {
|
||||||
data.textStatus = 'dirorzero';
|
data.textStatus = 'dirorzero';
|
||||||
|
@ -111,11 +219,10 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (totalSize > $('#max_upload').val()) {
|
if (selection.totalBytes > $('#max_upload').val()) {
|
||||||
data.textStatus = 'notenoughspace';
|
data.textStatus = 'notenoughspace';
|
||||||
data.errorThrown = t('files', 'Not enough space available');
|
data.errorThrown = t('files', 'Not enough space available');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.errorThrown) {
|
if (data.errorThrown) {
|
||||||
//don't upload anything
|
//don't upload anything
|
||||||
var fu = that.data('blueimp-fileupload') || that.data('fileupload');
|
var fu = that.data('blueimp-fileupload') || that.data('fileupload');
|
||||||
|
@ -123,8 +230,21 @@ $(document).ready(function() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.originalFiles.checked = true; // this will skip the checks on subsequent adds
|
//TODO refactor away:
|
||||||
|
//show cancel button
|
||||||
|
if($('html.lte9').length === 0 && data.dataType !== 'iframe') {
|
||||||
|
$('#uploadprogresswrapper input.stop').show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//all subsequent add calls for this selection can be ignored
|
||||||
|
//allow navigating to the selection from a context
|
||||||
|
//context.selection = data.originalFiles.selection;
|
||||||
|
|
||||||
|
//allow navigating to contexts / files of a selection
|
||||||
|
selection.files[data.files[0].name] = data;
|
||||||
|
|
||||||
|
OC.Upload.queueUpload(data);
|
||||||
|
|
||||||
//TODO check filename already exists
|
//TODO check filename already exists
|
||||||
/*
|
/*
|
||||||
|
@ -140,14 +260,6 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//add files to queue
|
|
||||||
OC.upload.addUpload(data);
|
|
||||||
|
|
||||||
//TODO refactor away:
|
|
||||||
//show cancel button
|
|
||||||
if($('html.lte9').length === 0 && data.dataType !== 'iframe') {
|
|
||||||
$('#uploadprogresswrapper input.stop').show();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -176,7 +288,8 @@ $(document).ready(function() {
|
||||||
$('#notification').fadeOut();
|
$('#notification').fadeOut();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
delete uploadingFiles[data.files[0].name];
|
var selection = OC.Upload.getSelection(data.originalFiles);
|
||||||
|
delete selection.uploads[data.files[0]];
|
||||||
},
|
},
|
||||||
progress: function(e, data) {
|
progress: function(e, data) {
|
||||||
// TODO: show nice progress bar in file row
|
// TODO: show nice progress bar in file row
|
||||||
|
@ -186,7 +299,8 @@ $(document).ready(function() {
|
||||||
if($('html.lte9').length > 0) {
|
if($('html.lte9').length > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var progress = (data.loaded/data.total)*100;
|
//var progress = (data.loaded/data.total)*100;
|
||||||
|
var progress = OC.Upload.progressBytes();
|
||||||
$('#uploadprogressbar').progressbar('value', progress);
|
$('#uploadprogressbar').progressbar('value', progress);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -204,27 +318,22 @@ $(document).ready(function() {
|
||||||
response = data.result[0].body.innerText;
|
response = data.result[0].body.innerText;
|
||||||
}
|
}
|
||||||
var result=$.parseJSON(response);
|
var result=$.parseJSON(response);
|
||||||
|
var selection = OC.Upload.getSelection(data.originalFiles);
|
||||||
|
|
||||||
if(typeof result[0] !== 'undefined' && result[0].status === 'success') {
|
if(typeof result[0] !== 'undefined'
|
||||||
OC.upload.nextUpload();
|
&& result[0].status === 'success'
|
||||||
|
) {
|
||||||
|
selection.loadedBytes+=data.loaded;
|
||||||
|
OC.Upload.nextUpload();
|
||||||
} else {
|
} else {
|
||||||
if (result[0].status === 'existserror') {
|
if (result[0].status === 'existserror') {
|
||||||
//TODO open dialog and retry with other name?
|
//show "file already exists" dialog
|
||||||
// get jqXHR reference
|
|
||||||
if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') {
|
|
||||||
var dirName = data.context.data('file');
|
|
||||||
var jqXHR = uploadingFiles[dirName][filename];
|
|
||||||
} else {
|
|
||||||
var jqXHR = uploadingFiles[filename];
|
|
||||||
}
|
|
||||||
//filenames can only be changed on the server side
|
|
||||||
//TODO show "file already exists" dialog
|
|
||||||
//options: abort | skip | replace / rename
|
|
||||||
//TODO reset all-files flag? when done with selection?
|
|
||||||
var original = result[0];
|
var original = result[0];
|
||||||
var replacement = data.files[0];
|
var replacement = data.files[0];
|
||||||
OC.dialogs.fileexists(data, original, replacement, OC.upload);
|
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
|
||||||
|
OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu);
|
||||||
} else {
|
} else {
|
||||||
|
delete selection.uploads[data.files[0]];
|
||||||
data.textStatus = 'servererror';
|
data.textStatus = 'servererror';
|
||||||
data.errorThrown = t('files', result.data.message);
|
data.errorThrown = t('files', result.data.message);
|
||||||
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
|
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
|
||||||
|
@ -232,19 +341,6 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = result[0].originalname;
|
|
||||||
|
|
||||||
// delete jqXHR reference
|
|
||||||
if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') {
|
|
||||||
var dirName = data.context.data('file');
|
|
||||||
delete uploadingFiles[dirName][filename];
|
|
||||||
if ($.assocArraySize(uploadingFiles[dirName]) === 0) {
|
|
||||||
delete uploadingFiles[dirName];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete uploadingFiles[filename];
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* called after last upload
|
* called after last upload
|
||||||
|
@ -252,6 +348,8 @@ $(document).ready(function() {
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
stop: function(e, data) {
|
stop: function(e, data) {
|
||||||
|
if(OC.Upload.progressBytes()>=100) {
|
||||||
|
|
||||||
if(data.dataType !== 'iframe') {
|
if(data.dataType !== 'iframe') {
|
||||||
$('#uploadprogresswrapper input.stop').hide();
|
$('#uploadprogresswrapper input.stop').hide();
|
||||||
}
|
}
|
||||||
|
@ -264,6 +362,7 @@ $(document).ready(function() {
|
||||||
$('#uploadprogressbar').progressbar('value', 100);
|
$('#uploadprogressbar').progressbar('value', 100);
|
||||||
$('#uploadprogressbar').fadeOut();
|
$('#uploadprogressbar').fadeOut();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var file_upload_handler = function() {
|
var file_upload_handler = function() {
|
||||||
|
|
|
@ -174,7 +174,7 @@ $(document).ready(function () {
|
||||||
FileActions.register('all', 'Delete', OC.PERMISSION_DELETE, function () {
|
FileActions.register('all', 'Delete', OC.PERMISSION_DELETE, function () {
|
||||||
return OC.imagePath('core', 'actions/delete');
|
return OC.imagePath('core', 'actions/delete');
|
||||||
}, function (filename) {
|
}, function (filename) {
|
||||||
if (Files.cancelUpload(filename)) {
|
if (OC.Upload.cancelUpload($('#dir').val(), filename)) {
|
||||||
if (filename.substr) {
|
if (filename.substr) {
|
||||||
filename = [filename];
|
filename = [filename];
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,13 +407,28 @@ $(document).ready(function(){
|
||||||
|
|
||||||
// handle upload events
|
// handle upload events
|
||||||
var file_upload_start = $('#file_upload_start');
|
var file_upload_start = $('#file_upload_start');
|
||||||
|
|
||||||
file_upload_start.on('fileuploaddrop', function(e, data) {
|
file_upload_start.on('fileuploaddrop', function(e, data) {
|
||||||
// only handle drop to dir if fileList exists
|
console.log('fileuploaddrop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
if ($('#fileList').length > 0) {
|
|
||||||
var dropTarget = $(e.originalEvent.target).closest('tr');
|
var dropTarget = $(e.originalEvent.target).closest('tr');
|
||||||
if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder
|
if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder
|
||||||
data.context = dropTarget;
|
|
||||||
var dirName = dropTarget.data('file');
|
// lookup selection for dir
|
||||||
|
var selection = OC.Upload.getSelection(data.files);
|
||||||
|
|
||||||
|
// remember drop target
|
||||||
|
selection.dropTarget = dropTarget;
|
||||||
|
|
||||||
|
selection.dir = dropTarget.data('file');
|
||||||
|
if (selection.dir !== '/') {
|
||||||
|
if ($('#dir').val() === '/') {
|
||||||
|
selection.dir = '/' + selection.dir;
|
||||||
|
} else {
|
||||||
|
selection.dir = $('#dir').val() + '/' + selection.dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update folder in form
|
// update folder in form
|
||||||
data.formData = function(form) {
|
data.formData = function(form) {
|
||||||
var formArray = form.serializeArray();
|
var formArray = form.serializeArray();
|
||||||
|
@ -422,28 +437,30 @@ $(document).ready(function(){
|
||||||
// array index 2 contains the directory
|
// array index 2 contains the directory
|
||||||
var parentDir = formArray[2]['value'];
|
var parentDir = formArray[2]['value'];
|
||||||
if (parentDir === '/') {
|
if (parentDir === '/') {
|
||||||
formArray[2]['value'] += dirName;
|
formArray[2]['value'] += selection.dir;
|
||||||
} else {
|
} else {
|
||||||
formArray[2]['value'] += '/'+dirName;
|
formArray[2]['value'] += '/' + selection.dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
return formArray;
|
return formArray;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
file_upload_start.on('fileuploadadd', function(e, data) {
|
file_upload_start.on('fileuploadadd', function(e, data) {
|
||||||
// only add to fileList if it exists
|
console.log('fileuploadadd ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
if ($('#fileList').length > 0) {
|
|
||||||
|
// lookup selection for dir
|
||||||
|
var selection = OC.Upload.getSelection(data.originalFiles);
|
||||||
|
|
||||||
if(FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1){//finish delete if we are uploading a deleted file
|
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
|
FileList.finishDelete(null, true); //delete file before continuing
|
||||||
}
|
}
|
||||||
|
|
||||||
// add ui visualization to existing folder
|
// add ui visualization to existing folder
|
||||||
var dropTarget = $(e.originalEvent.target).closest('tr');
|
if(selection.dropTarget && selection.dropTarget.data('type') === 'dir') {
|
||||||
if(dropTarget && dropTarget.data('type') === 'dir') {
|
|
||||||
// add to existing folder
|
// add to existing folder
|
||||||
var dirName = dropTarget.data('file');
|
var dirName = selection.dropTarget.data('file');
|
||||||
|
|
||||||
// set dir context
|
// set dir context
|
||||||
data.context = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName);
|
data.context = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName);
|
||||||
|
@ -453,6 +470,7 @@ $(document).ready(function(){
|
||||||
var currentUploads = parseInt(uploadtext.attr('currentUploads'));
|
var currentUploads = parseInt(uploadtext.attr('currentUploads'));
|
||||||
currentUploads += 1;
|
currentUploads += 1;
|
||||||
uploadtext.attr('currentUploads', currentUploads);
|
uploadtext.attr('currentUploads', currentUploads);
|
||||||
|
|
||||||
if(currentUploads === 1) {
|
if(currentUploads === 1) {
|
||||||
var img = OC.imagePath('core', 'loading.gif');
|
var img = OC.imagePath('core', 'loading.gif');
|
||||||
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
||||||
|
@ -462,11 +480,11 @@ $(document).ready(function(){
|
||||||
uploadtext.text(currentUploads + ' ' + t('files', 'files uploading'));
|
uploadtext.text(currentUploads + ' ' + t('files', 'files uploading'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
file_upload_start.on('fileuploaddone', function(e, data) {
|
file_upload_start.on('fileuploaddone', function(e, data) {
|
||||||
// only update the fileList if it exists
|
console.log('fileuploaddone ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
if ($('#fileList').length > 0) {
|
|
||||||
var response;
|
var response;
|
||||||
if (typeof data.result === 'string') {
|
if (typeof data.result === 'string') {
|
||||||
response = data.result;
|
response = data.result;
|
||||||
|
@ -504,7 +522,6 @@ $(document).ready(function(){
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// add as stand-alone row to filelist
|
// add as stand-alone row to filelist
|
||||||
var uniqueName = getUniqueName(data.files[0].name);
|
|
||||||
var size=t('files','Pending');
|
var size=t('files','Pending');
|
||||||
if (data.files[0].size>=0){
|
if (data.files[0].size>=0){
|
||||||
size=data.files[0].size;
|
size=data.files[0].size;
|
||||||
|
@ -512,9 +529,8 @@ $(document).ready(function(){
|
||||||
var date=new Date();
|
var date=new Date();
|
||||||
var param = {};
|
var param = {};
|
||||||
if ($('#publicUploadRequestToken').length) {
|
if ($('#publicUploadRequestToken').length) {
|
||||||
param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + uniqueName;
|
param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
//should the file exist in the list remove it
|
//should the file exist in the list remove it
|
||||||
FileList.remove(file.name);
|
FileList.remove(file.name);
|
||||||
|
|
||||||
|
@ -529,29 +545,74 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
file_upload_start.on('fileuploadalways', function(e, data) {
|
||||||
|
console.log('fileuploadalways ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
|
});
|
||||||
|
file_upload_start.on('fileuploadsend', function(e, data) {
|
||||||
|
console.log('fileuploadsend ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
|
|
||||||
|
// TODOD add vis
|
||||||
|
//data.context.element =
|
||||||
|
});
|
||||||
|
file_upload_start.on('fileuploadprogress', function(e, data) {
|
||||||
|
console.log('fileuploadprogress ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
|
});
|
||||||
|
file_upload_start.on('fileuploadprogressall', function(e, data) {
|
||||||
|
console.log('fileuploadprogressall ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
|
});
|
||||||
|
file_upload_start.on('fileuploadstop', function(e, data) {
|
||||||
|
console.log('fileuploadstop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
});
|
});
|
||||||
file_upload_start.on('fileuploadfail', function(e, data) {
|
file_upload_start.on('fileuploadfail', function(e, data) {
|
||||||
// only update the fileList if it exists
|
console.log('fileuploadfail ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
file_upload_start.on('fileuploadfail', function(e, data) {
|
||||||
|
console.log('fileuploadfail'+((data.files&&data.files.length>0)?' '+data.files[0].name:''));
|
||||||
|
|
||||||
|
// if we are uploading to a subdirectory
|
||||||
|
if (data.context && data.context.data('type') === 'dir') {
|
||||||
|
|
||||||
|
// 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'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// cleanup files, error notification has been shown by fileupload code
|
// cleanup files, error notification has been shown by fileupload code
|
||||||
var tr = data.context;
|
var tr = data.context;
|
||||||
if (typeof tr === 'undefined') {
|
if (typeof tr === 'undefined') {
|
||||||
tr = $('tr').filterAttr('data-file', data.files[0].name);
|
tr = $('tr').filterAttr('data-file', data.files[0].name);
|
||||||
}
|
}
|
||||||
if (tr.attr('data-type') === 'dir') {
|
if (tr.attr('data-type') === 'dir') {
|
||||||
|
|
||||||
//cleanup uploading to a dir
|
//cleanup uploading to a dir
|
||||||
var uploadtext = tr.find('.uploadtext');
|
var uploadtext = tr.find('.uploadtext');
|
||||||
var img = OC.imagePath('core', 'filetypes/folder.png');
|
var img = OC.imagePath('core', 'filetypes/folder.png');
|
||||||
tr.find('td.filename').attr('style','background-image:url('+img+')');
|
tr.find('td.filename').attr('style','background-image:url('+img+')');
|
||||||
uploadtext.text('');
|
uploadtext.text('');
|
||||||
uploadtext.hide(); //TODO really hide already
|
uploadtext.hide(); //TODO really hide already
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
//TODO add row when sending file
|
||||||
//remove file
|
//remove file
|
||||||
tr.fadeOut();
|
tr.fadeOut();
|
||||||
tr.remove();
|
tr.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
$('#notification').hide();
|
$('#notification').hide();
|
||||||
$('#notification').on('click', '.undo', function(){
|
$('#notification').on('click', '.undo', function(){
|
||||||
if (FileList.deleteFiles) {
|
if (FileList.deleteFiles) {
|
||||||
|
|
|
@ -1,31 +1,5 @@
|
||||||
var uploadingFiles = {};
|
var uploadingFiles = {};
|
||||||
Files={
|
Files={
|
||||||
cancelUpload:function(filename) {
|
|
||||||
if(uploadingFiles[filename]) {
|
|
||||||
uploadingFiles[filename].abort();
|
|
||||||
delete uploadingFiles[filename];
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
cancelUploads:function() {
|
|
||||||
$.each(uploadingFiles,function(index,file) {
|
|
||||||
if(typeof file['abort'] === 'function') {
|
|
||||||
file.abort();
|
|
||||||
var filename = $('tr').filterAttr('data-file',index);
|
|
||||||
filename.hide();
|
|
||||||
filename.find('input[type="checkbox"]').removeAttr('checked');
|
|
||||||
filename.removeClass('selected');
|
|
||||||
} else {
|
|
||||||
$.each(file,function(i,f) {
|
|
||||||
f.abort();
|
|
||||||
delete file[i];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
delete uploadingFiles[index];
|
|
||||||
});
|
|
||||||
procesSelection();
|
|
||||||
},
|
|
||||||
updateMaxUploadFilesize:function(response) {
|
updateMaxUploadFilesize:function(response) {
|
||||||
if(response == undefined) {
|
if(response == undefined) {
|
||||||
return;
|
return;
|
||||||
|
@ -117,7 +91,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// Trigger cancelling of file upload
|
// Trigger cancelling of file upload
|
||||||
$('#uploadprogresswrapper .stop').on('click', function() {
|
$('#uploadprogresswrapper .stop').on('click', function() {
|
||||||
Files.cancelUploads();
|
OC.Upload.cancelUploads();
|
||||||
|
procesSelection();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Show trash bin
|
// Show trash bin
|
||||||
|
|
|
@ -63,6 +63,9 @@ $(document).ready(function() {
|
||||||
$('#controls').append($('#additional_controls div#uploadprogresswrapper'));
|
$('#controls').append($('#additional_controls div#uploadprogresswrapper'));
|
||||||
|
|
||||||
// Cancel upload trigger
|
// Cancel upload trigger
|
||||||
$('#cancel_upload_button').click(Files.cancelUploads);
|
$('#cancel_upload_button').click(function() {
|
||||||
|
OC.Upload.cancelUploads();
|
||||||
|
procesSelection();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -207,14 +207,18 @@ var OCdialogs = {
|
||||||
* @param {object} controller a controller with onCancel, onSkip, onReplace and onRename methods
|
* @param {object} controller a controller with onCancel, onSkip, onReplace and onRename methods
|
||||||
*/
|
*/
|
||||||
fileexists:function(data, original, replacement, controller) {
|
fileexists:function(data, original, replacement, controller) {
|
||||||
if (typeof controller !== 'object') {
|
var selection = controller.getSelection(data.originalFiles);
|
||||||
controller = {};
|
if (selection.defaultAction) {
|
||||||
}
|
controller[selection.defaultAction](data);
|
||||||
var self = this;
|
} else {
|
||||||
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
||||||
var dialog_name = 'oc-dialog-fileexists-' + OCdialogs.dialogs_counter + '-content';
|
var dialog_name = 'oc-dialog-fileexists-' + OCdialogs.dialogs_counter + '-content';
|
||||||
var dialog_id = '#' + dialog_name;
|
var dialog_id = '#' + dialog_name;
|
||||||
var title = t('files','Replace »{filename}«?',{filename: original.name});
|
var title = t('files','Replace »{filename}«?',{filename: original.name});
|
||||||
|
var original_size= t('files','Size: {size}',{size: original.size});
|
||||||
|
var original_mtime = t('files','Last changed: {mtime}',{mtime: original.mtime});
|
||||||
|
var replacement_size= t('files','Size: {size}',{size: replacement.size});
|
||||||
|
var replacement_mtime = t('files','Last changed: {mtime}',{mtime: replacement.mtime});
|
||||||
var $dlg = $tmpl.octemplate({
|
var $dlg = $tmpl.octemplate({
|
||||||
dialog_name: dialog_name,
|
dialog_name: dialog_name,
|
||||||
title: title,
|
title: title,
|
||||||
|
@ -223,26 +227,29 @@ var OCdialogs = {
|
||||||
why: t('files','Another file with the same name already exists in "{dir}".',{dir:'somedir'}),
|
why: t('files','Another file with the same name already exists in "{dir}".',{dir:'somedir'}),
|
||||||
what: t('files','Replacing it will overwrite it\'s contents.'),
|
what: t('files','Replacing it will overwrite it\'s contents.'),
|
||||||
original_heading: t('files','Original file'),
|
original_heading: t('files','Original file'),
|
||||||
original_size: t('files','Size: {size}',{size: original.size}),
|
original_size: original_size,
|
||||||
original_mtime: t('files','Last changed: {mtime}',{mtime: original.mtime}),
|
original_mtime: original_mtime,
|
||||||
|
|
||||||
replacement_heading: t('files','Replace with'),
|
replacement_heading: t('files','Replace with'),
|
||||||
replacement_size: t('files','Size: {size}',{size: replacement.size}),
|
replacement_size: replacement_size,
|
||||||
replacement_mtime: t('files','Last changed: {mtime}',{mtime: replacement.mtime}),
|
replacement_mtime: replacement_mtime,
|
||||||
|
|
||||||
new_name_label: t('files','Choose a new name for the target.'),
|
new_name_label: t('files','Choose a new name for the target.'),
|
||||||
all_files_label: t('files','Use this action for all files.')
|
all_files_label: t('files','Use this action for all files.')
|
||||||
});
|
});
|
||||||
$('body').append($dlg);
|
$('body').append($dlg);
|
||||||
|
|
||||||
$(dialog_id + ' .original .icon').css('background-image','url('+OC.imagePath('core', 'filetypes/file.png')+')');
|
getMimeIcon(original.type,function(path){
|
||||||
$(dialog_id + ' .replacement .icon').css('background-image','url('+OC.imagePath('core', 'filetypes/file.png')+')');
|
$(dialog_id + ' .original .icon').css('background-image','url('+path+')');
|
||||||
$(dialog_id + ' #new-name').val(original.name);
|
});
|
||||||
|
getMimeIcon(replacement.type,function(path){
|
||||||
|
$(dialog_id + ' .replacement .icon').css('background-image','url('+path+')');
|
||||||
|
});
|
||||||
|
$(dialog_id + ' #newname').val(original.name);
|
||||||
|
|
||||||
|
|
||||||
$(dialog_id + ' #new-name').on('keyup', function(e){
|
$(dialog_id + ' #newname').on('keyup', function(e){
|
||||||
if ($(dialog_id + ' #new-name').val() === original.name) {
|
if ($(dialog_id + ' #newname').val() === original.name) {
|
||||||
|
|
||||||
$(dialog_id + ' + div .rename').removeClass('primary').hide();
|
$(dialog_id + ' + div .rename').removeClass('primary').hide();
|
||||||
$(dialog_id + ' + div .replace').addClass('primary').show();
|
$(dialog_id + ' + div .replace').addClass('primary').show();
|
||||||
} else {
|
} else {
|
||||||
|
@ -266,8 +273,17 @@ var OCdialogs = {
|
||||||
classes: 'skip',
|
classes: 'skip',
|
||||||
click: function(){
|
click: function(){
|
||||||
if ( typeof controller.onSkip !== 'undefined') {
|
if ( typeof controller.onSkip !== 'undefined') {
|
||||||
|
if($(dialog_id + ' #allfiles').prop('checked')){
|
||||||
|
selection.defaultAction = 'onSkip';
|
||||||
|
/*selection.defaultAction = function(){
|
||||||
|
controller.onSkip(data);
|
||||||
|
};*/
|
||||||
|
}
|
||||||
controller.onSkip(data);
|
controller.onSkip(data);
|
||||||
}
|
}
|
||||||
|
// trigger fileupload done with status skip
|
||||||
|
//data.result[0].status = 'skip';
|
||||||
|
//fileupload._trigger('done', data.e, data);
|
||||||
$(dialog_id).ocdialog('close');
|
$(dialog_id).ocdialog('close');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -276,6 +292,12 @@ var OCdialogs = {
|
||||||
classes: 'replace',
|
classes: 'replace',
|
||||||
click: function(){
|
click: function(){
|
||||||
if ( typeof controller.onReplace !== 'undefined') {
|
if ( typeof controller.onReplace !== 'undefined') {
|
||||||
|
if($(dialog_id + ' #allfiles').prop('checked')){
|
||||||
|
selection.defaultAction = 'onReplace';
|
||||||
|
/*selection.defaultAction = function(){
|
||||||
|
controller.onReplace(data);
|
||||||
|
};*/
|
||||||
|
}
|
||||||
controller.onReplace(data);
|
controller.onReplace(data);
|
||||||
}
|
}
|
||||||
$(dialog_id).ocdialog('close');
|
$(dialog_id).ocdialog('close');
|
||||||
|
@ -287,13 +309,15 @@ var OCdialogs = {
|
||||||
classes: 'rename',
|
classes: 'rename',
|
||||||
click: function(){
|
click: function(){
|
||||||
if ( typeof controller.onRename !== 'undefined') {
|
if ( typeof controller.onRename !== 'undefined') {
|
||||||
controller.onRename(data, $(dialog_id + ' #new-name').val());
|
//TODO use autorename when repeat is checked
|
||||||
|
controller.onRename(data, $(dialog_id + ' #newname').val());
|
||||||
}
|
}
|
||||||
$(dialog_id).ocdialog('close');
|
$(dialog_id).ocdialog('close');
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
$(dialog_id).ocdialog({
|
$(dialog_id).ocdialog({
|
||||||
|
width: 500,
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
modal: true,
|
modal: true,
|
||||||
buttons: buttonlist,
|
buttons: buttonlist,
|
||||||
|
@ -302,10 +326,23 @@ var OCdialogs = {
|
||||||
OCdialogs.dialogs_counter++;
|
OCdialogs.dialogs_counter++;
|
||||||
|
|
||||||
$(dialog_id + ' + div .rename').hide();
|
$(dialog_id + ' + div .rename').hide();
|
||||||
|
$(dialog_id + ' #newname').hide();
|
||||||
|
|
||||||
|
$(dialog_id + ' #newnamecb').on('change', function(){
|
||||||
|
if ($(dialog_id + ' #newnamecb').prop('checked')) {
|
||||||
|
$(dialog_id + ' #newname').fadeIn();
|
||||||
|
} else {
|
||||||
|
$(dialog_id + ' #newname').fadeOut();
|
||||||
|
$(dialog_id + ' #newname').val(original.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.fail(function() {
|
.fail(function() {
|
||||||
alert(t('core', 'Error loading file exists template'));
|
alert(t('core', 'Error loading file exists template'));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_getFilePickerTemplate: function() {
|
_getFilePickerTemplate: function() {
|
||||||
var defer = $.Deferred();
|
var defer = $.Deferred();
|
||||||
|
|
Loading…
Reference in New Issue