[Rt-commit] rt branch, 4.4/link_multiple_assets_to_new_ticket, created. rt-4.4.0-247-g2edbafc

Jim Brandt jbrandt at bestpractical.com
Tue Jun 14 13:38:49 EDT 2016


The branch, 4.4/link_multiple_assets_to_new_ticket has been created
        at  2edbafc7e0ee1cd6fd30316c1ff971a525ddd919 (commit)

- Log -----------------------------------------------------------------
commit 2edbafc7e0ee1cd6fd30316c1ff971a525ddd919
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Jun 14 13:35:44 2016 -0400

    Link multiple assets to a new ticket from asset bulk update
    
    Support creating a ticket from the asset bulk update page
    and linking all selected assets to the created ticket. The
    list of possible requestors is pulled from roles on all
    selected assets.
    
    The user is directed to the ticket create page for any
    final updates before creating the ticket.

diff --git a/share/html/Asset/CreateLinkedTicket.html b/share/html/Asset/CreateLinkedTicket.html
index e2753b1..864ba20 100644
--- a/share/html/Asset/CreateLinkedTicket.html
+++ b/share/html/Asset/CreateLinkedTicket.html
@@ -47,12 +47,30 @@
 %# END BPS TAGGED BLOCK }}}
 <%args>
 $Asset => undef
+ at Assets => ()
 $Requestors => ''
 </%args>
 <%init>
-my $asset = LoadAsset($Asset);
+my @asset_objs;
+my $single_asset;
+
+# Support passing a single asset or many, as with bulk update.
+if ( $Asset ){
+    push @asset_objs, LoadAsset($Asset);
+    $single_asset = 1;
+}
+elsif ( @Assets ){
+    @asset_objs = map { LoadAsset($_) } @Assets;
+    $single_asset = 1 if @asset_objs == 1;
+}
 </%init>
-<& /Elements/Header,
-    Title => loc("Create linked ticket for asset #[_1]: [_2]", $asset->id, $asset->Name) &>
+% if ($single_asset){
+    <& /Elements/Header,
+        Title => loc("Create linked ticket for asset #[_1]: [_2]", $asset_objs[0]->id, $asset_objs[0]->Name) &>
+%}
+%else{
+    <& /Elements/Header,
+        Title => loc("Create linked ticket for multiple assets") &>
+%}
 <& /Elements/Tabs &>
-<& /Asset/Elements/CreateLinkedTicket, AssetObj => $asset, Requestors => $Requestors &>
+<& /Asset/Elements/CreateLinkedTicket, AssetObj => \@asset_objs, Requestors => $Requestors &>
diff --git a/share/html/Asset/Elements/CreateLinkedTicket b/share/html/Asset/Elements/CreateLinkedTicket
index 17102bd..b3b87a2 100644
--- a/share/html/Asset/Elements/CreateLinkedTicket
+++ b/share/html/Asset/Elements/CreateLinkedTicket
@@ -50,21 +50,50 @@ $AssetObj
 $Requestors => ''
 </%args>
 <%init>
+my @asset_objs;
+if ( ref $AssetObj eq 'ARRAY' ){
+    # Accept an array of asset objects
+    @asset_objs = @$AssetObj;
+}
+else{
+    # Also support passing a single asset object
+    push @asset_objs, $AssetObj;
+}
+
 my @description = map { $m->interp->apply_escapes($_, 'h') }
-    $AssetObj->id, $AssetObj->Name;
+    $asset_objs[0]->id, $asset_objs[0]->Name;
+
+my $refers_to = join ' ', map { "asset:" . $_->id } @asset_objs;
+
+# Find possible requestors
+my %role_addresses;
+foreach my $asset (@asset_objs){
+    for my $role ($asset->Roles) {
+        # Create a hash with email addresses to easily de-dupe the lists from multiple assets
+        map { $role_addresses{$role}{$_} = 1 } $asset->RoleGroup($role)->MemberEmailAddresses;
+    }
+}
+
 </%init>
 <form action="<% RT->Config->Get("WebPath") %><% $session{CurrentUser}->Privileged ? "/Ticket" : "/SelfService" %>/Create.html" id="AssetCreateLinkedTicket">
-  <input name="new-RefersTo" value="asset:<% $AssetObj->id %>" type="hidden">
-  <input name="Subject" value="<% $AssetObj->Name %>" type="hidden">
+  <input name="new-RefersTo" value="<% $refers_to %>" type="hidden">
+  <input name="Subject" value="<% $asset_objs[0]->Name %>" type="hidden">
+% if ( @asset_objs == 1 ){
   <&|/l_unsafe,
     $m->scomp("/Elements/SelectNewTicketQueue"),
     @description &>Create a new ticket in the [_1] queue about asset #[_2]: [_3].</&>
+% }
+% else {
+<&|/l_unsafe,
+    $m->scomp("/Elements/SelectNewTicketQueue"),
+    &>Create a new ticket in the [_1] queue about multiple assets.</&>
+% }
 % if ($Requestors) {
     <input type="hidden" name="Requestors" value="<% $Requestors%>" />
 % } else {
 %     my $first = 1;
-%     for my $role ($AssetObj->Roles) {
-%         my $addr = $AssetObj->RoleGroup($role)->MemberEmailAddressesAsString;
+%     for my $role ($asset_objs[0]->Roles) {
+%         my $addr = join ', ', keys %{$role_addresses{$role}};
 %         next unless defined $addr and length $addr;
   <br>
   <label>
diff --git a/share/html/Asset/Helpers/CreateLinkedTicket b/share/html/Asset/Helpers/CreateLinkedTicket
index 6728b7b..f487d52 100644
--- a/share/html/Asset/Helpers/CreateLinkedTicket
+++ b/share/html/Asset/Helpers/CreateLinkedTicket
@@ -46,11 +46,19 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%args>
-$Asset
+ at Asset => ()
+$Asset => undef
 $Requestors => ''
 </%args>
 <%init>
-my $asset = LoadAsset($Asset);
+my @asset_objs;
+if ( @Asset ){
+    @asset_objs = map { LoadAsset($_) } @Asset;
+}
+elsif ( $Asset ){
+    push @asset_objs, LoadAsset($Asset);
+}
+
 </%init>
-<& /Asset/Elements/CreateLinkedTicket, AssetObj => $asset, Requestors => $Requestors &>
+<& /Asset/Elements/CreateLinkedTicket, AssetObj => \@asset_objs, Requestors => $Requestors &>
 % $m->abort;
diff --git a/share/html/Asset/Search/Bulk.html b/share/html/Asset/Search/Bulk.html
index 9780c10..87a0513 100644
--- a/share/html/Asset/Search/Bulk.html
+++ b/share/html/Asset/Search/Bulk.html
@@ -72,6 +72,12 @@
     CheckboxNameRegex => '/^UpdateAsset(All)?$/',
     CheckAll => 1, ClearAll => 1,
 &>
+<div class="submit">
+  <div class="buttons">
+  <span class="caption"></span>
+  <input type="submit" id="bulk-update-create-linked-ticket" name="CreateLinkedTicket"  value="Create Linked Ticket" class="button" alt="Create a ticket with checked assets linked" />
+  </div>
+</div>
 
 <&| /Widgets/TitleBox, title => loc("Basics"), class => "asset-basics asset-bulk-basics", title_class => "inverse" &>
 <table>
@@ -165,7 +171,12 @@ delete $ARGS{$_} foreach grep { $ARGS{$_} =~ /^$/ } keys %ARGS;
 
 $DECODED_ARGS->{'UpdateAssetAll'} = 1 unless @UpdateAsset;
 
-if ( $ARGS{Update} ) {
+if ( $ARGS{'CreateLinkedTicket'} ){
+    my $url = RT->Config->Get('WebURL') . "Asset/CreateLinkedTicket.html";
+    $url .= '?'. $m->comp( '/Elements/QueryString', 'Assets' => \@UpdateAsset );
+    RT::Interface::Web::Redirect($url);
+}
+elsif ( $ARGS{Update} ) {
     my @attributes  = $asset->WritableAttributes;
     @attributes = grep exists $ARGS{ 'Update'. $_ }, @attributes;
     my %basics = map { $_ => $ARGS{ 'Update'. $_ } } @attributes;
diff --git a/share/static/js/assets.js b/share/static/js/assets.js
index 853ba86..8d5aaa0 100644
--- a/share/static/js/assets.js
+++ b/share/static/js/assets.js
@@ -34,6 +34,25 @@ jQuery(function() {
             showModal
         );
     });
+    jQuery("#bulk-update-create-linked-ticket").click(function(ev){
+        ev.preventDefault();
+        var chkArray = [];
+
+        jQuery("input[name='UpdateAsset']:checked").each(function() {
+            chkArray.push(jQuery(this).val());
+        });
+
+        var selected = '';
+        for (var i = 0; i < chkArray.length; i++) {
+            selected += 'Asset=' + chkArray[i] + '&';
+        }
+        /* selected = chkArray.join(','); */
+        var url = RT.Config.WebHomePath + '/Asset/Helpers/CreateLinkedTicket?' + selected;
+        jQuery.post(
+            url,
+            showModal
+        );
+    });
     jQuery("#assets-create").click(function(ev){
         ev.preventDefault();
         jQuery.get(

-----------------------------------------------------------------------


More information about the rt-commit mailing list