Hide Pending from ticket form when it's not pending

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

Moderator: crythias

Post Reply
User avatar
crythias
Moderator
Posts: 9980
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA
Contact:

Hide Pending from ticket form when it's not pending

Post by crythias » 03 Sep 2012, 00:17

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 5.0.x (private/testing/public) on Linux with MySQL database. Also on github.
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
OTRS newbie
Posts: 2
Joined: 10 Sep 2012, 11:54
OTRS Version?: 3.1.4
Real Name: John Murray

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

Post by johnm » 10 Sep 2012, 12:00

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
OTRS newbie
Posts: 23
Joined: 25 Jul 2014, 15:39
OTRS Version?: 3.3.12

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

Post by DBSRAJW » 04 Dec 2014, 16:10

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

User avatar
crythias
Moderator
Posts: 9980
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA
Contact:

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

Post by crythias » 04 Dec 2014, 16:23

Kindly edit your post to include the version of OTRS that you're using.
OTRS 5.0.x (private/testing/public) on Linux with MySQL database. Also on github.
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

User avatar
stephan14x
OTRS newbie
Posts: 6
Joined: 08 Jan 2014, 08:54
OTRS Version?: 3.3.11
Real Name: Stephan Lang
Company: Bock 1 GmbH & Co. KG

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

Post by stephan14x » 15 Jan 2015, 23:48

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