[Bps-public-commit] rt-extension-formtools branch drop-customized-radio-checkbox-date-inputs created. 0.50-17-gef147e1

BPS Git Server git at git.bestpractical.com
Tue Apr 19 21:08:52 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-formtools".

The branch, drop-customized-radio-checkbox-date-inputs has been created
        at  ef147e10b0c2a9c070059acc8db624abda51e192 (commit)

- Log -----------------------------------------------------------------
commit ef147e10b0c2a9c070059acc8db624abda51e192
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 20 04:07:16 2022 +0800

    Update example to render radio using RT core feature
    
    Note that we need to set default value, to hide the "(no value)" option.

diff --git a/ex/RT-Example-FormTools/etc/initialdata b/ex/RT-Example-FormTools/etc/initialdata
index 466be4d..a657492 100644
--- a/ex/RT-Example-FormTools/etc/initialdata
+++ b/ex/RT-Example-FormTools/etc/initialdata
@@ -5,6 +5,7 @@ push @CustomFields, (
         Queue       => 0,
         Disabled    => 0,
         Pattern     => q'(?#Mandatory).',
+        RenderType  => 'List',
         Values      => [
             { Name      => "web", SortOrder => 1 },
             { Name      => "mail",  SortOrder => 2 },
@@ -17,3 +18,15 @@ push @CustomFields, (
         Disabled    => 0,
     },
 );
+
+our @Final = (
+    sub {
+        my $cf = RT::CustomField->new( RT->SystemUser );
+        $cf->Load('Systems');
+        my ( $ret, $msg ) = $cf->SetDefaultValues(
+            Object => RT->System,
+            Values => 'web',
+        );
+        warn "Could not set default value for Systems: $msg" unless $ret;
+    },
+);
diff --git a/ex/RT-Example-FormTools/html/Example/user_info b/ex/RT-Example-FormTools/html/Example/user_info
index 2fde65f..b73d12f 100644
--- a/ex/RT-Example-FormTools/html/Example/user_info
+++ b/ex/RT-Example-FormTools/html/Example/user_info
@@ -4,7 +4,7 @@
 
 <& /FormTools/Field, name => 'Requestors', label => 'Requested By', default => $session{'CurrentUser'}->EmailAddress  &> 
 
-<& /FormTools/Field, name => 'Systems', render_as => 'radio', default => 'web' &>
+<& /FormTools/Field, name => 'Systems' &>
 
 <& /FormTools/Next &>
 </&>

commit 38e5882c4d950e6083ae0464f264da77c935842b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 20 05:07:23 2022 +0800

    Bump minimal RT version for example too

diff --git a/ex/RT-Example-FormTools/Makefile.PL b/ex/RT-Example-FormTools/Makefile.PL
index 94950fd..fb60e1d 100644
--- a/ex/RT-Example-FormTools/Makefile.PL
+++ b/ex/RT-Example-FormTools/Makefile.PL
@@ -1,6 +1,7 @@
 use inc::Module::Install;
 
 RTx 'RT-Example-FormTools';
+requires_rt('4.2.3');
 
 sign;
 WriteAll;
diff --git a/ex/RT-Example-FormTools/lib/RT/Example/FormTools.pm b/ex/RT-Example-FormTools/lib/RT/Example/FormTools.pm
index 24f817f..6261f01 100644
--- a/ex/RT-Example-FormTools/lib/RT/Example/FormTools.pm
+++ b/ex/RT-Example-FormTools/lib/RT/Example/FormTools.pm
@@ -34,16 +34,10 @@ in case changes need to be made to your database.
 
 =item Edit your F</opt/rt4/etc/RT_SiteConfig.pm>
 
-If you are using RT 4.2 or greater, add this line:
+Add this line:
 
     Plugin('RT::Example::FormTools');
 
-For RT 4.0, add this line:
-
-    Set(@Plugins, qw(RT::Example::FormTools));
-
-or add C<RT::Example::FormTools> to your existing C<@Plugins> line.
-
 =item Clear your mason cache
 
     rm -rf /opt/rt4/var/mason_data/obj

commit 4e018fe104947e331987f70743b9803bda034772
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 20 03:43:38 2022 +0800

    Use RT core feature to render radio/checkbox/date
    
    No need to customize them for RT 4.2.3+

diff --git a/html/FormTools/Field b/html/FormTools/Field
index ccea114..f9ed1f7 100644
--- a/html/FormTools/Field
+++ b/html/FormTools/Field
@@ -170,14 +170,17 @@ $default = '' unless defined $default;
 
 % } else { # CF
 
-% unless ($render_as eq 'normal') {
+% unless ($render_as =~ /^(?:normal|radio|checkbox|date)/i) {
 <input type="hidden" class="hidden" name="<% $input_name %>-Magic" value="1" />
 % }
 
 
 % if ($render_as eq 'hidden') {
     <input type="hidden" class="hidden" name=<% $input_name %> value="<% $default %>">
-% } elsif ($render_as eq 'normal') {
+% } elsif ($render_as =~ /^(?:normal|radio|checkbox|date)/i) {
+%   if ($render_as !~ /^(?:normal)/i) {
+%       RT->Deprecated( Message => "render_as '$render_as' is ignored: RT already supports it in core" );
+%   }
     <& /Elements/EditCustomField, CustomField => $cf,
             ($cf->Type =~ /text/i) ? (Cols => $cols ||60) : (),
             ($cf->Type =~ /freeform/i) ? (Cols => $cols ||30) : (),
@@ -188,88 +191,6 @@ $default = '' unless defined $default;
 % if ($show_validation && $cf->FriendlyPattern) {
     <% loc("Input must match [_1]", $cf->FriendlyPattern) %>
 %}
-
-% } elsif ($render_as =~ /^radio/)  {
-%       my $selected = 0;
-% if ($empty_allowed) {
-        <input
-            type="radio"
-            id="<% $input_name %>"
-            name="<% $input_name %>"
-            value=""
-            <% !$default ? 'CHECKED' : '' %>
-        >
-        <label
-            for="<% $input_name %>"
-            class="radio-label"
-        >
-            <&|/l&>(no value)</&>
-        </label>
-%        if ($render_as =~ /vertical/) {
-            <br/>
-%        }
-
-% }
-% my $CFVs = $cf->Values;
-% while ($CFVs and my $value = $CFVs->Next ) {
-%       my $labelid = "$input_name-". $value->id;
-        <input
-            type="radio"
-            id="<% $labelid %>"
-            name="<% $input_name %>"
-            value="<%$value->Name%>"
-%  if ($default) {
-%       if (ref $default) {
-            <% (grep { $_ eq $value->Name} @$default) ? 'CHECKED' : '' %>
-%       } else {
-            <% ($default eq $value->Name) ? 'CHECKED' : '' %>
-%       }
-% }
-        >
-        <label
-            for="<% $labelid %>"
-            class="radio-label"
-        >
-            <% $value->Name %>
-        </label>
-
-%        if ($render_as =~ /vertical/) {
-            <br/>
-%        }
-
-% }
-% } elsif ($render_as =~  /^check/i)  {
-% my $CFVs = $cf->Values;
-% while ($CFVs and my $value = $CFVs->Next ) {
-%       my $labelid = "$input_name-". $value->id;
-        <input
-            type="checkbox"
-            id="<% $labelid %>"
-            name="<% $input_name %>"
-            value="<%$value->Name%>"
-%  if ($default) {
-%       if (ref $default) {
-            <% (grep { $_ eq $value->Name} @$default) ? 'CHECKED' : '' %>
-%       } else {
-            <% ($default eq $value->Name) ? 'CHECKED' : '' %>
-%       }
-% }
-        >
-        <label
-            for="<% $labelid %>"
-        >
-            <% $value->Name %>
-        </label>
-
-% if (defined $item_labels->{$value->Name}) {
-    <% $item_labels->{$value->Name} %>
-% }
-
-%        if ($render_as =~ /vertical/) {
-            <br/>
-%        }
-
-% }
 % } elsif ($render_as =~  /^boolean/i)  {
 %       my $value = 'Yes';
         <input type="checkbox" name="<% $input_name %>"  value="<% $value %>"
@@ -288,11 +209,6 @@ $default = '' unless defined $default;
         jQuery(function() { disable_form_field(true, '<% $disable %>') } );
     </script>
 % }
-
-% } elsif ($render_as =~  /^date/i)  {
-<& /Elements/SelectDate, Name => $input_name .'s', current => 0, 
-                         ($default ? (Default => $default) : ()) &>
-
 % } elsif ($render_as eq 'readonly' or $render_as eq 'readonly_plus_values') {
 
 % if (@values > 1) {

commit f0b84d1bd2e69f112ee1f41c7d9888c539299fbe
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 20 03:41:52 2022 +0800

    Clean up code: GetCustomFieldInputName is available since RT 4.2.3

diff --git a/html/FormTools/Field b/html/FormTools/Field
index 3f753c9..ccea114 100644
--- a/html/FormTools/Field
+++ b/html/FormTools/Field
@@ -64,17 +64,10 @@ if ( RT::Extension::FormTools::is_core_field($name) ) {
         $default ||= $values[0];
     }
 
-    if (RT::Interface::Web->can("GetCustomFieldInputName")) {
-        $input_name = GetCustomFieldInputName(
-            Object      => $ticket,
-            CustomField => $cf,
-        );
-    } else {
-        $input_name = "Object-RT::Ticket-"
-                       . ($ticket ? $ticket->id : '')
-                       . "-CustomField-" . $cf->id .'-Value';
-        $input_name .= "s" if $render_as =~ /^(radio|check|boolean)/
-    }
+    $input_name = GetCustomFieldInputName(
+        Object      => $ticket,
+        CustomField => $cf,
+    );
 }
 
 my $request_args = $m->request_args();

commit 187c3e5eafa75d36d8f09072dbded4a153f04a54
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 20 03:34:34 2022 +0800

    Bump minimal RT version to 4.2.3
    
    RT 4.0 has been EOL for years, and we will need 4.2.3+ to render
    radio/checkbox/date using RT core feature. (Need 596282b89 to get input
    names correctly)

diff --git a/META.yml b/META.yml
index 4faa106..3230215 100644
--- a/META.yml
+++ b/META.yml
@@ -19,10 +19,10 @@ no_index:
     - html
     - inc
 requires:
-  perl: 5.8.3
+  perl: 5.10.1
 resources:
   license: http://opensource.org/licenses/gpl-license.php
   repository: https://github.com/bestpractical/rt-extension-formtools
 version: '0.52'
 x_module_install_rtx_version: '0.43'
-x_requires_rt: 4.0.0
+x_requires_rt: 4.2.3
diff --git a/Makefile.PL b/Makefile.PL
index e81de23..fea329c 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,5 +1,6 @@
 use inc::Module::Install;
 RTx('RT-Extension-FormTools');
+requires_rt('4.2.3');
 
 repository('https://github.com/bestpractical/rt-extension-formtools');
 
diff --git a/README b/README
index 6e96cf5..53a4006 100644
--- a/README
+++ b/README
@@ -9,7 +9,7 @@ DESCRIPTION
     their own forms in Mason.
 
 RT VERSION
-    Works with RT 4.0 and 4.2
+    Works with RT 4.2.3+
 
 INSTALLATION
     perl Makefile.PL
@@ -18,16 +18,10 @@ INSTALLATION
         May need root permissions
 
     Edit your /opt/rt4/etc/RT_SiteConfig.pm
-        If you are using RT 4.2 or greater, add this line:
+        Add this line:
 
             Plugin('RT::Extension::FormTools');
 
-        For RT 4.0, add this line:
-
-            Set(@Plugins, qw(RT::Extension::FormTools));
-
-        or add RT::Extension::FormTools to your existing @Plugins line.
-
     Clear your mason cache
             rm -rf /opt/rt4/var/mason_data/obj
 
diff --git a/lib/RT/Extension/FormTools.pm b/lib/RT/Extension/FormTools.pm
index 4e5ba60..8cc5124 100644
--- a/lib/RT/Extension/FormTools.pm
+++ b/lib/RT/Extension/FormTools.pm
@@ -19,7 +19,7 @@ their own forms in Mason.
 
 =head1 RT VERSION
 
-Works with RT 4.0 and 4.2
+Works with RT 4.2.3+
 
 =head1 INSTALLATION
 
@@ -35,16 +35,10 @@ May need root permissions
 
 =item Edit your F</opt/rt4/etc/RT_SiteConfig.pm>
 
-If you are using RT 4.2 or greater, add this line:
+Add this line:
 
     Plugin('RT::Extension::FormTools');
 
-For RT 4.0, add this line:
-
-    Set(@Plugins, qw(RT::Extension::FormTools));
-
-or add C<RT::Extension::FormTools> to your existing C<@Plugins> line.
-
 =item Clear your mason cache
 
     rm -rf /opt/rt4/var/mason_data/obj

commit dc5b6a627c3950f5ddf0461d135169586cd3737b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Apr 20 03:33:42 2022 +0800

    Update M:I:RTx to 0.43

diff --git a/META.yml b/META.yml
index a127edc..4faa106 100644
--- a/META.yml
+++ b/META.yml
@@ -24,5 +24,5 @@ resources:
   license: http://opensource.org/licenses/gpl-license.php
   repository: https://github.com/bestpractical/rt-extension-formtools
 version: '0.52'
-x_module_install_rtx_version: '0.40'
+x_module_install_rtx_version: '0.43'
 x_requires_rt: 4.0.0
diff --git a/inc/Module/Install/RTx.pm b/inc/Module/Install/RTx.pm
index 7cad529..2889ece 100644
--- a/inc/Module/Install/RTx.pm
+++ b/inc/Module/Install/RTx.pm
@@ -6,9 +6,10 @@ use strict;
 use warnings;
 no warnings 'once';
 
+use Term::ANSIColor qw(:constants);
 use Module::Install::Base;
 use base 'Module::Install::Base';
-our $VERSION = '0.40';
+our $VERSION = '0.43';
 
 use FindBin;
 use File::Glob     ();
@@ -53,7 +54,7 @@ sub RTx {
         my @look = @INC;
         unshift @look, grep {defined and -d $_} @try;
         push @look, grep {defined and -d $_}
-            map { ( "$_/rt4/lib", "$_/lib/rt4", "$_/lib" ) } @prefixes;
+            map { ( "$_/rt5/lib", "$_/lib/rt5", "$_/rt4/lib", "$_/lib/rt4", "$_/lib" ) } @prefixes;
         last if eval {local @INC = @look; require RT; $RT::LocalLibPath};
 
         warn
@@ -76,6 +77,22 @@ sub RTx {
         $self->requires_rt('4.0.0');
     }
 
+    my $package = $name;
+    $package =~ s/-/::/g;
+    if ( $RT::CORED_PLUGINS{$package} ) {
+        my ($base_version) = $RT::VERSION =~ /(\d+\.\d+\.\d+)/;
+        die RED, <<"EOT";
+
+**** Error: Your installed version of RT ($RT::VERSION) already
+            contains this extension in core, so you don't need to
+            install it.
+
+            Check https://docs.bestpractical.com/rt/$base_version/RT_Config.html
+            to configure it.
+
+EOT
+    }
+
     # Installation locations
     my %path;
     my $plugin_path;
@@ -117,7 +134,7 @@ lexicons ::
     if( $extra_args->{'remove_files'} ){
         $self->include('Module::Install::RTx::Remove');
         our @remove_files;
-        eval { require "etc/upgrade/remove_files" }
+        eval { require "./etc/upgrade/remove_files" }
           or print "No remove file located, no files to remove\n";
         $remove_files = join ",", map {"q(\$(DESTDIR)$plugin_path/$name/$_)"} @remove_files;
     }
@@ -223,7 +240,7 @@ sub requires_rt {
     my @sorted = sort RT::Handle::cmp_version $version,$RT::VERSION;
 
     if ($sorted[-1] eq $version) {
-        die <<"EOT";
+        die RED, <<"EOT";
 
 **** Error: This extension requires RT $version. Your installed version
             of RT ($RT::VERSION) is too old.
@@ -249,12 +266,12 @@ sub requires_rt_plugin {
         unshift @INC, $path;
     } else {
         my $name = $self->name;
-        warn <<"EOT";
+        my $msg = <<"EOT";
 
 **** Warning: $name requires that the $plugin plugin be installed and
               enabled; it does not appear to be installed.
-
 EOT
+        warn RED, $msg, RESET, "\n";
     }
     $self->requires(@_);
 }
@@ -264,9 +281,8 @@ sub rt_too_new {
     my $name = $self->name;
     $msg ||= <<EOT;
 
-**** Error: Your installed version of RT (%s) is too new; this extension
-            only works with versions older than %s.
-
+**** Warning: Your installed version of RT (%s) is too new; this extension
+              has not been tested on your version of RT and may not work as expected.
 EOT
     $self->add_metadata("x_rt_too_new", $version) if $self->is_admin;
 
@@ -274,7 +290,7 @@ EOT
     my @sorted = sort RT::Handle::cmp_version $version,$RT::VERSION;
 
     if ($sorted[0] eq $version) {
-        die sprintf($msg,$RT::VERSION,$version);
+        warn RED, sprintf($msg,$RT::VERSION), RESET, "\n";
     }
 }
 
@@ -297,4 +313,4 @@ sub _load_rt_handle {
 
 __END__
 
-#line 468
+#line 484

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt-extension-formtools


More information about the Bps-public-commit mailing list