[Rt-commit] rt branch, 4.2/custom-field-groupings, updated. rt-4.0.8-477-gb4ca13d
Alex Vandiver
alexmv at bestpractical.com
Thu Nov 15 18:31:00 EST 2012
The branch, 4.2/custom-field-groupings has been updated
via b4ca13dbb9849296f28a0b2798801643ca54715e (commit)
via 69a7133fdc42ee2b37c0c835bb0adbfe02558b26 (commit)
via 0ee492afd186ac589af31b4a722ab1e3fe065ec0 (commit)
via 6402b7cb025d4e84773f3586c34541fd4a7fcf79 (commit)
from a79755e1acccc79e7732048bf92d5b0532d3016c (commit)
Summary of changes:
share/html/Admin/Groups/Modify.html | 4 +-
share/html/Admin/Queues/Modify.html | 6 +-
.../Articles/Article/Elements/EditCustomFields | 10 +--
share/html/Elements/EditCustomField | 24 +++---
share/html/Elements/EditCustomFields | 4 +-
share/html/Elements/ValidateCustomFields | 43 ++++------
share/html/Search/Bulk.html | 92 +++++++---------------
.../Ticket/Elements/EditTransactionCustomFields | 7 +-
share/html/Ticket/Update.html | 2 +-
9 files changed, 66 insertions(+), 126 deletions(-)
- Log -----------------------------------------------------------------
commit 6402b7cb025d4e84773f3586c34541fd4a7fcf79
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Nov 15 18:09:19 2012 -0500
Remove unnecessary passing of Default to EditCustomField
EditCustomField already pulls values from the top %DECODED_ARGS, making
the extra level of defaulting unnecessary -- and borderline incorrect,
as it pulls from %ARGS and not %DECODED_ARGS.
diff --git a/share/html/Articles/Article/Elements/EditCustomFields b/share/html/Articles/Article/Elements/EditCustomFields
index db719eb..0aeabb1 100644
--- a/share/html/Articles/Article/Elements/EditCustomFields
+++ b/share/html/Articles/Article/Elements/EditCustomFields
@@ -52,11 +52,7 @@
Object => $ArticleObj,
CustomField => $CustomField,
NamePrefix => $NamePrefix,
- Default =>
- ($CFContent->{$CustomField->Id} ||
- $ARGS{$NamePrefix .$CustomField->id .'-Values'} ||
- $ARGS{$NamePrefix .$CustomField->id .'-Value'})
- ,
+ Default => $CFContent->{$CustomField->Id},
Rows => 15,
Cols => 70
&></td>
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index fc4be7a..a0e745f 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -138,8 +138,6 @@ size="60" value="<% $ARGS{UpdateSubject} || "" %>" /></td></tr>
<td><& /Elements/EditCustomField,
CustomField => $CF,
NamePrefix => "Object-RT::Transaction--CustomField-",
- Default => $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Values'} ||
- $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Value'},
&><em><% $CF->FriendlyType %></em></td>
</td></tr>
% } # end if while
commit 0ee492afd186ac589af31b4a722ab1e3fe065ec0
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Nov 15 18:13:12 2012 -0500
Avoid computing NamePrefix by hand wherever possible
Rather than construct a NamePrefix by hand, let EditCustomField
construct it based on the class and id of the object passed in. This
abstracts out most of the naming of CF fields.
diff --git a/share/html/Admin/Groups/Modify.html b/share/html/Admin/Groups/Modify.html
index 4491a71..808445f 100644
--- a/share/html/Admin/Groups/Modify.html
+++ b/share/html/Admin/Groups/Modify.html
@@ -75,9 +75,7 @@
<% loc($CF->Name) %>:
</td><td>
<& /Elements/EditCustomField, CustomField => $CF,
- Object => $Group,
- ($Create ? (NamePrefix => 'Object-RT::Group--CustomField-')
- : () )&>
+ Object => $Group, &>
</td></tr>
% }
<tr>
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index c2cf094..b2bdf25 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -106,10 +106,8 @@
<tr valign="top"><td align="right">
<% loc($CF->Name) %>:
</td><td>
-<& /Elements/EditCustomField, CustomField => $CF,
- Object => $QueueObj,
- ($Create ? (NamePrefix => 'Object-RT::Queue--CustomField-')
- : () )&>
+<& /Elements/EditCustomField, CustomField => $CF,
+ Object => $QueueObj, &>
</td></tr>
% }
diff --git a/share/html/Articles/Article/Elements/EditCustomFields b/share/html/Articles/Article/Elements/EditCustomFields
index 0aeabb1..153a3ca 100644
--- a/share/html/Articles/Article/Elements/EditCustomFields
+++ b/share/html/Articles/Article/Elements/EditCustomFields
@@ -51,7 +51,6 @@
<td class="entry"><& /Elements/EditCustomField,
Object => $ArticleObj,
CustomField => $CustomField,
- NamePrefix => $NamePrefix,
Default => $CFContent->{$CustomField->Id},
Rows => 15,
Cols => 70
@@ -60,15 +59,12 @@
% }
<%INIT>
my $CustomFields;
-my $NamePrefix;
if ($ArticleObj->id && $ArticleObj->ClassObj->id) {
$CustomFields = $ArticleObj->CustomFields();
- $NamePrefix = "Object-RT::Article-".$ArticleObj->Id."-CustomField-";
}
else {
$CustomFields = $ClassObj->ArticleCustomFields();
- $NamePrefix = "Object-RT::Article--CustomField-";
}
</%INIT>
<%ARGS>
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 8b87fd4..02f9d10 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -55,18 +55,20 @@ unless ( $Type ) {
}
my $Values;
-if ( $Object && $Object->id ) {
- $NamePrefix ||= join '-',
- 'Object', ref($Object), $Object->Id, 'CustomField', '';
+if ( $Object ) {
+ $NamePrefix ||= join '-',
+ 'Object', ref($Object), ($Object->Id || ''), 'CustomField', '';
- $Values = $Object->CustomFieldValues( $CustomField->id );
- $Values->Columns(
- qw( id CustomField ObjectType ObjectId Disabled Content
- ContentType ContentEncoding SortOrder Creator Created
- LastUpdatedBy LastUpdated )
- );
- # Don't take care of $Values if there isn't values inside
- undef ( $Values ) unless ( $Values->Count );
+ if ( $Object->Id ) {
+ $Values = $Object->CustomFieldValues( $CustomField->id );
+ $Values->Columns(
+ qw( id CustomField ObjectType ObjectId Disabled Content
+ ContentType ContentEncoding SortOrder Creator Created
+ LastUpdatedBy LastUpdated )
+ );
+ # Don't take care of $Values if there isn't values inside
+ undef ( $Values ) unless ( $Values->Count );
+ }
}
# Always fill $Default with submited values if it's empty
diff --git a/share/html/Elements/EditCustomFields b/share/html/Elements/EditCustomFields
index d184d81..8964315 100644
--- a/share/html/Elements/EditCustomFields
+++ b/share/html/Elements/EditCustomFields
@@ -63,8 +63,8 @@
<& /Elements/EditCustomField,
%ARGS,
CustomField => $CustomField,
- NamePrefix => $NamePrefix,
Default => $default,
+ Object => $Object,
&>
% if (my $msg = $m->notes('InvalidField-' . $CustomField->Id)) {
<br />
@@ -79,7 +79,6 @@
% }
% $m->callback( %ARGS, CallbackName => 'AfterCustomFields' );
<%INIT>
-$NamePrefix ||= join '-', 'Object', ref($Object), ($Object->Id || ''), 'CustomField', '';
$CustomFields ||= $Object->CustomFields;
$CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
@@ -104,7 +103,6 @@ if ( $AsTable ) {
<%ARGS>
$Object
$CustomFields => undef
-$NamePrefix => ''
$Grouping => undef
$AsTable => 1
$InTable => 0
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index a0e745f..6412550 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -135,9 +135,9 @@ size="60" value="<% $ARGS{UpdateSubject} || "" %>" /></td></tr>
% while (my $CF = $TxnCFs->Next()) {
<tr>
<td align="right"><% $CF->Name %>:</td>
-<td><& /Elements/EditCustomField,
- CustomField => $CF,
- NamePrefix => "Object-RT::Transaction--CustomField-",
+<td><& /Elements/EditCustomField,
+ CustomField => $CF,
+ Object => RT::Transaction->new( $session{'CurrentUser'} ),
&><em><% $CF->FriendlyType %></em></td>
</td></tr>
% } # end if while
diff --git a/share/html/Ticket/Elements/EditTransactionCustomFields b/share/html/Ticket/Elements/EditTransactionCustomFields
index e296ce7..f2374eb 100644
--- a/share/html/Ticket/Elements/EditTransactionCustomFields
+++ b/share/html/Ticket/Elements/EditTransactionCustomFields
@@ -45,7 +45,7 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-% $m->callback( CallbackName => 'BeforeTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj, NamePrefix => $NamePrefix );
+% $m->callback( CallbackName => 'BeforeTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj );
% if ( $WRAP ) {
<<% $WRAP %> class="edit-transaction-custom-fields">
% }
@@ -60,7 +60,7 @@
<<% $CELL %>>
<& /Elements/EditCustomField,
CustomField => $CF,
- NamePrefix => $NamePrefix
+ Object => RT::Transaction->new( $session{'CurrentUser'} ),
&>
% if (my $msg = $m->notes('InvalidField-' . $CF->Id)) {
<br />
@@ -73,7 +73,7 @@
% if ( $WRAP ) {
</<% $WRAP %>>
% }
-% $m->callback( CallbackName => 'AfterTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj, NamePrefix => $NamePrefix );
+% $m->callback( CallbackName => 'AfterTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj );
<%INIT>
my $CustomFields;
@@ -98,7 +98,6 @@ if ( $AsTable ) {
</%INIT>
<%ARGS>
-$NamePrefix => "Object-RT::Transaction--CustomField-"
$TicketObj => undef
$QueueObj => undef
$AsTable => 0
commit 69a7133fdc42ee2b37c0c835bb0adbfe02558b26
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Nov 15 18:15:58 2012 -0500
Use new _ParseObjectCustomFieldArgs and _NormalizeObjectCustomFieldValue methods
This also obviates the need to pass in or compute an explicit
NamePrefix; rather, we accept an Object, and allow
_ParseObjectCustomFieldArgs to determine examine the complete set of
args to find the values to validate.
diff --git a/share/html/Elements/ValidateCustomFields b/share/html/Elements/ValidateCustomFields
index 855f460..e725055 100644
--- a/share/html/Elements/ValidateCustomFields
+++ b/share/html/Elements/ValidateCustomFields
@@ -48,38 +48,23 @@
<%INIT>
my ($valid, @res) = (1, ());
$CustomFields->GotoFirstItem;
+
+my $CFArgs = _ParseObjectCustomFieldArgs( $ARGSRef )->{ref($Object)}{$Object->Id || 0} || {};
+
while ( my $CF = $CustomFields->Next ) {
- my $field = $NamePrefix . $CF->Id . "-Value";
+ my $submitted = $CFArgs->{$CF->Id} || {};
- my $value;
- if ($ARGSRef->{"${field}s-Magic"} and exists $ARGSRef->{"${field}s"}) {
- $value = $ARGSRef->{"${field}s"};
+ # We only validate Single Combos -- multis can never be user input
+ next if $submitted->{"Values-Magic"} and exists $submitted->{"Values"}
+ and ref $submitted->{"Values"};
- # We only validate Single Combos -- multis can never be user input
- next if ref $value;
- }
- else {
- $value = $ARGSRef->{$field};
- }
- $m->notes(('Field-' . $CF->Id) => $value);
+ $m->notes(('Field-' . $CF->Id) => $submitted->{Value} );
- my @values = ();
- if ( ref $value eq 'ARRAY' ) {
- @values = @$value;
- } elsif ( $CF->Type =~ /text/i ) {
- @values = ($value);
- } else {
- @values = split /\r*\n/, ( defined $value ? $value : '');
- }
- @values = grep $_ ne '',
- map {
- s/\r+\n/\n/g;
- s/^\s+//;
- s/\s+$//;
- $_;
- }
- grep defined, @values;
- @values = ('') unless @values;
+ my @values = _NormalizeObjectCustomFieldValue(
+ CustomField => $CF,
+ Value => $submitted->{Values} || $submitted->{Value},
+ );
+ push @values, '' unless @values;
for my $value( @values ) {
if ($value) {
@@ -119,7 +104,7 @@ $m->notes('ValidFields', $valid);
return wantarray? ($valid, @res): $valid;
</%INIT>
<%ARGS>
+$Object => RT::Ticket->new( $session{'CurrentUser'})
$CustomFields
$ARGSRef
-$NamePrefix => "Object-RT::Ticket--CustomField-"
</%ARGS>
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index d3bc54a..5734f95 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -287,7 +287,7 @@ if ( $ARGS{'SubmitTicket'} ) {
my ($status, @msg) = $m->comp(
'/Elements/ValidateCustomFields',
CustomFields => $TicketObj->TransactionCustomFields,
- NamePrefix => "Object-RT::Transaction--CustomField-",
+ Object => RT::Transaction->new( $session{'CurrentUser'} ),
ARGSRef => \%ARGS
);
unless ( $status ) {
commit b4ca13dbb9849296f28a0b2798801643ca54715e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu Nov 15 18:19:41 2012 -0500
Use the _NormalizeObjectCustomFieldValue refactoring
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index 6412550..e54536c 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -299,13 +299,6 @@ my %queues;
$Tickets->RedoSearch();
-# pull out the labels for any custom fields we want to update
-
-my $cf_del_keys;
-@$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
-my $cf_add_keys;
-@$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
-
unless ( $ARGS{'AddMoreAttach'} ) {
# Add session attachments if any to be processed by ProcessUpdateMessage
$ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
@@ -345,60 +338,37 @@ unless ( $ARGS{'AddMoreAttach'} ) {
my @cfresults;
- foreach my $list ( $cf_add_keys, $cf_del_keys ) {
- next unless $list->[0];
+ foreach my $key ( keys %ARGS ) {
+ next unless $key =~ /^Bulk-(Add|Delete)-CustomField-(\d+)-(.*)$/;
+ my ($op,$cfid,$rest) = ($1, $2, $3);
+ next if $rest eq "Category";
+ my $cf = RT::CustomField->new( $session{'CurrentUser'} );
+ $cf->Load($cfid);
+ next unless $cf->Id;
- my $op;
- if ( $list->[0] =~ /Add/ ) {
- $op = 'add';
-
- }
- elsif ( $list->[0] =~ /Del/ ) {
- $op = 'del';
- }
- else {
- $RT::Logger->crit(
- "Got an op that was neither add nor delete. can never happen"
- . $list->[0] );
- last;
- }
+ my @values = _NormalizeObjectCustomFieldValue(
+ CustomField => $cf,
+ Value => $ARGS{$key},
+ Param => $key,
+ );
- foreach my $key (@$list) {
- my ( $cfid, $cf );
- next if $key =~ /CustomField-(\d+)-Category$/;
- if ( $key =~ /CustomField-(\d+)-/ ) {
- $cfid = $1;
- $cf = RT::CustomField->new( $session{'CurrentUser'} );
- $cf->Load($cfid);
+ my $current_values = $Ticket->CustomFieldValues($cfid);
+ foreach my $value (@values) {
+ if ( $op eq 'Delete' && $current_values->HasEntry($value) ) {
+ my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
+ Field => $cfid,
+ Value => $value
+ );
+ push @cfresults, $msg;
}
- else {next}
- my @values =
- ref( $ARGS{$key} ) eq 'ARRAY'
- ? @{ $ARGS{$key} }
- : ( $ARGS{$key} );
- map { s/(\r\n|\r)/\n/g; } @values; # fix the newlines
- # now break the multiline values into multivalues
- @values = map { split( /\n/, $_ ) } @values
- unless ( $cf->SingleValue );
-
- my $current_values = $Ticket->CustomFieldValues($cfid);
- foreach my $value (@values) {
- if ( $op eq 'del' && $current_values->HasEntry($value) ) {
- my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
- Field => $cfid,
- Value => $value
- );
- push @cfresults, $msg;
- }
-
- elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
- my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
- Field => $cfid,
- Value => $value
- );
- push @cfresults, $msg;
- }
+
+ elsif ( $op eq 'Add' && !$current_values->HasEntry($value) ) {
+ my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
+ Field => $cfid,
+ Value => $value
+ );
+ push @cfresults, $msg;
}
}
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list