PreventDoubleUpdate

From Request Tracker Wiki
Revision as of 12:26, 20 December 2010 by 173.10.126.249 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Occasionally if the server is slow, a user will click the "Update Ticket" button multiple times. This will result in multiple transactions. I prevent this using Javascript. Note that this hack is only to prevent an RT user from mistakenly posting several responses. It will not prevent a malicious user from making multiple updates. This has been tested with RT 3.8.8 in Firefox 3, Google Chrome 8, and Internet Explorer 8.

Create a javascript file called [local]/html/NoAuth/js/disableSubmit.js with the following:

function disableSubmit(whichButton)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        document.getElementById(whichButton).style.visibility = 'hidden';
    }
    // else, old browser.
}



Add the bolded line to your [local]/html/Elements/HeaderJavascript file:




% if ( RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'}) ) {



Modify the line in [local]/html/Ticket/Update.html. Original text:

<& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket' &>
% if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
<&|/Widgets/TitleBox, title => loc('Scrips and Recipients') &>
<& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>

Change to the following:

<& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket', OnClick => "javascript:disableSubmit('mFormSubmit')", id => 'mFormSubmit' &>
% if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
<&|/Widgets/TitleBox, title => loc('Scrips and Recipients') &>
<& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>



Now (after restarting the http server), clicking the "Update Ticket" button should cause the button to disappear and the ticket to update.