[Rt-commit] rt branch, custom_fields_application, updated. rt-3.8.7-184-gc367a2f
Ruslan Zakirov
ruz at bestpractical.com
Wed Feb 24 19:51:29 EST 2010
The branch, custom_fields_application has been updated
via c367a2fb7285d8388adc188b1fa70bcb9b1eabc7 (commit)
via 0ea2012828971c6ae4dab0d96f66bad1b44c5b3e (commit)
via f375754156410edfa5fa2b29e5d7e1519efe2dab (commit)
via 08533c90f683a601a1da22ab808e1c05c3237c18 (commit)
via ff4e8895d7ca573d33f0fbf362601d00a90f8988 (commit)
from 2eaeeef02f3dbd1b276134c14c42c5372331f148 (commit)
Summary of changes:
lib/RT/CustomField_Overlay.pm | 51 +++++++++++++++-------
share/html/Admin/CustomFields/index.html | 56 +++++++++++++-----------
share/html/Elements/RT__CustomField/ColumnMap | 14 ++++---
3 files changed, 72 insertions(+), 49 deletions(-)
- Log -----------------------------------------------------------------
commit ff4e8895d7ca573d33f0fbf362601d00a90f8988
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Feb 25 03:39:06 2010 +0300
IsGlobal -> IsApplied and returns object, not just boolean value
diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index a3785ab..f693710 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -1003,17 +1003,21 @@ sub _AppliedTo {
return ($res, $ocfs_alias);
}
-=head2 IsGlobal
+=head2 IsApplied
-Return true if this custom field is applied globally.
+Takes object id and returns corresponding L<RT::ObjectCustomField>
+record if this custom field is applied to the object. Use 0 to check
+if custom field is applied globally.
=cut
-sub IsGlobal {
+sub IsApplied {
my $self = shift;
+ my $id = shift;
my $ocf = RT::ObjectCustomField->new( $self->CurrentUser );
- $ocf->LoadByCols( CustomField => $self->id, ObjectId => 0 );
- return $ocf->id;
+ $ocf->LoadByCols( CustomField => $self->id, ObjectId => $id || 0 );
+ return undef unless $ocf->id;
+ return $ocf;
}
=head2 AddToObject OBJECT
commit 08533c90f683a601a1da22ab808e1c05c3237c18
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Feb 25 03:46:59 2010 +0300
don't allow to apply locally global CFs, unapply from local when applying globally
diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index f693710..b91fc32 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -1042,14 +1042,29 @@ sub AddToObject {
return ( 0, $self->loc('Permission Denied') );
}
- my $ObjectCF = RT::ObjectCustomField->new( $self->CurrentUser );
- $ObjectCF->LoadByCols( ObjectId => $id, CustomField => $self->Id );
- if ( $ObjectCF->Id ) {
- return ( 0, $self->loc("That is already the current value") );
+ if ( $self->IsApplied( $id ) ) {
+ return ( 0, $self->loc("Custom field is already applied to the object") );
}
- my ( $oid, $msg ) =
- $ObjectCF->Create( ObjectId => $id, CustomField => $self->Id );
+ if ( $id ) {
+ # applying locally
+ return (0, $self->loc("Couldn't apply custom field to an object as it's global already") )
+ if $self->IsApplied( 0 );
+ }
+ else {
+ my $applied = RT::ObjectCustomFields->new( $self->CurrentUser );
+ $applied->LimitToCustomField( $self->id );
+ while ( my $record = $applied->Next ) {
+ my ($status, $msg) = $record->Delete;
+ $RT::Logger->error($msg);
+ return (0, $self->loc("Couldn't remove custom field from an object"));
+ }
+ }
+
+ my $ocf = RT::ObjectCustomField->new( $self->CurrentUser );
+ my ( $oid, $msg ) = $ocf->Create(
+ ObjectId => $id, CustomField => $self->id,
+ );
return ( $oid, $msg );
}
commit f375754156410edfa5fa2b29e5d7e1519efe2dab
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Feb 25 03:48:27 2010 +0300
use IsApplied
diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index b91fc32..324cc24 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -1077,7 +1077,6 @@ Takes an object
=cut
-
sub RemoveFromObject {
my $self = shift;
my $object = shift;
@@ -1091,14 +1090,13 @@ sub RemoveFromObject {
return ( 0, $self->loc('Permission Denied') );
}
- my $ObjectCF = RT::ObjectCustomField->new( $self->CurrentUser );
- $ObjectCF->LoadByCols( ObjectId => $id, CustomField => $self->Id );
- unless ( $ObjectCF->Id ) {
+ my $ocf = $self->IsApplied( $id );
+ unless ( $ocf ) {
return ( 0, $self->loc("This custom field does not apply to that object") );
}
- # XXX: Delete doesn't return anything
- my ( $oid, $msg ) = $ObjectCF->Delete;
+ # XXX: Delete doesn't return anything
+ my ( $oid, $msg ) = $ocf->Delete;
return ( $oid, $msg );
}
commit 0ea2012828971c6ae4dab0d96f66bad1b44c5b3e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Feb 25 03:49:07 2010 +0300
CustomFields column map update
* FriendlyLookupType and LookupType
* IsApplied instead of IsGlobal
diff --git a/share/html/Elements/RT__CustomField/ColumnMap b/share/html/Elements/RT__CustomField/ColumnMap
index 327359e..a318c81 100644
--- a/share/html/Elements/RT__CustomField/ColumnMap
+++ b/share/html/Elements/RT__CustomField/ColumnMap
@@ -68,15 +68,15 @@ my $COLUMN_MAP = {
title => $c, attribute => $c,
value => sub { return $_[0]->$c() },
} }
- qw(Name Description Type Pattern)
+ qw(Name Description Type LookupType Pattern)
),
map(
{ my $c = $_; my $short = $c; $short =~ s/^Friendly//;
$c => {
- title => $short, attribute => $c,
+ title => $short, attribute => $short,
value => sub { return $_[0]->$c() },
} }
- qw(FriendlyType FriendlyPattern)
+ qw(FriendlyLookupType FriendlyType FriendlyPattern)
),
MaxValues => {
title => 'MaxValues', # loc
@@ -89,7 +89,7 @@ my $COLUMN_MAP = {
AppliedTo => {
title => 'Applied', # loc
value => sub {
- if ( $_[0]->IsGlobal ) {
+ if ( $_[0]->IsApplied ) {
return $_[0]->loc('Global');
}
@@ -98,11 +98,13 @@ my $COLUMN_MAP = {
my $found = 0;
my $res = '';
while ( my $record = $collection->Next ) {
+ $res .= ', ' if $res;
+
my $id = '';
$id = $record->Name if $record->can('Name');
$id ||= "#". $record->id;
- $res .= ', ' if $res;
$res .= $id;
+
$found++;
}
$res .= ', ...' if $found >= 10;
@@ -120,7 +122,7 @@ my $COLUMN_MAP = {
},
value => sub {
my $id = $_[0]->id;
- return '' if $_[0]->IsGlobal;
+ return '' if $_[0]->IsApplied;
my $name = $_[2] || 'RemoveCustomField';
my $arg = $m->request_args->{ $name };
commit c367a2fb7285d8388adc188b1fa70bcb9b1eabc7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Feb 25 03:50:57 2010 +0300
use CollectionList on index of all CFs
diff --git a/share/html/Admin/CustomFields/index.html b/share/html/Admin/CustomFields/index.html
index 139b8eb..513caa3 100644
--- a/share/html/Admin/CustomFields/index.html
+++ b/share/html/Admin/CustomFields/index.html
@@ -45,40 +45,38 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<& /Admin/Elements/Header, Title => loc('Select a Custom Field') &>
+<& /Admin/Elements/Header, Title => $title &>
<& /Admin/Elements/CustomFieldTabs,
current_tab => 'Admin/CustomFields/',
- Title => loc('Select a Custom Field') &>
+ Title => $title,
+&>
-% my @types;
-% my $prev_lookup = '';
-% while (my $CustomFieldObj = $CustomFields->Next) {
-% next unless $CustomFieldObj->CurrentUserHasRight('AdminCustomField');
-% my $lookup = $CustomFieldObj->FriendlyLookupType;
-% if ($lookup ne $prev_lookup) {
-% if ($prev_lookup) {
-</ul>
-% }
-<h2><% loc("Custom Fields for [_1]", $lookup) %></h2>
-<ul>
-% $prev_lookup = $lookup;
-% push @types, [$lookup, $CustomFieldObj->LookupType];
-% }
-%
-<li>
-<a href="Modify.html?id=<% $CustomFieldObj->id %>"><% $CustomFieldObj->Name %>: <% $CustomFieldObj->Description %></a>
-</li>
-% }
-% if ($prev_lookup) {
-</ul>
+% my $tmp = RT::CustomField->new( $session{'CurrentUser'} );
+% if ( $Type ) {
+<h2><% loc("Custom Fields for [_1]", $tmp->FriendlyLookupType( $Type )) %></h2>
% }
+<& /Elements/CollectionList,
+ OrderBy => 'LookupType|Name',
+ Order => 'ASC|ASC',
+ Rows => 50,
+ %ARGS,
+ Collection => $CustomFields,
+ Format => $Format,
+ DisplayFormat => ($Type? '' : '__FriendlyLookupType__,'). $Format,
+ AllowSorting => 1,
+ PassArguments => [
+ qw(Format Rows Page Order OrderBy),
+ qw(Type ShowDisabled)
+ ],
+&>
+
<form action="<%RT->Config->Get('WebPath')%>/Admin/CustomFields/index.html" method="get">
<&|/l&>Only show custom fields for:</&>
<select name="Type">
<option value="" <% !$Type && 'selected="selected"'%> ><% loc('(any)') %></option>
-% for (@types) {
-<option value="<% $_->[1] %>" <% $_->[1] eq $Type && 'selected="selected"'%> ><% $_->[0] %></option>
+% for my $type ( $tmp->LookupTypes ) {
+<option value="<% $type %>" <% $type eq $Type && 'selected="selected"'%> ><% $tmp->FriendlyLookupType( $type ) %></option>
% }
</select>
<br />
@@ -92,8 +90,12 @@
<%args>
$Type => ''
$ShowDisabled => 0
+
+$Format => undef
</%args>
<%INIT>
+my $title = loc('Select a Custom Field');
+
$Type ||= $ARGS{'type'} || '';
if ( !$Type && $ARGS{'type'} ) {
$Type ||= $ARGS{'type'};
@@ -104,5 +106,7 @@ my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
$CustomFields->UnLimit;
$CustomFields->{'find_disabled_rows'} = 1 if $ShowDisabled;
$CustomFields->LimitToLookupType( $Type ) if $Type;
-$CustomFields->OrderByCols( { FIELD => 'LookupType' }, { FIELD => 'Name' } );
+
+$Format ||= RT->Config->Get('AdminSearchResultFormat')->{'CustomFields'};
+
</%INIT>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list