Prepare for messages and prevent double submit

This commit is contained in:
Dennis Eichhorn 2018-02-14 17:33:50 +01:00
parent d00924bcd6
commit eba81f20c6
4 changed files with 63 additions and 4 deletions

View File

@ -30,5 +30,13 @@
jsOMS.Message.Notification.App.AppNotification.prototype.send = function(msg)
{
const tpl = document.getElementById('app-message');
if (tpl === null) {
return;
}
let output = document.importNode(tpl.content, true);
tpl.parentNode.appendChild(output);
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -0,0 +1,21 @@
/**
* App notification.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS) {
"use strict";
/** @namespace jsOMS.Message.Notification.App */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification');
jsOMS.Message.Notification.NotificationMessage = function (status, title, message)
{
this.status = 0;
this.title = title;
this.message = message;
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -196,6 +196,14 @@
return;
}
if (form.getMethod() !== jsOMS.Message.Request.RequestMethod.GET
&& Math.floor(Date.now()) - form.getLastSubmit() < 500
) {
return;
}
form.updateLastSubmit();
/* Handle default submit */
const request = new jsOMS.Message.Request.Request(),
self = this;
@ -214,6 +222,14 @@
let tempResponse = null,
success = null;
self.app.notifyManager.send(
new jsOMS.Message.Notification.NotificationMessage(
jsOMS.Message.Notification.NotificationLevel,
'Success',
'Successfully created object'
), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION
);
/* Handle responses (can be multiple response object) */
for (let k = 0; k < responseLength; ++k) {
tempResponse = response.getByIndex(k);
@ -225,6 +241,8 @@
}
}
} catch (e) {
console.log(e);
jsOMS.Log.Logger.instance.error('Invalid form response. \n'
+ 'URL: ' + form.getAction() + '\n'
+ 'Request: ' + JSON.stringify(form.getData()) + '\n'

View File

@ -29,7 +29,9 @@
this.initializeMembers();
this.bind();
this.success = null;
this.success = null;
this.lastSubmit = 0;
};
/**
@ -70,6 +72,16 @@
return this.action;
};
jsOMS.Views.FormView.prototype.getLastSubmit = function ()
{
return this.lastSubmit;
};
jsOMS.Views.FormView.prototype.updateLastSubmit = function ()
{
this.lastSubmit = Math.floor(Date.now());
};
/**
* Get submit elements
*
@ -196,9 +208,9 @@
try {
for (let i = 0; i < length; ++i) {
if ((elements[i].required && elements[i].value === '')
|| (typeof elements[i].pattern !== 'undefined'
&& elements[i].pattern !== ''
if ((elements[i].required && elements[i].value === '')
|| (typeof elements[i].pattern !== 'undefined'
&& elements[i].pattern !== ''
&& !(new RegExp(elements[i].pattern)).test(elements[i].value))
) {
return false;