reduced complexity, added listing conflicts to dialog
This commit is contained in:
parent
bf04daff82
commit
7c9d999243
|
@ -131,6 +131,7 @@ if (strpos($dir, '..') === false) {
|
||||||
|
|
||||||
$result[] = array('status' => 'success',
|
$result[] = array('status' => 'success',
|
||||||
'mime' => $meta['mimetype'],
|
'mime' => $meta['mimetype'],
|
||||||
|
'mtime' => $meta['mtime'],
|
||||||
'size' => $meta['size'],
|
'size' => $meta['size'],
|
||||||
'id' => $meta['fileid'],
|
'id' => $meta['fileid'],
|
||||||
'name' => basename($target),
|
'name' => basename($target),
|
||||||
|
|
|
@ -193,28 +193,54 @@ table.dragshadow td.size {
|
||||||
.oc-dialog .fileexists table {
|
.oc-dialog .fileexists table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.oc-dialog .fileexists .original .icon {
|
.oc-dialog .fileexists th {
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists th input[type='checkbox'] {
|
||||||
|
margin-right: 3px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists th:first-child {
|
||||||
|
width: 235px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists th label {
|
||||||
|
font-weight: normal;
|
||||||
|
color:black;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists th .count {
|
||||||
|
margin-left: 3px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists .conflict {
|
||||||
|
width: 100%;
|
||||||
|
height: 85px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists .conflict .filename {
|
||||||
|
color:#777;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists .icon {
|
||||||
width: 64px;
|
width: 64px;
|
||||||
height: 64px;
|
height: 64px;
|
||||||
margin: 5px 5px 5px 0px;
|
margin: 0px 5px 5px 5px;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: 64px 64px;
|
background-size: 64px 64px;
|
||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.oc-dialog .fileexists .replacement {
|
.oc-dialog .fileexists .replacement {
|
||||||
margin-top: 20px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.oc-dialog .fileexists .replacement .icon {
|
|
||||||
width: 64px;
|
|
||||||
height: 64px;
|
|
||||||
margin: 5px 5px 5px 0px;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-size: 64px 64px;
|
|
||||||
float: left;
|
float: left;
|
||||||
clear: both;
|
width: 235px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists .original {
|
||||||
|
float: left;
|
||||||
|
width: 235px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists .conflict-wrapper {
|
||||||
|
overflow-y:scroll;
|
||||||
|
max-height: 225px;
|
||||||
|
}
|
||||||
|
.oc-dialog .fileexists .conflict-wrapper input[type='checkbox'] {
|
||||||
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.oc-dialog .fileexists .toggle {
|
.oc-dialog .fileexists .toggle {
|
||||||
|
@ -234,9 +260,6 @@ table.dragshadow td.size {
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
.oc-dialog .fileexists h3 {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.oc-dialog .oc-dialog-buttonrow {
|
.oc-dialog .oc-dialog-buttonrow {
|
||||||
|
|
|
@ -1,4 +1,43 @@
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* and yet another idea how to handle file uploads:
|
||||||
|
* let the jquery fileupload thing handle as much as possible
|
||||||
|
*
|
||||||
|
* use singlefileupload
|
||||||
|
* on first add of every selection
|
||||||
|
* - check all files of originalFiles array with files in dir
|
||||||
|
* - on conflict show dialog
|
||||||
|
* - skip all -> remember as default action
|
||||||
|
* - replace all -> remember as default action
|
||||||
|
* - choose -> show choose dialog
|
||||||
|
* - mark files to keep
|
||||||
|
* - when only existing -> remember as single skip action
|
||||||
|
* - when only new -> remember as single replace action
|
||||||
|
* - when both -> remember as single autorename action
|
||||||
|
* - start uploading selection
|
||||||
|
*
|
||||||
|
* on send
|
||||||
|
* - if single action or default action
|
||||||
|
* - when skip -> abort upload
|
||||||
|
* ..- when replace -> add replace=true parameter
|
||||||
|
* ..- when rename -> add newName=filename parameter
|
||||||
|
* ..- when autorename -> add autorename=true parameter
|
||||||
|
*
|
||||||
|
* on fail
|
||||||
|
* - if server sent existserror
|
||||||
|
* - show dialog
|
||||||
|
* - on skip single -> abort single upload
|
||||||
|
* - on skip always -> remember as default action
|
||||||
|
* - on replace single -> replace single upload
|
||||||
|
* - on replace always -> remember as default action
|
||||||
|
* - on rename single -> rename single upload, propose autorename - when changed disable remember always checkbox
|
||||||
|
* - on rename always -> remember autorename as default action
|
||||||
|
* - resubmit data
|
||||||
|
*
|
||||||
|
* on uplad done
|
||||||
|
* - if last upload -> unset default action
|
||||||
|
*
|
||||||
|
* -------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* use put t ocacnel upload before it starts? use chunked uploads?
|
* use put t ocacnel upload before it starts? use chunked uploads?
|
||||||
*
|
*
|
||||||
|
@ -202,11 +241,11 @@ OC.Upload = {
|
||||||
data.submit();
|
data.submit();
|
||||||
},
|
},
|
||||||
logStatus:function(caption, e, data) {
|
logStatus:function(caption, e, data) {
|
||||||
console.log(caption+' ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes());
|
console.log(caption);
|
||||||
if (data) {
|
console.log(data);
|
||||||
console.log(data);
|
},
|
||||||
}
|
checkExistingFiles: function (selection, callbacks){
|
||||||
console.log(e);
|
callbacks.onNoConflicts(selection);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -214,44 +253,110 @@ $(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
|
||||||
|
autoUpload: false,
|
||||||
|
sequentialUploads: true,
|
||||||
|
|
||||||
//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
|
||||||
|
/**
|
||||||
|
* on first add of every selection
|
||||||
|
* - check all files of originalFiles array with files in dir
|
||||||
|
* - on conflict show dialog
|
||||||
|
* - skip all -> remember as single skip action for all conflicting files
|
||||||
|
* - replace all -> remember as single replace action for all conflicting files
|
||||||
|
* - choose -> show choose dialog
|
||||||
|
* - mark files to keep
|
||||||
|
* - when only existing -> remember as single skip action
|
||||||
|
* - when only new -> remember as single replace action
|
||||||
|
* - when both -> remember as single autorename action
|
||||||
|
* - start uploading selection
|
||||||
|
* @param {type} e
|
||||||
|
* @param {type} data
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
add: function(e, data) {
|
add: function(e, data) {
|
||||||
OC.Upload.logStatus('add', e, data);
|
OC.Upload.logStatus('add', e, data);
|
||||||
var that = $(this);
|
var that = $(this);
|
||||||
|
|
||||||
// lookup selection for dir
|
// we need to collect all data upload objects before starting the upload so we can check their existence
|
||||||
var selection = OC.Upload.getSelection(data.originalFiles);
|
// and set individual conflict actions. unfortunately there is only one variable that we can use to identify
|
||||||
|
// the selection a data upload is part of, so we have to collect them in data.originalFiles
|
||||||
|
// turning singleFileUploads off is not an option because we want to gracefully handle server errors like
|
||||||
|
// already exists
|
||||||
|
|
||||||
if (!selection.dir) {
|
// create a container where we can store the data objects
|
||||||
selection.dir = $('#dir').val();
|
if ( ! data.originalFiles.selection ) {
|
||||||
|
// initialize selection and remember number of files to upload
|
||||||
|
data.originalFiles.selection = {
|
||||||
|
uploads: [],
|
||||||
|
filesToUpload: data.originalFiles.length,
|
||||||
|
totalBytes: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var selection = data.originalFiles.selection;
|
||||||
|
|
||||||
|
// add uploads
|
||||||
|
if ( selection.uploads.length < selection.filesToUpload ){
|
||||||
|
// remember upload
|
||||||
|
selection.uploads.push(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! selection.checked ) {
|
//examine file
|
||||||
|
var file = data.files[0];
|
||||||
|
|
||||||
selection.totalBytes = 0;
|
if (file.type === '' && file.size === 4096) {
|
||||||
$.each(data.originalFiles, function(i, file) {
|
data.textStatus = 'dirorzero';
|
||||||
selection.totalBytes += file.size;
|
data.errorThrown = t('files', 'Unable to upload {filename} as it is a directory or has 0 bytes',
|
||||||
|
{filename: file.name}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (file.type === '' && file.size === 4096) {
|
// add size
|
||||||
data.textStatus = 'dirorzero';
|
selection.totalBytes += file.size;
|
||||||
data.errorThrown = t('files', 'Unable to upload {filename} as it is a directory or has 0 bytes',
|
|
||||||
{filename: file.name}
|
//check max upload size
|
||||||
);
|
if (selection.totalBytes > $('#max_upload').val()) {
|
||||||
return false;
|
data.textStatus = 'notenoughspace';
|
||||||
|
data.errorThrown = t('files', 'Not enough space available');
|
||||||
|
}
|
||||||
|
|
||||||
|
// end upload for whole selection on error
|
||||||
|
if (data.errorThrown) {
|
||||||
|
// trigger fileupload fail
|
||||||
|
var fu = that.data('blueimp-fileupload') || that.data('fileupload');
|
||||||
|
fu._trigger('fail', e, data);
|
||||||
|
return false; //don't upload anything
|
||||||
|
}
|
||||||
|
|
||||||
|
// check existing files whan all is collected
|
||||||
|
if ( selection.uploads.length >= selection.filesToUpload ) {
|
||||||
|
|
||||||
|
//remove our selection hack:
|
||||||
|
delete data.originalFiles.selection;
|
||||||
|
|
||||||
|
var callbacks = {
|
||||||
|
|
||||||
|
onNoConflicts: function (selection) {
|
||||||
|
$.each(selection.uploads, function(i, upload) {
|
||||||
|
upload.submit();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSkipConflicts: function (selection) {
|
||||||
|
//TODO mark conflicting files as toskip
|
||||||
|
},
|
||||||
|
onReplaceConflicts: function (selection) {
|
||||||
|
//TODO mark conflicting files as toreplace
|
||||||
|
},
|
||||||
|
onChooseConflicts: function (selection) {
|
||||||
|
//TODO mark conflicting files as chosen
|
||||||
|
},
|
||||||
|
onCancel: function (selection) {
|
||||||
|
$.each(selection.uploads, function(i, upload) {
|
||||||
|
upload.abort();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
if (selection.totalBytes > $('#max_upload').val()) {
|
OC.Upload.checkExistingFiles(selection, callbacks);
|
||||||
data.textStatus = 'notenoughspace';
|
|
||||||
data.errorThrown = t('files', 'Not enough space available');
|
|
||||||
}
|
|
||||||
if (data.errorThrown) {
|
|
||||||
//don't upload anything
|
|
||||||
var fu = that.data('blueimp-fileupload') || that.data('fileupload');
|
|
||||||
fu._trigger('fail', e, data);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO refactor away:
|
//TODO refactor away:
|
||||||
//show cancel button
|
//show cancel button
|
||||||
|
@ -260,14 +365,7 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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
|
||||||
/*
|
/*
|
||||||
|
@ -283,7 +381,7 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return true;
|
return true; // continue adding files
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* called after the first add, does NOT have the data param
|
* called after the first add, does NOT have the data param
|
||||||
|
@ -314,8 +412,8 @@ $(document).ready(function() {
|
||||||
$('#notification').fadeOut();
|
$('#notification').fadeOut();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
var selection = OC.Upload.getSelection(data.originalFiles);
|
//var selection = OC.Upload.getSelection(data.originalFiles);
|
||||||
OC.Upload.deleteSelectionUpload(selection, data.files[0].name);
|
//OC.Upload.deleteSelectionUpload(selection, data.files[0].name);
|
||||||
|
|
||||||
//if user pressed cancel hide upload progress bar and cancel button
|
//if user pressed cancel hide upload progress bar and cancel button
|
||||||
if (data.errorThrown === 'abort') {
|
if (data.errorThrown === 'abort') {
|
||||||
|
@ -339,8 +437,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();
|
//var progress = OC.Upload.progressBytes();
|
||||||
$('#uploadprogressbar').progressbar('value', progress);
|
$('#uploadprogressbar').progressbar('value', progress);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -359,15 +457,15 @@ $(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);
|
//var selection = OC.Upload.getSelection(data.originalFiles);
|
||||||
|
|
||||||
if(typeof result[0] !== 'undefined'
|
if(typeof result[0] !== 'undefined'
|
||||||
&& result[0].status === 'success'
|
&& result[0].status === 'success'
|
||||||
) {
|
) {
|
||||||
if (selection) {
|
//if (selection) {
|
||||||
selection.loadedBytes+=data.loaded;
|
// selection.loadedBytes+=data.loaded;
|
||||||
}
|
//}
|
||||||
OC.Upload.nextUpload();
|
//OC.Upload.nextUpload();
|
||||||
} else {
|
} else {
|
||||||
if (result[0].status === 'existserror') {
|
if (result[0].status === 'existserror') {
|
||||||
//show "file already exists" dialog
|
//show "file already exists" dialog
|
||||||
|
@ -385,10 +483,10 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if user pressed cancel hide upload chrome
|
//if user pressed cancel hide upload chrome
|
||||||
if (! OC.Upload.isProcessing()) {
|
//if (! OC.Upload.isProcessing()) {
|
||||||
$('#uploadprogresswrapper input.stop').fadeOut();
|
// $('#uploadprogresswrapper input.stop').fadeOut();
|
||||||
$('#uploadprogressbar').fadeOut();
|
// $('#uploadprogressbar').fadeOut();
|
||||||
}
|
//}
|
||||||
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -398,27 +496,27 @@ $(document).ready(function() {
|
||||||
*/
|
*/
|
||||||
stop: function(e, data) {
|
stop: function(e, data) {
|
||||||
OC.Upload.logStatus('stop', e, data);
|
OC.Upload.logStatus('stop', e, data);
|
||||||
if(OC.Upload.progressBytes()>=100) { //only hide controls when all selections have ended uploading
|
//if(OC.Upload.progressBytes()>=100) { //only hide controls when all selections have ended uploading
|
||||||
|
|
||||||
OC.Upload.cancelUploads(); //cleanup
|
//OC.Upload.cancelUploads(); //cleanup
|
||||||
|
|
||||||
if(data.dataType !== 'iframe') {
|
// if(data.dataType !== 'iframe') {
|
||||||
$('#uploadprogresswrapper input.stop').hide();
|
// $('#uploadprogresswrapper input.stop').hide();
|
||||||
}
|
// }
|
||||||
|
|
||||||
//IE < 10 does not fire the necessary events for the progress bar.
|
//IE < 10 does not fire the necessary events for the progress bar.
|
||||||
if($('html.lte9').length > 0) {
|
if($('html.lte9').length > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#uploadprogressbar').progressbar('value', 100);
|
// $('#uploadprogressbar').progressbar('value', 100);
|
||||||
$('#uploadprogressbar').fadeOut();
|
// $('#uploadprogressbar').fadeOut();
|
||||||
}
|
//}
|
||||||
//if user pressed cancel hide upload chrome
|
//if user pressed cancel hide upload chrome
|
||||||
if (! OC.Upload.isProcessing()) {
|
//if (! OC.Upload.isProcessing()) {
|
||||||
$('#uploadprogresswrapper input.stop').fadeOut();
|
// $('#uploadprogresswrapper input.stop').fadeOut();
|
||||||
$('#uploadprogressbar').fadeOut();
|
// $('#uploadprogressbar').fadeOut();
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -200,148 +200,221 @@ var OCdialogs = {
|
||||||
alert(t('core', 'Error loading message template'));
|
alert(t('core', 'Error loading message template'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
_fileexistsshown: false,
|
||||||
/**
|
/**
|
||||||
* Displays file exists dialog
|
* Displays file exists dialog
|
||||||
* @param {object} original a file with name, size and mtime
|
* @param {object} data upload object
|
||||||
* @param {object} replacement a file with name, size and mtime
|
* @param {object} original file with name, size and mtime
|
||||||
* @param {object} controller a controller with onCancel, onSkip, onReplace and onRename methods
|
* @param {object} replacement file with name, size and mtime
|
||||||
|
* @param {object} controller with onCancel, onSkip, onReplace and onRename methods
|
||||||
*/
|
*/
|
||||||
fileexists:function(data, original, replacement, controller) {
|
fileexists:function(data, original, replacement, controller) {
|
||||||
|
var self = this;
|
||||||
var selection = controller.getSelection(data.originalFiles);
|
var selection = controller.getSelection(data.originalFiles);
|
||||||
if (selection.defaultAction) {
|
if (selection.defaultAction) {
|
||||||
controller[selection.defaultAction](data);
|
controller[selection.defaultAction](data);
|
||||||
} else {
|
} else {
|
||||||
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
var dialog_name = 'oc-dialog-fileexists-content';
|
||||||
var dialog_name = 'oc-dialog-fileexists-' + OCdialogs.dialogs_counter + '-content';
|
var dialog_id = '#' + dialog_name;
|
||||||
var dialog_id = '#' + dialog_name;
|
if (this._fileexistsshown) {
|
||||||
var title = t('files','Replace »{filename}«?',{filename: original.name});
|
// add row
|
||||||
var original_size= t('files','Size: {size}',{size: original.size});
|
var conflict = $(dialog_id+ ' .conflict').last().clone();
|
||||||
var original_mtime = t('files','Last changed: {mtime}',{mtime: original.mtime});
|
conflict.find('.name').text(original.name);
|
||||||
var replacement_size= t('files','Size: {size}',{size: replacement.size});
|
conflict.find('.original .size').text(humanFileSize(original.size));
|
||||||
var replacement_mtime = t('files','Last changed: {mtime}',{mtime: replacement.mtime});
|
conflict.find('.original .mtime').text(formatDate(original.mtime*1000));
|
||||||
var $dlg = $tmpl.octemplate({
|
conflict.find('.replacement .size').text(humanFileSize(replacement.size));
|
||||||
dialog_name: dialog_name,
|
conflict.find('.replacement .mtime').text(formatDate(replacement.lastModifiedDate));
|
||||||
title: title,
|
|
||||||
type: 'fileexists',
|
|
||||||
|
|
||||||
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.'),
|
|
||||||
original_heading: t('files','Original file'),
|
|
||||||
original_size: original_size,
|
|
||||||
original_mtime: original_mtime,
|
|
||||||
|
|
||||||
replacement_heading: t('files','Replace with'),
|
|
||||||
replacement_size: replacement_size,
|
|
||||||
replacement_mtime: replacement_mtime,
|
|
||||||
|
|
||||||
new_name_label: t('files','Choose a new name for the target.'),
|
|
||||||
all_files_label: t('files','Use this action for all files.')
|
|
||||||
});
|
|
||||||
$('body').append($dlg);
|
|
||||||
|
|
||||||
getMimeIcon(original.type,function(path){
|
getMimeIcon(original.type,function(path){
|
||||||
$(dialog_id + ' .original .icon').css('background-image','url('+path+')');
|
conflict.find('.original .icon').css('background-image','url('+path+')');
|
||||||
});
|
});
|
||||||
getMimeIcon(replacement.type,function(path){
|
getMimeIcon(replacement.type,function(path){
|
||||||
$(dialog_id + ' .replacement .icon').css('background-image','url('+path+')');
|
conflict.find('.replacement .icon').css('background-image','url('+path+')');
|
||||||
});
|
});
|
||||||
$(dialog_id + ' #newname').val(original.name);
|
$(dialog_id+' .conflict').last().after(conflict);
|
||||||
|
$(dialog_id).parent().children('.oc-dialog-title').text(t('files','{count} file conflicts',{count:$(dialog_id+ ' .conflict').length}));
|
||||||
|
|
||||||
|
//set more recent mtime bold
|
||||||
|
if (replacement.lastModifiedDate.getTime() > original.mtime*1000) {
|
||||||
|
conflict.find('.replacement .mtime').css('font-weight', 'bold');
|
||||||
|
} else if (replacement.lastModifiedDate.getTime() < original.mtime*1000) {
|
||||||
|
conflict.find('.original .mtime').css('font-weight', 'bold');
|
||||||
|
} else {
|
||||||
|
//TODO add to same mtime colletion?
|
||||||
|
}
|
||||||
|
|
||||||
$(dialog_id + ' #newname').on('keyup', function(e){
|
// set bigger size bold
|
||||||
if ($(dialog_id + ' #newname').val() === original.name) {
|
if (replacement.size > original.size) {
|
||||||
$(dialog_id + ' + div .rename').removeClass('primary').hide();
|
conflict.find('.replacement .size').css('font-weight','bold');
|
||||||
$(dialog_id + ' + div .replace').addClass('primary').show();
|
} else if (replacement.size < original.size) {
|
||||||
} else {
|
conflict.find('.original .size').css('font-weight','bold');
|
||||||
$(dialog_id + ' + div .rename').addClass('primary').show();
|
} else {
|
||||||
$(dialog_id + ' + div .replace').removeClass('primary').hide();
|
//TODO add to same size colletion?
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
buttonlist = [{
|
//add checkbox toggling actions
|
||||||
text: t('core', 'Cancel'),
|
conflict.find('.replacement,.original').on('click', function(){
|
||||||
classes: 'cancel',
|
var checkbox = $(this).find('input[type="checkbox"]');
|
||||||
click: function(){
|
checkbox.prop('checkbox', !checkbox.prop('checkbox'));
|
||||||
if ( typeof controller.onCancel !== 'undefined') {
|
}).find('input[type="checkbox"]').prop('checkbox',false);
|
||||||
controller.onCancel(data);
|
|
||||||
}
|
//TODO show skip action for files with same size and mtime
|
||||||
$(dialog_id).ocdialog('close');
|
|
||||||
|
$(window).trigger('resize');
|
||||||
|
} else {
|
||||||
|
//create dialog
|
||||||
|
this._fileexistsshown = true;
|
||||||
|
$.when(this._getFileExistsTemplate()).then(function($tmpl) {
|
||||||
|
var title = t('files','One file conflict');
|
||||||
|
var original_size = humanFileSize(original.size);
|
||||||
|
var original_mtime = formatDate(original.mtime*1000);
|
||||||
|
var replacement_size= humanFileSize(replacement.size);
|
||||||
|
var replacement_mtime = formatDate(replacement.lastModifiedDate);
|
||||||
|
var $dlg = $tmpl.octemplate({
|
||||||
|
dialog_name: dialog_name,
|
||||||
|
title: title,
|
||||||
|
type: 'fileexists',
|
||||||
|
|
||||||
|
why: t('files','Which files do you want to keep?'),
|
||||||
|
what: t('files','If you select both versions, the copied file will have a number added to its name.'),
|
||||||
|
filename: original.name,
|
||||||
|
|
||||||
|
original_size: original_size,
|
||||||
|
original_mtime: original_mtime,
|
||||||
|
|
||||||
|
replacement_size: replacement_size,
|
||||||
|
replacement_mtime: replacement_mtime
|
||||||
|
});
|
||||||
|
$('body').append($dlg);
|
||||||
|
|
||||||
|
getMimeIcon(original.type,function(path){
|
||||||
|
$(dialog_id + ' .original .icon').css('background-image','url('+path+')');
|
||||||
|
});
|
||||||
|
getMimeIcon(replacement.type,function(path){
|
||||||
|
$(dialog_id + ' .replacement .icon').css('background-image','url('+path+')');
|
||||||
|
});
|
||||||
|
$(dialog_id + ' #newname').val(original.name);
|
||||||
|
|
||||||
|
$(dialog_id + ' #newname').on('keyup', function(e){
|
||||||
|
if ($(dialog_id + ' #newname').val() === original.name) {
|
||||||
|
$(dialog_id + ' + div .rename').removeClass('primary').hide();
|
||||||
|
$(dialog_id + ' + div .replace').addClass('primary').show();
|
||||||
|
} else {
|
||||||
|
$(dialog_id + ' + div .rename').addClass('primary').show();
|
||||||
|
$(dialog_id + ' + div .replace').removeClass('primary').hide();
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
{
|
|
||||||
text: t('core', 'Skip'),
|
buttonlist = [{
|
||||||
classes: 'skip',
|
text: t('core', 'Cancel'),
|
||||||
click: function(){
|
classes: 'cancel',
|
||||||
if ( typeof controller.onSkip !== 'undefined') {
|
click: function(){
|
||||||
if($(dialog_id + ' #allfiles').prop('checked')){
|
self._fileexistsshown = false;
|
||||||
selection.defaultAction = 'onSkip';
|
if ( typeof controller.onCancel !== 'undefined') {
|
||||||
/*selection.defaultAction = function(){
|
controller.onCancel(data);
|
||||||
controller.onSkip(data);
|
|
||||||
};*/
|
|
||||||
}
|
}
|
||||||
controller.onSkip(data);
|
$(dialog_id).ocdialog('close');
|
||||||
}
|
}
|
||||||
// trigger fileupload done with status skip
|
|
||||||
//data.result[0].status = 'skip';
|
|
||||||
//fileupload._trigger('done', data.e, data);
|
|
||||||
$(dialog_id).ocdialog('close');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: t('core', 'Replace'),
|
|
||||||
classes: 'replace',
|
|
||||||
click: function(){
|
|
||||||
if ( typeof controller.onReplace !== 'undefined') {
|
|
||||||
if($(dialog_id + ' #allfiles').prop('checked')){
|
|
||||||
selection.defaultAction = 'onReplace';
|
|
||||||
/*selection.defaultAction = function(){
|
|
||||||
controller.onReplace(data);
|
|
||||||
};*/
|
|
||||||
}
|
|
||||||
controller.onReplace(data);
|
|
||||||
}
|
|
||||||
$(dialog_id).ocdialog('close');
|
|
||||||
},
|
},
|
||||||
defaultButton: true
|
{
|
||||||
},
|
text: t('core', 'Continue'),
|
||||||
{
|
classes: 'continue',
|
||||||
text: t('core', 'Rename'),
|
click: function(){
|
||||||
classes: 'rename',
|
self._fileexistsshown = false;
|
||||||
click: function(){
|
if ( typeof controller.onRename !== 'undefined') {
|
||||||
if ( typeof controller.onRename !== 'undefined') {
|
//TODO use autorename when repeat is checked
|
||||||
//TODO use autorename when repeat is checked
|
controller.onRename(data, $(dialog_id + ' #newname').val());
|
||||||
controller.onRename(data, $(dialog_id + ' #newname').val());
|
}
|
||||||
|
$(dialog_id).ocdialog('close');
|
||||||
}
|
}
|
||||||
$(dialog_id).ocdialog('close');
|
}];
|
||||||
|
|
||||||
|
$(dialog_id).ocdialog({
|
||||||
|
width: 500,
|
||||||
|
closeOnEscape: true,
|
||||||
|
modal: true,
|
||||||
|
buttons: buttonlist,
|
||||||
|
closeButton: null
|
||||||
|
});
|
||||||
|
|
||||||
|
$(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);
|
||||||
}
|
}
|
||||||
}];
|
});
|
||||||
|
$(dialog_id).css('height','auto');
|
||||||
|
|
||||||
$(dialog_id).ocdialog({
|
var conflict = $(dialog_id + ' .conflict').last();
|
||||||
width: 500,
|
//set more recent mtime bold
|
||||||
closeOnEscape: true,
|
if (replacement.lastModifiedDate.getTime() > original.mtime*1000) {
|
||||||
modal: true,
|
conflict.find('.replacement .mtime').css('font-weight','bold');
|
||||||
buttons: buttonlist,
|
} else if (replacement.lastModifiedDate.getTime() < original.mtime*1000) {
|
||||||
closeButton: null
|
conflict.find('.original .mtime').css('font-weight','bold');
|
||||||
});
|
|
||||||
OCdialogs.dialogs_counter++;
|
|
||||||
|
|
||||||
$(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 {
|
} else {
|
||||||
$(dialog_id + ' #newname').fadeOut();
|
//TODO add to same mtime colletion?
|
||||||
$(dialog_id + ' #newname').val(original.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set bigger size bold
|
||||||
|
if (replacement.size > original.size) {
|
||||||
|
conflict.find('.replacement .size').css('font-weight','bold');
|
||||||
|
} else if (replacement.size < original.size) {
|
||||||
|
conflict.find('.original .size').css('font-weight','bold');
|
||||||
|
} else {
|
||||||
|
//TODO add to same size colletion?
|
||||||
|
}
|
||||||
|
|
||||||
|
//add checkbox toggling actions
|
||||||
|
//add checkbox toggling actions
|
||||||
|
$(dialog_id).find('.allnewfiles').on('click', function(){
|
||||||
|
var checkboxes = $(dialog_id).find('.replacement input[type="checkbox"]');
|
||||||
|
checkboxes.prop('checked', $(this).prop('checked'));
|
||||||
|
});
|
||||||
|
$(dialog_id).find('.allexistingfiles').on('click', function(){
|
||||||
|
var checkboxes = $(dialog_id).find('.original input[type="checkbox"]');
|
||||||
|
checkboxes.prop('checked', $(this).prop('checked'));
|
||||||
|
});
|
||||||
|
conflict.find('.replacement,.original').on('click', function(){
|
||||||
|
var checkbox = $(this).find('input[type="checkbox"]');
|
||||||
|
checkbox.prop('checked', !checkbox.prop('checked'));
|
||||||
|
});
|
||||||
|
|
||||||
|
//update counters
|
||||||
|
$(dialog_id).on('click', '.replacement,.allnewfiles', function(){
|
||||||
|
var count = $(dialog_id).find('.replacement input[type="checkbox"]:checked').length;
|
||||||
|
if (count === $(dialog_id+ ' .conflict').length) {
|
||||||
|
$(dialog_id).find('.allnewfiles').prop('checked', true);
|
||||||
|
$(dialog_id).find('.allnewfiles + .count').text(t('files','(all selected)'));
|
||||||
|
} else if (count > 0) {
|
||||||
|
$(dialog_id).find('.allnewfiles').prop('checked', false);
|
||||||
|
$(dialog_id).find('.allnewfiles + .count').text(t('files','({count} selected)',{count:count}));
|
||||||
|
} else {
|
||||||
|
$(dialog_id).find('.allnewfiles').prop('checked', false);
|
||||||
|
$(dialog_id).find('.allnewfiles + .count').text('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$(dialog_id).on('click', '.original,.allexistingfiles', function(){
|
||||||
|
var count = $(dialog_id).find('.original input[type="checkbox"]:checked').length;
|
||||||
|
if (count === $(dialog_id+ ' .conflict').length) {
|
||||||
|
$(dialog_id).find('.allexistingfiles').prop('checked', true);
|
||||||
|
$(dialog_id).find('.allexistingfiles + .count').text(t('files','(all selected)'));
|
||||||
|
} else if (count > 0) {
|
||||||
|
$(dialog_id).find('.allexistingfiles').prop('checked', false);
|
||||||
|
$(dialog_id).find('.allexistingfiles + .count').text(t('files','({count} selected)',{count:count}));
|
||||||
|
} else {
|
||||||
|
$(dialog_id).find('.allexistingfiles').prop('checked', false);
|
||||||
|
$(dialog_id).find('.allexistingfiles + .count').text('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function() {
|
||||||
|
alert(t('core', 'Error loading file exists template'));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
})
|
|
||||||
.fail(function() {
|
|
||||||
alert(t('core', 'Error loading file exists template'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_getFilePickerTemplate: function() {
|
_getFilePickerTemplate: function() {
|
||||||
|
|
Loading…
Reference in New Issue