From f88bd58915b933d7d07ade993ff018cded69bd0a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 12 Apr 2019 21:12:46 +0200 Subject: [PATCH] Fix bug related to backend response changes --- Message/Response/Response.js | 2 +- UI/ActionManager.js | 2 +- UI/Component/AdvancedInput.js | 4 +++- UI/Component/Form.js | 9 ++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Message/Response/Response.js b/Message/Response/Response.js index 9127635..c4303c8 100644 --- a/Message/Response/Response.js +++ b/Message/Response/Response.js @@ -32,7 +32,7 @@ export class Response { */ get (id) { - return this.responses[id]; + return typeof id === 'undefined' ? this.responses : this.responses[id]; }; /** diff --git a/UI/ActionManager.js b/UI/ActionManager.js index dd72b52..f44e2ed 100644 --- a/UI/ActionManager.js +++ b/UI/ActionManager.js @@ -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; diff --git a/UI/Component/AdvancedInput.js b/UI/Component/AdvancedInput.js index 731334d..f415f80 100644 --- a/UI/Component/AdvancedInput.js +++ b/UI/Component/AdvancedInput.js @@ -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; } diff --git a/UI/Component/Form.js b/UI/Component/Form.js index 2b80264..4845469 100644 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -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