[Rt-commit] rt branch, 4.2/generic-bulk-update-components, created. rt-4.1.17-177-g9548b9d
Ruslan Zakirov
ruz at bestpractical.com
Fri Aug 9 15:22:35 EDT 2013
The branch, 4.2/generic-bulk-update-components has been created
at 9548b9d7dc671b4ab357f3773275e04361d509fb (commit)
- Log -----------------------------------------------------------------
commit b3d31bdbd9d668bf90a90b334175259cec7a4586
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Aug 9 13:32:49 2013 +0400
BulkLinks editor suitable not only for Tickets
diff --git a/share/html/Ticket/Elements/BulkLinks b/share/html/Elements/BulkLinks
similarity index 79%
rename from share/html/Ticket/Elements/BulkLinks
rename to share/html/Elements/BulkLinks
index f740684..0ebccb4 100644
--- a/share/html/Ticket/Elements/BulkLinks
+++ b/share/html/Elements/BulkLinks
@@ -120,36 +120,38 @@
</td>
<td valign="top">
<h3><&|/l&>New Links</&></h3>
-<i><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&>
-</i><br />
+<em><&|/l&>Enter URIs to link to. Separate multiple entries with spaces.</&>
+</em><br />
<table>
+% if ($Collection->isa('RT::Tickets') || $ShowMerge ) {
<tr>
<td class="label"><&|/l&>Merge into</&>:</td>
- <td class="entry"><input name="Ticket-MergeInto" value="<% $ARGS{'Ticket-MergeInto'} || '' %>" /> <i><&|/l&>(only one ticket)</&></i></td>
+ <td class="entry"><input name="<% $record_type %>-MergeInto" value="<% $ARGS{ $record_type .'-MergeInto' } || '' %>" /> <i><&|/l&>(only one ticket)</&></i></td>
</tr>
+% }
<tr>
<td class="label"><&|/l&>Depends on</&>:</td>
- <td class="entry"><input name="Ticket-DependsOn" value="<% $ARGS{'Ticket-DependsOn'} || '' %>" /></td>
+ <td class="entry"><input name="<% $record_type %>-DependsOn" value="<% $ARGS{ $record_type .'-DependsOn' } || '' %>" /></td>
</tr>
<tr>
<td class="label"><&|/l&>Depended on by</&>:</td>
- <td class="entry"><input name="DependsOn-Ticket" value="<% $ARGS{'DependsOn-Ticket'} || '' %>" /></td>
+ <td class="entry"><input name="DependsOn-<% $record_type %>" value="<% $ARGS{ 'DependsOn-'. $record_type } || '' %>" /></td>
</tr>
<tr>
<td class="label"><&|/l&>Parents</&>:</td>
- <td class="entry"><input name="Ticket-MemberOf" value="<% $ARGS{'Ticket-MemberOf'} || '' %>" /></td>
+ <td class="entry"><input name="<% $record_type %>-MemberOf" value="<% $ARGS{ $record_type .'-MemberOf'} || '' %>" /></td>
</tr>
<tr>
<td class="label"><&|/l&>Children</&>:</td>
- <td class="entry"> <input name="MemberOf-Ticket" value="<% $ARGS{'MemberOf-Ticket'} || '' %>" /></td>
+ <td class="entry"> <input name="MemberOf-<% $record_type %>" value="<% $ARGS{ 'MemberOf-'. $record_type } || '' %>" /></td>
</tr>
<tr>
<td class="label"><&|/l&>Refers to</&>:</td>
- <td class="entry"><input name="Ticket-RefersTo" value="<% $ARGS{'Ticket-RefersTo'} || '' %>" /></td>
+ <td class="entry"><input name="<% $record_type %>-RefersTo" value="<% $ARGS{ $record_type .'-RefersTo'} || '' %>" /></td>
</tr>
<tr>
<td class="label"><&|/l&>Referred to by</&>:</td>
- <td class="entry"> <input name="RefersTo-Ticket" value="<% $ARGS{'RefersTo-Ticket'} || '' %>" /></td>
+ <td class="entry"> <input name="RefersTo-<% $record_type %>" value="<% $ARGS{ 'RefersTo-'. $record_type } || '' %>" /></td>
</tr>
</table>
</td>
@@ -157,32 +159,39 @@
</table>
<%ARGS>
-$Tickets => undef
+$Collection
+$ShowMerge => 0
</%ARGS>
<%INIT>
+
+my @types = qw/DependsOn DependedOnBy Members MemberOf RefersTo ReferredToBy/;
+
+my $record_type = $Collection->RecordClass;
+$record_type =~ s/^RT:://; $record_type =~ s/::/-/g;
+
my %hash;
-if ( $Tickets && $Tickets->Count ) {
- my $first_ticket = $Tickets->Next;
- # we only show current links that eixst on all the tickets
- for my $type ( qw/DependsOn DependedOnBy Members MemberOf RefersTo
- ReferredToBy/ ) {
+if ( $Collection->Count ) {
+ my $first_record = $Collection->Next;
+ # we only show current links that exist on all the records
+ for my $type ( @types ) {
my $target_or_base =
$type =~ /DependsOn|MemberOf|RefersTo/ ? 'Target' : 'Base';
- while ( my $link = $first_ticket->$type->Next ) {
+ my $links = $first_record->$type;
+ while ( my $link = $links->Next ) {
$hash{$type}{$link->$target_or_base} = $link;
}
}
- while ( my $ticket = $Tickets->Next ) {
- for my $type ( qw/DependsOn DependedOnBy Members MemberOf RefersTo
- ReferredToBy/ ) {
+ while ( my $record = $Collection->Next ) {
+ for my $type ( @types ) {
my $target_or_base =
$type =~ /DependsOn|MemberOf|RefersTo/ ? 'Target' : 'Base';
# if $hash{$type} is empty, no need to check any more
next unless $hash{$type} && keys %{$hash{$type}};
+
my %exists;
- while ( my $link = $ticket->$type->Next ) {
+ while ( my $link = $record->$type->Next ) {
$exists{$link->$target_or_base}++;
}
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index e1b0f9c..a56a545 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -203,7 +203,7 @@ $cfs->LimitToQueue($_) for keys %$seen_queues;
<&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
<em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
-<& /Ticket/Elements/BulkLinks, Tickets => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
+<& /Elements/BulkLinks, Collection => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
</&>
<& /Elements/Submit, Label => loc('Update') &>
commit 9548b9d7dc671b4ab357f3773275e04361d509fb
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Aug 9 14:32:51 2013 +0400
extract generic BulkCustomFields, not only for Tickets
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 030d32f..6cc96cd 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3463,6 +3463,49 @@ sub ProcessTransactionSquelching {
return %squelched;
}
+sub ProcessRecordBulkCustomFields {
+ my %args = (RecordObj => undef, ARGSRef => {}, @_);
+
+ my $ARGSRef = $args{'ARGSRef'};
+
+ my @results;
+ foreach my $key ( keys %$ARGSRef ) {
+ 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 @values = _NormalizeObjectCustomFieldValue(
+ CustomField => $cf,
+ Value => $ARGSRef->{$key},
+ Param => $key,
+ );
+
+ my $current_values = $args{'RecordObj'}->CustomFieldValues( $cfid );
+ foreach my $value (@values) {
+ if ( $op eq 'Delete' && $current_values->HasEntry($value) ) {
+ my ( $id, $msg ) = $args{'RecordObj'}->DeleteCustomFieldValue(
+ Field => $cfid,
+ Value => $value
+ );
+ push @results, $msg;
+ }
+
+ elsif ( $op eq 'Add' && !$current_values->HasEntry($value) ) {
+ my ( $id, $msg ) = $args{'RecordObj'}->AddCustomFieldValue(
+ Field => $cfid,
+ Value => $value
+ );
+ push @results, $msg;
+ }
+ }
+ }
+ return @results;
+}
+
=head2 _UploadedFile ( $arg );
Takes a CGI parameter name; if a file is uploaded under that name,
diff --git a/share/html/Elements/BulkCustomFields b/share/html/Elements/BulkCustomFields
new file mode 100644
index 0000000..9ee40dc
--- /dev/null
+++ b/share/html/Elements/BulkCustomFields
@@ -0,0 +1,44 @@
+<table>
+
+<tr>
+<th><&|/l&>Name</&></th>
+<th><&|/l&>Add values</&></th>
+<th><&|/l&>Delete values</&></th>
+</tr>
+
+% while (my $cf = $CustomFields->Next) {
+<tr>
+<td class="label"><% loc($cf->Name) %><br />
+<em>(<% $cf->FriendlyType %>)</em></td>
+% my $rows = 5;
+% my $cf_id = $cf->id;
+% my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows,
+% Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25,
+% Default => $ARGS{"Bulk-Add-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Add-CustomField-$cf_id-Value"}, );
+% my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf,
+% Rows => $rows, Multiple => 1, Cols => 25,
+% Default => $ARGS{"Bulk-Delete-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Delete-CustomField-$cf_id-Value"}, );
+% if ($cf->Type eq 'Select') {
+<td><& /Elements/EditCustomFieldSelect, @add &></td>
+<td><& /Elements/EditCustomFieldSelect, @del &></td>
+% } elsif ($cf->Type eq 'Combobox') {
+<td><& /Elements/EditCustomFieldCombobox, @add &></td>
+<td><& /Elements/EditCustomFieldCombobox, @del &></td>
+% } elsif ($cf->Type eq 'Freeform') {
+<td><& /Elements/EditCustomFieldFreeform, @add &></td>
+<td><& /Elements/EditCustomFieldFreeform, @del &></td>
+% } elsif ($cf->Type eq 'Text') {
+<td><& /Elements/EditCustomFieldText, @add &></td>
+<td> </td>
+% } else {
+% $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
+% }
+</tr>
+% }
+</table>
+<%ARGS>
+$CustomFields
+</%ARGS>
+<%INIT>
+return unless $CustomFields->Count;
+</%INIT>
\ No newline at end of file
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index a56a545..fdc99b0 100644
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -160,44 +160,9 @@ $cfs->LimitToGlobal();
$cfs->LimitToQueue($_) for keys %$seen_queues;
</%perl>
-% if ($cfs->Count) {
-<&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
-<table>
-<tr>
-<th><&|/l&>Name</&></th>
-<th><&|/l&>Add values</&></th>
-<th><&|/l&>Delete values</&></th>
-</tr>
-% while (my $cf = $cfs->Next()) {
-<tr>
-<td class="label"><% loc($cf->Name) %><br />
-<em>(<%$cf->FriendlyType%>)</em></td>
-% my $rows = 5;
-% my $cf_id = $cf->id;
-% my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows,
-% Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25,
-% Default => $ARGS{"Bulk-Add-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Add-CustomField-$cf_id-Value"}, );
-% my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf,
-% Rows => $rows, Multiple => 1, Cols => 25,
-% Default => $ARGS{"Bulk-Delete-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Delete-CustomField-$cf_id-Value"}, );
-% if ($cf->Type eq 'Select') {
-<td><& /Elements/EditCustomFieldSelect, @add &></td>
-<td><& /Elements/EditCustomFieldSelect, @del &></td>
-% } elsif ($cf->Type eq 'Combobox') {
-<td><& /Elements/EditCustomFieldCombobox, @add &></td>
-<td><& /Elements/EditCustomFieldCombobox, @del &></td>
-% } elsif ($cf->Type eq 'Freeform') {
-<td><& /Elements/EditCustomFieldFreeform, @add &></td>
-<td><& /Elements/EditCustomFieldFreeform, @del &></td>
-% } elsif ($cf->Type eq 'Text') {
-<td><& /Elements/EditCustomFieldText, @add &></td>
-<td> </td>
-% } else {
-% $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
-% }
-</tr>
-% }
-</table>
+% if ( $cfs->Count ) {
+<&|/Widgets/TitleBox, title => loc('Edit Custom Fields') &>
+<& /Elements/BulkCustomFields, $ARGS{'AddMoreAttach'} ? %ARGS : (), CustomFields => $cfs &>
</&>
% }
@@ -301,42 +266,8 @@ unless ( $ARGS{'AddMoreAttach'} ) {
@linkresults =
ProcessTicketLinks( TicketObj => $Ticket, TicketId => 'Ticket', ARGSRef => \%ARGS );
- my @cfresults;
-
- 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 @values = _NormalizeObjectCustomFieldValue(
- CustomField => $cf,
- Value => $ARGS{$key},
- Param => $key,
- );
-
- 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;
- }
-
- elsif ( $op eq 'Add' && !$current_values->HasEntry($value) ) {
- my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
- Field => $cfid,
- Value => $value
- );
- push @cfresults, $msg;
- }
- }
- }
+ my @cfresults = ProcessRecordBulkCustomFields( RecordObj => $Ticket, ARGSRef => \%ARGS );
+
my @tempresults = (
@watchresults, @basicresults, @dateresults,
@updateresults, @linkresults, @cfresults
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list