The file input type cannot take an initial path for obvious security reasons. So when going back to the first page show the currently selected filename along with an option to unset it.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/Submit.pl | 75 ++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 22 deletions(-)
diff --git a/testbot/web/Submit.pl b/testbot/web/Submit.pl index 2cc9c8022..b9ead7451 100644 --- a/testbot/web/Submit.pl +++ b/testbot/web/Submit.pl @@ -58,7 +58,7 @@ sub _Upload($) { my ($self) = @_;
- my $Src = $self->CGI->upload("FileName"); + my $Src = $self->CGI->upload("Upload"); if (defined $Src) { my $OldUMask = umask(002); @@ -76,7 +76,7 @@ sub _Upload($) { umask($OldUMask); delete $self->{FileName}; - $self->{ErrField} = "FileName"; + $self->{ErrField} = "Upload"; $self->{ErrMessage} = "Unable to save the uploaded file"; return undef; } @@ -84,7 +84,7 @@ sub _Upload($) else { delete $self->{FileName}; - $self->{ErrField} = "FileName"; + $self->{ErrField} = "Upload"; $self->{ErrMessage} = "Unable to upload the file"; return undef; } @@ -476,7 +476,8 @@ sub GetHeaderText($) } elsif ($self->{Page} == 1) { - return "Specify the patch file that you want to upload and submit " . + return defined $self->{FileName} ? "" : + "Specify the patch file that you want to upload and submit " . "for testing.<br>\n" . "You can also specify a Windows .exe file, this would normally be " . "a Wine test executable that you cross-compiled." @@ -539,9 +540,18 @@ sub GenerateFields($) elsif ($self->{Page} == 1) { print "<div class='ItemProperty'><label>File</label>", - "<div class='ItemValue'>", - "<input type='file' name='FileName' size='64' maxlength='64' />", - " <span class='Required'>*</span></div></div>\n"; + "<div class='ItemValue'>"; + if (defined $self->{FileName}) + { + $self->_GenerateStateField("FileName"); + print "<input type='submit' name='Action' value='Unset'/> $self->{FileName}"; + } + else + { + print "<input type='file' name='Upload' size='64' maxlength='64'/>", + " <span class='Required'>*</span>"; + } + print "</div></div>\n";
my $Branches = CreateBranches(); if (!defined $self->{Branch}) @@ -727,12 +737,42 @@ sub _SetPage($$) delete $self->{PropertyDescriptors}; }
+sub OnUnset($) +{ + my ($self) = @_; + + if (!$self->_ValidateFileName()) + { + # Ignore the error. What counts is not using a suspicious FileName. + delete $self->{ErrField}; + delete $self->{ErrMessage}; + } + elsif (defined $self->{FileName}) + { + my $StagingFilePath = $self->_GetStagingFilePath(); + unlink($StagingFilePath) if ($StagingFilePath); + delete $self->{FileName}; + } + delete $self->{TestExecutable}; + delete $self->{CmdLineArg}; + + return 1; +} + sub OnPage1Next($) { my ($self) = @_;
- if (!$self->_ValidateFileName() or !$self->_Upload() or !$self->Validate() or - !$self->_ValidateVMSelection("deselect")) + if (defined $self->{FileName}) + { + return undef if (!$self->_ValidateFileName()); + } + else + { + $self->{FileName} = $self->GetParam("Upload"); + return undef if (!$self->_ValidateFileName() or !$self->_Upload()); + } + if (!$self->Validate() or !$self->_ValidateVMSelection("deselect")) { return undef; } @@ -779,19 +819,6 @@ sub OnPage2Prev($) { my ($self) = @_;
- if (!$self->_ValidateFileName()) - { - # Ignore the error. What counts is not using a suspicious FileName. - delete $self->{ErrField}; - delete $self->{ErrMessage}; - } - elsif (defined $self->{FileName}) - { - my $StagingFilePath = $self->_GetStagingFilePath(); - unlink($StagingFilePath) if ($StagingFilePath); - delete $self->{FileName}; - } - $self->_SetPage(1); return 1; } @@ -1076,6 +1103,10 @@ sub OnAction($$) { return $self->{Page} == 3 ? $self->OnPage3Prev() : $self->OnPage2Prev(); } + elsif ($Action eq "Unset") + { + return $self->OnUnset(); + } elsif ($Action eq "Submit") { return $self->OnSubmit();
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/Submit.pl | 65 +++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 27 deletions(-)
diff --git a/testbot/web/Submit.pl b/testbot/web/Submit.pl index b9ead7451..a51ace650 100644 --- a/testbot/web/Submit.pl +++ b/testbot/web/Submit.pl @@ -589,12 +589,10 @@ sub GenerateFields($) { $self->_GenerateStateField("ShowAll"); print "<div class='CollectionBlock'><table>\n"; - print "<thead><tr><th class='Record'></th>\n"; - print "<th class='Record'>VM Name</th>\n"; - print "<th class='Record'>Description</th>\n"; - print "</thead><tbody>\n"; + print "<thead><tr><th class='Record'>";
- my $Even = 1; + # Check which VMs are selected and set the master default + my $MasterChecked = " checked"; foreach my $VMRow (@{$self->{VMRows}}) { next if ($VMRow->{Incompatible}); @@ -602,15 +600,47 @@ sub GenerateFields($) next if ($VMRow->{Extra} and !$VMRow->{Checked} and !$self->{ShowAll});
# By default select the base VMs that are ready to run tasks - my $VM = $VMRow->{VM}; if (!$self->{UserVMSelection} and !$VMRow->{Extra} and - $VM->Status !~ /^(?:offline|maintenance)$/) + $VMRow->{VM}->Status !~ /^(?:offline|maintenance)$/) { $VMRow->{Checked} = 1; } + $MasterChecked = "" if (!$VMRow->{Checked}); + } + + # Add a "Toggle All" pseudo action + print <<EOF; +<script type='text/javascript'> +<!-- +function SetAllVMCBs(master) +{ + var vmcbs = document.getElementsByClassName("vmcb"); + for (var i = 0; i < vmcbs.length; i++) + { + vmcbs[i].checked = master.checked; + } +} + +// Only put the JavaScript checkbox if JavaScript is enabled +document.write("<input type='checkbox' onchange='SetAllVMCBs(this);'$MasterChecked/>"); +//--> +</script> +EOF + print "</th>\n"; + print "<th class='Record'>VM Name</th>\n"; + print "<th class='Record'>Description</th>\n"; + print "</thead><tbody>\n"; + + my $Even = 1; + foreach my $VMRow (@{$self->{VMRows}}) + { + next if ($VMRow->{Incompatible}); + # Extra VMs may be hidden + next if ($VMRow->{Extra} and !$VMRow->{Checked} and !$self->{ShowAll}); + my $VM = $VMRow->{VM};
print "<tr class='", ($Even ? "even" : "odd"), - "'><td><input name='$VMRow->{Field}' type='checkbox'"; + "'><td><input class='vmcb' name='$VMRow->{Field}' type='checkbox'"; $Even = !$Even; print " checked='checked'" if ($VMRow->{Checked}); print "/></td>\n"; @@ -631,25 +661,6 @@ sub GenerateFields($) $self->_GenerateStateField("UserVMSelection"); print "</div><!--CollectionBlock-->\n";
- # Add a "Toggle All" pseudo action - print <<EOF; -<script type='text/javascript'> -<!-- -function ToggleAll() -{ - for (var i = 0; i < document.forms[0].elements.length; i++) - { - if (document.forms[0].elements[i].type == 'checkbox') - document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked); - } -} - -// Only put javascript link in document if javascript is enabled -document.write("<div class='ItemActions'><a href='javascript:void(0)' onClick='ToggleAll();'>Toggle All<\\\/a><\\\/div>"); -//--> -</script> -EOF - # Add a Show base/all VMs button separate from the other actions print "<div class='ItemActions'>\n"; print "<input type='submit' name='Action' value='",