[Rt-commit] rt branch, hierarchical-cf, created. 1df624d927e81c066637b1d698adcab117eaed59
Alex M Vandiver
alexmv at bestpractical.com
Tue Aug 25 16:46:50 EDT 2009
The branch, hierarchical-cf has been created
at 1df624d927e81c066637b1d698adcab117eaed59 (commit)
- Log -----------------------------------------------------------------
commit 9ba7d4c4f978d5689c7810bbfc90ee2c092129f1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Aug 17 14:57:24 2009 -0400
Add BasedOn attribute to CustomFields
diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index 7632795..27ddd1a 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -250,6 +250,18 @@ sub Create {
$self->SetValuesClass( $args{'ValuesClass'} );
}
+ if ( exists $args{'BasedOn'} ) {
+ my $BasedOn = RT::CustomField->new( $self->CurrentUser );
+ $BasedOn->Load($args{BasedOn});
+ if ( $BasedOn->id && $BasedOn->CurrentUserHasRight('SeeCustomField') ) {
+ $self->AddAttribute(
+ Name => "BasedOn",
+ Description => "Custom field whose CF we depend on",
+ Content => $BasedOn->id,
+ );
+ }
+ }
+
return ($rv, $msg) unless exists $args{'Queue'};
# Compat code -- create a new ObjectCustomField mapping
@@ -1251,4 +1263,37 @@ sub _URLTemplate {
}
}
+sub SetBasedOn {
+ my $self = shift;
+ my $value = shift;
+ $value = $value->id if ref $value;
+
+ $self->SetAttribute(
+ Name => "BasedOn",
+ Description => "Custom field whose CF we depend on",
+ Content => $value,
+ );
+}
+
+sub BasedOnObj {
+ my $self = shift;
+ my $obj = RT::CustomField->new( $self->CurrentUser );
+
+ my $attribute = $self->FirstAttribute("BasedOn");
+ $obj->Load($attribute->Content) if defined $attribute;
+ return $obj;
+}
+
+sub DerivativeCFs {
+ my $self = shift;
+ my $attrs = RT::Attributes->new( $self->CurrentUser );
+ $attrs->Limit( FIELD => 'ObjectType', VALUE => 'RT::CustomField' );
+ $attrs->Limit( FIELD => 'Name', VALUE => 'BasedOn' );
+ $attrs->Limit( FIELD => 'Content', VALUE => $self->id );
+
+ my @cfs;
+ push @cfs, $_->Object while $_ = $attrs->Next;
+ return @cfs;
+}
+
1;
commit 0c0a64fb608535820ce693b5fe326f3e3f986f14
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Aug 17 15:35:00 2009 -0400
Admin UI for chained custom fields
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index bbdc3ad..fca44ec 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -107,6 +107,19 @@
<i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
</div></td></tr>
+% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
+<tr><td class="label"><&|/l&>Categories are based on</&></td><td>
+<& /Admin/Elements/SelectCustomField,
+ Name => "BasedOn",
+ LookupType => $CustomFieldObj->LookupType,
+ Default => $CustomFieldObj->BasedOnObj,
+ Not => $CustomFieldObj->id,
+&>
+<div class="hints">
+<&|/l&>Some browsers may only load content from the same domain as your RT server.</&>
+</div></td></tr>
+% }
+
<tr><td class="label"> </td><td>
<input type="hidden" class="hidden" name="SetEnabled" value="1" />
<input type="checkbox" class="checkbox" name="Enabled" value="1" <% $EnabledChecked |n%> />
@@ -147,6 +160,7 @@ else {
Pattern => $Pattern,
LinkValueTo => $LinkValueTo,
IncludeContentForValue => $IncludeContentForValue,
+ BasedOn => $BasedOn,
);
$m->comp( "/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless $val;
push @results, $msg;
@@ -171,6 +185,8 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
);
$CustomFieldObj->SetValuesClass( $ValuesClass );
+ $CustomFieldObj->SetBasedOn( $BasedOn );
+
my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
# Delete any fields that want to be deleted
foreach my $key ( keys %ARGS ) {
@@ -182,8 +198,11 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
# Update any existing values
my $values = $CustomFieldObj->ValuesObj;
while ( my $value = $values->Next ) {
+ my $prefix = $paramtag . "-" . $value->Id;
+ $ARGS{"$prefix-Category"} = delete $ARGS{$_}
+ for grep /^$prefix-BasedOn-\d+-Values$/, keys %ARGS;
foreach my $attr qw(Name Description SortOrder Category) {
- my $param = "$paramtag-". $value->Id ."-". $attr;
+ my $param = "$prefix-$attr";
next unless exists $ARGS{$param};
next if ($value->$attr()||'') eq ($ARGS{$param}||'');
@@ -195,6 +214,8 @@ if ( $ARGS{'Update'} && $id ne 'new' ) {
# Add any new values
if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
+ $ARGS{"$paramtag-new-Category"} = delete $ARGS{$_}
+ for grep /^$paramtag-new-BasedOn-\d+-Values$/, keys %ARGS;
my ($id, $msg) = $CustomFieldObj->AddValue(
map { $_ => $ARGS{ $paramtag ."-new-$_" } }
qw( Name Description SortOrder Category )
@@ -231,4 +252,5 @@ $Enabled => 0
$ValuesClass => 'RT::CustomFieldValues'
$LinkValueTo => undef
$IncludeContentForValue => undef
+$BasedOn => undef
</%ARGS>
diff --git a/share/html/Admin/Elements/AddCustomFieldValue b/share/html/Admin/Elements/AddCustomFieldValue
index 60e459f..8818a19 100755
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Admin/Elements/AddCustomFieldValue
@@ -64,7 +64,14 @@
<td><input type="text" size="25" name="<% $paramtag %>-Name" /></td>
<td><input type="text" size="45" name="<% $paramtag %>-Description" /></td>
% if ( $CustomField->Type ne 'Combobox' ) {
-<td><input type="text" size="10" name="<% $paramtag %>-Category" /></td>
+<td>
+% my $BasedOnObj = $CustomField->BasedOnObj;
+% if ( $BasedOnObj->id ) {
+<& /Elements/EditCustomField, CustomField => $BasedOnObj, Rows => 1, NamePrefix => "$paramtag-BasedOn-", Default => "" &>
+% } else {
+<input type="text" size="10" name="<% $paramtag %>-Category" value="" />
+% }
+</td>
% }
</tr>
diff --git a/share/html/Admin/Elements/EditCustomFieldValues b/share/html/Admin/Elements/EditCustomFieldValues
index 445654b..cbb3c77 100755
--- a/share/html/Admin/Elements/EditCustomFieldValues
+++ b/share/html/Admin/Elements/EditCustomFieldValues
@@ -70,8 +70,13 @@
<td><input type="text" size="25" name="<% $paramtag %>-Name" value="<% $value->Name %>" /></td>
<td><input type="text" size="45" name="<% $paramtag %>-Description" value="<% $value->Description %>" /></td>
% if ( $CustomField->Type ne 'Combobox' ) {
-<td><input type="text" size="10" name="<% $paramtag %>-Category"
- value="<% $value->Category || '' %>" /></td>
+<td>
+% if ( $BasedOnObj->id ) {
+<& /Elements/EditCustomField, CustomField => $BasedOnObj, Rows => 1, NamePrefix => "$paramtag-BasedOn-", Default => $value->Category &>
+% } else {
+<input type="text" size="10" name="<% $paramtag %>-Category" value="<% $value->Category || '' %>" />
+% }
+</td>
% }
</tr>
% }
@@ -82,6 +87,7 @@
my $values = $CustomField->ValuesObj();
+my $BasedOnObj = $CustomField->BasedOnObj;
</%init>
<%args>
$CustomField => undef
diff --git a/share/html/Admin/Elements/AddCustomFieldValue b/share/html/Admin/Elements/SelectCustomField
old mode 100755
new mode 100644
similarity index 70%
copy from share/html/Admin/Elements/AddCustomFieldValue
copy to share/html/Admin/Elements/SelectCustomField
index 60e459f..1eb1f63
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Admin/Elements/SelectCustomField
@@ -45,30 +45,27 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<h3><&|/l&>Add Value</&></h3>
+<select name="<%$Name%>">
+<option value="" <% not $Default and qq[ selected="selected"] |n %>>--</option>
+% while (my $CustomFieldObj = $CustomFields->Next) {
+% next if $OnlySelectionType and not $CustomFieldObj->IsSelectionType;
+% next if $Not and $CustomFieldObj->id == $Not;
+<option value="<%$CustomFieldObj->id%>"<% $Default == $CustomFieldObj->id && qq[ selected="selected"] |n%>><% $CustomFieldObj->Name %></option>
+%}
+</select>
+<%INIT>
+my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
+$CustomFields->UnLimit;
+$CustomFields->LimitToLookupType( $LookupType ) if $LookupType;
+$CustomFields->OrderByCols( { FIELD => 'LookupType' }, { FIELD => 'Name' } );
-<table border="0">
-
-<tr>
-<th><&|/l&>Sort</&></th>
-<th><&|/l&>Name</&></th>
-<th><&|/l&>Description</&></th>
-% if ( $CustomField->Type ne 'Combobox' ) {
-<th><&|/l&>Category</&></th>
-% }
-</tr>
-
-% my $paramtag = "CustomField-". $CustomField->Id ."-Value-new";
-<tr>
-<td><input type="text" size="3" name="<% $paramtag %>-SortOrder" /></td>
-<td><input type="text" size="25" name="<% $paramtag %>-Name" /></td>
-<td><input type="text" size="45" name="<% $paramtag %>-Description" /></td>
-% if ( $CustomField->Type ne 'Combobox' ) {
-<td><input type="text" size="10" name="<% $paramtag %>-Category" /></td>
-% }
-</tr>
-
-</table>
-<%args>
-$CustomField => undef
-</%args>
+$Default = $Default->id || 0 if ref $Default;
+</%INIT>
+<%ARGS>
+$None => 1
+$Name => 'BasedOn'
+$Default => 0
+$LookupType => 'RT::Queue-RT::Ticket'
+$OnlySelectionType => 1
+$Not => 0
+</%ARGS>
commit 9006e7a0ea92c0775b7425bf931c7a81f100001b
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Aug 24 15:19:14 2009 -0400
Minor indent fixups
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index 2c98dcc..c1dafa8 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -48,29 +48,29 @@
%# Build up the set of cascading select boxes as "guides"
%# each one limits the options of the final one a bit
%# (perhaps by tweaking the .display style?)
-% my $selected = 0;
-% my @category;
-% my $id = $NamePrefix . $CustomField->Id;
-% my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
-% if (@category) {
-<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
-%# XXX - Hide this select from w3m?
- <select onchange="filter_cascade('<% $id %>-Values', this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
- <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
-% foreach my $cat (@category) {
-% my ($depth, $name) = @$cat;
- <option value="<% $name %>"><% ' ' x $depth |n %><% $name %></option>
-% }
- </select><br />
-% }
- <select name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
-% if ( $Rows && ( $Multiple || !@category ) ) {
- size="<% $Rows %>"
-% }
- <% $Multiple && qq[multiple="multiple"] |n %> >
- <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
-% $m->out($out);
- </select>
+% my $selected = 0;
+% my @category;
+% my $id = $NamePrefix . $CustomField->Id;
+% my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
+% if (@category) {
+ <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
+%# XXX - Hide this select from w3m?
+ <select onchange="filter_cascade('<% $id %>-Values', this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
+ <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
+% foreach my $cat (@category) {
+% my ($depth, $name) = @$cat;
+ <option value="<% $name %>"><% ' ' x $depth |n %><% $name %></option>
+% }
+ </select><br />
+% }
+<select name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
+% if ( $Rows && ( $Multiple || !@category ) ) {
+ size="<% $Rows %>"
+% }
+<% $Multiple && qq[multiple="multiple"] |n %> >
+<option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
+% $m->out($out);
+</select>
<%ARGS>
$Object => undef
$CustomField => undef
commit 1df624d927e81c066637b1d698adcab117eaed59
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Aug 24 16:31:26 2009 -0400
Display for chained custom fields
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index c1dafa8..6b205cd 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -51,8 +51,10 @@
% my $selected = 0;
% my @category;
% my $id = $NamePrefix . $CustomField->Id;
+% if ($CustomField->BasedOnObj->Id) {
+% }
% my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
-% if (@category) {
+% if (@category and not $CustomField->BasedOnObj->id) {
<script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
%# XXX - Hide this select from w3m?
<select onchange="filter_cascade('<% $id %>-Values', this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
@@ -63,7 +65,17 @@
% }
</select><br />
% }
-<select name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
+% my @Derivatives = map {$_->id} $CustomField->DerivativeCFs;
+% if (@Derivatives) {
+ <script type="text/javascript" src="<%RT->Config->Get('WebPath')%>/NoAuth/js/cascaded.js"></script>
+<script type="text/javascript"><!--
+doOnLoad( function () {<% join(";", map {"filter_cascade('$NamePrefix$_-Values',document.getElementById('$id-Values').value, 1)"} @Derivatives) |n%>} );
+--></script>
+<select onchange="<% join(";", map {"filter_cascade('$NamePrefix$_-Values', this.value, 1)"} @Derivatives) |n%>"
+% } else {
+<select
+% }
+ name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
% if ( $Rows && ( $Multiple || !@category ) ) {
size="<% $Rows %>"
% }
diff --git a/share/html/NoAuth/js/cascaded.js b/share/html/NoAuth/js/cascaded.js
index 9baaf71..ace4f38 100644
--- a/share/html/NoAuth/js/cascaded.js
+++ b/share/html/NoAuth/js/cascaded.js
@@ -52,6 +52,10 @@ function filter_cascade (id, val) {
var children = select.childNodes;
for (i in children) {
if (!children[i].label) { continue };
+ if ( val == '' && arguments.length == 3 ) {
+ hide(children[i]);
+ continue;
+ }
if ( val == '' || children[i].label.substr(0, val.length) == val) {
show(children[i]);
continue;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list