rename containsInvalidCharacters() to isFileNameValid() - NOTE: semantic has changed!

adding file name checks and notifications to isFileNameValid() for . and empty file name
This commit is contained in:
Thomas Mueller 2013-01-06 12:52:00 +01:00
parent a5dcbc3d8a
commit b4191b7da5
2 changed files with 17 additions and 5 deletions

View File

@ -149,7 +149,7 @@ var FileList={
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
var newname=input.val(); var newname=input.val();
if (Files.containsInvalidCharacters(newname) || newname === '.') { if (!Files.isFileNameValid(newname)) {
return false; return false;
} }
if (newname != name) { if (newname != name) {

View File

@ -26,17 +26,29 @@ Files={
}); });
procesSelection(); procesSelection();
}, },
containsInvalidCharacters:function (name) { isFileNameValid:function (name) {
if (name === '.') {
$('#notification').text(t('files', "'.' is an invalid file name."));
$('#notification').fadeIn();
return false;
}
if (name.length == 0) {
$('#notification').text(t('files', "File name cannot be empty."));
$('#notification').fadeIn();
return false;
}
// check for invalid characters
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*']; var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
for (var i = 0; i < invalid_characters.length; i++) { for (var i = 0; i < invalid_characters.length; i++) {
if (name.indexOf(invalid_characters[i]) != -1) { if (name.indexOf(invalid_characters[i]) != -1) {
$('#notification').text(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); $('#notification').text(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
$('#notification').fadeIn(); $('#notification').fadeIn();
return true; return false;
} }
} }
$('#notification').fadeOut(); $('#notification').fadeOut();
return false; return true;
} }
}; };
$(document).ready(function() { $(document).ready(function() {
@ -509,7 +521,7 @@ $(document).ready(function() {
$(this).append(input); $(this).append(input);
input.focus(); input.focus();
input.change(function(){ input.change(function(){
if (type != 'web' && Files.containsInvalidCharacters($(this).val())) { if (type != 'web' && !Files.isFileNameValid($(this).val())) {
return; return;
} else if( type == 'folder' && $('#dir').val() == '/' && $(this).val() == 'Shared') { } else if( type == 'folder' && $('#dir').val() == '/' && $(this).val() == 'Shared') {
$('#notification').text(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud')); $('#notification').text(t('files','Invalid folder name. Usage of "Shared" is reserved by Owncloud'));