prevent user from creating or renaming sth. to an existing filename

- show tooltip when violating naming constraints while typing
- when target filename exists on server fallback to dialog to interrupt the users flow because something unexpected went wrong
- fixes #5062
- also fixes some whitespace and codestyle issues in files js
- uses css selector over filterAttr in touched js files
This commit is contained in:
Jörn Friedrich Dreyer 2013-10-22 18:11:03 +02:00
parent cadd71ec8a
commit 45e6d96702
7 changed files with 523 additions and 435 deletions

View File

@ -56,6 +56,21 @@ function progress($notification_code, $severity, $message, $message_code, $bytes
$target = $dir.'/'.$filename;
$l10n = \OC_L10n::get('files');
if (\OC\Files\Filesystem::file_exists($target)) {
$result = array(
'success' => false,
'data' => array(
'message' => $l10n->t(
"The name %s is already used in the folder %s. Please choose a different name.",
array($newname, $dir))
)
);
OCP\JSON::error($result);
exit();
}
if($source) {
if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') {
OCP\JSON::error(array("data" => array( "message" => "Not a valid source" )));

View File

@ -49,7 +49,13 @@
background-repeat:no-repeat; cursor:pointer; }
#new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;}
#new .error, #fileList .error {
color: #e9322d;
border-color: #e9322d;
-webkit-box-shadow: 0 0 6px #f8b9b7;
-moz-box-shadow: 0 0 6px #f8b9b7;
box-shadow: 0 0 6px #f8b9b7;
}
/* FILE TABLE */

View File

@ -419,7 +419,9 @@ $(document).ready(function() {
// http://stackoverflow.com/a/6700/11236
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
if (obj.hasOwnProperty(key)) {
size++;
}
}
return size;
};
@ -432,7 +434,7 @@ $(document).ready(function() {
});
//add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
if(navigator.userAgent.search(/konqueror/i)==-1){
if (navigator.userAgent.search(/konqueror/i) === -1) {
$('#file_upload_start').attr('multiple', 'multiple');
}
@ -453,7 +455,7 @@ $(document).ready(function() {
//still not enough, start shorting down the current folder name
var crumb=$('div.crumb>a').last();
while($('div.controls').height() > 40 && crumb.text().length > 6) {
var text=crumb.text()
var text=crumb.text();
text = text.substr(0,text.length-6)+'...';
crumb.text(text);
}
@ -461,8 +463,11 @@ $(document).ready(function() {
$(document).click(function() {
$('#new>ul').hide();
$('#new').removeClass('active');
if ($('#new .error').length > 0) {
$('#new .error').tipsy('hide');
}
$('#new li').each(function(i,element) {
if($(element).children('p').length==0){
if ($(element).children('p').length === 0) {
$(element).children('form').remove();
$(element).append('<p>'+$(element).data('text')+'</p>');
}
@ -476,12 +481,14 @@ $(document).ready(function() {
$('#new').toggleClass('active');
});
$('#new li').click(function() {
if($(this).children('p').length==0){
if ($(this).children('p').length === 0) {
return;
}
$('#new .error').tipsy('hide');
$('#new li').each(function(i,element) {
if($(element).children('p').length==0){
if ($(element).children('p').length === 0) {
$(element).children('form').remove();
$(element).append('<p>'+$(element).data('text')+'</p>');
}
@ -491,29 +498,54 @@ $(document).ready(function() {
var text=$(this).children('p').text();
$(this).data('text',text);
$(this).children('p').remove();
// add input field
var form=$('<form></form>');
var input=$('<input type="text">');
form.append(input);
$(this).append(form);
var checkInput = function () {
var filename = input.val();
if (type === 'web' && filename.length === 0) {
throw t('files', 'URL cannot be empty.');
} else if (type !== 'web' && !Files.isFileNameValid(filename)) {
// Files.isFileNameValid(filename) throws an exception itself
} else if ($('#dir').val() === '/' && filename === 'Shared') {
throw t('files','Invalid name. Usage of \'Shared\' is reserved by ownCloud');
} else if (FileList.inList(filename)) {
throw t('files', '{new_name} already exists', {new_name: filename});
} else {
return true;
}
};
// verify filename on typing
input.keyup(function(event) {
try {
checkInput();
input.tipsy('hide');
input.removeClass('error');
} catch (error) {
input.attr('title', error);
input.tipsy({gravity: 'w', trigger: 'manual'});
input.tipsy('show');
input.addClass('error');
}
});
input.focus();
form.submit(function(event) {
event.stopPropagation();
event.preventDefault();
try {
checkInput();
var newname = input.val();
if(type == 'web' && newname.length == 0) {
OC.Notification.show(t('files', 'URL cannot be empty.'));
return false;
} else if (type != 'web' && !Files.isFileNameValid(newname)) {
return false;
} else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') {
OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud'));
return false;
}
if (FileList.lastAction) {
FileList.lastAction();
}
var name = getUniqueName(newname);
if (newname != name) {
if (newname !== name) {
FileList.checkName(name, newname, true);
var hidden = true;
} else {
@ -525,7 +557,7 @@ $(document).ready(function() {
OC.filePath('files', 'ajax', 'newfile.php'),
{dir:$('#dir').val(), filename:name},
function(result) {
if (result.status == 'success') {
if (result.status === 'success') {
var date = new Date();
// TODO: ideally addFile should be able to receive
// all attributes and set them automatically,
@ -541,7 +573,7 @@ $(document).ready(function() {
});
FileActions.display(tr.find('td.filename'), true);
} else {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
OC.dialogs.alert(result.data.message, t('core', 'Could not create file'));
}
}
);
@ -551,24 +583,24 @@ $(document).ready(function() {
OC.filePath('files','ajax','newfolder.php'),
{dir:$('#dir').val(), foldername:name},
function(result) {
if (result.status == 'success') {
if (result.status === 'success') {
var date=new Date();
FileList.addDir(name, 0, date, hidden);
var tr=$('tr').filterAttr('data-file',name);
var tr=$('tr[data-file="'+name+'"]');
tr.attr('data-id', result.data.id);
} else {
OC.dialogs.alert(result.data.message, t('core', 'Error'));
OC.dialogs.alert(result.data.message, t('core', 'Could not create folder'));
}
}
);
break;
case 'web':
if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){
if (name.substr(0,8) !== 'https://' && name.substr(0,7) !== 'http://') {
name = 'http://' + name;
}
var localName=name;
if(localName.substr(localName.length-1,1)=='/'){//strip /
localName=localName.substr(0,localName.length-1)
if (localName.substr(localName.length-1,1)==='/') {//strip /
localName=localName.substr(0,localName.length-1);
}
if (localName.indexOf('/')) {//use last part of url
localName=localName.split('/').pop();
@ -596,13 +628,14 @@ $(document).ready(function() {
$('#uploadprogressbar').fadeOut();
var date = new Date();
FileList.addFile(localName, size, date, false, hidden);
var tr=$('tr').filterAttr('data-file',localName);
var tr = $('tr[data-file="'+localName+'"]');
tr.data('mime', mime).data('id', id);
tr.attr('data-id', id);
var path = $('#dir').val()+'/'+localName;
lazyLoadPreview(path, mime, function(previewpath) {
tr.find('td.filename').attr('style', 'background-image:url('+previewpath+')');
});
FileActions.display(tr.find('td.filename'), true);
});
eventSource.listen('error',function(error) {
$('#uploadprogressbar').fadeOut();
@ -617,6 +650,12 @@ $(document).ready(function() {
$('#content').focus();
li.append('<p>'+li.data('text')+'</p>');
$('#new>a').click();
} catch (error) {
input.attr('title', error);
input.tipsy({gravity: 'w', trigger: 'manual'});
input.tipsy('show');
input.addClass('error');
}
});
});
window.file_upload_param = file_upload_param;

View File

@ -11,7 +11,7 @@ var FileList={
permissions = $('#permissions').val(),
isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
$fileList.empty().html(fileListHtml);
$('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').length > 0);
$('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').exists());
$fileList.find('tr').each(function () {
FileActions.display($(this).children('td.filename'));
});
@ -45,7 +45,7 @@ var FileList={
"href": linktarget
});
//split extension from filename for non dirs
if (type != 'dir' && name.indexOf('.')!=-1) {
if (type !== 'dir' && name.indexOf('.') !== -1) {
basename=name.substr(0,name.lastIndexOf('.'));
extension=name.substr(name.lastIndexOf('.'));
} else {
@ -58,7 +58,7 @@ var FileList={
name_span.append($('<span></span>').addClass('extension').text(extension));
}
//dirs can show the number of uploaded files
if (type == 'dir') {
if (type === 'dir') {
link_elem.append($('<span></span>').attr({
'class': 'uploadtext',
'currentUploads': 0
@ -68,7 +68,7 @@ var FileList={
tr.append(td);
//size column
if(size!=t('files', 'Pending')){
if (size !== t('files', 'Pending')) {
simpleSize = humanFileSize(size);
} else {
simpleSize=t('files', 'Pending');
@ -158,6 +158,7 @@ var FileList={
* @brief Changes the current directory and reload the file list.
* @param targetDir target directory (non URL encoded)
* @param changeUrl false if the URL must not be changed (defaults to true)
* @param {boolean} force set to true to force changing directory
*/
changeDirectory: function(targetDir, changeUrl, force) {
var $dir = $('#dir'),
@ -229,7 +230,7 @@ var FileList={
FileList.setDirectoryPermissions(result.data.permissions);
}
if(typeof(result.data.breadcrumb) != 'undefined'){
if (typeof(result.data.breadcrumb) !== 'undefined') {
$controls.find('.crumb').remove();
$controls.prepend(result.data.breadcrumb);
@ -252,10 +253,10 @@ var FileList={
$('.notCreatable').toggleClass('hidden', isCreatable);
},
remove:function(name) {
$('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy');
$('tr').filterAttr('data-file',name).remove();
$('tr[data-file="'+name+'"]').find('td.filename').draggable('destroy');
$('tr[data-file="'+name+'"]').remove();
FileList.updateFileSummary();
if($('tr[data-file]').length==0){
if ( ! $('tr[data-file]').exists() ) {
$('#emptycontent').removeClass('hidden');
}
},
@ -268,20 +269,22 @@ var FileList={
pos = fileElements.length - 1;
} else {
for(pos = 0; pos<fileElements.length-1; pos++) {
if(name.localeCompare($(fileElements[pos]).attr('data-file'))>0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){
if (name.localeCompare($(fileElements[pos]).attr('data-file')) > 0
&& name.localeCompare($(fileElements[pos+1]).attr('data-file')) < 0)
{
break;
}
}
}
if(fileElements.length){
if(pos==-1){
if (fileElements.exists()) {
if (pos === -1) {
$(fileElements[0]).before(element);
} else {
$(fileElements[pos]).after(element);
}
}else if(type=='dir' && $('tr[data-file]').length>0){
} else if (type === 'dir' && $('tr[data-file]').exists()) {
$('tr[data-file]').first().before(element);
} else if(type=='file' && $('tr[data-file]').length>0) {
} else if (type === 'file' && $('tr[data-file]').exists()) {
$('tr[data-file]').last().before(element);
} else {
$('#fileList').append(element);
@ -290,11 +293,11 @@ var FileList={
FileList.updateFileSummary();
},
loadingDone:function(name, id) {
var mime, tr=$('tr').filterAttr('data-file',name);
var mime, tr = $('tr[data-file="'+name+'"]');
tr.data('loading', false);
mime = tr.data('mime');
tr.attr('data-mime', mime);
if (id != null) {
if (id) {
tr.attr('data-id', id);
}
var path = getPathForPreview(name);
@ -304,14 +307,14 @@ var FileList={
tr.find('td.filename').draggable(dragOptions);
},
isLoading:function(name) {
return $('tr').filterAttr('data-file',name).data('loading');
return $('tr[data-file="'+name+'"]').data('loading');
},
rename:function(name){
rename:function(oldname) {
var tr, td, input, form;
tr=$('tr').filterAttr('data-file',name);
tr = $('tr[data-file="'+oldname+'"]');
tr.data('renaming',true);
td = tr.children('td.filename');
input=$('<input type="text" class="filename"/>').val(name);
input = $('<input type="text" class="filename"/>').val(oldname);
form = $('<form></form>');
form.append(input);
td.children('a.name').hide();
@ -324,16 +327,27 @@ var FileList={
}
input.selectRange(0, len);
var checkInput = function () {
var filename = input.val();
if (filename !== oldname) {
if (!Files.isFileNameValid(filename)) {
// Files.isFileNameValid(filename) throws an exception itself
} else if($('#dir').val() === '/' && filename === 'Shared') {
throw t('files','Invalid name. Usage of \'Shared\' is reserved by ownCloud');
} else if (FileList.inList(filename)) {
throw t('files', '{new_name} already exists', {new_name: filename});
}
}
return true;
};
form.submit(function(event) {
event.stopPropagation();
event.preventDefault();
try {
var newname = input.val();
if (!Files.isFileNameValid(newname)) {
return false;
} else if (newname != name) {
if (FileList.checkName(name, newname, false)) {
newname = name;
} else {
if (newname !== oldname) {
checkInput();
// save background image, because it's replaced by a spinner while async request
var oldBackgroundImage = td.css('background-image');
// mark as loading
@ -343,16 +357,16 @@ var FileList={
data: {
dir : $('#dir').val(),
newname: newname,
file: name
file: oldname
},
success: function(result) {
if (!result || result.status === 'error') {
OC.Notification.show(result.data.message);
newname = name;
OC.dialogs.alert(result.data.message, t('core', 'Could not rename file'));
// revert changes
newname = oldname;
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)));
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
var basename=newname.substr(0,newname.lastIndexOf('.'));
} else {
@ -360,7 +374,7 @@ var FileList={
}
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if (td.find('a.name span.extension').length === 0 ) {
if ( ! td.find('a.name span.extension').exists() ) {
td.find('a.name span.nametext').append('<span class="extension"></span>');
}
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
@ -368,34 +382,55 @@ var FileList={
tr.find('.fileactions').effect('highlight', {}, 5000);
tr.effect('highlight', {}, 5000);
}
// reinsert row
tr.detach();
FileList.insertElement( tr.attr('data-file'), tr.attr('data-type'),tr );
// remove loading mark and recover old image
td.css('background-image', oldBackgroundImage);
}
});
}
}
input.tipsy('hide');
tr.data('renaming',false);
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 {
// FIXME this will fail if the path contains the filename.
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
var basename = newname;
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
basename = newname.substr(0, newname.lastIndexOf('.'));
}
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') {
if (td.find('a.name span.extension').length == 0 ) {
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if ( ! td.find('a.name span.extension').exists() ) {
td.find('a.name span.nametext').append('<span class="extension"></span>');
}
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
}
form.remove();
td.children('a.name').show();
} catch (error) {
input.attr('title', error);
input.tipsy({gravity: 'w', trigger: 'manual'});
input.tipsy('show');
input.addClass('error');
}
return false;
});
input.keyup(function(event) {
if (event.keyCode == 27) {
// verify filename on typing
try {
checkInput();
input.tipsy('hide');
input.removeClass('error');
} catch (error) {
input.attr('title', error);
input.tipsy({gravity: 'w', trigger: 'manual'});
input.tipsy('show');
input.addClass('error');
}
if (event.keyCode === 27) {
input.tipsy('hide');
tr.data('renaming',false);
form.remove();
td.children('a.name').show();
@ -409,29 +444,14 @@ var FileList={
form.trigger('submit');
});
},
checkName:function(oldName, newName, isNewFile) {
if (isNewFile || $('tr').filterAttr('data-file', newName).length > 0) {
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>&nbsp;<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);
return true;
} else {
return false;
}
inList:function(filename) {
return $('#fileList tr[data-file="'+filename+'"]').length;
},
replace:function(oldName, newName, isNewFile) {
// Finish any existing actions
$('tr').filterAttr('data-file', oldName).hide();
$('tr').filterAttr('data-file', newName).hide();
var tr = $('tr').filterAttr('data-file', oldName).clone();
$('tr[data-file="'+oldName+'"]').hide();
$('tr[data-file="'+newName+'"]').hide();
var tr = $('tr[data-file="'+oldName+'"]').clone();
tr.attr('data-replace', 'true');
tr.attr('data-file', newName);
var td = tr.children('td.filename');
@ -466,8 +486,8 @@ var FileList={
finishReplace:function() {
if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) {
$.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');
if (result && result.status === 'success') {
$('tr[data-replace="true"').removeAttr('data-replace');
} else {
OC.dialogs.alert(result.data.message, 'Error moving file');
}
@ -483,7 +503,7 @@ var FileList={
files=[files];
}
for (var i=0; i<files.length; i++) {
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date").children(".action.delete");
var deleteAction = $('tr[data-file="'+files[i]+'"]').children("td.date").children(".action.delete");
deleteAction.removeClass('delete-icon').addClass('progress-icon');
}
// Finish any existing actions
@ -495,9 +515,9 @@ var FileList={
$.post(OC.filePath('files', 'ajax', 'delete.php'),
{dir:$('#dir').val(),files:fileNames},
function(result) {
if (result.status == 'success') {
if (result.status === 'success') {
$.each(files,function(index,file) {
var files = $('tr').filterAttr('data-file',file);
var files = $('tr[data-file="'+file+'"]');
files.remove();
files.find('input[type="checkbox"]').removeAttr('checked');
files.removeClass('selected');
@ -507,14 +527,14 @@ var FileList={
FileList.updateFileSummary();
} else {
$.each(files,function(index,file) {
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date").children(".action.delete");
var deleteAction = $('tr[data-file="'+files[i]+'"]').children("td.date").children(".action.delete");
deleteAction.removeClass('progress-icon').addClass('delete-icon');
});
}
});
},
createFileSummary: function() {
if( $('#fileList tr').length > 0 ) {
if ( $('#fileList tr').exists() ) {
var totalDirs = 0;
var totalFiles = 0;
var totalSize = 0;
@ -536,7 +556,7 @@ var FileList={
var infoVars = {
dirs: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">',
files: '</span><span class="fileinfo">'+fileInfo+'</span>'
}
};
var info = t('files', '{dirs} and {files}', infoVars);
@ -621,7 +641,7 @@ var FileList={
showMask: function() {
// in case one was shown before
var $mask = $('#content .mask');
if ($mask.length){
if ($mask.exists()) {
return;
}
@ -645,13 +665,13 @@ var FileList={
},
scrollTo:function(file) {
//scroll to and highlight preselected file
var scrolltorow = $('tr[data-file="'+file+'"]');
if (scrolltorow.length > 0) {
scrolltorow.addClass('searchresult');
$(window).scrollTop(scrolltorow.position().top);
var $scrolltorow = $('tr[data-file="'+file+'"]');
if ($scrolltorow.exists()) {
$scrolltorow.addClass('searchresult');
$(window).scrollTop($scrolltorow.position().top);
//remove highlight when hovered over
scrolltorow.one('hover', function(){
scrolltorow.removeClass('searchresult');
$scrolltorow.one('hover', function() {
$scrolltorow.removeClass('searchresult');
});
}
},
@ -665,7 +685,7 @@ var FileList={
});
//do not use scrollto to prevent removing searchresult css class
var first = $('#fileList tr.searchresult').first();
if (first.length !== 0) {
if (first.exists()) {
$(window).scrollTop(first.position().top);
}
},
@ -695,7 +715,7 @@ $(document).ready(function(){
// if from file list, need to prepend parent dir
if (dir) {
var parentDir = $('#dir').val() || '/';
if (parentDir[parentDir.length - 1] != '/'){
if (parentDir[parentDir.length - 1] !== '/') {
parentDir += '/';
}
dir = parentDir + dir;
@ -800,7 +820,7 @@ $(document).ready(function(){
}
var date=new Date();
var param = {};
if ($('#publicUploadRequestToken').length) {
if ($('#publicUploadRequestToken').exists()) {
param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name;
}
//should the file exist in the list remove it
@ -857,7 +877,7 @@ $(document).ready(function(){
$('#notification').on('click', '.undo', function() {
if (FileList.deleteFiles) {
$.each(FileList.deleteFiles,function(index,file) {
$('tr').filterAttr('data-file',file).show();
$('tr[data-file="'+file+'"]').show();
});
FileList.deleteCanceled=true;
FileList.deleteFiles=null;
@ -867,10 +887,10 @@ $(document).ready(function(){
FileList.deleteCanceled = false;
FileList.deleteFiles = [FileList.replaceOldName];
} else {
$('tr').filterAttr('data-file', FileList.replaceOldName).show();
$('tr[data-file="'+FileList.replaceOldName+'"]').show();
}
$('tr').filterAttr('data-replace', 'true').remove();
$('tr').filterAttr('data-file', FileList.replaceNewName).show();
$('tr[data-replace="true"').remove();
$('tr[data-file="'+FileList.replaceNewName+'"]').show();
FileList.replaceCanceled = true;
FileList.replaceOldName = null;
FileList.replaceNewName = null;
@ -885,7 +905,7 @@ $(document).ready(function(){
});
});
$('#notification:first-child').on('click', '.suggest', function() {
$('tr').filterAttr('data-file', $('#notification > span').attr('data-oldName')).show();
$('tr[data-file="'+$('#notification > span').attr('data-oldName')+'"]').show();
OC.Notification.hide();
});
$('#notification:first-child').on('click', '.cancel', function() {
@ -953,7 +973,7 @@ $(document).ready(function(){
if (targetDir) {
FileList.changeDirectory(targetDir, false);
}
}
};
if (parseInt($('#ajaxLoad').val(), 10) === 1) {
// need to initially switch the dir to the one from the hash (IE8)

View File

@ -1,6 +1,6 @@
Files={
updateMaxUploadFilesize:function(response) {
if(response == undefined) {
if (response === undefined) {
return;
}
if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
@ -9,7 +9,7 @@ Files={
$('#usedSpacePercent').val(response.data.usedSpacePercent);
Files.displayStorageWarnings();
}
if(response[0] == undefined) {
if (response[0] === undefined) {
return;
}
if (response[0].uploadMaxFilesize !== undefined) {
@ -22,23 +22,18 @@ Files={
},
isFileNameValid:function (name) {
if (name === '.') {
OC.Notification.show(t('files', '\'.\' is an invalid file name.'));
return false;
}
if (name.length == 0) {
OC.Notification.show(t('files', 'File name cannot be empty.'));
return false;
throw t('files', '\'.\' is an invalid file name.');
} else if (name.length === 0) {
throw t('files', 'File name cannot be empty.');
}
// check for invalid characters
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
for (var i = 0; i < invalid_characters.length; i++) {
if (name.indexOf(invalid_characters[i]) != -1) {
OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
return false;
if (name.indexOf(invalid_characters[i]) !== -1) {
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
}
}
OC.Notification.hide();
return true;
},
displayStorageWarnings: function() {
@ -127,9 +122,9 @@ Files={
},
resizeBreadcrumbs: function (width, firstRun) {
if (width != Files.lastWidth) {
if (width !== Files.lastWidth) {
if ((width < Files.lastWidth || firstRun) && width < Files.breadcrumbsWidth) {
if (Files.hiddenBreadcrumbs == 0) {
if (Files.hiddenBreadcrumbs === 0) {
Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth;
$(Files.breadcrumbs[1]).find('a').hide();
$(Files.breadcrumbs[1]).append('<span>...</span>');
@ -141,12 +136,12 @@ Files={
Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth;
$(Files.breadcrumbs[i]).hide();
Files.hiddenBreadcrumbs = i;
i++
i++;
}
} else if (width > Files.lastWidth && Files.hiddenBreadcrumbs > 0) {
var i = Files.hiddenBreadcrumbs;
while (width > Files.breadcrumbsWidth && i > 0) {
if (Files.hiddenBreadcrumbs == 1) {
if (Files.hiddenBreadcrumbs === 1) {
Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth;
$(Files.breadcrumbs[1]).find('span').remove();
$(Files.breadcrumbs[1]).find('a').show();
@ -215,7 +210,7 @@ $(document).ready(function() {
var rows = $(this).parent().parent().parent().children('tr');
for (var i = start; i < end; i++) {
$(rows).each(function(index) {
if (index == i) {
if (index === i) {
var checkbox = $(this).children().children('input:checkbox');
$(checkbox).attr('checked', 'checked');
$(checkbox).parent().parent().addClass('selected');
@ -233,14 +228,14 @@ $(document).ready(function() {
$(checkbox).attr('checked', 'checked');
$(checkbox).parent().parent().toggleClass('selected');
var selectedCount = $('td.filename input:checkbox:checked').length;
if (selectedCount == $('td.filename input:checkbox').length) {
if (selectedCount === $('td.filename input:checkbox').length) {
$('#select_all').attr('checked', 'checked');
}
}
procesSelection();
} else {
var filename=$(this).parent().parent().attr('data-file');
var tr=$('tr').filterAttr('data-file',filename);
var tr=$('tr[data-file="'+filename+'"]');
var renaming=tr.data('renaming');
if (!renaming && !FileList.isLoading(filename)) {
FileActions.currentFile = $(this).parent();
@ -280,7 +275,7 @@ $(document).ready(function() {
var rows = $(this).parent().parent().parent().children('tr');
for (var i = start; i < end; i++) {
$(rows).each(function(index) {
if (index == i) {
if (index === i) {
var checkbox = $(this).children().children('input:checkbox');
$(checkbox).attr('checked', 'checked');
$(checkbox).parent().parent().addClass('selected');
@ -293,7 +288,7 @@ $(document).ready(function() {
if (!$(this).attr('checked')) {
$('#select_all').attr('checked',false);
} else {
if(selectedCount==$('td.filename input:checkbox').length){
if (selectedCount===$('td.filename input:checkbox').length) {
$('#select_all').attr('checked',true);
}
}
@ -306,7 +301,8 @@ $(document).ready(function() {
var dir=$('#dir').val()||'/';
OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
// use special download URL if provided, e.g. for public shared files
if ( (downloadURL = document.getElementById("downloadURL")) ) {
var downloadURL = document.getElementById("downloadURL");
if ( downloadURL ) {
window.location = downloadURL.value+"&download&files=" + encodeURIComponent(fileslist);
} else {
window.location = OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist });
@ -400,10 +396,10 @@ function scanFiles(force, dir, users){
}
scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource);
scannerEventSource.listen('count',function(count) {
console.log(count + ' files scanned')
console.log(count + ' files scanned');
});
scannerEventSource.listen('folder',function(path) {
console.log('now scanning ' + path)
console.log('now scanning ' + path);
});
scannerEventSource.listen('done',function(count) {
scanFiles.scanning=false;
@ -418,7 +414,7 @@ scanFiles.scanning=false;
function boolOperationFinished(data, callback) {
result = jQuery.parseJSON(data.responseText);
Files.updateMaxUploadFilesize(result);
if(result.status == 'success'){
if (result.status === 'success') {
callback.call();
} else {
alert(result.data.message);
@ -435,7 +431,7 @@ var createDragShadow = function(event){
var selectedFiles = getSelectedFilesTrash();
if (!isDragSelected && selectedFiles.length == 1) {
if (!isDragSelected && selectedFiles.length === 1) {
//revert the selection
$(event.target).parents('tr').find('td input:first').prop('checked',false);
}
@ -468,7 +464,7 @@ var createDragShadow = function(event){
});
return dragshadow;
}
};
//options for file drag/drop
var dragOptions={
@ -478,7 +474,7 @@ var dragOptions={
stop: function(event, ui) {
$('#fileList tr td.filename').addClass('ui-draggable');
}
}
};
// sane browsers support using the distance option
if ( $('html.ie').length === 0) {
dragOptions['distance'] = 20;
@ -501,10 +497,10 @@ var folderDropOptions={
if (result) {
if (result.status === 'success') {
//recalculate folder size
var oldSize = $('#fileList tr').filterAttr('data-file',target).data('size');
var newSize = oldSize + $('#fileList tr').filterAttr('data-file',file).data('size');
$('#fileList tr').filterAttr('data-file',target).data('size', newSize);
$('#fileList tr').filterAttr('data-file',target).find('td.filesize').text(humanFileSize(newSize));
var oldSize = $('#fileList tr[data-file="'+target+'"]').data('size');
var newSize = oldSize + $('#fileList tr[data-file="'+file+'"]').data('size');
$('#fileList tr[data-file="'+target+'"]').data('size', newSize);
$('#fileList tr[data-file="'+target+'"]').find('td.filesize').text(humanFileSize(newSize));
FileList.remove(file);
procesSelection();
@ -521,20 +517,20 @@ var folderDropOptions={
});
},
tolerance: 'pointer'
}
};
var crumbDropOptions={
drop: function( event, ui ) {
var target=$(this).data('dir');
var dir = $('#dir').val();
while(dir.substr(0,1)=='/'){//remove extra leading /'s
while(dir.substr(0,1) === '/') {//remove extra leading /'s
dir=dir.substr(1);
}
dir = '/' + dir;
if(dir.substr(-1,1)!='/'){
if (dir.substr(-1,1) !== '/') {
dir = dir + '/';
}
if(target==dir || target+'/'==dir){
if (target === dir || target+'/' === dir) {
return;
}
var files = ui.helper.find('tr');
@ -559,13 +555,17 @@ var crumbDropOptions={
});
},
tolerance: 'pointer'
}
};
function procesSelection() {
var selected = getSelectedFilesTrash();
var selectedFiles=selected.filter(function(el){return el.type=='file'});
var selectedFolders=selected.filter(function(el){return el.type=='dir'});
if(selectedFiles.length==0 && selectedFolders.length==0) {
var selectedFiles = selected.filter(function(el) {
return el.type==='file';
});
var selectedFolders = selected.filter(function(el) {
return el.type==='dir';
});
if (selectedFiles.length === 0 && selectedFolders.length === 0) {
$('#headerName>span.name').text(t('files','Name'));
$('#headerSize').text(t('files','Size'));
$('#modified').text(t('files','Modified'));
@ -600,8 +600,8 @@ function procesSelection(){
/**
* @brief get a list of selected files
* @param string property (option) the property of the file requested
* @return array
* @param {string} property (option) the property of the file requested
* @return {array}
*
* possible values for property: name, mime, size and type
* if property is set, an array with that property for each file is returnd
@ -670,7 +670,7 @@ function lazyLoadPreview(path, mime, ready, width, height) {
}
function getUniqueName(name) {
if($('tr').filterAttr('data-file',name).length>0){
if ($('tr[data-file="'+name+'"]').exists()) {
var parts=name.split('.');
var extension = "";
if (parts.length > 1) {
@ -681,7 +681,7 @@ function getUniqueName(name){
var num=2;
if (numMatch && numMatch.length>0) {
num=parseInt(numMatch[numMatch.length-1])+1;
base=base.split('(')
base=base.split('(');
base.pop();
base=$.trim(base.join('('));
}

View File

@ -52,6 +52,14 @@ class App {
$result['data'] = array(
'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud")
);
// rename to existing file is denied
} else if ($this->view->file_exists($dir . '/' . $newname)) {
$result['data'] = array(
'message' => $this->l10n->t(
"The name %s is already used in the folder %s. Please choose a different name.",
array($newname, $dir))
);
} else if (
// rename to "." is denied
$newname !== '.' and

View File

@ -933,7 +933,7 @@ jQuery.fn.selectRange = function(start, end) {
*/
jQuery.fn.exists = function(){
return this.length > 0;
}
};
/**
* Calls the server periodically every 15 mins to ensure that session doesnt