From a4d39d5873ddab59595ec8b40b35429fcee6406b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 25 Jul 2016 12:55:11 +0200 Subject: [PATCH] fix etemplate2.postSubmit() to not destroy any eT2 session, by unbinding window.onbeforeunload and rebinding it again after 100ms Before postSubmit was unbinding only if current etemplates destroy_session was bound and causes so an other etemplates session_destroy to fire. postSubmit now allways rebinds the session_destroy handler of current etemplate assuming it is only used for downloads, where current etemplate (and session) should persist. --- api/js/etemplate/etemplate2.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/etemplate2.js b/api/js/etemplate/etemplate2.js index 232cf7c741..28d45a1103 100644 --- a/api/js/etemplate/etemplate2.js +++ b/api/js/etemplate/etemplate2.js @@ -305,6 +305,13 @@ etemplate2.prototype.unbind_unload = function() { window.onbeforeunload = null; } + else + { + var onbeforeunload = window.onbeforeunload; + window.onbeforeunload = null; + // bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!) + window.setTimeout(function(){window.onbeforeunload = onbeforeunload;}, 100); + } delete this.destroy_session; }; @@ -756,8 +763,10 @@ etemplate2.prototype.submit = function(button, async, no_validation, _container) }; /** - * Does a full form post submit. - * Only use this one if you need it, use the ajax submit() instead + * Does a full form post submit necessary for downloads + * + * Only use this one if you need it, use the ajax submit() instead. + * It ensures eT2 session continues to exist on server by unbinding unload handler and rebinding it. */ etemplate2.prototype.postSubmit = function() { @@ -793,6 +802,9 @@ etemplate2.prototype.postSubmit = function() input.value = egw().jsonEncode(values); form.append(input); form.appendTo(jQuery('body')).submit(); + + // bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!) + window.setTimeout(jQuery.proxy(this.bind_unload, this), 100); } };