[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.8.8-193-g73d5d63
Thomas Sibley
trs at bestpractical.com
Fri Jul 30 12:58:12 EDT 2010
The branch, 3.9-trunk has been updated
via 73d5d63eda9d0f4d691bf5e2a34730de8bb4f10e (commit)
from 2cd4839558c56ab3d26197673239a7ab5f468b64 (commit)
Summary of changes:
lib/RT/CustomField_Overlay.pm | 84 ++++++++++++++++++++
share/html/Admin/CustomFields/Modify.html | 31 +++++++
...CustomFieldType => SelectCustomFieldRenderType} | 11 ++-
share/html/Elements/EditCustomFieldSelect | 10 +++
4 files changed, 131 insertions(+), 5 deletions(-)
copy share/html/Admin/Elements/{SelectCustomFieldType => SelectCustomFieldRenderType} (92%)
- Log -----------------------------------------------------------------
commit 73d5d63eda9d0f4d691bf5e2a34730de8bb4f10e
Author: Thomas Sibley <trs at bestpractical.com>
Date: Fri Jul 30 12:58:12 2010 -0400
Add the concept of render types to custom fields
CFs of type 'Select' can now be rendered as a select box (traditional
RT) or dropdown on a per-CF basis.
diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index f33bb90..6c661be 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -99,6 +99,14 @@ our %FieldTypes = (
],
);
+our %RenderTypes = (
+ Select => [
+ # Default is the first one
+ 'Select box', # loc
+ 'Dropdown', # loc
+ ],
+);
+
our %FRIENDLY_OBJECT_TYPES = ();
@@ -488,6 +496,22 @@ sub Types {
# }}}
+=head2 HasRenderTypes
+
+Returns a boolean value indicating whether the L</RenderTypes> and
+L</RenderType> methods make sense for this custom field.
+
+Currently true only for type C<Select>.
+
+=cut
+
+sub HasRenderTypes {
+ my $self = shift;
+ my $type = @_? shift : $self->Type;
+ return undef unless $type;
+ return defined $RenderTypes{$type};
+}
+
# {{{ IsSelectionType
=head2 IsSelectionType
@@ -833,6 +857,66 @@ sub TypeComposites {
return grep !/(?:[Tt]ext|Combobox)-0/, map { ("$_-1", "$_-0") } $self->Types;
}
+=head2 RenderType
+
+Returns the type of form widget to render for this custom field. Currently
+this only affects fields which return true for L</HasRenderTypes>.
+
+=cut
+
+sub RenderType {
+ my $self = shift;
+ return '' unless $self->HasRenderTypes;
+
+ my $type = $self->FirstAttribute( 'RenderType' );
+ $type = $type->Content if $type;
+ return $type || $self->DefaultRenderType;
+}
+
+=head2 SetRenderType TYPE
+
+Sets this custom field's render type.
+
+=cut
+
+sub SetRenderType {
+ my ($self, $type) = @_;
+ return unless $self->HasRenderTypes;
+
+ if ( not defined $type ) {
+ return $self->DeleteAttribute( 'RenderType' );
+ }
+ return $self->SetAttribute( Name => 'RenderType', Content => $type );
+}
+
+=head2 DefaultRenderType [TYPE]
+
+Returns the default render type for this custom field's type or the TYPE
+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];
+}
+
+=head2 RenderTypes [TYPE]
+
+Returns the valid render types for this custom field's type or the TYPE
+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}};
+}
+
=head2 SetLookupType
Autrijus: care to doc how LookupTypes work?
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index 4892aa4..5263360 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -70,6 +70,18 @@
Default => $CustomFieldObj->TypeComposite, &>
</td></tr>
+% if ( $CustomFieldObj->Id and $CustomFieldObj->HasRenderTypes ) {
+<tr>
+ <td class="label"><&|/l&>Render Type</&></td>
+ <td>
+ <& /Admin/Elements/SelectCustomFieldRenderType,
+ Name => "RenderType",
+ Type => $CustomFieldObj->Type,
+ Default => $CustomFieldObj->RenderType, &>
+ </td>
+</tr>
+% }
+
% if ( $CustomFieldObj->Id and $CustomFieldObj->IsSelectionType and RT->Config->Get('CustomFieldValuesSources') and ( scalar(@{RT->Config->Get('CustomFieldValuesSources')}) > 0 ) ) {
<tr><td class="label"><&|/l&>Field values source:</&></td><td>
<& /Admin/Elements/EditCustomFieldValuesSource, CustomField => $CustomFieldObj &>
@@ -185,6 +197,24 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
);
$CustomFieldObj->SetValuesClass( $ValuesClass );
+ # 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) ) {
+ 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 );
+ }
+ }
+ else {
+ # Delete it if we no longer support render types
+ $CustomFieldObj->SetRenderType( undef );
+ }
+
$CustomFieldObj->SetBasedOn( $BasedOn );
my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
@@ -249,6 +279,7 @@ $Name => undef
$SetEnabled => undef
$Enabled => 0
$ValuesClass => 'RT::CustomFieldValues'
+$RenderType => undef
$LinkValueTo => undef
$IncludeContentForValue => undef
$BasedOn => undef
diff --git a/share/html/Admin/Elements/SelectCustomFieldRenderType b/share/html/Admin/Elements/SelectCustomFieldRenderType
new file mode 100755
index 0000000..c8ee825
--- /dev/null
+++ b/share/html/Admin/Elements/SelectCustomFieldRenderType
@@ -0,0 +1,61 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2010 Best Practical Solutions, LLC
+%# <jesse 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 }}}
+<select name="<%$Name%>">
+%for my $option ($cf->RenderTypes($Type)) {
+<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);
+</%INIT>
+<%ARGS>
+$Default => undef
+$Type => 'Select'
+$Name => 'RenderType'
+</%ARGS>
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index 143fda1..7f62657 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -91,6 +91,7 @@ doOnLoad( function () {
% $m->out($out);
</select>
% }
+
<select
name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
% if ( $Rows && ( $Multiple || !@category ) ) {
@@ -100,6 +101,14 @@ doOnLoad( function () {
<option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
% $m->out($out);
</select>
+<%init>
+# Handle render types
+$RenderType ||= $CustomField->RenderType;
+if ( $RenderType eq 'Dropdown' ) {
+ # Turn it into a dropdown
+ $Rows = 0;
+}
+</%init>
<%ARGS>
$Object => undef
$CustomField => undef
@@ -109,6 +118,7 @@ $Values => undef
$Multiple => 0
$Rows => undef
$HideCategory => 0
+$RenderType => undef
</%ARGS>
<%METHOD options>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list