mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-18 01:58: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 ()
|
||||
{
|
||||
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 || {}));
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@
|
|||
*/
|
||||
jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request)
|
||||
{
|
||||
console.log(data);
|
||||
if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') {
|
||||
this.messages[key][request](data);
|
||||
} else if (typeof this.messages[key] !== 'undefined') {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,8 @@
|
|||
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);
|
||||
self.submit(self.forms[id]);
|
||||
});
|
||||
|
|
@ -92,18 +93,30 @@
|
|||
};
|
||||
|
||||
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()) {
|
||||
this.app.logger.debug('Form "' + form.getId() + '" has invalid values.');
|
||||
return;
|
||||
}
|
||||
|
||||
/* Handle injects */
|
||||
let injects = form.getSubmitInjects();
|
||||
for(let property in injects) {
|
||||
injects[property](form.getElement());
|
||||
}
|
||||
|
||||
/* Handle default submit */
|
||||
let request = new jsOMS.Message.Request.Request(),
|
||||
self = this;
|
||||
|
|
@ -132,8 +145,13 @@
|
|||
self.app.responseManager.run(tempResponse.type, tempResponse, request);
|
||||
}
|
||||
}
|
||||
} catch (exception) {
|
||||
self.app.logger.error('Invalid form response: ' + JSON.stringify(xhr));
|
||||
} catch (e) {
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
(function (jsOMS, undefined) {
|
||||
(function (jsOMS, undefined)
|
||||
{
|
||||
"use strict";
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.Views');
|
||||
|
||||
jsOMS.Views.FormView = function (id) {
|
||||
jsOMS.Views.FormView = function (id)
|
||||
{
|
||||
this.id = id;
|
||||
|
||||
this.initializeMembers();
|
||||
|
|
@ -83,11 +85,15 @@
|
|||
let elements = this.getFormElements(),
|
||||
length = elements.length;
|
||||
|
||||
try {
|
||||
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))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
|
@ -146,7 +152,8 @@
|
|||
case 'button':
|
||||
this.bindButton(elements[i]);
|
||||
break;
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -170,7 +177,8 @@
|
|||
case 'button':
|
||||
this.bindButton(elements[i]);
|
||||
break;
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
(function (jsOMS, undefined) {
|
||||
(function (jsOMS, undefined)
|
||||
{
|
||||
jsOMS.Autoloader = {};
|
||||
jsOMS.Autoloader.loaded = [];
|
||||
jsOMS.Autoloader.namespaced = [];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user