fix page leaving checks

remotes/origin/stable6
Jörn Friedrich Dreyer 11 years ago
parent 796e137e82
commit 673e0c01a7
  1. 130
      apps/files/js/file-upload.js
  2. 21
      apps/files/js/filelist.js
  3. 11
      core/js/oc-dialogs.js

@ -124,43 +124,12 @@ function supportAjaxUploadWithProgress() {
//TODO clean uploads when all progress has completed
OC.Upload = {
/**
* map to lookup the selections for a given directory.
* @type Array
*/
_selections: {},
_selectionCount: 0,
/*
* 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-' + this._selectionCount++;
this._selections[originalFiles.selectionKey] = {
selectionKey:originalFiles.selectionKey,
files:{},
totalBytes:0,
loadedBytes:0,
currentFile:0,
uploads:{},
checked:false
};
}
return this._selections[originalFiles.selectionKey];
},
_uploads: [],
cancelUpload:function(dir, filename) {
var self = this;
var deleted = false;
jQuery.each(this._selections, function(i, selection) {
//FIXME _selections
jQuery.each(this._uploads, function(i, jqXHR) {
if (selection.dir === dir && selection.uploads[filename]) {
deleted = self.deleteSelectionUpload(selection, filename);
return false; // end searching through selections
@ -168,69 +137,34 @@ OC.Upload = {
});
return deleted;
},
deleteUpload:function(data) {
delete data.jqXHR;
},
cancelUploads:function() {
console.log('canceling uploads');
var self = this;
jQuery.each(this._selections,function(i, selection){
self.deleteSelection(selection.selectionKey);
jQuery.each(this._uploads,function(i, jqXHR){
jqXHR.abort();
});
this._queue = [];
this._isProcessing = false;
},
_isProcessing:false,
isProcessing:function(){
return this._isProcessing;
this._uploads = [];
},
startUpload:function(){
if (this._queue.length > 0) {
this._isProcessing = true;
this.nextUpload();
return true;
} else {
return false;
rememberUpload:function(jqXHR){
if (jqXHR) {
this._uploads.push(jqXHR);
}
},
nextUpload:function(){
if (this._queue.length > 0) {
var data = this._queue.pop();
var selection = this.getSelection(data.originalFiles);
selection.uploads[data.files[0]] = data.submit();
} else {
//queue is empty, we are done
this._isProcessing = false;
OC.Upload.cancelUploads();
}
},
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;
isProcessing:function(){
var count = 0;
jQuery.each(this._uploads,function(i, data){
if (data.state() === 'pending') {
count++;
}
});
return total;
return count > 0;
},
onCancel:function(data) {
//TODO cancel all uploads of this selection
var selection = this.getSelection(data.originalFiles);
OC.Upload.deleteSelection(selection.selectionKey);
//FIXME hide progressbar
this.cancelUploads();
},
onContinue:function(conflicts) {
var self = this;
@ -253,19 +187,16 @@ OC.Upload = {
});
},
onSkip:function(data){
OC.Upload.logStatus('skip', null, data);
//var selection = this.getSelection(data.originalFiles);
//selection.loadedBytes += data.loaded;
//this.nextUpload();
//TODO trigger skip? what about progress?
this.logStatus('skip', null, data);
this.deleteUpload(data);
},
onReplace:function(data){
OC.Upload.logStatus('replace', null, data);
this.logStatus('replace', null, data);
data.data.append('resolution', 'replace');
data.submit();
},
onAutorename:function(data){
OC.Upload.logStatus('autorename', null, data);
this.logStatus('autorename', null, data);
data.data.append('resolution', 'autorename');
data.submit();
},
@ -415,6 +346,9 @@ $(document).ready(function() {
start: function(e) {
OC.Upload.logStatus('start', e, null);
},
submit: function (e, data) {
OC.Upload.rememberUpload(data);
},
fail: function(e, data) {
OC.Upload.logStatus('fail', e, data);
if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) {
@ -432,6 +366,7 @@ $(document).ready(function() {
}
//var selection = OC.Upload.getSelection(data.originalFiles);
//OC.Upload.deleteSelectionUpload(selection, data.files[0].name);
OC.Upload.deleteUpload(data);
},
/**
* called for every successful upload
@ -449,8 +384,9 @@ $(document).ready(function() {
response = data.result[0].body.innerText;
}
var result=$.parseJSON(response);
//var selection = OC.Upload.getSelection(data.originalFiles);
delete data.jqXHR;
if(typeof result[0] === 'undefined') {
data.textStatus = 'servererror';
data.errorThrown = t('files', 'Could not get result from server.');
@ -463,7 +399,7 @@ $(document).ready(function() {
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu);
} else if (result[0].status !== 'success') {
delete data.jqXHR;
//delete data.jqXHR;
data.textStatus = 'servererror';
data.errorThrown = t('files', result.data.message);
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');

@ -522,6 +522,9 @@ $(document).ready(function(){
var dropTarget = $(e.originalEvent.target).closest('tr');
if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder
// remember as context
data.context = dropTarget;
var dir = dropTarget.data('file');
// update folder in form
@ -546,19 +549,15 @@ $(document).ready(function(){
OC.Upload.logStatus('filelist handle fileuploadadd', e, data);
// lookup selection for dir
var selection = OC.Upload.getSelection(data.originalFiles);
//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
FileList.finishDelete(null, true); //delete file before continuing
}
// add ui visualization to existing folder
if(selection.dropTarget && selection.dropTarget.data('type') === 'dir') {
if(data.context && data.context.data('type') === 'dir') {
// add to existing folder
var dirName = selection.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');
@ -578,6 +577,10 @@ $(document).ready(function(){
}
});
file_upload_start.on('fileuploadsend', function(e, data) {
OC.Upload.logStatus('filelist handle fileuploadsend', e, data);
return true;
});
file_upload_start.on('fileuploadstart', function(e, data) {
OC.Upload.logStatus('filelist handle fileuploadstart', e, data);
});
@ -608,7 +611,7 @@ $(document).ready(function(){
var img = OC.imagePath('core', 'filetypes/folder.png');
data.context.find('td.filename').attr('style','background-image:url('+img+')');
uploadtext.text(translatedText);
uploadtext.show();
uploadtext.hide();
} else {
uploadtext.text(translatedText);
}
@ -648,6 +651,7 @@ $(document).ready(function(){
}
//if user pressed cancel hide upload chrome
/*
if (! OC.Upload.isProcessing()) {
//cleanup uploading to a dir
var uploadtext = $('tr .uploadtext');
@ -656,6 +660,7 @@ $(document).ready(function(){
uploadtext.fadeOut();
uploadtext.attr('currentUploads', 0);
}
*/
});
file_upload_start.on('fileuploadalways', function(e, data) {
@ -677,7 +682,7 @@ $(document).ready(function(){
OC.Upload.logStatus('filelist handle fileuploadstop', e, data);
//if user pressed cancel hide upload chrome
if (! OC.Upload.isProcessing()) {
if (data.errorThrown === 'abort') {
//cleanup uploading to a dir
var uploadtext = $('tr .uploadtext');
var img = OC.imagePath('core', 'filetypes/folder.png');

@ -262,10 +262,10 @@ var OCdialogs = {
//TODO show skip action for files with same size and mtime in bottom row
};
var selection = controller.getSelection(data.originalFiles);
if (selection.defaultAction) {
controller[selection.defaultAction](data);
} else {
//var selection = controller.getSelection(data.originalFiles);
//if (selection.defaultAction) {
// controller[selection.defaultAction](data);
//} else {
var dialog_name = 'oc-dialog-fileexists-content';
var dialog_id = '#' + dialog_name;
if (this._fileexistsshown) {
@ -306,6 +306,7 @@ var OCdialogs = {
if ( typeof controller.onCancel !== 'undefined') {
controller.onCancel(data);
}
$(dialog_id).ocdialog('close');
$(dialog_id).ocdialog('destroy').remove();
}
},
@ -382,7 +383,7 @@ var OCdialogs = {
alert(t('core', 'Error loading file exists template'));
});
}
}
//}
},
_getFilePickerTemplate: function() {
var defer = $.Deferred();

Loading…
Cancel
Save