[Bps-public-commit] rt-extension-formtools branch dynamic-forms-from-config updated. 0.53-50-g4c3f762

BPS Git Server git at git.bestpractical.com
Thu Oct 12 20:36:31 UTC 2023


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, dynamic-forms-from-config has been updated
       via  4c3f7620d79e7bb6183fb85e068c36802879eaf6 (commit)
       via  61d6f10fc456a778762a80c430a0b38588ebd5ba (commit)
      from  c5dbf54e18b8e5c8dd845d5252018091ab0e34cb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4c3f7620d79e7bb6183fb85e068c36802879eaf6
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 12 16:17:56 2023 -0400

    Support to enable/disable forms

diff --git a/html/Admin/FormTools/index.html b/html/Admin/FormTools/index.html
index 68f0913..3c00092 100644
--- a/html/Admin/FormTools/index.html
+++ b/html/Admin/FormTools/index.html
@@ -2,11 +2,24 @@
 <& /Elements/Tabs &>
 <& /Elements/ListActions, actions => \@results &>
 
+<form method="post" action="<% RT->Config->Get('WebPath') %>/Admin/FormTools/index.html">
+  <div class="form-row">
+    <div class="col-auto">
+      <div class="custom-control custom-checkbox">
+        <input type="checkbox" class="custom-control-input checkbox" id="FindDisabledForms" name="FindDisabledForms" value="1" <% $FindDisabledForms ? 'checked="checked"': '' |n%> />
+        <label class="custom-control-label" for="FindDisabledForms"><&|/l&>Include disabled forms in listing.</&></label>
+      </div>
+    </div>
+    <div class="col-auto">
+      <input type="submit" name="Go" class="form-control btn btn-primary" value="<&|/l&>Go!</&>" />
+    </div>
+  </div>
   <table class="table collection collection-as-table" cellspacing="0">
     <tbody>
       <tr class="collection-as-table">
         <th class="collection-as-table"><&|/l&>Name</&></th>
         <th class="collection-as-table"><&|/l&>Creates Tickets in Queue</&></th>
+        <th class="collection-as-table"><&|/l&>Enabled</&></th>
       </tr>
 % my $i = 0;
 % for my $form_ref ( @forms ) {
@@ -14,11 +27,25 @@
       <tr class="<% $i % 2 ? 'oddline' : 'evenline' %>">
         <td class="collection-as-table"><a href="<% RT->Config->Get('WebURL') %>Admin/FormTools/Modify.html?id=<% $form_ref->{'id'} %>"><% $form_ref->{'name'} %></a></td>
         <td class="collection-as-table"><% $form_ref->{'queue_name'} %></td>
+        <td class="collection-as-table">
+          <div class="custom-control custom-checkbox">
+            <input type="checkbox" class="custom-control-input checkbox" id="enable-form-<% $form_ref->{'id'} %>" name="enable-form-<% $form_ref->{'id'} %>" value="1" <% $form_ref->{disabled} ? '' : 'checked="checked"' %> />
+            <label class="custom-control-label" for="enable-form-<% $form_ref->{'id'} %>"></label>
+          </div>
+        </td>
       </tr>
 %    ++$i;
 % }
     </tbody>
   </table>
+  <div class="form-row">
+    <div class="col-12">
+      <div align="right">
+        <input type="submit" name="Submit" class="form-control btn btn-primary" value="<&|/l&>Update</&>" />
+      </div>
+    </div>
+  </div>
+</form>
 
 <%init>
 my @results;
@@ -27,8 +54,62 @@ my $forms = RT::Attributes->new( $session{'CurrentUser'} );
 $forms->Limit( FIELD => 'Name', VALUE => 'FormTools Form' );
 
 my @unsorted_forms;
+
+if ( $Submit ) {
+    while ( my $form = $forms->Next ) {
+        my $id = $form->Id;
+        my $content = $form->Content;
+        my $name = $form->Description;
+
+        my $changed;
+        if ( $ARGS{"enable-form-$id"} ) {
+            if ( $content->{disabled} ) {
+                $content->{disabled} = 0;
+                $changed = 1;
+            }
+        }
+        else {
+            if ( !$content->{disabled} ) {
+                $content->{disabled} = 1;
+                $changed = 1;
+            }
+        }
+
+        if ( $changed ) {
+            my ( $ret, $msg ) = $form->SetContent($content);
+            if ($ret) {
+                if ( $content->{disabled} ) {
+                    push @results, loc('Disabled [_1]', $name);
+                }
+                else {
+                    push @results, loc('Enabled [_1]', $name);
+                }
+            }
+            else {
+                if ( $content->{disabled} ) {
+                    push @results, loc( "Couldn't disable [_1]: [_2]", $name, $msg );
+                }
+                else {
+                    push @results, loc( "Couldn't enable [_1]: [_2]", $name, $msg );
+                }
+            }
+        }
+    }
+}
+
+
+if ( @results ) {
+    MaybeRedirectForResults(
+        Actions   => \@results,
+        Path      => '/Admin/FormTools/index.html',
+        Arguments => { FindDisabledForms => $FindDisabledForms },
+    );
+}
+
 while ( my $form = $forms->Next ) {
     my $form_ref = $form->Content;
+    next if !$FindDisabledForms && $form_ref->{disabled};
+
     $form_ref->{'name'} = $form->Description;
     $form_ref->{'id'} = $form->Id;
 
@@ -54,4 +135,6 @@ $m->callback(
 
 </%init>
 <%args>
+$Submit            => undef
+$FindDisabledForms => undef
 </%args>

commit 61d6f10fc456a778762a80c430a0b38588ebd5ba
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 12 12:42:03 2023 -0400

    Use current user to create forms so we know the actor

diff --git a/html/Admin/FormTools/Create.html b/html/Admin/FormTools/Create.html
index 062b839..58f2ed1 100644
--- a/html/Admin/FormTools/Create.html
+++ b/html/Admin/FormTools/Create.html
@@ -29,7 +29,7 @@ if ( $Create ) {
     push @results, loc('Missing Queue') unless $Queue;
 
     if ( $Description && $Queue ) {
-        my $form = RT::Attribute->new( RT->SystemUser );
+        my $form = RT::Attribute->new( $session{CurrentUser} );
         my ($ret) = $form->LoadByCols( Name => 'FormTools Form', Description => $Description );
         if ($ret) {
             push @results, loc( 'Name [_1] already exists', $Description );

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

Summary of changes:
 html/Admin/FormTools/Create.html |  2 +-
 html/Admin/FormTools/index.html  | 83 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)


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


More information about the Bps-public-commit mailing list