[Rt-commit] rt branch, 4.2/scrip-custom-code-textareas-visible-only-when-needed, repushed

Dustin Collins strega at bestpractical.com
Sat Sep 3 21:02:51 EDT 2016


The branch 4.2/scrip-custom-code-textareas-visible-only-when-needed was deleted and repushed:
       was f00328ba497506a6c05a53129bfdcf24458e2913
       now 12caab7c2b7d042b1ce98add3c5568c7fcaeac6a

1:  f00328b ! 1:  12caab7 Hide scrip custom code fields when appropriate
    @@ -19,6 +19,11 @@
         create/modify page down to one consistent form, rather than two
         confusingly-related sections, each with its own Save Changes button.
         
    +    In order to ease the transition for custom deployments, two new methods
    +    (UserEditableIDs and IsUserEditable) have been added to ScripCondition
    +    and ScripAction to allow users to easily inform RT of conditions or
    +    actions they have made user editable.
    +    
         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
    @@ -32,6 +37,113 @@
         
         Fixes: I#32260
     
    +diff --git a/lib/RT/ScripAction.pm b/lib/RT/ScripAction.pm
    +--- a/lib/RT/ScripAction.pm
    ++++ b/lib/RT/ScripAction.pm
    +@@
    +     return $self->{'Action'};
    + }
    + 
    ++=head2 IsUserEditable
    ++
    ++Returns 1 if the action can be edited by a user, otherwise 0.
    ++
    ++=cut
    ++
    ++sub IsUserEditable {
    ++    my $self = shift;
    ++
    ++    my @userEditableIDs = $self->UserEditableIDs;
    ++    my %hashedIDs = map { $_ => 1 } @userEditableIDs;
    ++    my $id = ($self->id || 0);
    ++
    ++    return exists($hashedIDs{$id}) ? 1 : 0;
    ++}
    ++
    ++
    ++=head2 UserEditableIds
    ++
    ++Returns an array of ScripCondition 'id's that should be user editable.
    ++
    ++=cut
    ++
    ++sub UserEditableIDs {
    ++    my $self = shift;
    ++
    ++    my @ids = ();
    ++
    ++    #Adds UserDefined ScripAction id
    ++    my $userDefinedAction = $self->new($self->CurrentUser);
    ++    $userDefinedAction->LoadByCols(ExecModule => 'UserDefined');
    ++    my $userDefinedId = $userDefinedAction->id||0;
    ++    if ( $userDefinedId > 0 ) {
    ++        push @ids, $userDefinedId;
    ++    }
    ++
    ++    #push additional values here onto @ids to allow them to be user editable
    ++    
    ++    return @ids;
    ++}
    ++
    ++
    + =head2 id
    + 
    + Returns the current value of id.
    +
    +diff --git a/lib/RT/ScripCondition.pm b/lib/RT/ScripCondition.pm
    +--- a/lib/RT/ScripCondition.pm
    ++++ b/lib/RT/ScripCondition.pm
    +@@
    + }
    + 
    + 
    ++=head2 IsUserEditable
    ++
    ++Returns 1 if the action can be edited by a user, otherwise 0.
    ++
    ++=cut
    ++
    ++sub IsUserEditable {
    ++    my $self = shift;
    ++
    ++    my @userEditableIDs = $self->UserEditableIDs;
    ++    my %hashedIDs = map { $_ => 1 } @userEditableIDs;
    ++
    ++    my $id = ($self->id || 0);
    ++
    ++    return exists($hashedIDs{$id}) ? 1 : 0;
    ++}
    ++
    ++
    ++=head2 UserEditableIds
    ++
    ++Returns an array of ScripCondition 'id's that should be user editable.
    ++
    ++=cut
    ++
    ++sub UserEditableIDs {
    ++    my $self = shift;
    ++
    ++    my @ids = ();
    ++
    ++    #Adds UserDefined ScripCondition id
    ++    my $userDefinedCondition = $self->new($self->CurrentUser);
    ++    $userDefinedCondition->LoadByCols(ExecModule => 'UserDefined');
    ++    my $userDefinedId = $userDefinedCondition->id||0;
    ++    if ( $userDefinedId > 0 ) {
    ++        push @ids, $userDefinedId;
    ++    }
    ++
    ++    #push additional values here onto @ids to allow them to be user editable
    ++
    ++    return @ids;
    ++}
    ++
    ++
    + 
    + =head2 id
    + 
    +
     diff --git a/share/html/Admin/Scrips/Create.html b/share/html/Admin/Scrips/Create.html
     --- a/share/html/Admin/Scrips/Create.html
     +++ b/share/html/Admin/Scrips/Create.html
    @@ -59,7 +171,7 @@
      &></td></tr>
      
     +% if ($canExecuteCode) {
    -+<tr class="CustomIsApplicableCode <% ($Scrip->ScripCondition||0) == $userDefinedCondition->id ? '' : 'hidden' %>">
    ++<tr class="CustomIsApplicableCode <% $Scrip->ConditionObj->IsUserEditable ? '' : '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>
    @@ -72,13 +184,13 @@
      &></td></tr>
      
     +% if ($canExecuteCode) {
    -+<tr class="CustomPrepareCode <% ($Scrip->ScripAction||0) == $userDefinedAction->id ? '' : 'hidden' %>">
    ++<tr class="CustomPrepareCode <% $Scrip->ActionObj->IsUserEditable ? '' : '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' %>">
    ++<tr class="CustomCommitCode <% $Scrip->ActionObj->IsUserEditable ? '' : '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>
    @@ -93,8 +205,9 @@
     +<script type="text/javascript">
     +jQuery(function () {
     +    jQuery("select[name=ScripCondition]").change(function (e) {
    -+        var scripConditionId = jQuery(this).val();
    -+        if (scripConditionId == <% $userDefinedCondition->id %>) {
    ++        var scripConditionId = parseInt(jQuery(this).val());
    ++        var userEditableIDs = [<% join( ', ', RT::ScripCondition->new($session{CurrentUser})->UserEditableIDs ) %>]
    ++        if (userEditableIDs.indexOf(scripConditionId) > -1) {
     +            jQuery(".CustomIsApplicableCode").removeClass('hidden');
     +        }else{
     +            jQuery(".CustomIsApplicableCode").addClass('hidden');
    @@ -102,8 +215,9 @@
     +    });
     +
     +    jQuery("select[name=ScripAction]").change(function (e) {
    -+        var scripActionId = jQuery(this).val();
    -+        if (scripActionId == <% $userDefinedAction->id %>) {
    ++        var scripConditionId = parseInt(jQuery(this).val());
    ++        var userEditableIDs = [<% join( ', ', RT::ScripAction->new($session{CurrentUser})->UserEditableIDs ) %>]
    ++        if (userEditableIDs.indexOf(scripConditionId) > -1) {
     +            jQuery(".CustomPrepareCode, .CustomCommitCode").removeClass('hidden');
     +        }else{
     +            jQuery(".CustomPrepareCode, .CustomCommitCode").addClass('hidden');
    @@ -118,12 +232,6 @@
      </%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



More information about the rt-commit mailing list