[PATCH 2/2] testbot/Submit: Replace the "Toggle All" action with a more standard "master" checkbox.

Francois Gouget fgouget at codeweavers.com
Mon Sep 30 20:37:10 CDT 2019


Signed-off-by: Francois Gouget <fgouget at 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='",
-- 
2.20.1



More information about the wine-devel mailing list