Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/ObjectModel/CGI/Table.pm | 84 ++++++++++++++++++++++++++++ testbot/web/Submit.pl | 26 ++------- testbot/web/js/table.js | 26 +++++++++ 3 files changed, 116 insertions(+), 20 deletions(-) create mode 100644 testbot/lib/ObjectModel/CGI/Table.pm create mode 100644 testbot/web/js/table.js
diff --git a/testbot/lib/ObjectModel/CGI/Table.pm b/testbot/lib/ObjectModel/CGI/Table.pm new file mode 100644 index 000000000..b55fa4157 --- /dev/null +++ b/testbot/lib/ObjectModel/CGI/Table.pm @@ -0,0 +1,84 @@ +# -*- Mode: Perl; perl-indent-level: 2; indent-tabs-mode: nil -*- +# Provides a wrapper for the table JavaScript code. +# +# Copyright 2022 Francois Gouget +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +use strict; + +package ObjectModel::CGI::Table; + +use Exporter 'import'; +our @EXPORT = qw(GetTableJSFile GenerateMasterCheckbox); + + +=pod +=over 12 + +=item C<GetTableJSFile()> + +Returns the path to the file containing the table JavaScript code. + +=back +=cut + +sub GetTableJSFile() +{ + return "/js/table.js"; +} + + +=pod +=over 12 + +=item C<GenerateMasterCheckbox()> + +Generates a master checkbox that changes all the checkboxes with the specified +'cbgroup' value. + +=over + +=item CbGroup +A string identifying this group of checkboxes. + +=item Checked +True if the initial state should be checked. + +=item Attrs +A string containing extra attributes to be inserted in this master checkbox +tag. It should not contain the type, checked and onchange attributes. + +=back +=back +=cut + +sub GenerateMasterCheckbox($;$$) +{ + my ($CbGroup, $Checked, $Attrs) = @_; + + $Attrs ||= ""; + $Checked = $Checked ? " checked" : ""; + print <<EOF; +<script type='text/javascript'> +<!-- +// Only add the master checkbox if JavaScript is enabled +document.write("<input$Attrs type='checkbox' onchange='SetCheckboxes(this, "$CbGroup");'$Checked>"); +//--> +</script> +EOF +} + +1; diff --git a/testbot/web/Submit.pl b/testbot/web/Submit.pl index 8a1cc3c1d..cf00ed53d 100644 --- a/testbot/web/Submit.pl +++ b/testbot/web/Submit.pl @@ -30,6 +30,8 @@ use POSIX qw(:fcntl_h); # For SEEK_XXX
use ObjectModel::BasicPropertyDescriptor; use ObjectModel::EnumPropertyDescriptor; +use ObjectModel::CGI::Table; + use WineTestBot::Branches; use WineTestBot::Config; use WineTestBot::Engine::Notify; @@ -773,11 +775,12 @@ sub GenerateFields($) if ($self->{Page} == 2 or $self->{Page} == 4) { $self->_GenerateStateField("ShowAll"); + $self->GenerateImportJS(GetTableJSFile()); print "<div class='CollectionBlock'><table>\n"; print "<thead><tr><th class='Record'>";
# Check which VMs are selected and set the master default - my $MasterChecked = " checked"; + my $MasterChecked = 1; foreach my $VMRow (@{$self->{VMRows}}) { next if ($VMRow->{Incompatible}); @@ -793,27 +796,10 @@ sub GenerateFields($) { $VMRow->{Checked} = 1; } - $MasterChecked = "" if (!$VMRow->{Checked}); + $MasterChecked = 0 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 + GenerateMasterCheckbox("vmcb", $MasterChecked); print "</th>\n"; print "<th class='Record'>VM Name</th>\n"; print "<th class='Record'>Options</th>\n"; diff --git a/testbot/web/js/table.js b/testbot/web/js/table.js new file mode 100644 index 000000000..350dd8453 --- /dev/null +++ b/testbot/web/js/table.js @@ -0,0 +1,26 @@ +/* Copyright 2022 Francois Gouget + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +"use strict"; + +function SetCheckboxes(master, group) +{ + var cbs = document.getElementsByClassName(group); + for (var i = 0; i < cbs.length; i++) + { + cbs[i].checked = master.checked; + } +}