Skip to content
Snippets Groups Projects
Commit 24a08c68 authored by Vincent Petry's avatar Vincent Petry
Browse files

New file box now has default file name + extension

Whenever a user creates a file or folder in the web UI, the input field
will contain a default file name, pre-selected up to the extension for
easier typing.

The purpose is mostly to prevent users creating text files without an
extension.

Fixes #6045
parent f23d641b
Branches
No related tags found
No related merge requests found
...@@ -510,9 +510,13 @@ $(document).ready(function() { ...@@ -510,9 +510,13 @@ $(document).ready(function() {
// add input field // add input field
var form = $('<form></form>'); var form = $('<form></form>');
var input = $('<input type="text">'); var input = $('<input type="text">');
var newName = $(this).attr('data-newname') || '';
if (newName) {
input.val(newName);
}
form.append(input); form.append(input);
$(this).append(form); $(this).append(form);
var lastPos;
var checkInput = function () { var checkInput = function () {
var filename = input.val(); var filename = input.val();
if (type === 'web' && filename.length === 0) { if (type === 'web' && filename.length === 0) {
...@@ -543,6 +547,12 @@ $(document).ready(function() { ...@@ -543,6 +547,12 @@ $(document).ready(function() {
}); });
input.focus(); input.focus();
// pre select name up to the extension
lastPos = newName.lastIndexOf('.');
if (lastPos === -1) {
lastPos = newName.length;
}
input.selectRange(0, lastPos);
form.submit(function(event) { form.submit(function(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<a><?php p($l->t('New'));?></a> <a><?php p($l->t('New'));?></a>
<ul> <ul>
<li style="background-image:url('<?php p(OCP\mimetype_icon('text/plain')) ?>')" <li style="background-image:url('<?php p(OCP\mimetype_icon('text/plain')) ?>')"
data-type='file'><p><?php p($l->t('Text file'));?></p></li> data-type='file' data-newname='<?php p($l->t('New text file.txt')) ?>'><p><?php p($l->t('Text file'));?></p></li>
<li style="background-image:url('<?php p(OCP\mimetype_icon('dir')) ?>')" <li style="background-image:url('<?php p(OCP\mimetype_icon('dir')) ?>')"
data-type='folder'><p><?php p($l->t('Folder'));?></p></li> data-type='folder' data-newname='<?php p($l->t('New folder')) ?>'><p><?php p($l->t('Folder'));?></p></li>
<li style="background-image:url('<?php p(OCP\image_path('core', 'places/link.svg')) ?>')" <li style="background-image:url('<?php p(OCP\image_path('core', 'places/link.svg')) ?>')"
data-type='web'><p><?php p($l->t('From link'));?></p></li> data-type='web'><p><?php p($l->t('From link'));?></p></li>
</ul> </ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment