Select Sub-queue in new customer ticket

Moderator: crythias

Locked
ricardogarfe
Znuny newbie
Posts: 3
Joined: 23 Jan 2014, 17:10
Znuny Version: 3.3.3
Real Name: Ricardo García Fernández
Company: eXcentia

Select Sub-queue in new customer ticket

Post by ricardogarfe »

Hi !
I'm trying to develop a GUI solution for the customre to be capable of select a sub-queue based on selected queue when creates a new ticket.
Subqueue selected will be stored as queue for created ticket. It's to create easy and short queue/subqueue selection menu.

I've develop in CusomerTicketMessage.dtl a new label for SubQueue:

Edit: Removing

Code: Select all

<!-- dtl:block:SubQueue -->
works !

Code: Select all

<!-- dtl:block:SubQueue -->
<div>
    <label for="SubQueueID" class="Mandatory">
        <span class="Marker">*</span>
        $Text{"SubQueue"}
    </label>
    $Data{"SubQueueStrg"}
    <div id="DestError" class="TooltipErrorMessage" ><p>$Text{"This field is required."}</p></div>
    <div id="DestServerError" class="TooltipErrorMessage NoJavaScriptMessage$QData{"SubQueueInvalid"}" ><p>$Text{"This field is required."}</p></div>
    <div class="Clear"></div>
</div><!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    $('#SubQueueID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'SubQueueID', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
    });
//]]></script>
<!--dtl:js_on_document_complete-->
<!-- dtl:block:SubQueue -->
Furthermore I've created in CustomerTicketMessage.pm a method to retrieve a SubQueue and print into a select object via AJAXUpdate:

Code: Select all

sub _GetSubQueue {
  my ( $Self, %Param ) = @_;
  
  $Self->{LogObject}->Log(
      Priority => 'debug', 
      Message  => "_GetSubQueue" 
  );

  my %Result = ();
  if (defined($_[1])) {
      my $Queue = $_[1];
      my @elems = split(/\|\|/,$Queue);
      my $QName = $elems[-1];
      my $QId = $elems[0];
      my %Queues = $Self->{QueueObject}->QueueList( Valid => 1 );

      my $QueueName = $Queues{$QId} . "::" ;
      $Self->{LogObject}->Log(
          Priority => 'debug', 
          Message  => "_GetSubQueue [" . $QId . "] [" . $QueueName . "]" 
      );

      while ((my $Key, my $Value) = each(%Queues)){
          # Filter 
          if ( index($Value, $QueueName) == 0 ) {
              $Value =~ s/^$QueueName//g;
              $Value =~ s/::/ - /g;
              $Result{$Key} = $Value;
              $Self->{LogObject}->Log(
                  Priority => 'debug', 
                  Message  => "_GetSubQueue [" . $Key . "] [" . $Value . "]" 
              ); 
          }
      }
  
      if (defined($Queue)) {
          $Self->{LogObject}->Log(
              Priority => 'debug', 
              Message  => "_GetSubQueue " . $Queue 
          );    
      }
  }
  
  return \%Result;
}
Retrieving the result as JSON update from selected queue:

Code: Select all

my $SubQueues = $Self->_GetSubQueue($Param{ToSelected});
$Param{SubQueueStrg} = $Self->{LayoutObject}->BuildSelection(
    Data         => $SubQueues,
    Name         => 'SubQueueID',
    SelectedID   => $Param{SubQueueID},
    PossibleNone => 0,
    TreeView     => $TreeView,
    Translation  => 0,
 );

$Self->{LogObject}->Log(
    Priority => 'debug', 
    Message  => "_MaskNew SubQueues: " . $SubQueues . "Param: " . $Param{SubQueueStrg}
);
JSON:

Code: Select all

{
    Name         => 'SubQueueID',
    Data         => $SubQueues,
    SelectedID   => $GetParam{SubQueueID},
    PossibleNone => 1,
    Translation  => 0,
    TreeView     => $TreeView,
    Max          => 100,
},
In OTRS log I can see the result:

Code: Select all

 AJAXUpdate SubQueues: HASH(0x7fa97b55b030)Param: <select id="SubQueueID" name="SubQueueID">
  <option value="74">SubQueue001</option>
  <option value="76">SubQueue002</option>
  <option value="157">SubQueue003</option>
  <option value="75">SubQueue004</option>
</select> <a href="#" title="$Text{"Show Tree Selection"}" class="ShowTreeSelection">$Text{"Show Tree Selection"}</a>
But in my GUI I not capable to see anything...
I think I've forget some comunication between the layers, and if there is another solution or a workaround could be very helpful!

I'm new in perl and, of course in OTRS framework :)
Thanks in advance,
Ricardo.
Last edited by ricardogarfe on 23 Jan 2014, 18:05, edited 1 time in total.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Select Sub-queue in new customer ticket

Post by reneeb »

In the .dtl you should find several of this code snippet

Code: Select all

Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'SubQueueID', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
They should look similiar to this one. In each you have to add "'SubQueueID'" after "'SLAID'"

e.g.

Code: Select all

ore.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'TypeID', ['Dest', 'PriorityID', 'ServiceID', 'SLAID', 'SubQueueID', $Data{"DynamicFieldNamesStrg"}]);
and

Code: Select all

Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', 'SubQueueID', $Data{"DynamicFieldNamesStrg"}]);
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
ricardogarfe
Znuny newbie
Posts: 3
Joined: 23 Jan 2014, 17:10
Znuny Version: 3.3.3
Real Name: Ricardo García Fernández
Company: eXcentia

Re: Select Sub-queue in new customer ticket

Post by ricardogarfe »

Thanks for the tip !

I have this code snippet for SubQueueID to update other fields

Code: Select all

<script type="text/javascript">//<![CDATA[
    $('#SubQueueID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'SubQueueID', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
    });
//]]></script>
And when I update dest field I've added SubQueueId to be updated in JS:

Code: Select all

<script type="text/javascript">//<![CDATA[
    $('#Dest').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SubQueueID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
    });
//]]></script>
I've solved the problem removing <!-- dtl:block:Queue --> notation but I don't know why... I'm very confused :S because this is commented code, I'm I right ?
Thanks !
ricardogarfe
Znuny newbie
Posts: 3
Joined: 23 Jan 2014, 17:10
Znuny Version: 3.3.3
Real Name: Ricardo García Fernández
Company: eXcentia

Re: Select Sub-queue in new customer ticket

Post by ricardogarfe »

Thanks a lot guys!

Now my problem is that when I change my QueueID to save selected subqueue for new ticket. OTRS returns an client side error related to selected subqueue because customer can't select this subqueue in the view.
otrs-subqueue.png
I mean, in system configuration Edit Config Settings in Ticket -> Frontend::Customer::Ticket::ViewNew I defined first level queues to be selected by the customer. If I add a subqueue I can save new tickets perfect, but this subqueue is selectable via frontend customer GUI, I don't want this behaviour. I think if I define an ACL to show first level queues in GUI could fix this problem.

Is there any other solution for define a behaviour selecting a queue and its subqueue in customer's new ticket view ?

Edit: I change the NewQueueID validation with SubqueueID validation, here was the problem because subqueue hasn't been show in queue list:

Code: Select all

        # prevent tamper with (Queue/Dest), see bug#9408
        if ( $NewQueueID && !$IsUpload ) {

            # get the original list of queues to display
            my $Tos = $Self->_GetTos(
                %GetParam,
                %ACLCompatGetParam,
                QueueID => $NewQueueID,
            );

            $LogObject->Log(
                Priority => 'debug', 
                Message  => "ParentQueue: [" . $ParentQueue . "], SubDest: [" . $SubDest . "]" 
            );

            if ($ParentQueue ne $SubDest) {
                my $SubQueues = $Self->_GetSubQueue($ParentQueue);
                
                if (!$SubQueues->{$SubDest}){
                    $Error{QueueInvalid} = 'ServerError';
                }
            }
            
            # check if current selected QueueID exists in the list of queues,\
            # otherwise rise an error
            if (!$SubDest && !$Tos->{$NewQueueID} ) {
                $Error{QueueInvalid} = 'ServerError';
            }

            # set the correct queue name in $To if it was altered
            if (!$SubDest && $To ne $Tos->{$NewQueueID} ) {
                $To = $Tos->{$NewQueueID}
            }
        }
Great
Thanks in advance !
Ricardo.
You do not have the required permissions to view the files attached to this post.
Locked