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

Dustin Collins strega at bestpractical.com
Wed Sep 21 21:30:15 EDT 2016


The branch 4.2/scrip-custom-code-textareas-visible-only-when-needed was deleted and repushed:
       was 963d166a840d248b4c6b0c81c9f1a72bcdd12120
       now 2a74a29af2fcaf955670e5342ba88a4532ba08dd

1:  963d166 ! 1:  2a74a29 Hide scrip custom code fields when appropriate
    @@ -2,66 +2,127 @@
     
         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.
    -    
    -    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 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.
    +    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.
    +    
    +    In order to ease the transition for custom deployments, a new method
    +    (IsUserEditable) is added to RT::Condition and RT::Action to allow
    +    users to easily inform RT of condition or action objects they have
    +    made user editable.
    +    
    +    Add Condition method to RT::ScripCondition for easily obtaining the
    +    RT::Condition object, simillar to the Action method on RT::ScripAction.
    +    Add lazy loading check to RT:ScripAction->Action.
    +    
    +    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/lib/RT/Action.pm b/lib/RT/Action.pm
    +--- a/lib/RT/Action.pm
    ++++ b/lib/RT/Action.pm
    +@@
    +   return (0, $self->loc("Prepare Stubbed"));
    + }
    + 
    ++=head2 IsUserEditable
    ++Return 1 if the action can be edited by a user, otherwise 0.
    ++=cut
    ++sub IsUserEditable {
    ++    return 0;
    ++}
    + 
    + RT::Base->_ImportOverlays();
    + 
    +
    +diff --git a/lib/RT/Action/UserDefined.pm b/lib/RT/Action/UserDefined.pm
    +--- a/lib/RT/Action/UserDefined.pm
    ++++ b/lib/RT/Action/UserDefined.pm
    +@@
    +     return ($retval);
    + }
    + 
    ++sub IsUserEditable {
    ++    return 1;
    ++}
    ++
    + =head2 Commit
    + 
    + This happens on every transaction. it's always applicable
    +
    +diff --git a/lib/RT/Condition.pm b/lib/RT/Condition.pm
    +--- a/lib/RT/Condition.pm
    ++++ b/lib/RT/Condition.pm
    +@@
    +   return(undef);
    + }
    + 
    ++=head2 IsUserEditable
    ++Return 1 if the condition can be edited by a user, otherwise 0.
    ++=cut
    ++sub IsUserEditable {
    ++    my $self = shift;
    ++    return 0;
    ++}
    ++
    + sub DESTROY {
    +     my $self = shift;
    + 
    +
    +diff --git a/lib/RT/Condition/UserDefined.pm b/lib/RT/Condition/UserDefined.pm
    +--- a/lib/RT/Condition/UserDefined.pm
    ++++ b/lib/RT/Condition/UserDefined.pm
    +@@
    +     return ($retval);
    + }
    + 
    ++=head2 IsUserEditable
    ++Return 1 if the condition can be edited by a user, otherwise 0.
    ++=cut
    ++sub IsUserEditable {
    ++    return 1;
    ++}
    ++
    + RT::Base->_ImportOverlays();
    + 
    + 1;
     
     diff --git a/lib/RT/ScripAction.pm b/lib/RT/ScripAction.pm
     --- a/lib/RT/ScripAction.pm
     +++ b/lib/RT/ScripAction.pm
     @@
    + 
    + sub Action {
    +     my $self = shift;
    ++    unless (defined $self->{'Action'}) {
    ++        $self->LoadAction;
    ++    }
          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
      
    @@ -71,56 +132,25 @@
     --- 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.
    +     
    + }
    + 
    ++=head2 Condition
    ++
    ++Return the actual RT::Condition object for this scrip.
     +
     +=cut
     +
    -+sub IsUserEditable {
    ++sub Condition {
     +    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;
    ++    unless (defined $self->{'Condition'}) {
    ++        $self->LoadCondition;
     +    }
    -+
    -+    #push additional values here onto @ids to allow them to be user editable
    -+
    -+    return @ids;
    -+}
    -+
    -+
    -+
    - =head2 id
    - 
    - Returns the current value of id.
    ++    return $self->{'Condition'};
    ++}
    + 
    + =head2 IsApplicable
    + 
     
     diff --git a/share/html/Admin/Scrips/Create.html b/share/html/Admin/Scrips/Create.html
     --- a/share/html/Admin/Scrips/Create.html
    @@ -149,7 +179,7 @@
      &></td></tr>
      
     +% if ($canExecuteCode) {
    -+<tr class="CustomIsApplicableCode <% $Scrip->ConditionObj->IsUserEditable ? '' : 'hidden' %>">
    ++<tr class="CustomIsApplicableCode <% $editableConditionInitiallyHidden ? '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>
    @@ -162,13 +192,13 @@
      &></td></tr>
      
     +% if ($canExecuteCode) {
    -+<tr class="CustomPrepareCode <% $Scrip->ActionObj->IsUserEditable ? '' : 'hidden' %>">
    ++<tr class="CustomPrepareCode <% $editableActionInitiallyHidden ? '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->ActionObj->IsUserEditable ? '' : 'hidden' %>">
    ++<tr class="CustomCommitCode <% $editableActionInitiallyHidden ? '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>
    @@ -184,7 +214,7 @@
     +jQuery(function () {
     +    jQuery("select[name=ScripCondition]").change(function (e) {
     +        var scripConditionId = parseInt(jQuery(this).val());
    -+        var userEditableIDs = [<% join( ', ', RT::ScripCondition->new($session{CurrentUser})->UserEditableIDs ) %>]
    ++        var userEditableIDs = [<% join( ', ', @editableConditionIDs) %>]
     +        if (userEditableIDs.indexOf(scripConditionId) > -1) {
     +            jQuery(".CustomIsApplicableCode").removeClass('hidden');
     +        }else{
    @@ -194,7 +224,7 @@
     +
     +    jQuery("select[name=ScripAction]").change(function (e) {
     +        var scripConditionId = parseInt(jQuery(this).val());
    -+        var userEditableIDs = [<% join( ', ', RT::ScripAction->new($session{CurrentUser})->UserEditableIDs ) %>]
    ++        var userEditableIDs = [<% join( ', ', @editableActionIDs) %>]
     +        if (userEditableIDs.indexOf(scripConditionId) > -1) {
     +            jQuery(".CustomPrepareCode, .CustomCommitCode").removeClass('hidden');
     +        }else{
    @@ -209,7 +239,29 @@
      $Queue => undef
      </%ARGS>
      <%INIT>
    ++
     +my $canExecuteCode = ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode'));
    ++
    ++my $editableConditionInitiallyHidden = ($Scrip->ConditionObj->Id) ? !$Scrip->ConditionObj->Condition->IsUserEditable : 1;
    ++my @editableConditionIDs;
    ++my $ScripConditions = RT::ScripConditions->new($session{'CurrentUser'});
    ++$ScripConditions->UnLimit;
    ++while (my $ScripCondition = $ScripConditions->Next) {
    ++    if ($ScripCondition->Condition->IsUserEditable) {
    ++        push @editableConditionIDs, $ScripCondition->Id;
    ++    }
    ++}
    ++
    ++my $editableActionInitiallyHidden = ($Scrip->ActionObj->Id) ? !$Scrip->ActionObj->Action->IsUserEditable : 1;
    ++my @editableActionIDs;
    ++my $ScripActions = RT::ScripActions->new($session{'CurrentUser'});
    ++$ScripActions->UnLimit;
    ++while (my $ScripAction = $ScripActions->Next) {
    ++    if ($ScripAction->Action->IsUserEditable) {
    ++        push @editableActionIDs, $ScripAction->Id;
    ++    }
    ++}
    ++
      </%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