Fix bug related to backend response changes

This commit is contained in:
Dennis Eichhorn 2019-04-12 21:12:46 +02:00
parent 7e3858f4a2
commit f88bd58915
4 changed files with 11 additions and 6 deletions

View File

@ -32,7 +32,7 @@ export class Response {
*/
get (id)
{
return this.responses[id];
return typeof id === 'undefined' ? this.responses : this.responses[id];
};
/**

View File

@ -63,7 +63,7 @@ export class ActionManager {
listenerLength = listeners.length,
self = this;
// For everey action an event is registered
// For every action an event is registered
for (let i = 0; i < listenerLength; ++i) {
let c = [e], hasSelector = false;

View File

@ -121,7 +121,7 @@ export class AdvancedInput {
*/
remoteCallback(self, data)
{
data = JSON.parse(data.response);
data = JSON.parse(data.response)[0];
const dataLength = data.length;
console.table(data);
@ -251,6 +251,7 @@ export class AdvancedInput {
let value = '';
for (let j = 0; j < fieldLength; ++j) {
// todo: this is always the same value (the data-tpl-value of the parent container, change for the future to do only once or create uuid from multiple values?)
value = document.activeElement.querySelectorAll('[data-tpl-value="' + newTag.firstElementChild.getAttribute('data-tpl-value') + '"]')[0].getAttribute('data-value');
fields[j].setAttribute('data-value', value);
@ -258,6 +259,7 @@ export class AdvancedInput {
}
// don't allow duplicate
// todo: create a data-duplicat=true attribute to allow duplication and then have a count as part of the uuid (maybe row id)
if (self.tagElement.querySelectorAll('[data-tpl-uuid="' + uuid + '"').length !== 0) {
return;
}

View File

@ -4,6 +4,9 @@ import { Request } from '../../Message/Request/Request.js';
import { RequestMethod } from '../../Message/Request/RequestMethod.js';
import { Response } from '../../Message/Response/Response.js';
import { ResponseType } from '../../Message/Response/ResponseType.js';
import { NotificationMessage } from '../../Message/Notification/NotificationMessage.js';
import { NotificationLevel } from '../../Message/Notification/NotificationLevel.js';
import { NotificationType } from '../../Message/Notification/NotificationType.js';
/**
* Form manager class.
@ -246,17 +249,17 @@ export class Form {
console.log(xhr.response);
try {
const o = JSON.parse(xhr.response),
const o = JSON.parse(xhr.response)[0],
response = new Response(o);
let successInject = null;
if ((successInject = form.getSuccess()) !== null) {
successInject(response);
} else if (typeof response.get(0) !== 'undefined' && typeof response.get(0).type !== 'undefined') {
} else if (typeof response.get('type') !== 'undefined') {
// todo: am i using this now and should all cases be handled with the successInjection?
// maybe there could be global response actions where injecting them to every form would not make any sense
// however not many if any use cases come to mind right now where this would be necessary
self.app.responseManager.run(response.get(0).type, response.get(0), request);
self.app.responseManager.run(response.get('type'), response.get(), request);
} else if (typeof o.status !== 'undefined') {
self.app.notifyManager.send(
new NotificationMessage(o.status, o.title, o.message), NotificationType.APP_NOTIFICATION