[Rt-commit] [rtir] 01/01: Constituency's selected value is lost on page reload

Kevin Falcone falcone at bestpractical.com
Wed Sep 17 16:13:22 EDT 2014


This is an automated email from the git hooks/post-receive script.

falcone pushed a commit to branch 3.0/track-constituency-on-reload
in repository rtir.

commit 3427457e0ecaea472ceb9643fe781a6eebbf4338
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Sep 17 14:16:59 2014 -0400

    Constituency's selected value is lost on page reload
    
    If you click Add More Files or trip over a mandatory CF and the Create
    page is presented again, your selection for Constituency will be lost.
    
    From the initial "Constituency on Create" commit 7ae47f4c this has been
    wrong.  It blindly recalculates the default and tells you to like it.
    
    The code is of course duplicated between IR/Investigation/Block creation
    and Incident creation rather than being part of the EditConstituency
    custom code.
    
    EditCustomField already knows how to retrieve submitted values on
    redisplay, so instead of calculating a Default in Create.html and passing
    that down (hammering any other attempts to figure out what the Default value
    should be) we let the normal CF code figure out what the value should be
    and if nothing is provided, EditConstituency does localized work to grab
    the passed down Child/Incident that we propagate Constituency from or
    pulls the default from the normal places.  Bonus?  The CF Default code
    is only in one place now.
    
    Additional Bonus.  Now when you Edit a Ticket and change constituency and
    reload that page (to search for a user, or when tripping over a
    mandatory CF) it doesn't lose your change to Constituency.
---
 html/RTIR/Create.html               |  7 ++-----
 html/RTIR/Elements/EditConstituency | 10 +++++++++-
 html/RTIR/Incident/Create.html      |  7 ++-----
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/html/RTIR/Create.html b/html/RTIR/Create.html
index ccdb62b..cc91e34 100644
--- a/html/RTIR/Create.html
+++ b/html/RTIR/Create.html
@@ -128,14 +128,11 @@
     <td class="label"><&|/l&>Constituency</&>:</td>
     <td class="value">
 % if ( !$Incident[0] || RT->Config->Get('_RTIR_Constituency_Propagation') eq 'no' ) {
-% my $default;
-% $default = $IncidentObj[0]->FirstCustomFieldValue('Constituency') if $Incident[0];
-% $default ||= RT::IR::DefaultConstituency( $QueueObj );
-% $default ||= scalar RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'};
       <& /RTIR/Elements/EditRTIRField, 
          QueueObj => $QueueObj, 
          Name     => 'Constituency',
-         Default  => $default &>
+         ($Incident[0] ? (PropagationObject => $IncidentObj[0]) : ()),
+       &>
 % } else {
 % #TODO: hacks, we need way to define CF value on Create, but don't allow user to change it
       <input type="hidden" class="hidden" name="<% $constituency_field %>-Magic" value="1" />
diff --git a/html/RTIR/Elements/EditConstituency b/html/RTIR/Elements/EditConstituency
index 43e2d80..40ab802 100644
--- a/html/RTIR/Elements/EditConstituency
+++ b/html/RTIR/Elements/EditConstituency
@@ -51,7 +51,7 @@
 %       my $selected = 0;
 %       my @category;
 %       my $id = $NamePrefix . $CustomField->Id;
-%       my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category, Object => $Object);
+%       my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category, Object => $Object, Default => $Default);
 %       if (@category) {
 <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
 %#      XXX - Hide this select from w3m?
@@ -77,6 +77,12 @@ if ( $RenderType eq 'Dropdown' ) {
     # Turn it into a dropdown
     $Rows = 0;
 }
+
+unless ($Default) {
+    $Default = $PropagationObject->FirstCustomFieldValue('Constituency') if $PropagationObject;
+    $Default ||= RT::IR::DefaultConstituency( $QueueObj );
+    $Default ||= scalar RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'};
+}
 </%INIT>
 <%ARGS>
 $Object => undef
@@ -87,6 +93,8 @@ $Values => undef
 $Multiple => 0
 $Rows => undef
 $RenderType => undef
+$PropagationObject => undef
+$QueueObj => undef
 </%ARGS>
 
 <%METHOD options>
diff --git a/html/RTIR/Incident/Create.html b/html/RTIR/Incident/Create.html
index 9f11a67..91442ae 100644
--- a/html/RTIR/Incident/Create.html
+++ b/html/RTIR/Incident/Create.html
@@ -133,14 +133,11 @@ if ( $ChildObj && !$ChildObj->CurrentUserHasRight('ModifyTicket') ) {
 <tr><td class="label"><&|/l&>Constituency</&>:</td>
 <td class="value">
 % if ( !$ChildObj || RT->Config->Get('_RTIR_Constituency_Propagation') eq 'no' ) {
-% my $default;
-% $default = $ChildObj->FirstCustomFieldValue('Constituency') if $ChildObj;
-% $default ||= RT::IR::DefaultConstituency( $QueueObj );
-% $default ||= scalar RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'};
 <& /RTIR/Elements/EditRTIRField,
+    %ARGS,
     QueueObj => $QueueObj,
     Name     => 'Constituency',
-    Default  => $default,
+    PropagationObject => $ChildObj,
 &>
 % } else {
 % #TODO: hacks, we need way to define CF value on Create, but don't allow user to change it

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list