Api: Add a timeout for form submit

If a submit takes more than 30s, give a warning and hide the loader so the user can try to salvage their changes.
This commit is contained in:
nathan 2023-07-10 09:06:41 -06:00
parent 2de5326f53
commit 0c050ad9f3
2 changed files with 23 additions and 1 deletions

View File

@ -1087,7 +1087,28 @@ export class etemplate2
{
api.loading_prompt('et2_submit_spinner', false);
}, this, async);
request.sendRequest();
const request_promise = request.sendRequest();
// Set up timeout for 30 seconds
let warning_message = null;
const timeout_id = window.setTimeout(() =>
{
// Do not abort request, it might still come
api.debug("warn", "Request '" + this.menuaction + "' timeout")
warning_message = api.message(api.lang("No response from server: your data is probably NOT saved"), "warning");
api.loading_prompt('et2_submit_spinner', false);
}, 30000);
// Cancel timeout
request_promise.then(() =>
{
// Responded * and response processed *
clearTimeout(timeout_id);
if(warning_message)
{
warning_message.close();
}
});
}
else
{

View File

@ -951,6 +951,7 @@ no filters common en No filters
no history for this record common en No history for this record
no key for recipient: common en No key for recipient:
no matches found common en No matches found.
no response from server: your data is probably not saved common en No response from server: your data is probably NOT saved
no results match common en No results match
no rights to export more than %1 entries! common en No rights to export more than %1 entries!
no row to swap with !!! common en No row to swap with!