From b47bf5464a17402f432981fc201c59a85123c836 Mon Sep 17 00:00:00 2001 From: Tobias Nteireho Date: Fri, 13 Sep 2024 19:11:21 -0500 Subject: [PATCH] add expose invalid answers. WIP fire alerter --- demo/viewer/viewer.html | 4 +-- index.dev.html | 2 +- index.html | 2 +- package-lock.json | 4 +-- package.json | 2 +- src/footer/footerVersion.js | 2 +- src/mobile/pages/pages-vm.js | 47 ++++++++++++++++++++++++++++++++++++ src/mobile/pages/pages.js | 34 ++++++++++++++++++++++++++ 8 files changed, 89 insertions(+), 8 deletions(-) diff --git a/demo/viewer/viewer.html b/demo/viewer/viewer.html index bff1e6eb..8d682172 100644 --- a/demo/viewer/viewer.html +++ b/demo/viewer/viewer.html @@ -53,9 +53,9 @@ diff --git a/index.dev.html b/index.dev.html index e4b42ede..8130a666 100644 --- a/index.dev.html +++ b/index.dev.html @@ -59,6 +59,6 @@ errRepURL: '' })); - + \ No newline at end of file diff --git a/index.html b/index.html index 8130a666..552f1129 100644 --- a/index.html +++ b/index.html @@ -59,6 +59,6 @@ errRepURL: '' })); - + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9641530d..6701c27c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@caliorg/a2jviewer", - "version": "8.1.7-10", + "version": "8.1.7-11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@caliorg/a2jviewer", - "version": "8.1.7-10", + "version": "8.1.7-11", "license": "GNU AGPL v3.0", "dependencies": { "@caliorg/a2jdeps": "^7.1.7", diff --git a/package.json b/package.json index f9f89895..b63066a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@caliorg/a2jviewer", - "version": "8.1.7-10", + "version": "8.1.7-11", "description": "A2J Viewer standalone and preview app.", "main": "a2jviewer/app", "scripts": { diff --git a/src/footer/footerVersion.js b/src/footer/footerVersion.js index b3b3d28d..8121ebc2 100644 --- a/src/footer/footerVersion.js +++ b/src/footer/footerVersion.js @@ -1,6 +1,6 @@ const version = { - number: '8.1.7-10', + number: '8.1.7-11', date: '2024-09-13' } diff --git a/src/mobile/pages/pages-vm.js b/src/mobile/pages/pages-vm.js index 686ca280..041e8fac 100644 --- a/src/mobile/pages/pages-vm.js +++ b/src/mobile/pages/pages-vm.js @@ -257,6 +257,7 @@ export default DefineMap.extend('PagesVM', { if (!validator.get(answer.type)(answer.values[i])) { //delete answer.values[i] answer.values[i] = null + Object.defineProperty(answer, "invalid", "true") } } } @@ -279,6 +280,52 @@ export default DefineMap.extend('PagesVM', { return answers }, + /** + * @property {String} pages.ViewModel.prototype.answersString answersString + * @parent pages.ViewModel + * + * XML version of the `answers` entered by the user. + * + * This is POSTed to `setDataURL` when user finishes the interview, + * and populated when a user loads saved answers. + */ + answersValidated: { + get () { + //console.log(this.answers.serialize()) + //console.log(this.validatedAnswers(this.answers.serialize())) + // const parsed = Parser.parseANX(this.answers.serialize()) + const parsed = this.validatedAnswers(this.answers.serialize()) + return parsed + } +}, + + + /** + * @property {String} pages.ViewModel.prototype.answersString answersString + * @parent pages.ViewModel + * + * XML version of the `answers` entered by the user. + * + * This is POSTed to `setDataURL` when user finishes the interview, + * and populated when a user loads saved answers. + */ + invalidAnswers: { + get () { + //console.log(this.answers.serialize()) + //console.log(this.validatedAnswers(this.answers.serialize())) + // const parsed = Parser.parseANX(this.answers.serialize()) + let answers = this.answersValidated + Object.keys(answers).forEach(function filter (name) { + if (!answers[name].invalid) { + delete answers[name] + } + + }) + + return answers + } +}, + /** * @property {String} pages.ViewModel.prototype.answersString answersString * @parent pages.ViewModel diff --git a/src/mobile/pages/pages.js b/src/mobile/pages/pages.js index 4b01423b..0f992b8f 100644 --- a/src/mobile/pages/pages.js +++ b/src/mobile/pages/pages.js @@ -8,6 +8,8 @@ import Preview from '~/src/models/preview' import { analytics } from '~/src/util/analytics' import stache from 'can-stache' import '~/src/mobile/util/helpers' +import constants from '~/src/models/constants' + stache.registerPartial('assemble-form', assembleFormTpl) stache.registerPartial('save-answers-form', saveAnswersFormTpl) @@ -110,6 +112,38 @@ export default Component.extend({ }) }, + 'button.save-answers click': function (el, ev) { + + ev.preventDefault() + + const button = new DefineMap({ next: constants.qIDSUCCESS }) + + const vm = this.viewModel + let postBody = { + authorid: vm.interview.authorId, + interviewPath: vm.interview.interviewPath, + guideTitle: vm.interview.title, + invalidAnswers: vm.invalidAnswers + } + + /*** + * !!! Change this in pproduction to prod server!!! + */ + fetch("https://staging.a2jauthor.org/a2jauthor/bad-answer-alert.php", { + method: "POST", + body: JSON.stringify(postBody), + headers: { + "Content-type": "application/json; charset=UTF-8" + } + }) + .then((response) => response.json()) + .then((json) => console.log(json)); + + + vm.navigate(button, el, ev) + + }, + // This event is fired when the Exit, Success, or AssembleSuccess button is clicked, // it waits to asynchronously submit the form that posts the XML answers // to the `setDataURL` endpoint.