[Bps-public-commit] rt-extension-formtools branch dynamic-forms-from-config updated. 0.53-18-g8f29bec
BPS Git Server
git at git.bestpractical.com
Fri Sep 22 21:29:51 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 8f29becf851b0008f2f5c098468f461b24dd8389 (commit)
via 733ff241165aa8945bac56918ec04ad7276d651e (commit)
from 99584f1d93e40808302e43fc70590ea0805d07a1 (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 8f29becf851b0008f2f5c098468f461b24dd8389
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Sep 22 17:29:14 2023 -0400
Support to edit form name/content via web UI
diff --git a/html/Admin/FormTools/Advanced.html b/html/Admin/FormTools/Advanced.html
new file mode 100644
index 0000000..739c7a2
--- /dev/null
+++ b/html/Admin/FormTools/Advanced.html
@@ -0,0 +1,101 @@
+<& /Admin/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions, actions => \@results &>
+
+<form action="<%RT->Config->Get('WebPath')%>/Admin/FormTools/Advanced.html" name="ModifyFormToolsAdvanced" method="post" enctype="multipart/form-data" class="mx-auto max-width-md">
+ <input type="hidden" class="hidden" name="id" value="<% $id %>" />
+ <div class="form-row">
+ <div class="col-3 label">
+ <&|/l&>Name</&>:
+ </div>
+ <div class="col-9 value">
+ <input name="Description" class="form-control" value="<% $ARGS{Description} // $form_attribute->Description %>"/>
+ </div>
+ </div>
+ <div class="form-row">
+ <div class="col-3 label">
+ <&|/l&>Content</&>:
+ </div>
+ <div class="col-9 value">
+ <textarea class="form-control" rows="30" name="Content"><% $ARGS{Content} || $encoded_content %></textarea>
+ </div>
+ </div>
+
+ <div class="form-row">
+ <div class="col-12">
+ <& /Elements/Submit, Label => loc('Save Changes'), Name => 'Update' &>
+ </div>
+ </div>
+
+</form>
+
+<%INIT>
+Abort("No form id found") unless $id;
+
+my $form_attribute = RT::Attribute->new($session{'CurrentUser'});
+my ($ok, $msg) = $form_attribute->Load($id);
+
+unless ( $ok ) {
+ Abort("Unable to load form with id $id");
+}
+
+my $content = $form_attribute->Content;
+my $encoded_content = JSON::to_json($content, { canonical => 1, pretty => 1 } );
+
+my ($title, @results);
+$title = loc("Modify form [_1]", $form_attribute->Description);
+
+if ( $Update ) {
+ Abort( loc('Permission Denied') )
+ unless $session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'SuperUser' );
+
+ if ( $ARGS{Description} ) {
+
+ if ( $ARGS{Description} ne $form_attribute->Description ) {
+ my $attr = RT::Attribute->new( RT->SystemUser );
+ my ($ret) = $attr->LoadByCols( Name => 'FormTools Form', Description => $ARGS{Description} );
+ if ($ret) {
+ push @results, loc( 'Name [_1] already exists', $ARGS{Description} );
+ }
+ else {
+ my ( $ret, $msg ) = $form_attribute->SetDescription( $ARGS{Description} );
+ if ($ret) {
+ push @results, loc('Updated name');
+ }
+ else {
+ push @results, loc( "Couldn't update name: [_1]", $msg );
+ }
+ }
+ }
+ }
+ else {
+ push @results, loc('Missing Name');
+ }
+
+ my $new_content = eval { JSON::from_json( $ARGS{Content} ) };
+ if ( $@ ) {
+ push @results, loc( "Couldn't decode JSON" );
+ }
+ # because of different line endings, $encoded_content and submitted
+ # $ARGS{Content} could differ even user doesn't change any thing.
+ elsif ( $form_attribute->_SerializeContent($new_content) ne $form_attribute->_SerializeContent($content) ) {
+ my ( $ret, $msg ) = $form_attribute->SetContent($new_content);
+ if ($ret) {
+ push @results, loc('Updated content');
+ }
+ else {
+ push @results, loc( "Couldn't update content: [_1]", $msg );
+ }
+ }
+
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Path => '/Admin/FormTools/Advanced.html',
+ Arguments => { id => $id, Content => $ARGS{Content} },
+ );
+}
+</%INIT>
+<%ARGS>
+$id => undef
+$Update => undef
+</%ARGS>
diff --git a/html/Callbacks/FormTools/Elements/Tabs/Privileged b/html/Callbacks/FormTools/Elements/Tabs/Privileged
index 24ad687..ab2b30c 100644
--- a/html/Callbacks/FormTools/Elements/Tabs/Privileged
+++ b/html/Callbacks/FormTools/Elements/Tabs/Privileged
@@ -26,6 +26,7 @@ if ( $m->request_path =~ m{^/Admin/FormTools/} ) {
$page->child( modify => title => loc('Modify'), path => "/Admin/FormTools/Modify.html?id=" . $id );
$page->child( description => title => loc('Description'), path => "/Admin/FormTools/Describe.html?id=" . $id );
+ $page->child( advanced => title => loc('Advanced'), path => "/Admin/FormTools/Advanced.html?id=" . $id );
}
}
commit 733ff241165aa8945bac56918ec04ad7276d651e
Author: sunnavy <sunnavy at bestpractical.com>
Date: Fri Sep 22 17:01:55 2023 -0400
Support to create forms via web UI
diff --git a/html/Admin/FormTools/Create.html b/html/Admin/FormTools/Create.html
new file mode 100644
index 0000000..cbe5b7a
--- /dev/null
+++ b/html/Admin/FormTools/Create.html
@@ -0,0 +1,81 @@
+<& /Admin/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions, actions => \@results &>
+
+<form action="<%RT->Config->Get('WebPath')%>/Admin/FormTools/Create.html" name="CreateFormTools" method="post" enctype="multipart/form-data" class="mx-auto max-width-sm">
+ <div class="form-row">
+ <div class="col-3 label">
+ <&|/l&>Name</&>:
+ </div>
+ <div class="col-9 value">
+ <input name="Description" class="form-control" value="<% $ARGS{Description} // '' %>"/>
+ </div>
+ </div>
+ <div class="form-row">
+ <div class="col-3 label">
+ <span class="prev-icon-helper"><&|/l&>Queue</&>:</span>\
+ <span class="far fa-question-circle icon-helper" data-toggle="tooltip" data-placement="top" data-original-title="<% loc("Tickets will be created in this queue") %>"></span>
+ </div>
+ <div class="col-9 value">
+ <& /Elements/SelectQueue, Name => 'Queue', Default => $ARGS{Queue} &>
+ </div>
+ </div>
+
+ <div class="form-row">
+ <div class="col-12">
+ <& /Elements/Submit, Label => loc('Create'), Name => 'Create' &>
+ </div>
+ </div>
+
+</form>
+
+<%INIT>
+Abort( loc('Permission Denied') )
+ unless $session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'SuperUser' );
+
+my ($title, @results);
+$title = loc('Create form');
+
+if ( $Create ) {
+ push @results, loc('Missing Name') unless $Description;
+ push @results, loc('Missing Queue') unless $Queue;
+
+ if ( $Description && $Queue ) {
+ my $form = RT::Attribute->new( RT->SystemUser );
+ my ($ret) = $form->LoadByCols( Name => 'FormTools Form', Description => $Description );
+ if ($ret) {
+ push @results, loc( 'Name [_1] already exists', $Description );
+ }
+ else {
+ my ( $ret, $msg ) = $form->Create(
+ Name => 'FormTools Form',
+ Description => $ARGS{Description},
+ Object => RT->System,
+ Content => { queue => $ARGS{Queue} },
+ );
+
+ if ($ret) {
+ MaybeRedirectForResults(
+ Actions => [ loc('Created form [_1]', $Description) ],
+ Path => '/Admin/FormTools/Modify.html',
+ Arguments => { id => $form->Id },
+ );
+ }
+ else {
+ push @results, loc( "Couldn't create the form: [_1]", $msg );
+ }
+ }
+ }
+
+ MaybeRedirectForResults(
+ Actions => \@results,
+ Path => '/Admin/FormTools/Create.html',
+ Arguments => { Description => $Description, Queue => $Queue },
+ );
+}
+</%INIT>
+<%ARGS>
+$Description => undef
+$Queue => undef
+$Create => undef
+</%ARGS>
diff --git a/html/Callbacks/FormTools/Elements/Tabs/Privileged b/html/Callbacks/FormTools/Elements/Tabs/Privileged
index 4fff02e..24ad687 100644
--- a/html/Callbacks/FormTools/Elements/Tabs/Privileged
+++ b/html/Callbacks/FormTools/Elements/Tabs/Privileged
@@ -11,6 +11,10 @@ if ( $session{'CurrentUser'}->HasRight( Object => RT->System, Right => 'SuperUse
}
if ( $m->request_path =~ m{^/Admin/FormTools/} ) {
+ my $page = PageMenu();
+ $page->child( select => title => loc('Select'), path => "/Admin/FormTools/index.html" );
+ $page->child( create => title => loc('Create'), path => "/Admin/FormTools/Create.html" );
+
if ( ( $HTML::Mason::Commands::DECODED_ARGS->{'id'} || '' ) =~ /^(\d+)$/ ) {
my $id = $1;
my $form_attribute = RT::Attribute->new($session{'CurrentUser'});
@@ -20,8 +24,6 @@ if ( $m->request_path =~ m{^/Admin/FormTools/} ) {
RT->Logger->error("Unable to load form with id $id");
}
- my $page = PageMenu();
- $page->child( select => title => loc('Select'), path => "/Admin/FormTools/index.html?id=" . $id );
$page->child( modify => title => loc('Modify'), path => "/Admin/FormTools/Modify.html?id=" . $id );
$page->child( description => title => loc('Description'), path => "/Admin/FormTools/Describe.html?id=" . $id );
}
-----------------------------------------------------------------------
Summary of changes:
html/Admin/FormTools/Advanced.html | 101 ++++++++++++++++++++++
html/Admin/FormTools/Create.html | 81 +++++++++++++++++
html/Callbacks/FormTools/Elements/Tabs/Privileged | 7 +-
3 files changed, 187 insertions(+), 2 deletions(-)
create mode 100644 html/Admin/FormTools/Advanced.html
create mode 100644 html/Admin/FormTools/Create.html
hooks/post-receive
--
rt-extension-formtools
More information about the Bps-public-commit
mailing list