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

Dustin Collins strega at bestpractical.com
Wed Aug 31 17:47:05 EDT 2016


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

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

    Hide scrip custom code fields when appropriate
    
    The textareas for condition, action prepare, and action commit code
    only make sense for scrips that use "User Defined" condition or
    action. This commit shows or hides each textarea (using JavaScript)
    based on whether the scrip's current configuration will use its
    contents. This is meant to reduce user confusion about when these
    textareas take effect, and significantly reduce the length of the page
    in the common case of no "User Defined" code.
    
    To reinforce to users the relationship between the dropdown and its
    custom code textarea(s), we've moved each textarea up into the form,
    right below to its dropdown. If the fields were to remain in two
    separate sections, then users wouldn't notice the show/hide action at
    a distance and would wonder why the textareas appear only some of the
    time. This also reduces the perceived complexity of the scrip
    create/modify page down to one consistent form, rather than two
    confusingly-related sections, each with its own Save Changes button.
    
    Now that we've moved the textareas to be inline with the rest of the
    form, there arises a new problem where specifying lots of code would
    cause the rest of the page (e.g. Template selection) to scroll
    offscreen. So adapting the size of the textbox to how many lines are
    in the provided code (+3 lines for buffer) has been replaced with a
    constant of 6 rows. Users will still be able to use their browser's
    textarea resize tool to make the code entry fields longer.
    
    There is no animation for the show/hide actions because jQuery's
    slideUp and slideDown animations cannot handle table tags.
    
    Fixes: I#32260

diff --git a/share/html/Admin/Scrips/Create.html b/share/html/Admin/Scrips/Create.html
index 7cc3406..4af7a7f 100644
--- a/share/html/Admin/Scrips/Create.html
+++ b/share/html/Admin/Scrips/Create.html
@@ -75,14 +75,6 @@
     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..e3aa92b 100644
--- a/share/html/Admin/Scrips/Elements/EditBasics
+++ b/share/html/Admin/Scrips/Elements/EditBasics
@@ -56,19 +56,70 @@
     Default => $ARGS{"ScripCondition"} || $Scrip->ConditionObj->Id,
 &></td></tr>
 
+% if ($canExecuteCode) {
+<tr class="CustomIsApplicableCode <% ($Scrip->ScripCondition||0) == $userDefinedCondition->id ? '' : 'hidden' %>">
+<td class="label"><&|/l&>Condition 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="CustomPrepareCode <% ($Scrip->ScripAction||0) == $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="CustomCommitCode <% ($Scrip->ScripAction||0) == $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(".CustomPrepareCode, .CustomCommitCode").removeClass('hidden');
+        }else{
+            jQuery(".CustomPrepareCode, .CustomCommitCode").addClass('hidden');
+        }
+    });
+});
+</script>
+
 <%ARGS>
 $Scrip
 $Queue => undef
 </%ARGS>
 <%INIT>
+my $canExecuteCode = ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode'));
+
+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