[Rt-commit] rt branch, 4.4/cf-default-values, created. rt-4.2.3-208-gbbbece1

? sunnavy sunnavy at bestpractical.com
Fri Jun 20 11:25:32 EDT 2014


The branch, 4.4/cf-default-values has been created
        at  bbbece1fbd0556792c10e5478f7c9130100a62f1 (commit)

- Log -----------------------------------------------------------------
commit 555e1a6ed8bf484943bbaa7accf77e5bb25abe06
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jun 11 00:01:02 2014 +0800

    added ticket cf global default values support

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 49e386f..9fa9a37 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1884,9 +1884,116 @@ sub BasedOnObj {
 }
 
 
+sub SupportDefaultValues {
+    my $self = shift;
+    return 0 unless $self->id;
+    return 0 unless $self->LookupType =~ /RT::Ticket$/;
+    return $self->Type !~ /^(?:Image|Binary)$/;
+}
+
+sub DefaultValues {
+    my $self = shift;
+    my %args = (
+        Object => RT->System,
+        @_,
+    );
+    my $attr = $args{Object}->FirstAttribute('CustomFieldDefaultValues');
+    return $attr->Content->{$self->id} if $attr && $attr->Content;
+    return undef;
+}
+
+sub SetDefaultValues {
+    my $self = shift;
+    my %args = (
+        Object => RT->System,
+        Values => undef,
+        @_,
+    );
+    my $attr = $args{Object}->FirstAttribute( 'CustomFieldDefaultValues' );
+    my ( $old_content, $old_values );
+    $old_content = $attr->Content if $attr && $attr->Content;
+    $old_values = $old_content->{ $self->id } if $old_content;
+
+    my $ret = $args{Object}->SetAttribute(
+        Name    => 'CustomFieldDefaultValues',
+        Content => {
+            %{ $old_content || {} }, $self->id => $args{Values},
+        },
+    );
+
+    if ( defined $old_values && length $old_values ) {
+        $old_values = join ', ', @$old_values if ref $old_values eq 'ARRAY';
+    }
+    else {
+        $old_values = $self->loc('(no value)');
+    }
 
+    my $new_values = $args{Values};
+    if ( defined $new_values && length $new_values ) {
+        $new_values = join ', ', @$new_values if ref $new_values eq 'ARRAY';
+    }
+    else {
+        $new_values = $self->loc( '(no value)' );
+    }
+
+    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]", $old_values, $new_values ) );
+    }
+}
 
+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' ) {
+        @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 && $self->Type eq 'Select' ) {
+                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 {
+            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..87092cc 100644
--- a/lib/RT/CustomFieldValue.pm
+++ b/lib/RT/CustomFieldValue.pm
@@ -119,6 +119,16 @@ sub _Set {
     return $self->SUPER::_Set( @_ ); 
 } 
 
+sub SetName {
+    my $self = shift;
+    my $value = shift;
+    my ( $ret, $msg ) = $self->_Set(
+        Field => 'Name',
+        Value => $value,
+    );
+
+    return ( $ret, $msg );
+}
 
 =head2 id
 
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 42abbca..f9e901c 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -468,11 +468,13 @@ sub Create {
     }
 
     # Add all the custom fields
+    my %cf_added;
     foreach my $arg ( keys %args ) {
         next unless $arg =~ /^CustomField-(\d+)$/i;
         my $cfid = $1;
         my $cf = $self->LoadCustomFieldByIdentifier($cfid);
         next unless $cf->ObjectTypeFromLookupType->isa(ref $self);
+        $cf_added{$cfid}++;
 
         foreach my $value (
             UNIVERSAL::isa( $args{$arg} => 'ARRAY' ) ? @{ $args{$arg} } : ( $args{$arg} ) )
@@ -495,6 +497,25 @@ sub Create {
         }
     }
 
+    my $cfs = $self->QueueObj->TicketCustomFields;
+    while ( my $cf = $cfs->Next ) {
+        next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
+        my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+        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 @non_fatal_errors, $msg unless $status;
+        }
+    }
+
     # Deal with setting up links
 
     # TODO: Adding link may fire scrips on other end and those scrips
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index eea4532..34d6908 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">
@@ -230,6 +238,7 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
         Object        => $CustomFieldObj,
         ARGSRef       => \%ARGS
     );
+
     if ( ($ValuesClass||'RT::CustomFieldValues') ne $CustomFieldObj->ValuesClass ) {
         my $original = $CustomFieldObj->ValuesClass;
         my ($good, $msg) = $CustomFieldObj->SetValuesClass( $ValuesClass );
@@ -267,6 +276,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 ) {
@@ -308,6 +325,7 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
         $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
 CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
     }
+    $CustomFieldObj->CleanupDefaultValues;
 }
 
 if ( $CustomFieldObj->id && $CustomFieldObj->IsOnlyGlobal ) {
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 0b36592..585c048 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;
+}
+
 my $MaxValues = $CustomField->MaxValues;
 if ($MaxValues == 1 && $Values) {
     # what exactly is this doing?  Without the "unless" it breaks RTFM
diff --git a/share/html/Elements/EditCustomFieldCombobox b/share/html/Elements/EditCustomFieldCombobox
index 259859e..81e9e06 100644
--- a/share/html/Elements/EditCustomFieldCombobox
+++ b/share/html/Elements/EditCustomFieldCombobox
@@ -45,6 +45,8 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+% $Name ||= $NamePrefix . $CustomField->Id . ( $Multiple ? '-Values' : '-Value' );
+
 % while ($Values and my $value = $Values->Next and $Multiple) {
 <input type="checkbox" id="<%$delete_name%>" class="checkbox CF-<%$CustomField->id%>-Edit" name="<%$delete_name%>" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" />
 <label for="<%$delete_name%>"><% $value->Content %></label>
diff --git a/share/html/Elements/EditCustomFieldFreeform b/share/html/Elements/EditCustomFieldFreeform
index 4280172..fd8dd97 100644
--- a/share/html/Elements/EditCustomFieldFreeform
+++ b/share/html/Elements/EditCustomFieldFreeform
@@ -69,6 +69,8 @@ if ( $Multiple and $Values ) {
 unless ( $Multiple ) {
     $Default =~ s/\s*\n+\s*/ /g if $Default;
 }
+
+$Default = join "\n", @$Default if $Default && ref $Default eq 'ARRAY';
 </%INIT>
 <%ARGS>
 $Object => undef

commit 2dd02eb5e5d52a92784b2a86040897fd2da45c50
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jun 15 11:54:35 2014 +0800

    queue-level default custom fields

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 9fa9a37..827db85 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1898,7 +1898,15 @@ sub DefaultValues {
         @_,
     );
     my $attr = $args{Object}->FirstAttribute('CustomFieldDefaultValues');
-    return $attr->Content->{$self->id} if $attr && $attr->Content;
+    my $values;
+    $values = $attr->Content->{$self->id} if $attr && $attr->Content;
+    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;
 }
 
@@ -1910,16 +1918,18 @@ sub SetDefaultValues {
         @_,
     );
     my $attr = $args{Object}->FirstAttribute( 'CustomFieldDefaultValues' );
-    my ( $old_content, $old_values );
-    $old_content = $attr->Content if $attr && $attr->Content;
-    $old_values = $old_content->{ $self->id } if $old_content;
+    my ( $old_values, $old_content, $new_values );
+    if ( $attr && $attr->Content ) {
+        $old_content = $attr->Content;
+        $old_values = $old_content->{ $self->id };
+    }
 
-    my $ret = $args{Object}->SetAttribute(
-        Name    => 'CustomFieldDefaultValues',
-        Content => {
-            %{ $old_content || {} }, $self->id => $args{Values},
-        },
-    );
+    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';
@@ -1928,7 +1938,7 @@ sub SetDefaultValues {
         $old_values = $self->loc('(no value)');
     }
 
-    my $new_values = $args{Values};
+    $new_values = $args{Values};
     if ( defined $new_values && length $new_values ) {
         $new_values = join ', ', @$new_values if ref $new_values eq 'ARRAY';
     }
@@ -1936,6 +1946,15 @@ sub SetDefaultValues {
         $new_values = $self->loc( '(no value)' );
     }
 
+    return 1 if $new_values eq $old_values;
+
+    my $ret = $args{Object}->SetAttribute(
+        Name    => 'CustomFieldDefaultValues',
+        Content => {
+            %{ $old_content || {} }, $self->id => $args{Values},
+        },
+    );
+
     if ( $ret ) {
         return ( $ret, $self->loc( 'Default values changed from [_1] to [_2]', $old_values, $new_values ) );
     }
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index f9e901c..bc14fdb 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -500,7 +500,7 @@ sub Create {
     my $cfs = $self->QueueObj->TicketCustomFields;
     while ( my $cf = $cfs->Next ) {
         next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
-        my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+        my $values = $cf->DefaultValues(Object => $self->QueueObj);
         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..c6f2a1d
--- /dev/null
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -0,0 +1,84 @@
+%# 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 %>" />
+<h2><&|/l&>Ticket Custom Fields</&></h2>
+<& /Elements/EditCustomFields, CustomFields => $ticket_cfs, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}), QueueObj => $queue &>
+
+<& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
+</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 $ticket_cfs = $queue->TicketCustomFields;
+
+my @results;
+if ( $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;
+        }
+    }
+}
+</%INIT>
+<%ARGS>
+$id => undef
+</%ARGS>
diff --git a/share/html/Elements/AddLinks b/share/html/Elements/AddLinks
index 74b2372..fddb331 100644
--- a/share/html/Elements/AddLinks
+++ b/share/html/Elements/AddLinks
@@ -95,6 +95,7 @@ $exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;
     <td class="entry"> <input name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" <% $exclude |n%>/></td>
   </tr>
   <& /Elements/EditCustomFields,
+        %ARGS,
         Object          => $Object,
         Grouping        => 'Links',
         InTable         => 1,
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 585c048..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;
+    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 0b3a50e..fb435b4 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 d7706ce648362d2674db23d98ddaa016fd76c118
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 12 19:15:43 2014 +0800

    queue-level default values for priority/starts/due
    
    with this, we can drop the old InitialPriority/FinalPriority/DefaultDueIn

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 2876d90..bddfc2d 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2905,7 +2905,7 @@ Set(%AdminSearchResultFormat,
     Queues =>
         q{'<a href="__WebPath__/Admin/Queues/Modify.html?id=__id__">__id__</a>/TITLE:#'}
         .q{,'<a href="__WebPath__/Admin/Queues/Modify.html?id=__id__">__Name__</a>/TITLE:Name'}
-        .q{,__Description__,__Address__,__Priority__,__DefaultDueIn__,__Disabled__,__Lifecycle__},
+        .q{,__Description__,__Address__,__Disabled__,__Lifecycle__},
 
     Groups =>
         q{'<a href="__WebPath__/Admin/Groups/Modify.html?id=__id__">__id__</a>/TITLE:#'}
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 1030eb2..b91696a 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..1130ec6
--- /dev/null
+++ b/etc/upgrade/4.3.2/content
@@ -0,0 +1,31 @@
+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 ) {
+                $queue->SetAttribute( Name => 'DefaultValues', Content => \%default );
+                RT->Logger->warning("updated default values for queue " . $queue->Name);
+            }
+        }
+        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 6ca78c4..cd7fca0 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,
@@ -943,60 +937,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. 
@@ -1069,12 +1009,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 => 
@@ -1155,6 +1089,56 @@ sub PreInflate {
     return 1;
 }
 
+sub DefaultValue {
+    my $self = shift;
+    my $field = shift;
+    return undef unless $field =~ /^(?:(?:Initial|Final)Priority|Due|Starts)$/;
+    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 = $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]", $args{Name}, $old_value, $new_value ) );
+    }
+}
 
 
 RT::Base->_ImportOverlays();
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index bc14fdb..a766d00 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,15 +322,17 @@ 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 );
     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 c6f2a1d..28b389a 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -51,6 +51,23 @@
 
 <form method="post" action="DefaultValues.html" name="ModifyDefaultValues" id="ModifyDefaultValues">
 <input type="hidden" name="id" value="<% $queue->id %>" />
+
+<h2><&|/l&>Core Fields</&></h2>
+<table border="0">
+<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>
+<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>
+</table>
+
 <h2><&|/l&>Ticket Custom Fields</&></h2>
 <& /Elements/EditCustomFields, CustomFields => $ticket_cfs, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}), QueueObj => $queue &>
 
@@ -66,6 +83,14 @@ my $ticket_cfs = $queue->TicketCustomFields;
 
 my @results;
 if ( $ARGS{Update} ) {
+    for my $field ( qw/InitialPriority FinalPriority Starts 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 2957465..e0f5c64 100644
--- a/share/html/Admin/Queues/index.html
+++ b/share/html/Admin/Queues/index.html
@@ -76,7 +76,7 @@
 % }
 
 <select name="QueueField">
-% foreach my $col (qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn)) {
+% foreach my $col (qw(Name Description CorrespondAddress CommentAddress FinalPriority )) {
 <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 7183871..266dce8 100644
--- a/share/html/Elements/RT__Queue/ColumnMap
+++ b/share/html/Elements/RT__Queue/ColumnMap
@@ -57,10 +57,6 @@ my $COLUMN_MAP = {
         attribute => 'Disabled',
         value     => sub { return $_[0]->Disabled? $_[0]->loc('Disabled'): $_[0]->loc('Enabled') },
     },
-    Priority => {
-        title     => 'Priority', # loc
-        value     => sub { return $_[0]->InitialPriority .'-'. $_[0]->FinalPriority },
-    },
     Address  => {
         title     => 'Address', # loc
         value     => sub { return ($_[0]->CorrespondAddress||'-') .'/'. ($_[0]->CommentAddress||'-') },
@@ -98,7 +94,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 fd3e3c0..a3658f6 100644
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -104,7 +104,9 @@ else {
         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 => 'ISO', Value => $queue->DefaultValue('Due') );
+        }
         $starts->SetToNow;
 
         return [
@@ -120,9 +122,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 57e66df..a0f6fa2 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>
@@ -255,8 +255,8 @@
   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&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></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,
     Object => $ticket,
diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
index af25bd0..fa760c6 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(

commit d5293aef4617934d137a4002e548c348c9c8dbd9
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Jun 15 19:31:15 2014 +0800

    make default values page be like ticket create or display pages
    
    i.e. split fields into various widgets(including custom groupings)
    
    also add Reset button so we can reset cf valus to system default

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/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 28b389a..5c37ef7 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -52,26 +52,83 @@
 <form method="post" action="DefaultValues.html" name="ModifyDefaultValues" id="ModifyDefaultValues">
 <input type="hidden" name="id" value="<% $queue->id %>" />
 
-<h2><&|/l&>Core Fields</&></h2>
-<table border="0">
-<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>
-<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>
-</table>
+<div class="ticket-info-basics">
+    <&| /Widgets/TitleBox, title => loc('Basics') &>
+    <table border="0">
+    <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}),
+        CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+        Grouping => 'Basics',
+        InTable => 1,
+    &>
+    </table>
+    </&>
+</div>
 
-<h2><&|/l&>Ticket Custom Fields</&></h2>
-<& /Elements/EditCustomFields, CustomFields => $ticket_cfs, NamePrefix => 'Default-', Object => RT::Ticket->new($session{CurrentUser}), QueueObj => $queue &>
+<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-',
+        Object => RT::Ticket->new($session{CurrentUser}),
+        CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
+        Grouping => 'Dates',
+        InTable => 1,
+    &>
+    </table>
+    </&>
+</div>
+
+% my $groupings = RT->Config->Get('CustomFieldGroupings');
+% if ( $groupings && $groupings->{'RT::Ticket'} && grep { $_ eq 'People' } @{$groupings->{'RT::Ticket'}} ) {
+<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 ( $groupings && $groupings->{'RT::Ticket'} && grep { $_ eq 'Links' } @{$groupings->{'RT::Ticket'}} ) {
+<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}) &>
 
 <& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
+<& /Elements/Submit, Name => 'Reset', Label => loc('Reset Custom Field Values to Default') &>
 </form>
 
 <%INIT>
@@ -79,10 +136,16 @@ 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 $ticket_cfs = $queue->TicketCustomFields;
 
 my @results;
-if ( $ARGS{Update} ) {
+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 $field ( qw/InitialPriority FinalPriority Starts Due/ ) {
         my ($ret, $msg) = $queue->SetDefaultValue(
             Name => $field,
@@ -103,6 +166,11 @@ if ( $ARGS{Update} ) {
         }
     }
 }
+
+MaybeRedirectForResults(
+    Actions   => \@results,
+    Arguments => { id => $queue->id },
+);
 </%INIT>
 <%ARGS>
 $id => undef

commit d261f620fabf1b1b541abae3712f271e14342191
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 003109b..13da46b 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 bbbece1fbd0556792c10e5478f7c9130100a62f1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jun 20 21:22:06 2014 +0800

    allow default values for txn cfs
    
    I got an interesting cache issue when implementing this:
    
    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).
    
    I got around this by explicitly clearing the cache in
    RT::Transaction::UpdateCustomFields to get back compatibility.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 827db85..a867044 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1887,7 +1887,7 @@ sub BasedOnObj {
 sub SupportDefaultValues {
     my $self = shift;
     return 0 unless $self->id;
-    return 0 unless $self->LookupType =~ /RT::Ticket$/;
+    return 0 unless $self->LookupType =~ /RT::(?:Ticket|Transaction)$/;
     return $self->Type !~ /^(?:Image|Binary)$/;
 }
 
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index f6329b5..1e43ea5 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1398,6 +1398,7 @@ sub UpdateCustomFields {
         $args = \%args;
     }
 
+    my %cf_added;
     foreach my $arg ( keys %$args ) {
         next
           unless ( $arg =~
@@ -1407,6 +1408,7 @@ sub UpdateCustomFields {
         my $values = $args->{$arg};
         my $cf = $self->LoadCustomFieldByIdentifier($cfid);
         next unless $cf->ObjectTypeFromLookupType->isa(ref $self);
+        $cf_added{$cfid}++;
         foreach
           my $value ( UNIVERSAL::isa( $values, 'ARRAY' ) ? @$values : $values )
         {
@@ -1421,6 +1423,25 @@ sub UpdateCustomFields {
             );
         }
     }
+
+    my $cfs = $self->Object->TransactionCustomFields;
+    while ( my $cf = $cfs->Next ) {
+        next if $cf_added{$cf->id} || !$cf->SupportDefaultValues;
+        my $values = $cf->DefaultValues(Object => RT->System); # TODO support queue-level default values
+        foreach my $value ( UNIVERSAL::isa( $values => 'ARRAY' ) ? @$values : $values ) {
+            next if $self->CustomFieldValueIsEmpty(
+                Field => $cf->id,
+                Value => $value,
+            );
+
+            $self->_AddCustomFieldValue(
+                Field             => $cf->id,
+                Value             => $value,
+                RecordTransaction => 0,
+            );
+        }
+    }
+    $self->Object->_expire if $self->Object->can('_expire');
 }
 
 =head2 LoadCustomFieldByIdentifier
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 5c37ef7..5397565 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -72,6 +72,7 @@
         Grouping => 'Basics',
         InTable => 1,
     &>
+    <& /Elements/EditCustomFields, CustomFields => $queue->TicketTransactionCustomFields->LimitToDefaultValuesSupportedTypes, NamePrefix => 'Default-', Object => RT::Transaction->new($session{CurrentUser}), QueueObj => $queue &>
     </table>
     </&>
 </div>

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


More information about the rt-commit mailing list