[Rt-commit] rt branch, 4.4/default-values, created. rt-4.2.5-193-g7d87a78

? sunnavy sunnavy at bestpractical.com
Thu Sep 4 12:14:12 EDT 2014


The branch, 4.4/default-values has been created
        at  7d87a78217366619dacfa0a50b49170fb8963d47 (commit)

- Log -----------------------------------------------------------------
commit afd5b615b986d3370975756a8da93e5c1d993633
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jun 15 20:58:17 2014 +0800

    make datepicker less zealous
    
    don't show datepicker if there are relative strings there

diff --git a/share/static/js/util.js b/share/static/js/util.js
index b665c0e..96ffc91 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -186,8 +186,15 @@ jQuery(function() {
         changeMonth: true,
         changeYear: true,
         showOtherMonths: true,
+        showOn: 'none',
         selectOtherMonths: true
     };
+    jQuery(".datepicker").focus(function() {
+        var val = jQuery(this).val();
+        if ( !val.match(/[a-z]/i) ) {
+            jQuery(this).datepicker('show');
+        }
+    });
     jQuery(".datepicker:not(.withtime)").datepicker(opts);
     jQuery(".datepicker.withtime").datetimepicker( jQuery.extend({}, opts, {
         stepHour: 1,

commit 0bb6abb2f4641896d3a77ccca5bb0c3cdc699026
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Aug 19 09:36:46 2014 +0800

    system level cf default values support

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 19b27e4..666ca87 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1040,12 +1040,15 @@ sub ValidateContextObject {
 
 sub _Set {
     my $self = shift;
-
+    my %args = @_;
     unless ( $self->CurrentUserHasRight('AdminCustomField') ) {
         return ( 0, $self->loc('Permission Denied') );
     }
-    return $self->SUPER::_Set( @_ );
-
+    my ($ret, $msg) = $self->SUPER::_Set( @_ );
+    if ( $args{Field} =~ /^(?:MaxValues|Type|LookupType|ValuesClass)$/ ) {
+        $self->CleanupDefaultValues;
+    }
+    return ($ret, $msg);
 }
 
 
@@ -2025,9 +2028,141 @@ sub BasedOnObj {
 }
 
 
+sub SupportDefaultValues {
+    my $self = shift;
+    return 0 unless $self->id;
+    return 0 unless $self->LookupType =~ /RT::(?:Ticket|Transaction)$/;
+    return $self->Type !~ /^(?:Image|Binary)$/;
+}
+
+sub DefaultValues {
+    my $self = shift;
+    my %args = (
+        Object => RT->System,
+        @_,
+    );
+    my $attr = $args{Object}->FirstAttribute('CustomFieldDefaultValues');
+    my $values;
+    $values = $attr->Content->{$self->id} if $attr && $attr->Content;
+    return $values;
+}
+
+sub SetDefaultValues {
+    my $self = shift;
+    my %args = (
+        Object => RT->System,
+        Values => undef,
+        @_,
+    );
+    my $attr = $args{Object}->FirstAttribute( 'CustomFieldDefaultValues' );
+    my ( $old_values, $old_content, $new_values );
+    if ( $attr && $attr->Content ) {
+        $old_content = $attr->Content;
+        $old_values = $old_content->{ $self->id };
+    }
 
+    if ( defined $old_values && length $old_values ) {
+        $old_values = join ', ', @$old_values if ref $old_values eq 'ARRAY';
+    }
 
+    $new_values = $args{Values};
+    if ( defined $new_values && length $new_values ) {
+        $new_values = join ', ', @$new_values if ref $new_values eq 'ARRAY';
+    }
 
+    return 1 if ( $new_values // '' ) eq ( $old_values // '' );
+
+    my ($ret, $msg) = $args{Object}->SetAttribute(
+        Name    => 'CustomFieldDefaultValues',
+        Content => {
+            %{ $old_content || {} }, $self->id => $args{Values},
+        },
+    );
+
+    $old_values = $self->loc('(no value)') unless defined $old_values && length $old_values;
+    $new_values = $self->loc( '(no value)' ) unless defined $new_values && length $new_values;
+
+    if ( $ret ) {
+        return ( $ret, $self->loc( 'Default values changed from [_1] to [_2]', $old_values, $new_values ) );
+    }
+    else {
+        return ( $ret, $self->loc( "Can't change default values from [_1] to [_2]: [_3]", $old_values, $new_values, $msg ) );
+    }
+}
+
+sub CleanupDefaultValues {
+    my $self  = shift;
+    my $attrs = RT::Attributes->new( $self->CurrentUser );
+    $attrs->Limit( FIELD => 'Name', VALUE => 'CustomFieldDefaultValues' );
+
+    my @values;
+    if ( $self->Type eq 'Select' ) {
+        # Select has a limited list valid values, we need to exclude invalid ones
+        @values = map { $_->Name } @{ $self->Values->ItemsArrayRef || [] };
+    }
+
+    while ( my $attr = $attrs->Next ) {
+        my $content = $attr->Content;
+        next unless $content;
+        my $changed;
+        if ( $self->SupportDefaultValues ) {
+            if ( $self->MaxValues == 1 && ref $content->{ $self->id } eq 'ARRAY' ) {
+                $content->{ $self->id } = $content->{ $self->id }[ 0 ];
+                $changed = 1;
+            }
+
+            my $default_values = $content->{ $self->id };
+            if ( $default_values ) {
+                if ( $self->Type eq 'Select' ) {
+                    if ( ref $default_values ne 'ARRAY' && $default_values =~ /\n/ ) {
+
+                        # e.g. multiple values Freeform cf has 2 default values: foo and "bar",
+                        # the values will be stored as "foo\nbar".  so we need to convert it to ARRAY for Select cf.
+                        # this could happen when we change a Freeform cf into a Select one
+
+                        $default_values = [ split /\s*\n+\s*/, $default_values ];
+                        $content->{ $self->id } = $default_values;
+                        $changed = 1;
+                    }
+
+                    if ( ref $default_values eq 'ARRAY' ) {
+                        my @new_defaults;
+                        for my $default ( @$default_values ) {
+                            if ( grep { $_ eq $default } @values ) {
+                                push @new_defaults, $default;
+                            }
+                            else {
+                                $changed = 1;
+                            }
+                        }
+
+                        $content->{ $self->id } = \@new_defaults if $changed;
+                    }
+                    elsif ( !grep { $_ eq $default_values } @values ) {
+                        delete $content->{ $self->id };
+                        $changed = 1;
+                    }
+                }
+                else {
+                    # ARRAY default values only happen for Select cf. we need to convert it to a scalar for other cfs.
+                    # this could happen when we change a Select cf into a Freeform one
+
+                    if ( ref $default_values eq 'ARRAY' ) {
+                        $content->{ $self->id } = join "\n", @$default_values;
+                        $changed = 1;
+                    }
+                }
+            }
+        }
+        else {
+            if ( exists $content->{ $self->id } ) {
+                delete $content->{ $self->id };
+                $changed = 1;
+            }
+        }
+        $attr->SetContent( $content ) if $changed;
+    }
+}
 
 =head2 id
 
diff --git a/lib/RT/CustomFieldValue.pm b/lib/RT/CustomFieldValue.pm
index 1ba73ef..ee0102a 100644
--- a/lib/RT/CustomFieldValue.pm
+++ b/lib/RT/CustomFieldValue.pm
@@ -100,9 +100,16 @@ sub ValidateName {
     return defined $_[1] && length $_[1];
 };
 
+sub Delete {
+    my $self = shift;
+    my ( $ret, $msg ) = $self->SUPER::Delete;
+    $self->CustomFieldObj->CleanupDefaultValues;
+    return ( $ret, $msg );
+}
+
 sub _Set { 
     my $self = shift; 
-
+    my %args = @_;
     my $cf_id = $self->CustomField; 
 
     my $cf = RT::CustomField->new( $self->CurrentUser ); 
@@ -116,8 +123,12 @@ sub _Set {
         return (0, $self->loc('Permission Denied')); 
     } 
 
-    return $self->SUPER::_Set( @_ ); 
-} 
+    my ($ret, $msg) = $self->SUPER::_Set( @_ ); 
+    if ( $args{Field} eq 'Name' ) {
+        $cf->CleanupDefaultValues;
+    }
+    return ($ret, $msg);
+}
 
 
 =head2 id
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index eab9a10..0cd2549 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -321,6 +321,19 @@ sub LimitToGlobal  {
   $self->LimitToLookupType( 'RT::Queue-RT::Ticket' );
 }
 
+=head2 LimitToDefaultValuesSupportedTypes
+
+Limits the Custom Field collection to ones of which types support default values.
+
+=cut
+
+sub LimitToDefaultValuesSupportedTypes {
+    my $self = shift;
+    $self->Limit( FIELD => 'Type', VALUE => 'Binary', OPERATOR => '!=', ENTRYAGGREGATOR => 'AND' );
+    $self->Limit( FIELD => 'Type', VALUE => 'Image', OPERATOR => '!=', ENTRYAGGREGATOR => 'AND' );
+    return $self;
+}
+
 
 =head2 ApplySortOrder
 
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 37c40b0..df6173a 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2102,6 +2102,37 @@ sub _AddCustomFieldValue {
     }
 }
 
+=head2 AddCustomFieldDefaultValues
+
+Add default values to object's empty custom fields.
+
+=cut
+
+sub AddCustomFieldDefaultValues {
+    my $self = shift;
+    my $cfs  = $self->CustomFields;
+    my @msgs;
+    while ( my $cf = $cfs->Next ) {
+        next if $self->CustomFieldValues($cf->id)->Count || !$cf->SupportDefaultValues;
+        my $values = $cf->DefaultValues( Object => RT->System );
+        foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
+            next if $self->CustomFieldValueIsEmpty(
+                Field => $cf->id,
+                Value => $value,
+            );
+
+            my ( $status, $msg ) = $self->_AddCustomFieldValue(
+                Field             => $cf->id,
+                Value             => $value,
+                RecordTransaction => 0,
+            );
+            push @msgs, $msg unless $status;
+        }
+    }
+    return ( 0, @msgs ) if @msgs;
+    return 1;
+}
+
 =head2 CustomFieldValueIsEmpty { Field => FIELD, Value => VALUE }
 
 Check if the custom field value is empty.
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index f039357..f6e24f5 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -495,6 +495,9 @@ sub Create {
         }
     }
 
+    my ( $status, @msgs ) = $self->AddCustomFieldDefaultValues;
+    push @non_fatal_errors, @msgs unless $status;
+
     # Deal with setting up links
 
     # TODO: Adding link may fire scrips on other end and those scrips
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index f6df440..7e3a9c4 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1421,6 +1421,8 @@ sub UpdateCustomFields {
             );
         }
     }
+
+    $self->AddCustomFieldDefaultValues;
 }
 
 =head2 LoadCustomFieldByIdentifier
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index eea4532..fb0a6f2 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -127,6 +127,14 @@ jQuery( function() {
     Values  => \@CFvalidations,
 &></td></tr>
 
+% if ( $CustomFieldObj->SupportDefaultValues ) {
+<tr class="edit_default_values"><td class="label"><&|/l, $CustomFieldObj->MaxValues &>Default [numerate,_1,value,values]</&></td>
+<td>
+<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj &>
+</td>
+</tr>
+% }
+
 <tr><td class="label"><&|/l&>Link values to</&></td><td>
 <input size="60" name="LinkValueTo"  value="<% $CustomFieldObj->LinkValueTo || $LinkValueTo || '' %>" />
 <div class="hints">
@@ -267,6 +275,14 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
         push @results, $msg;
     }
 
+    if ( $CustomFieldObj->SupportDefaultValues ) {
+        my ($ret, $msg) = $CustomFieldObj->SetDefaultValues(
+            Object => RT->System,
+            Values => $ARGS{'Default-' . $CustomFieldObj->id . '-Value'} // $ARGS{'Default-' . $CustomFieldObj->id . '-Values'},
+        );
+        push @results, $msg;
+    }
+
     my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
     # Delete any fields that want to be deleted
     foreach my $key ( keys %ARGS ) {
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 0b36592..d945bac 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -90,6 +90,10 @@ if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
     }
 }
 
+if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
+    $Default = $CustomField->DefaultValues(Object => RT->System);
+}
+
 my $MaxValues = $CustomField->MaxValues;
 if ($MaxValues == 1 && $Values) {
     # what exactly is this doing?  Without the "unless" it breaks RTFM

commit 7f9f5a169068a671dff910f34a03e82695f91100
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Aug 19 11:01:15 2014 +0800

    queue level cf default values support

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 6126aad..266b3e7 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1571,6 +1571,16 @@ sub UpdateOption {
     return 1;
 }
 
+sub ObjectHasCustomFieldGrouping {
+    my $self        = shift;
+    my %args        = ( Object => undef, Grouping => undef, @_ );
+    my $object_type = RT::CustomField->_GroupingClass($args{Object});
+    my $groupings   = RT->Config->Get( 'CustomFieldGroupings' );
+    return 0 unless $groupings;
+    return 1 if $groupings->{$object_type} && grep { $_ eq $args{Grouping} } @{ $groupings->{$object_type} };
+    return 0;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 666ca87..bb1c2b2 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -2044,7 +2044,14 @@ sub DefaultValues {
     my $attr = $args{Object}->FirstAttribute('CustomFieldDefaultValues');
     my $values;
     $values = $attr->Content->{$self->id} if $attr && $attr->Content;
-    return $values;
+    return $values if defined $values;
+
+    if ( !$args{Object}->isa( 'RT::System' ) ) {
+        my $system_attr = RT::System->FirstAttribute( 'CustomFieldDefaultValues' );
+        $values = $system_attr->Content->{$self->id} if $system_attr && $system_attr->Content;
+        return $values if defined $values;
+    }
+    return undef;
 }
 
 sub SetDefaultValues {
@@ -2061,6 +2068,13 @@ sub SetDefaultValues {
         $old_values = $old_content->{ $self->id };
     }
 
+    if ( !$args{Object}->isa( 'RT::System' ) && !defined $old_values ) {
+        my $system_attr = RT::System->FirstAttribute( 'CustomFieldDefaultValues' );
+        if ( $system_attr && $system_attr->Content ) {
+            $old_values = $system_attr->Content->{ $self->id };
+        }
+    }
+
     if ( defined $old_values && length $old_values ) {
         $old_values = join ', ', @$old_values if ref $old_values eq 'ARRAY';
     }
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index df6173a..ce96189 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2114,7 +2114,8 @@ sub AddCustomFieldDefaultValues {
     my @msgs;
     while ( my $cf = $cfs->Next ) {
         next if $self->CustomFieldValues($cf->id)->Count || !$cf->SupportDefaultValues;
-        my $values = $cf->DefaultValues( Object => RT->System );
+        my ( $on ) = grep { $_->isa( $cf->RecordClassFromLookupType ) } $cf->ACLEquivalenceObjects;
+        my $values = $cf->DefaultValues( Object => $on || RT->System );
         foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
             next if $self->CustomFieldValueIsEmpty(
                 Field => $cf->id,
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
new file mode 100644
index 0000000..16c50be
--- /dev/null
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -0,0 +1,168 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2014 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 }}}
+<& /Admin/Elements/Header, Title => $title &>
+<& /Elements/Tabs &>
+<& /Elements/ListActions, actions => \@results &>
+
+<form method="post" action="DefaultValues.html" name="ModifyDefaultValues" id="ModifyDefaultValues">
+<input type="hidden" name="id" value="<% $queue->id %>" />
+
+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Basics') ) {
+<div class="ticket-info-basics">
+    <&| /Widgets/TitleBox, title => loc('Basics') &>
+    <table>
+    <& /Elements/EditCustomFields,
+        NamePrefix => 'Default-',
+        Object => RT::Ticket->new($session{CurrentUser}),
+        CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+        Grouping => 'Basics',
+        InTable => 1,
+    &>
+    </table>
+    </&>
+</div>
+% }
+
+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Dates') ) {
+<div class="ticket-info-dates">
+    <&|/Widgets/TitleBox, title => loc("Dates") &>
+    <table>
+    <& /Elements/EditCustomFields,
+        NamePrefix => 'Default-',
+        Object => RT::Ticket->new($session{CurrentUser}),
+        CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+        Grouping => 'Dates',
+        InTable => 1,
+    &>
+    </table>
+    </&>
+</div>
+% }
+
+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'People') ) {
+<div class="ticket-info-people">
+    <&|/Widgets/TitleBox, title => loc("People") &>
+    <table>
+    <& /Elements/EditCustomFields,
+        NamePrefix => 'Default-',
+        Object => RT::Ticket->new($session{CurrentUser}),
+        CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+        Grouping => 'People',
+        InTable => 1,
+    &>
+    </table>
+    </&>
+</div>
+% }
+
+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Links') ) {
+<div class="ticket-info-links">
+    <&|/Widgets/TitleBox, title => loc("Links") &>
+    <table>
+    <& /Elements/EditCustomFields,
+        NamePrefix => 'Default-',
+        Object => RT::Ticket->new($session{CurrentUser}),
+        CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+        Grouping => 'Links',
+        InTable => 1,
+    &>
+    </table>
+    </&>
+</div>
+% }
+
+<& /Elements/EditCustomFieldCustomGroupings, CustomFieldGenerator => sub { $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes }, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}) &>
+
+<div class="ticket-info-cfs">
+    <&|/Widgets/TitleBox, title => loc("Transaction Custom Fields") &>
+    <table>
+    <& /Elements/EditCustomFields, CustomFields => $queue->TicketTransactionCustomFields->LimitToDefaultValuesSupportedTypes, NamePrefix => 'Default-', Object => RT::Transaction->new($session{CurrentUser}), QueueObj => $queue, InTable => 1 &>
+    </table>
+    </&>
+</div>
+
+<& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
+<& /Elements/Submit, Name => 'Reset', Label => loc('Reset Custom Field Values to Default') &>
+</form>
+
+<%INIT>
+my $queue = RT::Queue->new( $session{CurrentUser} );
+$queue->Load($id) || Abort( loc( "Couldn't load object [_1]", $id ) );
+
+my $title = loc( 'Default Values for queue [_1]', $queue->Name );
+
+my @results;
+if ( $ARGS{Reset} ) {
+    my $attr = $queue->FirstAttribute( 'CustomFieldDefaultValues' );
+    if ( $attr ) {
+        $attr->Delete;
+        push @results, "Custom Field default values are reset";
+    }
+}
+elsif ( $ARGS{Update} ) {
+    for my $cf_id ( map { /^Default-(\d+)-/ ? $1 : ()  } keys %ARGS ) {
+        my $cf = RT::CustomField->new($session{CurrentUser});
+        $cf->Load($cf_id);
+        if ( $cf->id && $cf->SupportDefaultValues ) {
+            my ($ret, $msg) = $cf->SetDefaultValues(
+                Object => $queue,
+                Values => $ARGS{'Default-' . $cf->id . '-Value'} // $ARGS{'Default-' . $cf->id . '-Values'},
+            );
+            push @results, $msg;
+        }
+    }
+}
+
+MaybeRedirectForResults(
+    Actions   => \@results,
+    Arguments => { id => $queue->id },
+);
+</%INIT>
+<%ARGS>
+$id => undef
+</%ARGS>
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index d945bac..e4d7316 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -91,7 +91,8 @@ if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
 }
 
 if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
-    $Default = $CustomField->DefaultValues(Object => RT->System);
+    my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
+    $Default = $CustomField->DefaultValues(Object => $on || RT->System);
 }
 
 my $MaxValues = $CustomField->MaxValues;
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 881bace..b2ff96d 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -307,6 +307,7 @@ my $build_admin_menu = sub {
                 $queue->child( 'group-rights' => title => loc('Group Rights'), path => "/Admin/Queues/GroupRights.html?id=".$id );
                 $queue->child( 'user-rights' => title => loc('User Rights'), path => "/Admin/Queues/UserRights.html?id=" . $id );
                 $queue->child( 'history' => title => loc('History'), path => "/Admin/Queues/History.html?id=" . $id );
+                $queue->child( 'default-values' => title => loc('Default Values'), path => "/Admin/Queues/DefaultValues.html?id=" . $id );
 
                 $m->callback( CallbackName => 'PrivilegedQueue', queue_id => $id, page_menu => $queue);
             }

commit 43763320983d87481ae157a3dc316fb05f15aa81
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jun 29 18:00:18 2014 +0800

    clear caches after each web request for tests(thanks to chmrr++)
    
    considering that a txn's ObjectType is RT::Ticket, as we load the ticket object
    in RT::Transaction::UpdateCustomFields(by calling $self->Object), it also
    creates a ticket object cache(e.g. in ticket creation stage), which breaks
    t/web/ticket_owner.t. in that test, the code is like:
    
        my $ticket = RT::Ticket->new( $user_a );
        my ($id, $txn, $msg) = $ticket->Create(
            Queue => $queue->id,
            Subject => 'test',
        );
        ok $id, 'created a ticket #'. $id or diag "error: $msg";
        is $ticket->Owner, RT->Nobody->id, 'correct owner';
    
        $agent_a->goto_ticket( $id );
        $agent_a->follow_link_ok({text => 'Take'}, 'Ticket -> Take');
    
        $ticket = RT::Ticket->new( RT->SystemUser );
        $ticket->Load( $id );
        ok $ticket->id, 'loaded the ticket';
        is $ticket->Owner, $user_a->id, 'correct owner';
    
    so we first create a ticket in the test script process(which also creates a
    cache), then take the ticket via web ui(which belongs to another process).
    after that, in the test script process again, since there is a cache, the last
    owner test fails(it loads the cached one).
    
    this fix gets round this issue by clearing caches after every web request.

diff --git a/lib/RT/Test/Web.pm b/lib/RT/Test/Web.pm
index b5c7229..7c24284 100644
--- a/lib/RT/Test/Web.pm
+++ b/lib/RT/Test/Web.pm
@@ -67,6 +67,12 @@ sub new {
     my $self = $instance = $class->SUPER::new(@args);
     weaken $instance;
     $self->cookie_jar(HTTP::Cookies->new);
+    # Clear our caches of anything that the server process may have done
+    $self->add_handler(
+        response_done => sub {
+            RT::Record->FlushCache;
+        },
+    ) if RT::Record->can( "FlushCache" );
 
     return $self;
 }

commit 6b37a8afb56ca8e70c40de934d553a472be3151e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jun 29 23:39:12 2014 +0800

    no need to clear these caches explicitly
    
    because they are automatically cleared(after web requests).
    see also 4376332

diff --git a/t/web/dashboards-basics.t b/t/web/dashboards-basics.t
index c3533a3..1f7f630 100644
--- a/t/web/dashboards-basics.t
+++ b/t/web/dashboards-basics.t
@@ -120,7 +120,6 @@ $form->value('Searches-body-Available' => $my_tickets );
 $m->click_button(name => 'add');
 $m->content_contains("Dashboard updated");
 
-RT::Record->FlushCache if RT::Record->can('FlushCache');
 $dashboard = RT::Dashboard->new($currentuser);
 $dashboard->LoadById($id);
 
diff --git a/t/web/reminders.t b/t/web/reminders.t
index 98a8d69..f28e1a2 100644
--- a/t/web/reminders.t
+++ b/t/web/reminders.t
@@ -68,7 +68,6 @@ $m->form_name('UpdateReminders');
 $m->field("Reminder-Subject-$reminder_id" => "changed the subject");
 $m->submit;
 
-DBIx::SearchBuilder::Record::Cachable->FlushCache;
 $reminder = RT::Ticket->new($user);
 $reminder->Load($reminder_id);
 is($reminder->Subject, 'changed the subject');
@@ -79,7 +78,6 @@ $m->form_name('UpdateReminders');
 $m->tick("Complete-Reminder-$reminder_id" => 1);
 $m->submit;
 
-DBIx::SearchBuilder::Record::Cachable->FlushCache;
 $reminder = RT::Ticket->new($user);
 $reminder->Load($reminder_id);
 is($reminder->Status, 'resolved');
@@ -101,7 +99,6 @@ $m->goto_ticket($ticket->id);
 $m->form_name('UpdateReminders');
 $m->submit;
 
-DBIx::SearchBuilder::Record::Cachable->FlushCache;
 $reminder = RT::Ticket->new($user);
 $reminder->Load($reminder_id);
 is($reminder->Status, 'resolved');

commit 5971ba1ac1d794c0c6fa665e7089e1129d6e0366
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Aug 19 11:07:40 2014 +0800

    queue-level default values for priority/due
    
    thus we can drop the old InitialPriority/FinalPriority/DefaultDueIn
    
    because the schema changes happen first before the content change in database
    upgrade action, we need to split the upgrade steps across 2 versions:
    
    * in the first version, copy the columns' values into the new attributes
    * in the second version, drop the columns.

diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 58665c7..847adfa 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -29,9 +29,6 @@ CREATE TABLE Queues (
         CommentAddress          VARCHAR2(120),
         Lifecycle               VARCHAR2(32),
         SubjectTag              VARCHAR2(120),
-        InitialPriority         NUMBER(11,0) DEFAULT 0 NOT NULL,
-        FinalPriority           NUMBER(11,0) DEFAULT 0 NOT NULL,
-        DefaultDueIn            NUMBER(11,0) DEFAULT 0 NOT NULL,
         Creator                 NUMBER(11,0) DEFAULT 0 NOT NULL,
         Created                 DATE,
         LastUpdatedBy           NUMBER(11,0) DEFAULT 0 NOT NULL,
diff --git a/etc/schema.Pg b/etc/schema.Pg
index 356441b..c1ef22f 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -52,9 +52,6 @@ CREATE TABLE Queues (
   CommentAddress varchar(120) NULL  ,
   Lifecycle varchar(32) NULL,
   SubjectTag varchar(120) NULL  ,
-  InitialPriority integer NOT NULL DEFAULT 0  ,
-  FinalPriority integer NOT NULL DEFAULT 0  ,
-  DefaultDueIn integer NOT NULL DEFAULT 0  ,
   Creator integer NOT NULL DEFAULT 0  ,
   Created TIMESTAMP NULL  ,
   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index 7ba11f7..b748d85 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -30,9 +30,6 @@ CREATE TABLE Queues (
   CommentAddress varchar(120) collate NOCASE NULL  ,
   Lifecycle varchar(32) collate NOCASE NULL  ,
   SubjectTag varchar(120) collate NOCASE NULL  ,
-  InitialPriority integer NULL DEFAULT 0 ,
-  FinalPriority integer NULL DEFAULT 0 ,
-  DefaultDueIn integer NULL DEFAULT 0 ,
   Creator integer NULL DEFAULT 0 ,
   Created DATETIME NULL  ,
   LastUpdatedBy integer NULL DEFAULT 0 ,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index 21ff5cb..f1458b4 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -26,9 +26,6 @@ CREATE TABLE Queues (
   CommentAddress varchar(120) NULL,
   Lifecycle varchar(32) NULL,
   SubjectTag varchar(120) NULL,
-  InitialPriority integer NOT NULL DEFAULT 0  ,
-  FinalPriority integer NOT NULL DEFAULT 0  ,
-  DefaultDueIn integer NOT NULL DEFAULT 0  ,
   Creator integer NOT NULL DEFAULT 0  ,
   Created DATETIME NULL  ,
   LastUpdatedBy integer NOT NULL DEFAULT 0  ,
diff --git a/etc/upgrade/4.3.2/content b/etc/upgrade/4.3.2/content
new file mode 100644
index 0000000..3cfadfe
--- /dev/null
+++ b/etc/upgrade/4.3.2/content
@@ -0,0 +1,36 @@
+use strict;
+use warnings;
+
+our @Initial = (
+    sub {
+        use RT::Queues;
+        my $queues = RT::Queues->new(RT->SystemUser);
+        $queues->UnLimit;
+        $queues->{'find_disabled_rows'} = 1;
+        while ( my $queue = $queues->Next ) {
+            next if $queue->FirstAttribute('DefaultValues');
+            my %default;
+            for my $priority ( qw/InitialPriority FinalPriority/ ) {
+                $default{$priority} = $queue->__Value($priority) if $queue->__Value($priority);
+            }
+            if ( my $due = $queue->__Value('DefaultDueIn') ) {
+                if ( $due == 1 ) {
+                    $default{Due} = "$due day";
+                }
+                else {
+                    $default{Due} = "$due days";
+                }
+            }
+            if ( %default ) {
+                my ($ret, $msg) = $queue->SetAttribute( Name => 'DefaultValues', Content => \%default );
+                if ( $ret ) {
+                    RT->Logger->debug("updated default values for queue " . $queue->Name);
+                }
+                else {
+                    RT->Logger->error("Can't update default values for queue " . $queue->Name . ': ' . $msg);
+                }
+            }
+        }
+        return 1;
+    },
+);
diff --git a/etc/upgrade/4.3.3/schema.Oracle b/etc/upgrade/4.3.3/schema.Oracle
new file mode 100644
index 0000000..5d6c073
--- /dev/null
+++ b/etc/upgrade/4.3.3/schema.Oracle
@@ -0,0 +1 @@
+ALTER TABLE Queues DROP( InitialPriority, FinalPriority, DefaultDueIn );
diff --git a/etc/upgrade/4.3.3/schema.Pg b/etc/upgrade/4.3.3/schema.Pg
new file mode 100644
index 0000000..530a3be
--- /dev/null
+++ b/etc/upgrade/4.3.3/schema.Pg
@@ -0,0 +1,4 @@
+ALTER TABLE Queues
+    DROP COLUMN InitialPriority,
+    DROP COLUMN FinalPriority,
+    DROP COLUMN DefaultDueIn;
diff --git a/etc/upgrade/4.3.3/schema.mysql b/etc/upgrade/4.3.3/schema.mysql
new file mode 100644
index 0000000..530a3be
--- /dev/null
+++ b/etc/upgrade/4.3.3/schema.mysql
@@ -0,0 +1,4 @@
+ALTER TABLE Queues
+    DROP COLUMN InitialPriority,
+    DROP COLUMN FinalPriority,
+    DROP COLUMN DefaultDueIn;
diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index ea409ea..60e3160 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -146,9 +146,6 @@ Arguments: ARGS is a hash of named parameters.  Valid parameters are:
   Description
   CorrespondAddress
   CommentAddress
-  InitialPriority
-  FinalPriority
-  DefaultDueIn
  
 If you pass the ACL check, it creates the queue and returns its queue id.
 
@@ -164,9 +161,6 @@ sub Create {
         CommentAddress    => '',
         Lifecycle         => 'default',
         SubjectTag        => undef,
-        InitialPriority   => 0,
-        FinalPriority     => 0,
-        DefaultDueIn      => 0,
         Sign              => undef,
         SignAuto          => undef,
         Encrypt           => undef,
@@ -947,60 +941,6 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 =cut
 
 
-=head2 InitialPriority
-
-Returns the current value of InitialPriority. 
-(In the database, InitialPriority is stored as int(11).)
-
-
-
-=head2 SetInitialPriority VALUE
-
-
-Set InitialPriority to VALUE. 
-Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
-(In the database, InitialPriority will be stored as a int(11).)
-
-
-=cut
-
-
-=head2 FinalPriority
-
-Returns the current value of FinalPriority. 
-(In the database, FinalPriority is stored as int(11).)
-
-
-
-=head2 SetFinalPriority VALUE
-
-
-Set FinalPriority to VALUE. 
-Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
-(In the database, FinalPriority will be stored as a int(11).)
-
-
-=cut
-
-
-=head2 DefaultDueIn
-
-Returns the current value of DefaultDueIn. 
-(In the database, DefaultDueIn is stored as int(11).)
-
-
-
-=head2 SetDefaultDueIn VALUE
-
-
-Set DefaultDueIn to VALUE. 
-Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
-(In the database, DefaultDueIn will be stored as a int(11).)
-
-
-=cut
-
-
 =head2 Creator
 
 Returns the current value of Creator. 
@@ -1073,12 +1013,6 @@ sub _CoreAccessible {
         {read => 1, write => 1, sql_type => 12, length => 120,  is_blob => 0,  is_numeric => 0,  type => 'varchar(120)', default => ''},
         Lifecycle => 
         {read => 1, write => 1, sql_type => 12, length => 32,  is_blob => 0, is_numeric => 0,  type => 'varchar(32)', default => 'default'},
-        InitialPriority => 
-        {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
-        FinalPriority => 
-        {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
-        DefaultDueIn => 
-        {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
         Creator => 
         {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
         Created => 
@@ -1159,6 +1093,55 @@ sub PreInflate {
     return 1;
 }
 
+sub DefaultValue {
+    my $self = shift;
+    my $field = shift;
+    my $attr = $self->FirstAttribute('DefaultValues');
+    return undef unless $attr && $attr->Content;
+    return $attr->Content->{$field};
+}
+
+sub SetDefaultValue {
+    my $self = shift;
+    my %args = (
+        Name  => undef,
+        Value => undef,
+        @_
+    );
+    my $field = shift;
+    my $attr = $self->FirstAttribute('DefaultValues');
+
+    my ($old_value, $old_content, $new_value);
+    if ( $attr && $attr->Content ) {
+        $old_content = $attr->Content;
+        $old_value = $old_content->{$args{Name}};
+    }
+
+    unless ( defined $old_value && length $old_value ) {
+        $old_value = $self->loc('(no value)');
+    }
+
+    $new_value = $args{Value};
+    unless ( defined $new_value && length $new_value ) {
+        $new_value = $self->loc( '(no value)' );
+    }
+
+    return 1 if $new_value eq $old_value;
+
+    my ($ret, $msg) = $self->SetAttribute(
+        Name    => 'DefaultValues',
+        Content => {
+            %{ $old_content || {} }, $args{Name} => $args{Value},
+        },
+    );
+
+    if ( $ret ) {
+        return ( $ret, $self->loc( 'Default value of [_1] changed from [_2] to [_3]', $args{Name}, $old_value, $new_value ) );
+    }
+    else {
+        return ( $ret, $self->loc( "Can't change default value of [_1] from [_2] to [_3]: [_4]", $args{Name}, $old_value, $new_value, $msg ) );
+    }
+}
 
 
 RT::Base->_ImportOverlays();
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index f6e24f5..18a6724 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -300,12 +300,12 @@ sub Create {
 
     #Initial Priority
     # If there's no queue default initial priority and it's not set, set it to 0
-    $args{'InitialPriority'} = $QueueObj->InitialPriority || 0
+    $args{'InitialPriority'} = $QueueObj->DefaultValue('InitialPriority') || 0
         unless defined $args{'InitialPriority'};
 
     #Final priority
     # If there's no queue default final priority and it's not set, set it to 0
-    $args{'FinalPriority'} = $QueueObj->FinalPriority || 0
+    $args{'FinalPriority'} = $QueueObj->DefaultValue('FinalPriority') || 0
         unless defined $args{'FinalPriority'};
 
     # Priority may have changed from InitialPriority, for the case
@@ -322,9 +322,8 @@ sub Create {
     if ( defined $args{'Due'} ) {
         $Due->Set( Format => 'ISO', Value => $args{'Due'} );
     }
-    elsif ( my $due_in = $QueueObj->DefaultDueIn ) {
-        $Due->SetToNow;
-        $Due->AddDays( $due_in );
+    elsif ( my $default = $QueueObj->DefaultValue('Due') ) {
+        $Due->Set( Format => 'unknown', Value => $default );
     }
 
     my $Starts = RT::Date->new( $self->CurrentUser );
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 16c50be..92f3da9 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -52,10 +52,19 @@
 <form method="post" action="DefaultValues.html" name="ModifyDefaultValues" id="ModifyDefaultValues">
 <input type="hidden" name="id" value="<% $queue->id %>" />
 
-% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Basics') ) {
 <div class="ticket-info-basics">
     <&| /Widgets/TitleBox, title => loc('Basics') &>
     <table>
+    <tr><td class="label"><&|/l&>Priority</&>:</td>
+    <td><& /Elements/SelectPriority,
+        Name => "InitialPriority",
+        Default => $queue->DefaultValue('InitialPriority'),
+    &></td></tr>
+    <tr><td class="label"><&|/l&>Final Priority</&>:</td>
+    <td><& /Elements/SelectPriority,
+        Name => "FinalPriority",
+        Default => $queue->DefaultValue('FinalPriority'),
+    &><br /><span><em><&|/l&>requires running rt-crontool</&></em></span></td></tr>
     <& /Elements/EditCustomFields,
         NamePrefix => 'Default-',
         Object => RT::Ticket->new($session{CurrentUser}),
@@ -66,12 +75,11 @@
     </table>
     </&>
 </div>
-% }
 
-% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Dates') ) {
 <div class="ticket-info-dates">
     <&|/Widgets/TitleBox, title => loc("Dates") &>
     <table>
+    <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $queue->DefaultValue('Due') || '' &></td></tr>
     <& /Elements/EditCustomFields,
         NamePrefix => 'Default-',
         Object => RT::Ticket->new($session{CurrentUser}),
@@ -82,7 +90,6 @@
     </table>
     </&>
 </div>
-% }
 
 % if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'People') ) {
 <div class="ticket-info-people">
@@ -145,6 +152,13 @@ if ( $ARGS{Reset} ) {
     }
 }
 elsif ( $ARGS{Update} ) {
+    for my $field ( qw/InitialPriority FinalPriority Due/ ) {
+        my ($ret, $msg) = $queue->SetDefaultValue(
+            Name => $field,
+            Value => $ARGS{$field},
+        );
+        push @results, $msg;
+    }
     for my $cf_id ( map { /^Default-(\d+)-/ ? $1 : ()  } keys %ARGS ) {
         my $cf = RT::CustomField->new($session{CurrentUser});
         $cf->Load($cf_id);
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index f497e6c..f89a376 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -92,22 +92,6 @@
 <br /><span><em><&|/l , RT->Config->Get('CommentAddress')&>(If left blank, will default to [_1])</&></em></span></td>
 </tr>
 
-<tr><td align="right"><&|/l&>Priority starts at</&>:</td>
-<td><& /Elements/SelectPriority,
-    Name => "InitialPriority",
-    Default => $Create? 0: $QueueObj->InitialPriority || $InitialPriority,
-&></td>
-<td align="right"><&|/l&>Over time, priority moves toward</&>:</td>
-<td><& /Elements/SelectPriority,
-    Name => "FinalPriority",
-    Default => $Create? 0: $QueueObj->FinalPriority || $FinalPriority,
-&><br /><span><em><&|/l&>requires running rt-crontool</&></em></span></td>
-</tr>
-
-<tr><td align="right"><&|/l&>Requests should be due in</&>:</td>
-<td colspan="3"><input name="DefaultDueIn" value="<% ($Create) ? "" : $QueueObj->DefaultDueIn || $DefaultDueIn || "" %>" /> <&|/l&>days</&>.</td>
-</tr>
-
 % my $CFs = $QueueObj->CustomFields;
 % while (my $CF = $CFs->Next) {
 <tr valign="top"><td align="right">
@@ -192,7 +176,7 @@ unless ($Create) {
 if ( $QueueObj->Id ) {
     $title = loc('Configuration for queue [_1]', $QueueObj->Name );
     my @attribs= qw(Description CorrespondAddress CommentAddress Name
-        InitialPriority FinalPriority DefaultDueIn Sign SignAuto Encrypt Lifecycle SubjectTag Disabled);
+        Sign SignAuto Encrypt Lifecycle SubjectTag Disabled);
 
     # we're asking about enabled on the web page but really care about disabled
     if ( $SetEnabled ) {
@@ -260,9 +244,6 @@ $Create => undef
 $Description => undef
 $CorrespondAddress => undef
 $CommentAddress => undef
-$InitialPriority => undef
-$FinalPriority => undef
-$DefaultDueIn => undef
 $SetEnabled => undef
 $SetCrypt => undef
 $Enabled => undef
diff --git a/share/html/Admin/Queues/index.html b/share/html/Admin/Queues/index.html
index 8bfb691..506dce6 100644
--- a/share/html/Admin/Queues/index.html
+++ b/share/html/Admin/Queues/index.html
@@ -57,7 +57,7 @@
 % }
 
 <select name="QueueField">
-% foreach my $col (qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn Lifecycle SubjectTag)) {
+% foreach my $col (qw(Name Description CorrespondAddress CommentAddress Lifecycle SubjectTag)) {
 <option <% $QueueField eq $col ? 'selected="selected"' : '' |n %> value="<% $col %>"><% loc($col) %></option>
 % }
 </select>
diff --git a/share/html/Elements/RT__Queue/ColumnMap b/share/html/Elements/RT__Queue/ColumnMap
index 3bb47ab..69b7506 100644
--- a/share/html/Elements/RT__Queue/ColumnMap
+++ b/share/html/Elements/RT__Queue/ColumnMap
@@ -57,9 +57,21 @@ my $COLUMN_MAP = {
         attribute => 'Disabled',
         value     => sub { return $_[0]->Disabled? $_[0]->loc('Disabled'): $_[0]->loc('Enabled') },
     },
+    InitialPriority => {
+        title     => 'InitialPriority', # loc
+        value     => sub { $_[0]->DefaultValue('InitialPriority') || '' },
+    },
+    FinalPriority => {
+        title     => 'FinalPriority', # loc
+        value     => sub { $_[0]->DefaultValue('FinalPriority') || '' },
+    },
     Priority => {
         title     => 'Priority', # loc
-        value     => sub { return $_[0]->InitialPriority .'-'. $_[0]->FinalPriority },
+        value     => sub { return join '-', $_[0]->DefaultValue('InitialPriority') || '', $_[0]->DefaultValue('FinalPriority') || '' },
+    },
+    DefaultDueIn => {
+        title     => 'DefaultDueIn', # loc
+        value     => sub { return $_[0]->DefaultValue('Due') || '' },
     },
     Address  => {
         title     => 'Address', # loc
@@ -97,7 +109,6 @@ my $COLUMN_MAP = {
 
 foreach my $field (qw(
     Name Description CorrespondAddress CommentAddress
-    InitialPriority FinalPriority DefaultDueIn
 )) {
     $COLUMN_MAP->{$field} = {
         title => $field,
diff --git a/share/html/REST/1.0/Forms/queue/default b/share/html/REST/1.0/Forms/queue/default
index cef67cd..3c21411 100644
--- a/share/html/REST/1.0/Forms/queue/default
+++ b/share/html/REST/1.0/Forms/queue/default
@@ -60,7 +60,7 @@ my %data = %$changes;
 my $queue = RT::Queue->new($session{CurrentUser});
 
 my @fields =
-  qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn Disabled);
+  qw(Name Description CorrespondAddress CommentAddress Disabled);
 if ( $fields && %$fields ) {
     @fields = grep { exists $fields->{ lc $_ } } @fields;
 }
@@ -84,9 +84,6 @@ else {
                 Description => "",
                 CommentAddress => "",
                 CorrespondAddress => "",
-                InitialPriority => "",
-                FinalPriority => "",
-                DefaultDueIn => "",
             },
             0
         ];
diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index b84980d..bdc6777 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -103,8 +103,13 @@ else {
         my $queue = RT::Queue->new($session{CurrentUser});
         my $starts = RT::Date->new($session{CurrentUser});
         $queue->Load(1);
-        $due->SetToNow;
-        $due->AddDays($queue->DefaultDueIn) if $queue->DefaultDueIn;
+        if ( $queue->DefaultValue('Due') ) {
+            $due->Set( Format => 'unknown', Value => $queue->DefaultValue('Due') );
+        }
+        else {
+            $due->SetToNow;
+        }
+
         $starts->SetToNow;
 
         return [
@@ -120,9 +125,9 @@ else {
                 AdminCc          => [],
                 Owner            => "",
                 Status           => "new",
-                Priority         => $queue->InitialPriority,
-                InitialPriority  => $queue->InitialPriority,
-                FinalPriority    => $queue->FinalPriority,
+                Priority         => $queue->DefaultValue('InitialPriority'),
+                InitialPriority  => $queue->DefaultValue('InitialPriority'),
+                FinalPriority    => $queue->DefaultValue('FinalPriority'),
                 TimeEstimated    => 0,
                 Starts           => $starts->ISO,
                 Due              => $due->ISO,
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index e1a2ea3..7a5c4aa 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -225,12 +225,12 @@
 <tr><td class="label"><&|/l&>Priority</&>:</td>
 <td><& /Elements/SelectPriority,
     Name => "InitialPriority",
-    Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
+    Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->DefaultValue('InitialPriority'),
 &></td></tr>
 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
 <td><& /Elements/SelectPriority,
     Name => "FinalPriority",
-    Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
+    Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->DefaultValue('FinalPriority'),
 &></td></tr>
 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
 <td>
@@ -256,7 +256,7 @@
 
 <table>
 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
-<tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
+<tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || $QueueObj->DefaultValue('Due') || '' &></td></tr>
 <& /Elements/EditCustomFields,
     %ARGS,
     Object => $ticket,
diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
index 42ebbec..d54390f 100644
--- a/share/html/m/ticket/create
+++ b/share/html/m/ticket/create
@@ -342,12 +342,12 @@ $showrows->(
     loc("Priority") => $m->scomp(
         "/Elements/SelectPriority",
         Name    => "InitialPriority",
-        Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
+        Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->DefaultValue('InitialPriority'),
     ),
     loc("Final Priority") => $m->scomp(
         "/Elements/SelectPriority",
         Name    => "FinalPriority",
-        Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
+        Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->DefaultValue('FinalPriority'),
     ),
 
     loc("Time Estimated") => '<span class="timefield">'.$m->scomp(
@@ -381,7 +381,7 @@ $showrows->(
 <%perl>
 $showrows->(
     loc("Starts") => $m->scomp( "/Elements/SelectDate", Name => "Starts", Default => ( $ARGS{Starts} || '' )),
-    loc("Due")    => $m->scomp( "/Elements/SelectDate", Name => "Due",    Default => ($ARGS{Due}    || '' ))
+    loc("Due")    => $m->scomp( "/Elements/SelectDate", Name => "Due",    Default => ($ARGS{Due} || $QueueObj->DefaultValue('Due') || '' ))
 );
 
 </%perl>

commit 7d87a78217366619dacfa0a50b49170fb8963d47
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jun 29 20:20:55 2014 +0800

    queue level default value for Starts

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 18a6724..5782cc3 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -330,6 +330,9 @@ sub Create {
     if ( defined $args{'Starts'} ) {
         $Starts->Set( Format => 'ISO', Value => $args{'Starts'} );
     }
+    elsif ( my $default = $QueueObj->DefaultValue('Starts') ) {
+        $Starts->Set( Format => 'unknown', Value => $default );
+    }
 
     my $Started = RT::Date->new( $self->CurrentUser );
     if ( defined $args{'Started'} ) {
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 92f3da9..cc67e51 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -79,6 +79,7 @@
 <div class="ticket-info-dates">
     <&|/Widgets/TitleBox, title => loc("Dates") &>
     <table>
+    <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $queue->DefaultValue('Starts') || '' &></td></tr>
     <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $queue->DefaultValue('Due') || '' &></td></tr>
     <& /Elements/EditCustomFields,
         NamePrefix => 'Default-',
@@ -152,7 +153,7 @@ if ( $ARGS{Reset} ) {
     }
 }
 elsif ( $ARGS{Update} ) {
-    for my $field ( qw/InitialPriority FinalPriority Due/ ) {
+    for my $field ( qw/InitialPriority FinalPriority Starts Due/ ) {
         my ($ret, $msg) = $queue->SetDefaultValue(
             Name => $field,
             Value => $ARGS{$field},
diff --git a/share/html/Elements/RT__Queue/ColumnMap b/share/html/Elements/RT__Queue/ColumnMap
index 69b7506..0651b64 100644
--- a/share/html/Elements/RT__Queue/ColumnMap
+++ b/share/html/Elements/RT__Queue/ColumnMap
@@ -73,6 +73,10 @@ my $COLUMN_MAP = {
         title     => 'DefaultDueIn', # loc
         value     => sub { return $_[0]->DefaultValue('Due') || '' },
     },
+    DefaultStarts => {
+        title     => 'DefaultStarts', # loc
+        value     => sub { return $_[0]->DefaultValue('Starts') || '' },
+    },
     Address  => {
         title     => 'Address', # loc
         value     => sub { return ($_[0]->CorrespondAddress||'-') .'/'. ($_[0]->CommentAddress||'-') },
diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index bdc6777..271bb0b 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -110,7 +110,12 @@ else {
             $due->SetToNow;
         }
 
-        $starts->SetToNow;
+        if ( $queue->DefaultValue('Starts') ) {
+            $starts->Set( Format => 'unknown', Value => $queue->DefaultValue('Starts') );
+        }
+        else {
+            $starts->SetToNow;
+        }
 
         return [
             "# Required: id, Queue",
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 7a5c4aa..d7323bd 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -255,7 +255,7 @@
   color => "#663366" &>
 
 <table>
-<tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
+<tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || $QueueObj->DefaultValue('Starts') || '' &></td></tr>
 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || $QueueObj->DefaultValue('Due') || '' &></td></tr>
 <& /Elements/EditCustomFields,
     %ARGS,
diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
index d54390f..3524b41 100644
--- a/share/html/m/ticket/create
+++ b/share/html/m/ticket/create
@@ -380,7 +380,7 @@ $showrows->(
 
 <%perl>
 $showrows->(
-    loc("Starts") => $m->scomp( "/Elements/SelectDate", Name => "Starts", Default => ( $ARGS{Starts} || '' )),
+    loc("Starts") => $m->scomp( "/Elements/SelectDate", Name => "Starts", Default => ( $ARGS{Starts} || $QueueObj->DefaultValue('Starts') || '' )),
     loc("Due")    => $m->scomp( "/Elements/SelectDate", Name => "Due",    Default => ($ARGS{Due} || $QueueObj->DefaultValue('Due') || '' ))
 );
 

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


More information about the rt-commit mailing list