Skip to content

Commit

Permalink
Merge pull request #2339 from drgrice1/file-manager-new-file-delay-cr…
Browse files Browse the repository at this point in the history
…eate

Delay file creation when a new file is created in the file manager.
  • Loading branch information
Alex-Jordan authored Feb 29, 2024
2 parents 28d304c + 9e37b12 commit b150659
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions htdocs/js/FileManager/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
}
});

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

// The bits for types from least to most significant digit are set in the directoryListing method of
Expand Down
17 changes: 4 additions & 13 deletions lib/WeBWorK/ContentGenerator/Instructor/FileManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -588,20 +588,11 @@ sub unpack_archive ($c, $archive) {
return $num_extracted == @members;
}

# Make a new file and edit it
# Open the edit page with no contents. This does not actually create a file.
# That is done when the user clicks save on the edit page.
sub NewFile ($c) {
if ($c->param('confirmed')) {
my $name = $c->param('name');
if (my $file = $c->verifyName($name, 'file')) {
if (open(my $NEWFILE, '>:encoding(UTF-8)', $file)) {
close $NEWFILE;
return $c->RefreshEdit('', $name);
} else {
$c->addbadmessage($c->maketext(q{Can't create file: [_1]}, $!));
}
}
}

return $c->RefreshEdit('', $c->param('name'))
if $c->param('confirmed') && $c->verifyName($c->param('name'), 'file');
return $c->Confirm($c->maketext('New file name:'), '', $c->maketext('New File'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
</div>
</div>
<div class="row">
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Cancel'), %button %></div>
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Revert'), %button %></div>
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Save'), %button %></div>
<div class="col-md-6 col-12 my-2">
% my $canRevert = -f "$c->{courseRoot}/$c->{pwd}/$file";
<div class="col-md-2 <%= $canRevert ? 'col-4' : 'col-6' %> my-2">
<%= submit_button maketext('Cancel'), %button %>
</div>
% if ($canRevert) {
<div class="col-md-2 col-4 my-2"><%= submit_button maketext('Revert'), %button %></div>
% }
<div class="col-md-2 <%= $canRevert ? 'col-4' : 'col-6' %> my-2">
<%= submit_button maketext('Save'), %button %>
</div>
<div class="<%= $canRevert ? 'col-md-6' : 'col-md-8' %> col-12 my-2">
<div class="input-group">
<%= submit_button maketext('Save As'), name => 'action', class => 'btn btn-sm btn-secondary' =%>
<%= text_field name => '', size => 20, class => 'form-control form-control-sm' =%>
Expand Down

0 comments on commit b150659

Please sign in to comment.