[Rt-commit] rt branch, 4.2/scrip-custom-code-textareas-visible-only-when-needed, created. rt-4.2.13-53-gab55e15

Dustin Collins strega at bestpractical.com
Mon Aug 29 15:37:28 EDT 2016


The branch, 4.2/scrip-custom-code-textareas-visible-only-when-needed has been created
        at  ab55e15efcb873e70c59e3c7a86f2d5f5ba9c0fc (commit)

- Log -----------------------------------------------------------------
commit ab55e15efcb873e70c59e3c7a86f2d5f5ba9c0fc
Author: Dustin Collins <strega at bestpractical.com>
Date:   Mon Aug 29 11:39:25 2016 -0400

    Scrip custom code textures are now visible only for 'User Defined' condition and action.
    
    Fixes I#32260

diff --git a/share/html/Admin/Scrips/Create.html b/share/html/Admin/Scrips/Create.html
index 7cc3406..f563165 100644
--- a/share/html/Admin/Scrips/Create.html
+++ b/share/html/Admin/Scrips/Create.html
@@ -74,15 +74,7 @@
     Label => loc('Create'),
     Name => 'Create',
 &>
-
-% if ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode')) {
-<& Elements/EditCustomCode, %ARGS, Scrip => $scrip &>
-<& /Elements/Submit,
-    Label => loc('Create'),
-    Name => 'Create',
-&>
-% }
-
+        
 </form>
 <%ARGS>
 $Queue => 0
diff --git a/share/html/Admin/Scrips/Elements/EditBasics b/share/html/Admin/Scrips/Elements/EditBasics
index aad681c..57e5856 100644
--- a/share/html/Admin/Scrips/Elements/EditBasics
+++ b/share/html/Admin/Scrips/Elements/EditBasics
@@ -45,6 +45,9 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+
+% my $canExecuteCode = ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode'));
+
 <tr><td class="label"><&|/l&>Description</&>:</td><td class="value">\
 <input name="Description" \
     size="60" \
@@ -56,19 +59,68 @@
     Default => $ARGS{"ScripCondition"} || $Scrip->ConditionObj->Id,
 &></td></tr>
 
+% if ($canExecuteCode) {
+<tr class="CustomIsApplicableCode <% $Scrip->ScripCondition == $userDefinedCondition->id ? '' : 'hidden' %>">
+<td class="label"><&|/l&>Custom code</&>:</td><td class="value">\
+% my $conditionCode = $ARGS{ CustomIsApplicableCode } || $Scrip->CustomIsApplicableCode() || '';
+<textarea cols="80" rows="<% 6 %>" name="CustomIsApplicableCode"><% $conditionCode %></textarea>
+</td></tr>
+% }
+
 <tr><td class="label"><&|/l&>Action</&>:</td><td class="value">\
 <& /Admin/Elements/SelectScripAction,
     Default => $ARGS{"ScripAction"} || $Scrip->ActionObj->Id,
 &></td></tr>
 
+% if ($canExecuteCode) {
+<tr class="CustomPrepareAndCommitCode <% $Scrip->ScripAction == $userDefinedAction->id ? '' : 'hidden' %>">
+<td class="label"><&|/l&>Prepare code</&>:</td><td class="value">\
+% my $prepareCode = $ARGS{ CustomPrepareCode } || $Scrip->CustomPrepareCode() || '';
+<textarea cols="80" rows="<% 6 %>" name="CustomPrepareCode"><% $prepareCode %></textarea>
+</td></tr>
+
+<tr class="CustomPrepareAndCommitCode <% $Scrip->ScripAction == $userDefinedAction->id ? '' : 'hidden' %>">
+<td class="label"><&|/l&>Commit code</&>:</td><td class="value">\
+% my $commitCode = $ARGS{ CustomCommitCode } || $Scrip->CustomCommitCode() || '';
+<textarea cols="80" rows="<% 6 %>" name="CustomCommitCode"><% $commitCode %></textarea>
+</td></tr>
+% }
+
 <tr><td class="label"><&|/l&>Template</&>:</td><td class="value">\
 <& SelectTemplate,
     Default => $ARGS{"Template"}, Scrip => $Scrip, Queue => $Queue,
 &></td></tr>
 
+<script type="text/javascript">
+jQuery(function () {
+    jQuery("select[name=ScripCondition]").change(function (e) {
+        var scripConditionId = jQuery(this).val();
+        if (scripConditionId == <% $userDefinedCondition->id %>) {
+            jQuery(".CustomIsApplicableCode").removeClass('hidden');
+        }else{
+            jQuery(".CustomIsApplicableCode").addClass('hidden');
+        }
+    });
+
+    jQuery("select[name=ScripAction]").change(function (e) {
+        var scripActionId = jQuery(this).val();
+        if (scripActionId == <% $userDefinedAction->id %>) {
+            jQuery(".CustomPrepareAndCommitCode").removeClass('hidden');
+        }else{
+            jQuery(".CustomPrepareAndCommitCode").addClass('hidden');
+        }
+    });
+});
+</script>
+
 <%ARGS>
 $Scrip
 $Queue => undef
 </%ARGS>
 <%INIT>
+my $userDefinedCondition = RT::ScripCondition->new($session{CurrentUser});
+$userDefinedCondition->LoadByCols(ExecModule => 'UserDefined');
+
+my $userDefinedAction = RT::ScripAction->new($session{CurrentUser});
+$userDefinedAction->LoadByCols(ExecModule => 'UserDefined');
 </%INIT>
diff --git a/share/html/Admin/Scrips/Elements/EditCustomCode b/share/html/Admin/Scrips/Elements/EditCustomCode
deleted file mode 100644
index 1c6247e..0000000
--- a/share/html/Admin/Scrips/Elements/EditCustomCode
+++ /dev/null
@@ -1,77 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
-%#                                          <sales at bestpractical.com>
-%#
-%# (Except where explicitly superseded by other copyright notices)
-%#
-%#
-%# LICENSE:
-%#
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org.
-%#
-%# This work is distributed in the hope that it will be useful, but
-%# WITHOUT ANY WARRANTY; without even the implied warranty of
-%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-%# General Public License for more details.
-%#
-%# You should have received a copy of the GNU General Public License
-%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-%# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-%#
-%#
-%# CONTRIBUTION SUBMISSION POLICY:
-%#
-%# (The following paragraph is not intended to limit the rights granted
-%# to you to modify and distribute this software under the terms of
-%# the GNU General Public License and is only of importance to you if
-%# you choose to contribute your changes and enhancements to the
-%# community by submitting them to Best Practical Solutions, LLC.)
-%#
-%# By intentionally submitting any modifications, corrections or
-%# derivatives to this work, or any other work intended for use with
-%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-%# you are the copyright holder for those contributions and you grant
-%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-%# royalty-free, perpetual, license to use, copy, create derivative
-%# works based on those contributions, and sublicense and distribute
-%# those contributions and any derivatives thereof.
-%#
-%# END BPS TAGGED BLOCK }}}
-<&| /Widgets/TitleBox, title => loc('User Defined conditions and results') &>
-
-<table>
-<tr><td colspan="2" class="comment">
-<i><&|/l&>(Use these fields when you choose 'User Defined' for a condition or action)</&></i>
-</td></tr>
-
-% while ( my ($method, $desc) = splice @list, 0, 2 ) {
-<tr><td class="labeltop"><% $desc %>:</td><td class="value">
-% my $code = $ARGS{ $method } || $Scrip->$method() || '';
-% my $lines = @{[ $code =~ /\n/gs ]} + 3;
-% $lines = $min_lines if $lines < $min_lines;
-<textarea cols="80" rows="<% $lines %>" name="<% $method %>"><% $code %></textarea>
-</td></tr>
-% }
-
-</table>
-</&>
-<%ARGS>
-$Scrip
-</%ARGS>
-<%INIT>
-my @list = (
-    CustomIsApplicableCode => loc('Custom condition'),
-    CustomPrepareCode      => loc('Custom action preparation code'),
-    CustomCommitCode       => loc('Custom action commit code'),
-);
-
-my $min_lines = 10;
-</%INIT>
diff --git a/share/html/Admin/Scrips/Modify.html b/share/html/Admin/Scrips/Modify.html
index 618c48d..d5929e3 100644
--- a/share/html/Admin/Scrips/Modify.html
+++ b/share/html/Admin/Scrips/Modify.html
@@ -88,11 +88,6 @@
 
 <& /Elements/Submit, Label => loc('Save Changes'), Name => 'Update', Reset => 1 &>
 
-% if ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode')) {
-<& Elements/EditCustomCode, %ARGS, Scrip => $scrip &>
-<& /Elements/Submit, Label => loc('Save Changes'), Name => 'Update', Reset => 1 &>
-% }
-
 </form>
 <%ARGS>
 $id     => undef

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


More information about the rt-commit mailing list