[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.8.8-195-g972d9a4
Thomas Sibley
trs at bestpractical.com
Fri Jul 30 14:03:41 EDT 2010
The branch, 3.9-trunk has been updated
via 972d9a4377cbcf496105bd34d6e2846e366219e5 (commit)
from 806ee09e8d6437d67aae5b64d6e5c7f973aa1d65 (commit)
Summary of changes:
lib/RT/CustomField_Overlay.pm | 58 +++++++++++++-------
share/html/Admin/CustomFields/Modify.html | 20 ++++---
.../Admin/Elements/SelectCustomFieldRenderType | 6 +-
3 files changed, 54 insertions(+), 30 deletions(-)
- Log -----------------------------------------------------------------
commit 972d9a4377cbcf496105bd34d6e2846e366219e5
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Jul 30 14:04:51 2010 -0400
Key RenderTypes on TypeComposite so we can use MaxValues
diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 24ae33a..1a1bac1 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -100,12 +100,18 @@ our %FieldTypes = (
);
our %RenderTypes = (
- Select => [
- # Default is the first one
- 'Select box', # loc
- 'Dropdown', # loc
- 'List', # loc
- ],
+ Select => {
+ multiple => [
+ # Default is the first one
+ 'Select box', # loc
+ 'List', # loc
+ ],
+ single => [
+ 'Select box', # loc
+ 'Dropdown', # loc
+ 'List', # loc
+ ]
+ },
);
@@ -497,7 +503,7 @@ sub Types {
# }}}
-=head2 HasRenderTypes
+=head2 HasRenderTypes [TYPE_COMPOSITE]
Returns a boolean value indicating whether the L</RenderTypes> and
L</RenderType> methods make sense for this custom field.
@@ -508,9 +514,9 @@ Currently true only for type C<Select>.
sub HasRenderTypes {
my $self = shift;
- my $type = @_? shift : $self->Type;
+ my ($type, $max) = split /-/, (@_ ? shift : $self->TypeComposite), 2;
return undef unless $type;
- return defined $RenderTypes{$type};
+ return defined $RenderTypes{$type}->{ $max == 1 ? 'single' : 'multiple' };
}
# {{{ IsSelectionType
@@ -828,6 +834,12 @@ sub SetTypeComposite {
my ($status, $msg) = $self->SetMaxValues( $max_values );
return ($status, $msg) unless $status;
}
+ my $render = $self->RenderType;
+ if ( $render and not grep { $_ eq $render } $self->RenderTypes ) {
+ # We switched types and our render type is no longer valid, so unset it
+ # and use the default
+ $self->SetRenderType( undef );
+ }
return 1, $self->loc(
"Type changed from '[_1]' to '[_2]'",
$self->FriendlyTypeComposite( $old ),
@@ -887,35 +899,43 @@ sub SetRenderType {
if ( not defined $type ) {
return $self->DeleteAttribute( 'RenderType' );
}
+
+ if ( not grep { $_ eq $type } $self->RenderTypes ) {
+ return (0, $self->loc("Invalid Render Type for custom field of type [_1]",
+ $self->FriendlyType));
+ }
+
return $self->SetAttribute( Name => 'RenderType', Content => $type );
}
-=head2 DefaultRenderType [TYPE]
+=head2 DefaultRenderType [TYPE COMPOSITE]
Returns the default render type for this custom field's type or the TYPE
-specified as an argument.
+COMPOSITE specified as an argument.
=cut
sub DefaultRenderType {
my $self = shift;
- my $type = @_ ? shift : $self->Type;
- return unless $type and $self->HasRenderTypes($type);
- return $RenderTypes{$type}->[0];
+ my $composite = @_ ? shift : $self->TypeComposite;
+ my ($type, $max) = split /-/, $composite, 2;
+ return unless $type and $self->HasRenderTypes($composite);
+ return defined $RenderTypes{$type}->{ $max == 1 ? 'single' : 'multiple' }[0];
}
-=head2 RenderTypes [TYPE]
+=head2 RenderTypes [TYPE COMPOSITE]
Returns the valid render types for this custom field's type or the TYPE
-specified as an argument.
+COMPOSITE specified as an argument.
=cut
sub RenderTypes {
my $self = shift;
- my $type = @_ ? shift : $self->Type;
- return unless $type and $self->HasRenderTypes($type);
- return @{$RenderTypes{$type}};
+ my $composite = @_ ? shift : $self->TypeComposite;
+ my ($type, $max) = split /-/, $composite, 2;
+ return unless $type and $self->HasRenderTypes($composite);
+ return @{$RenderTypes{$type}->{ $max == 1 ? 'single' : 'multiple' }};
}
=head2 SetLookupType
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index 5263360..dc25567 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -75,9 +75,9 @@
<td class="label"><&|/l&>Render Type</&></td>
<td>
<& /Admin/Elements/SelectCustomFieldRenderType,
- Name => "RenderType",
- Type => $CustomFieldObj->Type,
- Default => $CustomFieldObj->RenderType, &>
+ Name => "RenderType",
+ TypeComposite => $CustomFieldObj->TypeComposite,
+ Default => $CustomFieldObj->RenderType, &>
</td>
</tr>
% }
@@ -199,15 +199,19 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
# Set the render type if we have it, but unset it if the new type doesn't
# support render types
- my ($cftype) = split /-/, $TypeComposite;
- if ( $CustomFieldObj->HasRenderTypes($cftype) ) {
+ if ( $CustomFieldObj->HasRenderTypes($TypeComposite) ) {
my $original = $CustomFieldObj->RenderType;
if ( defined $RenderType and $RenderType ne $original ) {
# It's changed! Let's update it.
- $CustomFieldObj->SetRenderType( $RenderType );
- push @results, loc("[_1] changed from '[_2]' to '[_3]'",
- loc("Render Type"), $original, $RenderType );
+ my ($good, $msg) = $CustomFieldObj->SetRenderType( $RenderType );
+
+ if ( $good ) {
+ $msg = loc("[_1] changed from '[_2]' to '[_3]'",
+ loc("Render Type"), $original, $RenderType );
+ }
+
+ push @results, $msg;
}
}
else {
diff --git a/share/html/Admin/Elements/SelectCustomFieldRenderType b/share/html/Admin/Elements/SelectCustomFieldRenderType
index c8ee825..ac8f5fd 100755
--- a/share/html/Admin/Elements/SelectCustomFieldRenderType
+++ b/share/html/Admin/Elements/SelectCustomFieldRenderType
@@ -46,16 +46,16 @@
%#
%# END BPS TAGGED BLOCK }}}
<select name="<%$Name%>">
-%for my $option ($cf->RenderTypes($Type)) {
+%for my $option ($cf->RenderTypes($TypeComposite)) {
<option value="<%$option%>"<%$option eq $Default && qq[ selected="selected"] |n%>><% $option %></option>
%}
</select>
<%INIT>
my $cf = RT::CustomField->new($session{'CurrentUser'});
-$Default ||= $cf->DefaultRenderType($Type);
+$Default ||= $cf->DefaultRenderType($TypeComposite);
</%INIT>
<%ARGS>
$Default => undef
-$Type => 'Select'
+$TypeComposite => 'Select-0'
$Name => 'RenderType'
</%ARGS>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list