Module: tools Branch: master Commit: 69fe9a569f7eb9c313e82bc61ce5370a8b4d85f3 URL: https://source.winehq.org/git/tools.git/?a=commit;h=69fe9a569f7eb9c313e82bc6...
Author: Francois Gouget fgouget@codeweavers.com Date: Tue Apr 5 14:20:41 2022 +0200
testbot/cgi: Let FormPage operate in read-only mode.
The FormPage is in read-write mode by default as this is the most common case, but calling SetReadWrite(0) puts it in read-only mode where it shows the field values but does not allow modifying them.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/lib/ObjectModel/CGI/FormPage.pm | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/testbot/lib/ObjectModel/CGI/FormPage.pm b/testbot/lib/ObjectModel/CGI/FormPage.pm index dfcd55e..c6a8c6b 100644 --- a/testbot/lib/ObjectModel/CGI/FormPage.pm +++ b/testbot/lib/ObjectModel/CGI/FormPage.pm @@ -70,6 +70,8 @@ properties that the form should show or allow editing, as specified by DisplayProperty(). It may be undefined if determining the property list is delegated to GetPropertyDescriptors().
+By default the form allows modifying the field values. + See also Page::new().
=back @@ -82,11 +84,30 @@ sub _initialize($$$$) $self->SUPER::_initialize($Request, $RequiredRole);
$self->{PropertyDescriptors} = $PropertyDescriptors; + $self->{RW} = 1; $self->{HasRequired} = !1; $self->{ActionPerformed} = !1; $self->{Method} = "post"; }
+=pod +=over 12 + +=item C<SetReadWrite()> + +If set to true, the form allows editing the fields. +Otherwise it only shows their values. + +=back +=cut + +sub SetReadWrite($$) +{ + my ($self, $RW) = @_; + + $self->{RW} = $RW; +} +
# # Property handling @@ -167,10 +188,12 @@ sub DisplayProperty($$) # type the appropriate key value would also be cumbersome so this is # currently not supported. But they can be displayed. $PropertyDescriptor->GetClass() eq "Itemref" ? "ro" : - # All other properties can be edited... + # All other properties can displayed, + !$self->{RW} ? "ro" : + # and even edited if in read-write mode... $PropertyDescriptor->GetClass() ne "Basic" ? "rw" : $PropertyDescriptor->GetType() ne "S" ? "rw" : - # ...except autoincrement ones (shown as <unset> if undefined) + # ...except autoincrement ones "ro"; }