Page 1 of 1

Automatic save draft reply

Posted: Thu Mar 16, 2023 7:45 am
by lhesk
I want wrote jquery script which automatic save draft reply because sometimes when server have some bug or accidentally I close browser I have to write again responde. I think the maybe the same problem have another which use hesk.

I don't know why my code below doesn't save the response but sends a message to the client.

Code: Select all

if(window.location.href.indexOf("admin_ticket.php?track") > -1)
{
  var timeleft = 100;
  var downloadTimer = setInterval(function(){
  if(timeleft <= 0){
	clearInterval(downloadTimer);
  }

   if(timeleft == 0){        	
     $('input[name="save_reply"]').on("click", function(){
           $('form[name="form1"]').submit();
      });
    $('input[name="save_reply"]').trigger("click");
     }
     timeleft -= 1;
    }, 1000);
}

Re: Automatic save draft reply

Posted: Fri Mar 17, 2023 10:39 am
by Klemen
The proper way to handle this would be using asynchronous calls.

This should be useful for other users, too, so I've prepared a file to do just this:

1. backup existing Hesk files and database
2. Download this archive
3. upload the files inside the archive to your Hesk's admin folder
4. give it a test

Hesk should now save reply drafts automatically every minute.

If you want to change the saving frequency, open the admin_ticket.php file and change the value of

Code: Select all

var draft_save_every_x_seconds = 60;
Don't set the value too low though as Hesk will then be constantly sending requests and doing database queries.

Re: Automatic save draft reply

Posted: Fri Mar 17, 2023 10:58 am
by lhesk
That code is great and it's what I needed.

I think that you can add this solution to next Hesk update and give user possibilite set this value in Setting->Hesk.

Re: Automatic save draft reply

Posted: Fri Mar 17, 2023 11:25 am
by Klemen
That's the plan, yes.