[tools] testbot/web: Use SimpleCollectionPage for the VMs page.

Francois Gouget fgouget at codeweavers.com
Mon Apr 4 11:15:13 CDT 2022


Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/web/admin/VMsList.pl | 49 ++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/testbot/web/admin/VMsList.pl b/testbot/web/admin/VMsList.pl
index 18952253f..d957b4472 100644
--- a/testbot/web/admin/VMsList.pl
+++ b/testbot/web/admin/VMsList.pl
@@ -2,6 +2,7 @@
 # VM list page
 #
 # Copyright 2009 Ge van Geldorp
+# 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
@@ -19,58 +20,62 @@
 
 use strict;
 
-package VMsListPage;
+package VMsBlock;
 
-use ObjectModel::CGI::CollectionPage;
-our @ISA = qw(ObjectModel::CGI::CollectionPage);
-
-use WineTestBot::VMs;
+use ObjectModel::CGI::CollectionBlock;
+our @ISA = qw(ObjectModel::CGI::CollectionBlock);
 
 
-sub _initialize($$$)
+sub Create($$)
 {
-  my ($self, $Request, $RequiredRole) = @_;
+  my ($Collection, $EnclosingPage) = @_;
 
-  $self->SUPER::_initialize($Request, $RequiredRole, CreateVMs());
+  return VMsBlock->new($Collection, $EnclosingPage);
 }
 
-sub DisplayProperty($$$)
+sub DisplayProperty($$)
 {
-  my ($self, $CollectionBlock, $PropertyDescriptor) = @_;
+  my ($self, $PropertyDescriptor) = @_;
 
   my $PropertyName = $PropertyDescriptor->GetName();
-
   return $PropertyName eq "Name" || $PropertyName eq "Type" ||
          $PropertyName eq "Role" || $PropertyName eq "Status" ||
          $PropertyName eq "Description";
 }
 
-sub SortKeys($$$)
+sub SortKeys($$)
 {
-  my ($self, $CollectionBlock, $Keys) = @_;
+  my ($self, $Keys) = @_;
 
   return $self->{Collection}->SortKeysBySortOrder($Keys);
 }
 
-sub OnItemAction($$$$)
+sub OnItemAction($$$)
 {
-  my ($self, $CollectionBlock, $VM, $Action) = @_;
+  my ($self, $VM, $Action) = @_;
 
   if ($Action eq "Delete")
   {
     $VM->Role("deleted");
-    # Setting $self->{ErrField} is only useful on form pages
-    (my $_ErrProperty, $self->{ErrMessage}) = $VM->Save();
-    return !defined $self->{ErrMessage};
+    my ($_ErrProperty, $ErrMessage) = $VM->Save();
+    if (defined $ErrMessage)
+    {
+      # Setting ErrField is only useful on form pages
+      $self->{EnclosingPage}->SetError(undef, $ErrMessage);
+      return 0;
+    }
+    return 1;
   }
 
-  return $self->SUPER::OnItemAction($CollectionBlock, $VM, $Action);
+  return $self->SUPER::OnItemAction($VM, $Action);
 }
 
 
 package main;
 
-my $Request = shift;
+use ObjectModel::CGI::SimpleCollectionPage;
+use WineTestBot::VMs;
 
-my $VMsListPage = VMsListPage->new($Request, "admin");
-$VMsListPage->GeneratePage();
+my $Request = shift;
+my $Page = ObjectModel::CGI::SimpleCollectionPage->new($Request, "admin", CreateVMs(), \&VMsBlock::Create);
+$Page->GeneratePage();
-- 
2.30.2




More information about the wine-devel mailing list