[Bps-public-commit] rt-extension-formtools branch privileged-forms-listing created. 0.53-56-g2fa490e

BPS Git Server git at git.bestpractical.com
Mon Oct 16 20:20:52 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, privileged-forms-listing has been created
        at  2fa490ea3b9ac2430b02a4e39de95b33c761ec6d (commit)

- Log -----------------------------------------------------------------
commit 2fa490ea3b9ac2430b02a4e39de95b33c761ec6d
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Oct 16 15:54:53 2023 -0400

    Add a BeforeCreate callback

diff --git a/html/Forms/dhandler b/html/Forms/dhandler
index fbcfb22..9a73a1d 100644
--- a/html/Forms/dhandler
+++ b/html/Forms/dhandler
@@ -156,6 +156,9 @@ if ( $ARGS{Back} and $ARGS{Back} eq 'Back' ) {
 my ($ticket_obj, @results);
 if ( $create_ticket ) {
 
+    $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, results => \@results,
+                  FormName => $form_name, PageName => $page );
+
     # We override Abort elsewhere so we'll get $ticket_obj here even if
     # the current user has no rights to see the newly created ticket.
 

commit 85bebb05622ba7610de7ef580913588efe6bcd6d
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Oct 16 15:14:00 2023 -0400

    Add a Back button to form pages

diff --git a/html/Forms/dhandler b/html/Forms/dhandler
index c1c78c9..fbcfb22 100644
--- a/html/Forms/dhandler
+++ b/html/Forms/dhandler
@@ -32,7 +32,7 @@ foreach my $element ( @{$form_config->{'formtools-pages'}{$page}{'content'}} ) {
 </%perl>
 
 % if ( $form_config->{'formtools-pages'}{$page}{'next'} ) {
- <& /FormTools/Next, Label => $button_label &>
+ <& /FormTools/Next, Label => $button_label, Back => $show_back &>
 % }
 </&>
 <%init>
@@ -98,10 +98,6 @@ $m->notes( page_title => $form_config->{'formtools-pages'}{$page}{'name'} );
 my $base_path = '/Forms/';
 $base_path = '/SelfService' . $base_path if $SelfService;
 
-# Try to create a ticket if we're on the last page and
-# "create_ticket" is submitted as an arg from the second-to-last
-# page.
-
 my $validation = $form_config->{'formtools-pages'}{$page}{'validation'};
 
 if ( $validation and not $ARGS{'validation_ok'} ) {
@@ -109,6 +105,54 @@ if ( $validation and not $ARGS{'validation_ok'} ) {
     $create_ticket = 0;
 }
 
+my @form_pages
+    = sort { ( $form_config->{'formtools-pages'}{$a}{sort_order} || 0 ) <=> ( $form_config->{'formtools-pages'}{$b}{sort_order} || 0 ) }
+    keys %{ $form_config->{'formtools-pages'} };
+
+my $show_back = 0;
+my $index = 0;
+my $back_page;
+
+# When validation is enabled for this page, it submits to itself
+# first, so the back button only needs to go back 1. Otherwise,
+# current page was "next" on submit, so we need to go back 2.
+my $go_back_count = $validation ? 1 : 2;
+
+foreach my $page_index ( @form_pages ) {
+    if ( $page_index eq $page ) {
+        $back_page = $form_pages[$index - $go_back_count];
+        last;
+    }
+    $index++;
+}
+
+# Don't show the back button on the first page
+$show_back = 1 if $index > 0;
+
+# Did the user click Back?
+if ( $ARGS{Back} and $ARGS{Back} eq 'Back' ) {
+    # Avoid trying to go back again
+    delete $ARGS{Back};
+
+    # Don't create a ticket when going back
+    delete $ARGS{'create_ticket'} if $ARGS{'create_ticket'};
+    $create_ticket = 0;
+
+    $_form_tools_next = '';
+    delete $ARGS{'_form_tools_next'} if $ARGS{'_form_tools_next'};
+
+    # Redirect to the previous page
+    MaybeRedirectForResults(
+        Path      => $base_path . $form_name . '/' . $back_page,
+        Arguments => \%ARGS,
+        Force     => 1,
+    );
+}
+
+# Try to create a ticket if we're on the last page and
+# "create_ticket" is submitted as an arg from the second-to-last
+# page.
+
 my ($ticket_obj, @results);
 if ( $create_ticket ) {
 

commit f4f6ea00b5f6a972446f83fed6f64c8c37ff31f4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Oct 16 14:30:10 2023 -0400

    Show Next for button label until Submit page

diff --git a/html/Forms/dhandler b/html/Forms/dhandler
index 668ffa5..c1c78c9 100644
--- a/html/Forms/dhandler
+++ b/html/Forms/dhandler
@@ -9,6 +9,7 @@
 <%perl>
 # Build the current page here dyamically from config
 
+my $button_label = loc('Next');
 foreach my $element ( @{$form_config->{'formtools-pages'}{$page}{'content'}} ) {
     if ( $element->{type} eq 'raw_html' ) {
         $m->out( $element->{html} );
@@ -20,11 +21,18 @@ foreach my $element ( @{$form_config->{'formtools-pages'}{$page}{'content'}} ) {
     elsif ( $element->{type} eq 'component' ) {
         $m->comp('/FormTools/' . $element->{comp_name}, %{$element->{arguments}});
     }
+
+    if ( $element->{type} eq 'hidden'
+         and $element->{'input-name'} eq 'create_ticket' ) {
+
+        # This is the page that will submit, so change the button label
+        $button_label = loc('Submit');
+    }
 }
 </%perl>
 
 % if ( $form_config->{'formtools-pages'}{$page}{'next'} ) {
- <& /FormTools/Next &>
+ <& /FormTools/Next, Label => $button_label &>
 % }
 </&>
 <%init>

commit 7611d1c995ef3b0abc932a5d7ff22d82a9da1505
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Oct 16 13:53:24 2023 -0400

    Add a Forms Home page for privileged users
    
    Sending privileged users to /SelfService/Forms.html caused
    the SelfService menu to be displayed, which would be
    confusing for privileged users.

diff --git a/html/Callbacks/FormTools/Elements/Tabs/Privileged b/html/Callbacks/FormTools/Elements/Tabs/Privileged
index ab2b30c..7c48c7b 100644
--- a/html/Callbacks/FormTools/Elements/Tabs/Privileged
+++ b/html/Callbacks/FormTools/Elements/Tabs/Privileged
@@ -30,6 +30,12 @@ if ( $m->request_path =~ m{^/Admin/FormTools/} ) {
     }
 }
 
+# Forms home page for all privileged users
+my $formtools = Menu->child('home')->child(
+    formtools => title => loc('Forms'),
+    path      => '/Forms.html',
+);
+
 </%init>
 <%args>
 $Path
diff --git a/html/Forms.html b/html/Forms.html
new file mode 100644
index 0000000..dc6cd3c
--- /dev/null
+++ b/html/Forms.html
@@ -0,0 +1,4 @@
+<& /Elements/Header, Title => loc("Forms Home") &>
+<& /Elements/Tabs &>
+
+<& /Elements/Forms/ListForms &>

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


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


More information about the Bps-public-commit mailing list