Now using inline input field for rename action
Also added validation of file name.
This commit is contained in:
parent
d56ef4f0b6
commit
fd4f4bf99a
@ -124,6 +124,11 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
/*margin-left:-50%;*/
|
/*margin-left:-50%;*/
|
||||||
}
|
}
|
||||||
|
#document-title>input {
|
||||||
|
margin: 0;
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
#odf-close{
|
#odf-close{
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
@ -307,17 +307,75 @@ var documentsMain = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// FIXME: copy/pasted from Files.isFileNameValid, needs refactor into core
|
||||||
|
isFileNameValid:function (name) {
|
||||||
|
if (name === '.') {
|
||||||
|
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) {
|
||||||
|
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
onRenamePrompt: function() {
|
onRenamePrompt: function() {
|
||||||
var name = documentsMain.fileName;
|
var name = documentsMain.fileName;
|
||||||
var lastPos = name.lastIndexOf('.');
|
var lastPos = name.lastIndexOf('.');
|
||||||
var extension = name.substr(lastPos + 1);
|
var extension = name.substr(lastPos + 1);
|
||||||
name = name.substr(0, lastPos);
|
name = name.substr(0, lastPos);
|
||||||
// FIXME: don't use an ugly prompt but an inline field
|
var input = $('<input type="text" class="filename"/>').val(name);
|
||||||
// FIXME: check for invalid characters
|
$('#document-title').append(input);
|
||||||
var newName = prompt(t('document', 'Please enter the document name'), name);
|
$('#document-title>div').hide();
|
||||||
if (newName !== null && newName !== '') {
|
|
||||||
documentsMain.renameDocument(newName + '.' + extension);
|
input.on('blur', function(){
|
||||||
}
|
var newName = input.val();
|
||||||
|
if (!newName || newName === name) {
|
||||||
|
input.tipsy('hide');
|
||||||
|
input.remove();
|
||||||
|
$('#document-title>div').show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newName = newName + '.' + extension;
|
||||||
|
try {
|
||||||
|
input.tipsy('hide');
|
||||||
|
input.removeClass('error');
|
||||||
|
if (documentsMain.isFileNameValid(newName)) {
|
||||||
|
input.tipsy('hide');
|
||||||
|
input.remove();
|
||||||
|
$('#document-title>div').show();
|
||||||
|
documentsMain.renameDocument(newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
input.attr('title', error);
|
||||||
|
input.tipsy({gravity: 'n', trigger: 'manual'});
|
||||||
|
input.tipsy('show');
|
||||||
|
input.addClass('error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.on('keyup', function(event){
|
||||||
|
if (event.keyCode === 27) {
|
||||||
|
// cancel by putting in an empty value
|
||||||
|
$(this).val('');
|
||||||
|
$(this).blur();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
$(this).blur();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.focus();
|
||||||
|
input.selectRange(0, name.length);
|
||||||
},
|
},
|
||||||
|
|
||||||
onClose: function() {
|
onClose: function() {
|
||||||
@ -471,7 +529,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document.body).on('click', '#document-title', documentsMain.onRenamePrompt);
|
$(document.body).on('click', '#document-title>div', documentsMain.onRenamePrompt);
|
||||||
$(document.body).on('click', '#odf-close', documentsMain.onClose);
|
$(document.body).on('click', '#odf-close', documentsMain.onClose);
|
||||||
$(document.body).on('click', '#odf-invite', documentsMain.onInvite);
|
$(document.body).on('click', '#odf-invite', documentsMain.onInvite);
|
||||||
$(document.body).on('click', '#odf-join', function(event){
|
$(document.body).on('click', '#odf-join', function(event){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user