[Rt-commit] rt branch, 4.2/generic-bulk-update-components, created. rt-4.1.17-177-gafbcb67

Ruslan Zakirov ruz at bestpractical.com
Tue Aug 20 07:17:19 EDT 2013


The branch, 4.2/generic-bulk-update-components has been created
        at  afbcb679af48e52e4d8360463a5d7293866056dc (commit)

- Log -----------------------------------------------------------------
commit 68ba8e85a4c809bc7a52aa49341439518429ec2c
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..30d3a08 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 Enter tickets or 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 afbcb679af48e52e4d8360463a5d7293866056dc
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..22b07a6
--- /dev/null
+++ b/share/html/Elements/BulkCustomFields
@@ -0,0 +1,91 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+%#                                          <sales 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 }}}
+<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