TimeWorked-like custom fields, RT#11168
[freeside.git] / rt / share / html / Admin / CustomFields / Modify.html
index f75607a..5ef3212 100644 (file)
@@ -1,40 +1,40 @@
 %# BEGIN BPS TAGGED BLOCK {{{
-%# 
+%#
 %# COPYRIGHT:
-%# 
-%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
-%#                                          <jesse@bestpractical.com>
-%# 
+%#
+%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%#                                          <sales@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
@@ -43,7 +43,7 @@
 %# 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 &>
 <& /Admin/Elements/CustomFieldTabs,
         Default => $CustomFieldObj->LookupType, &>
 </td></tr>
 
+% if ( $CustomFieldObj->Id 
+%     and $CustomFieldObj->LookupType =~ /RT::Transaction/ ) {
+<tr><td class="label"><&|/l&>Display&nbsp;with</&></td>
+<td><& /Admin/Elements/EditCustomFieldUILocation,
+        CustomField => $CustomFieldObj &>
+</td></tr>
+% }
+
 <tr><td class="label"><&|/l&>Validation</&></td>
 <td><& /Widgets/ComboBox,
     Name    => 'Pattern',
 % }
 
 <tr><td class="label">&nbsp;</td><td>
+<input type="checkbox" class="checkbox" name="Required" value="1" <% $RequiredChecked |n%> />
+<&|/l&>Required for ticket resolution</&>
+</td></tr>
+
+<tr><td class="label">&nbsp;</td><td>
 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
 <input type="checkbox" class="checkbox" name="Enabled" value="1" <% $EnabledChecked |n%> />
 <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
@@ -171,11 +184,12 @@ else {
 }
 
 if ( $ARGS{'Update'} && $id ne 'new' ) {
-
     #we're asking about enabled on the web page but really care about disabled.
     $ARGS{'Disabled'} = $Disabled = $Enabled? 0 : 1;
+   
+    $ARGS{'Required'} ||= 0;
 
-    my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
+    my @attribs = qw(Disabled Required Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
     push @results, UpdateRecordObject(
         AttributesRef => \@attribs,
         Object        => $CustomFieldObj,
@@ -185,6 +199,8 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
 
     $CustomFieldObj->SetBasedOn( $BasedOn );
 
+    $CustomFieldObj->SetUILocation( $UILocation );
+
     my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
     # Delete any fields that want to be deleted
     foreach my $key ( keys %ARGS ) {
@@ -193,14 +209,24 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
         push (@results, $msg);
     }
 
+    # Clean up values
+    foreach my $param (grep /^$paramtag-/, keys(%ARGS)) {
+      for ($ARGS{$param}) {
+        s/\r+\n/\n/g;
+        s/^\s+//;
+        s/\s+$//;
+      }
+    }
+
     # Update any existing values
     my $values = $CustomFieldObj->ValuesObj;
     while ( my $value = $values->Next ) {
         foreach my $attr qw(Name Description SortOrder Category) {
             my $param = join("-", $paramtag, $value->Id, $attr);
             next unless exists $ARGS{$param};
+            $ARGS{$param} =~ s/^\s+//;
+            $ARGS{$param} =~ s/\s+$//;
             next if ($value->$attr()||'') eq ($ARGS{$param}||'');
-
             my $mutator = "Set$attr";
             my ($id, $msg) = $value->$mutator( $ARGS{$param} );
             push (@results, $msg);
@@ -210,8 +236,10 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
     # Add any new values
     if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
         my ($id, $msg) = $CustomFieldObj->AddValue(
-            map { $_ => $ARGS{ $paramtag ."-new-$_" } }
-                qw( Name Description SortOrder Category )
+            map { 
+                $ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
+                $ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
+                $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
         );
         push (@results, $msg);
     }
@@ -222,6 +250,9 @@ $id = $CustomFieldObj->id if $CustomFieldObj->id;
 my $EnabledChecked = qq[checked="checked"];
 $EnabledChecked = '' if $CustomFieldObj->Disabled;
 
+my $RequiredChecked = '';
+$RequiredChecked = qq[checked="checked"] if $CustomFieldObj->Required;
+
 my @CFvalidations = (
     '(?#Mandatory).',
     '(?#Digits)^[\d.]+$',
@@ -246,4 +277,5 @@ $ValuesClass => 'RT::CustomFieldValues'
 $LinkValueTo => undef
 $IncludeContentForValue => undef
 $BasedOn => undef
+$UILocation => undef
 </%ARGS>