mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-16 01:08:41 +00:00
Fixing request & response behavior
With regard to login and report creation.
This commit is contained in:
parent
cd3b8a221a
commit
4458ddc121
|
|
@ -21,5 +21,49 @@
|
||||||
*/
|
*/
|
||||||
jsOMS.Message.Request.RequestManager = function ()
|
jsOMS.Message.Request.RequestManager = function ()
|
||||||
{
|
{
|
||||||
|
this.groups = {};
|
||||||
|
this.callbacks = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Message.Request.RequestManager.prototype.addGroup = function(id, group)
|
||||||
|
{
|
||||||
|
if(typeof this.groups[group] == 'undefined') {
|
||||||
|
this.groups[group] = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.groups[group][id] = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Message.Request.RequestManager.prototype.hasOutstanding = function(group)
|
||||||
|
{
|
||||||
|
if(typeof this.groups[group] === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let id in this.groups[group]) {
|
||||||
|
if (!this.groups[group][id]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Message.Request.RequestManager.prototype.triggerDone = function(id, group)
|
||||||
|
{
|
||||||
|
if(typeof this.groups[group] !== 'undefined') {
|
||||||
|
this.groups[group][id] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.hasOutstanding(group)) {
|
||||||
|
this.callbacks[group]();
|
||||||
|
delete this.callbacks[group];
|
||||||
|
delete this.groups[group];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.Message.Request.RequestManager.prototype.setDone = function(group, callback)
|
||||||
|
{
|
||||||
|
this.callbacks[group] = callback;
|
||||||
};
|
};
|
||||||
}(window.jsOMS = window.jsOMS || {}));
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@
|
||||||
*/
|
*/
|
||||||
jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request)
|
jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request)
|
||||||
{
|
{
|
||||||
console.log(data);
|
|
||||||
if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') {
|
if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') {
|
||||||
this.messages[key][request](data);
|
this.messages[key][request](data);
|
||||||
} else if (typeof this.messages[key] !== 'undefined') {
|
} else if (typeof this.messages[key] !== 'undefined') {
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@
|
||||||
this.forms[id] = new jsOMS.Views.FormView(id);
|
this.forms[id] = new jsOMS.Views.FormView(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.forms[id].getSubmit().addEventListener('click', function(event) {
|
this.forms[id].getSubmit().addEventListener('click', function (event)
|
||||||
|
{
|
||||||
jsOMS.preventAll(event);
|
jsOMS.preventAll(event);
|
||||||
self.submit(self.forms[id]);
|
self.submit(self.forms[id]);
|
||||||
});
|
});
|
||||||
|
|
@ -92,18 +93,30 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.UI.FormManager.prototype.submit = function (form)
|
jsOMS.UI.FormManager.prototype.submit = function (form)
|
||||||
|
{
|
||||||
|
/* Handle injects */
|
||||||
|
let self = this,
|
||||||
|
injects = form.getSubmitInjects(),
|
||||||
|
counter = 0;
|
||||||
|
|
||||||
|
for (let property in injects) {
|
||||||
|
counter++;
|
||||||
|
this.app.requestManager.addGroup(counter, form.getId());
|
||||||
|
|
||||||
|
injects[property](form.getElement(), counter, form.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.app.requestManager.setDone(form.getId(), function() {self.submitForm(form)});
|
||||||
|
this.app.requestManager.triggerDone('?', form.getId());
|
||||||
|
};
|
||||||
|
|
||||||
|
jsOMS.UI.FormManager.prototype.submitForm = function(form)
|
||||||
{
|
{
|
||||||
if (!form.isValid()) {
|
if (!form.isValid()) {
|
||||||
this.app.logger.debug('Form "' + form.getId() + '" has invalid values.');
|
this.app.logger.debug('Form "' + form.getId() + '" has invalid values.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle injects */
|
|
||||||
let injects = form.getSubmitInjects();
|
|
||||||
for(let property in injects) {
|
|
||||||
injects[property](form.getElement());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle default submit */
|
/* Handle default submit */
|
||||||
let request = new jsOMS.Message.Request.Request(),
|
let request = new jsOMS.Message.Request.Request(),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
@ -132,8 +145,13 @@
|
||||||
self.app.responseManager.run(tempResponse.type, tempResponse, request);
|
self.app.responseManager.run(tempResponse.type, tempResponse, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (e) {
|
||||||
self.app.logger.error('Invalid form response: ' + JSON.stringify(xhr));
|
console.log(e);
|
||||||
|
self.app.logger.error('Invalid form response. \n' +
|
||||||
|
'URL: ' + form.getAction() + '\n' +
|
||||||
|
'Request: ' + JSON.stringify(form.getData()) + '\n' +
|
||||||
|
'Response: ' + xhr.response
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
(function (jsOMS, undefined) {
|
(function (jsOMS, undefined)
|
||||||
|
{
|
||||||
"use strict";
|
"use strict";
|
||||||
jsOMS.Autoloader.defineNamespace('jsOMS.Views');
|
jsOMS.Autoloader.defineNamespace('jsOMS.Views');
|
||||||
|
|
||||||
jsOMS.Views.FormView = function (id) {
|
jsOMS.Views.FormView = function (id)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
this.initializeMembers();
|
this.initializeMembers();
|
||||||
|
|
@ -83,11 +85,15 @@
|
||||||
let elements = this.getFormElements(),
|
let elements = this.getFormElements(),
|
||||||
length = elements.length;
|
length = elements.length;
|
||||||
|
|
||||||
|
try {
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
if ((elements[i].required && elements[i].value === '') || (typeof elements[i].pattern !== 'undefined' && elements[i].pattern !== '' && (new RegExp(elements[i].pattern)).test(elements[i].value))) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
@ -146,7 +152,8 @@
|
||||||
case 'button':
|
case 'button':
|
||||||
this.bindButton(elements[i]);
|
this.bindButton(elements[i]);
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
|
;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -170,7 +177,8 @@
|
||||||
case 'button':
|
case 'button':
|
||||||
this.bindButton(elements[i]);
|
this.bindButton(elements[i]);
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
|
;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
(function (jsOMS, undefined) {
|
(function (jsOMS, undefined)
|
||||||
|
{
|
||||||
jsOMS.Autoloader = {};
|
jsOMS.Autoloader = {};
|
||||||
jsOMS.Autoloader.loaded = [];
|
jsOMS.Autoloader.loaded = [];
|
||||||
jsOMS.Autoloader.namespaced = [];
|
jsOMS.Autoloader.namespaced = [];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user