Hide Pending from ticket form when it's not pending

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Forum rules
Dont create your support topics here! No new topics with questions allowed!
Post Reply
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Hide Pending from ticket form when it's not pending

Post by crythias »

In AgentTicketEmail (or AgentTicketPhone) (Addresses this IdeaScale entry)

Change

Code: Select all

<script type="text/javascript">//<![CDATA[
    $('#NextStateID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'NextStateID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', $Data{"DynamicFieldNamesStrg"}, 'To', 'Cc', 'Bcc']);
    });
//]]></script>
to

Code: Select all

<script type="text/javascript">//<![CDATA[
   $('#lblPending').hide();
   $('#fldPending').hide();
    $('#NextStateID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'NextStateID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', $Data{"DynamicFieldNamesStrg"}, 'To', 'Cc', 'Bcc']);

   if ($('#NextStateID :selected').text().indexOf("pending") >-1)
         { $('#lblPending').show(); $('#fldPending').show(); } else { $('#lblPending').hide();  $('#fldPending').hide(); }
    });
//]]></script>
In AgentTicketCompose:
Change

Code: Select all

<script type="text/javascript">//<![CDATA[
    $('#StateID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#ComposeTicket'), 'AJAXUpdate', 'StateID', [ $Data{"DynamicFieldNamesStrg"} ]);
    });
//]]></script>
to

Code: Select all

<script type="text/javascript">//<![CDATA[
   $('#lblPending').hide();
   $('#fldPending').hide();
    $('#StateID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#ComposeTicket'), 'AJAXUpdate', 'StateID', [ $Data{"DynamicFieldNamesStrg"} ]);
   if ($('#StateID :selected').text().indexOf("pending") >-1)
         { $('#lblPending').show(); $('#fldPending').show(); } else { $('#lblPending').hide();  $('#fldPending').hide(); }
    });
//]]></script>
and for each of them, change
<label>$Text{"Pending Date"} to <label id="lblPending">$Text{"Pending Date"} and
<div class="Field"> to <div class="Field" id="fldPending">
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
johnm
Znuny newbie
Posts: 2
Joined: 10 Sep 2012, 11:54
Znuny Version: 3.1.4
Real Name: John Murray

Re: Hide Pending from ticket form when it's not pending

Post by johnm »

Those mods don't cater for the NextState field's default value being configured as a "pending" one. Here are my amended versions of the changed sections:

In AgentTicketEmail (or AgentTicketPhone):

Code: Select all

<script type="text/javascript">//<![CDATA[
    $('#NextStateID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'NextStateID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'PriorityID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID', $Data{"DynamicFieldNamesStrg"}, 'To', 'Cc', 'Bcc']);

   if ($('#NextStateID :selected').text().indexOf("pending") >-1)
         { $('#lblPending').show(); $('#fldPending').show(); } else { $('#lblPending').hide();  $('#fldPending').hide(); }

    });
    
    $('#NextStateID').change();
    
//]]></script>
In AgentTicketCompose:

Code: Select all

<script type="text/javascript">//<![CDATA[
    $('#StateID').bind('change', function (Event) {
        Core.AJAX.FormUpdate($('#ComposeTicket'), 'AJAXUpdate', 'StateID', [ $Data{"DynamicFieldNamesStrg"} ]);

   if ($('#StateID :selected').text().indexOf("pending") >-1)
         { $('#lblPending').show(); $('#fldPending').show(); } else { $('#lblPending').hide();  $('#fldPending').hide(); }

    });
    
    $('#NextStateID').change();
    
//]]></script>
DBSRAJW
Znuny newbie
Posts: 23
Joined: 25 Jul 2014, 15:39
Znuny Version: 3.3.12

Re: Hide Pending from ticket form when it's not pending

Post by DBSRAJW »

Hi

To be honest both versions I tried to include, but failed with both of them. My favorite would be the version of John Murray, anyway in the attached files it is the version of crythias. As understood the version of John should be choosen, if the panding states can also have different names than including the word "panding", what is the case for us.

Result after deploying the files: just nothing. No error message, but also no change regarding the due date field.

Maybe source code was changed since 2012 to much to get it to work fine anymore without that deep programming knowledge.
I have made the changes once for the AgentTicketPhone.dtl and for the AgentTicketEmail.dtl for test purposes.

If somebody would like to help and take a look at my source code, I will attach it as zip file to this article (only the AgentTicketPhone.dtl, as I have done the tests several times and killed my made changes everytime again, just to ensure, I have not made mistakes while implementing mentioned changes).

Thank you very much in advance
Best regards
DBSRAJW

EDIT: I am using OTRS Version 3.3.7. (sorry for that)
You do not have the required permissions to view the files attached to this post.
Last edited by DBSRAJW on 04 Dec 2014, 17:22, edited 1 time in total.
OTRS version: 3.3.12
Operating System: VM / Debian7
Database type: MySQL
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Hide Pending from ticket form when it's not pending

Post by crythias »

Kindly edit your post to include the version of OTRS that you're using.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
stephan14x
Znuny newbie
Posts: 6
Joined: 08 Jan 2014, 08:54
Znuny Version: 6.0.18
Real Name: Stephan Lang
Company: Bock 1 GmbH & Co. KG

Re: Hide Pending from ticket form when it's not pending

Post by stephan14x »

Hi,

i have just written a blog post on how to add javascript to OTRS without editing the templates.
Using my method I have modified your javascript to hide or show the pending date time select

Code: Select all

$( document ).ready(function() {

    var CurrentAction = $.getUrlVar('Action');

    if ( CurrentAction == 'AgentTicketPhone' )
    {
        if ( $('#NextStateID').length )
        {
            OnlyShowPendingDateTimeOnPendingState('#NewPhoneTicket');
            $('#NextStateID').bind('change.CustomChange', function() { OnlyShowPendingDateTimeOnPendingState('#NewPhoneTicket') } );
        }
    }

    if ( CurrentAction == 'AgentTicketEmail' )
    {
        if ( $('#NextStateID').length )
        {
            OnlyShowPendingDateTimeOnPendingState('#NewEmailTicket');
            $('#NextStateID').bind('change.CustomChange', function() { OnlyShowPendingDateTimeOnPendingState('#NewEmailTicket') } );
        }
    }

});

function OnlyShowPendingDateTimeOnPendingState ( FormID )
{
    if ($('#NextStateID :selected').text().indexOf("pending") >-1)
    {
         $('#Month').parent().show();
         $(FormID).find('label').each( function ()
         {
             if ( $(this).html() == 'Pending date:' ) { $(this).show(); };
         } );
    }
    else
    {
        $('#Month').parent().hide();
        $(FormID).find('label').each( function ( i )
        {
            if ( $(this).html() == 'Pending date:' ) { $(this).hide(); };
        } );
    }
}

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split(';');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
Unfortunately there are a lot of elements in otrs that miss an ID so you have to search for them...
OTRS 3.3.11 | MySQL 5.1 | CentOS 6.6 on VMware ESXi | Active Directory Backend for Agents and Customers
Handle with care. All information is provided as is without any warranty. Do not test on a production system.
Post Reply