From 3f9b035f4dea3dfb83b68da5368b0faa1b05001c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 30 Jul 2018 21:51:09 +0200 Subject: [PATCH] Fix minor bugs and double submit leak --- Event/EventManager.js | 7 +++++-- UI/ActionManager.js | 1 - UI/Component/Form.js | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Event/EventManager.js b/Event/EventManager.js index 9ec0c16..adc54a1 100644 --- a/Event/EventManager.js +++ b/Event/EventManager.js @@ -111,16 +111,19 @@ */ trigger (group, id = '', data = null) { - if (!this.callbacks.hasOwnProperty(group)) { + if (!this.callbacks.hasOwnProperty(group) || Math.abs(Date.now() - this.callbacks[group].lastRun) < 500) { return false; } + console.log(group, id); + if (typeof this.groups[group] !== 'undefined') { this.groups[group][id] = true; } if (!this.hasOutstanding(group)) { // todo if it is route then call dispatcher? + this.callbacks[group].lastRun = Date.now(); this.callbacks[group].func(data); if (this.callbacks[group].remove) { @@ -215,7 +218,7 @@ return false; } - this.callbacks[group] = {remove: remove, reset: reset, func: callback}; + this.callbacks[group] = {remove: remove, reset: reset, func: callback, lastRun: 0}; return true; }; diff --git a/UI/ActionManager.js b/UI/ActionManager.js index adda6f6..406bdb3 100644 --- a/UI/ActionManager.js +++ b/UI/ActionManager.js @@ -78,7 +78,6 @@ } let childLength = c.length; - for (let j = 0; j < childLength; ++j) { this.bindListener(c[j].id, listeners[i]); } diff --git a/UI/Component/Form.js b/UI/Component/Form.js index db2be4e..3a9cf4e 100644 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -200,7 +200,7 @@ } if (form.getMethod() !== jsOMS.Message.Request.RequestMethod.GET - && Math.floor(Date.now()) - form.getLastSubmit() < 500 + && Math.abs(Date.now() - form.getLastSubmit()) < 500 ) { return; } @@ -235,10 +235,10 @@ successInject(response); } else if (typeof response.get(0) !== 'undefined' && typeof response.get(0).type !== 'undefined') { self.app.responseManager.run(response.get(0).type, response.get(0), request); - } + } } catch (e) { console.log(e); - + jsOMS.Log.Logger.instance.error('Invalid form response. \n' + 'URL: ' + form.getAction() + '\n' + 'Request: ' + JSON.stringify(form.getData()) + '\n' @@ -247,7 +247,7 @@ } }); - request.setResultCallback(0, function (xhr) + request.setResultCallback(0, function (xhr) { self.app.notifyManager.send( new jsOMS.Message.Notification.NotificationMessage(