Skip to content

Commit b150659

Browse files
authored
Merge pull request #2339 from drgrice1/file-manager-new-file-delay-create
Delay file creation when a new file is created in the file manager.
2 parents 28d304c + 9e37b12 commit b150659

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

htdocs/js/FileManager/filemanager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
}
5555
});
5656

57-
// If on the confirmation page, then focus the "name" input.
58-
form.querySelector('input[name="name"]')?.focus();
57+
// If on the confirmation page (and not the edit page), then focus the "name" input.
58+
if (!form.getElementsByName('data')[0]) form.getElementsByName('name')[0]?.focus();
5959
}
6060

6161
// The bits for types from least to most significant digit are set in the directoryListing method of

lib/WeBWorK/ContentGenerator/Instructor/FileManager.pm

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -588,20 +588,11 @@ sub unpack_archive ($c, $archive) {
588588
return $num_extracted == @members;
589589
}
590590

591-
# Make a new file and edit it
591+
# Open the edit page with no contents. This does not actually create a file.
592+
# That is done when the user clicks save on the edit page.
592593
sub NewFile ($c) {
593-
if ($c->param('confirmed')) {
594-
my $name = $c->param('name');
595-
if (my $file = $c->verifyName($name, 'file')) {
596-
if (open(my $NEWFILE, '>:encoding(UTF-8)', $file)) {
597-
close $NEWFILE;
598-
return $c->RefreshEdit('', $name);
599-
} else {
600-
$c->addbadmessage($c->maketext(q{Can't create file: [_1]}, $!));
601-
}
602-
}
603-
}
604-
594+
return $c->RefreshEdit('', $c->param('name'))
595+
if $c->param('confirmed') && $c->verifyName($c->param('name'), 'file');
605596
return $c->Confirm($c->maketext('New file name:'), '', $c->maketext('New File'));
606597
}
607598

templates/ContentGenerator/Instructor/FileManager/refresh_edit.html.ep

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@
1212
</div>
1313
</div>
1414
<div class="row">
15-
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Cancel'), %button %></div>
16-
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Revert'), %button %></div>
17-
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Save'), %button %></div>
18-
<div class="col-md-6 col-12 my-2">
15+
% my $canRevert = -f "$c->{courseRoot}/$c->{pwd}/$file";
16+
<div class="col-md-2 <%= $canRevert ? 'col-4' : 'col-6' %> my-2">
17+
<%= submit_button maketext('Cancel'), %button %>
18+
</div>
19+
% if ($canRevert) {
20+
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Revert'), %button %></div>
21+
% }
22+
<div class="col-md-2 <%= $canRevert ? 'col-4' : 'col-6' %> my-2">
23+
<%= submit_button maketext('Save'), %button %>
24+
</div>
25+
<div class="<%= $canRevert ? 'col-md-6' : 'col-md-8' %> col-12 my-2">
1926
<div class="input-group">
2027
<%= submit_button maketext('Save As'), name => 'action', class => 'btn btn-sm btn-secondary' =%>
2128
<%= text_field name => '', size => 20, class => 'form-control form-control-sm' =%>

0 commit comments

Comments
 (0)