Skip to content

Commit

Permalink
Delay file creation when a new file is created in the file manager.
Browse files Browse the repository at this point in the history
Instead of creating the file when the new file confirmation page is
submitted, create the file when "Save" (or "Save As") is clicked from
the edit page that opens next.

This was requested in issue #2326.

Also, don't focus the `name` input on the edit page.  That is a bit
annoying.  Only focus that input on the confirmation page.  That is the
only page that has a `data` input.
  • Loading branch information
drgrice1 committed Feb 26, 2024
1 parent 65a1b74 commit dd8f462
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 dd8f462

Please sign in to comment.