Skip to content

Commit

Permalink
add expose invalid answers. WIP fire alerter
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasnteireho committed Sep 14, 2024
1 parent aa9cd78 commit b47bf54
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 8 deletions.
4 changes: 2 additions & 2 deletions demo/viewer/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<script main="@empty"
env="production"
config="../package.json!npm"
src="../dist/bundles/app.js?v=1726244993659"
src="../dist/bundles/app.js?v=1726264879172"
cache-key="v"
cache-version="1726244993659"
cache-version="1726264879172"
base-url="../">
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion index.dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
errRepURL: ''
}));
</script>
<script src="node_modules/steal/steal.production.js?v=1726195110818" cache-key="v" cache-version="1726195110818" main="@caliorg/a2jviewer/app"></script>
<script src="node_modules/steal/steal.production.js?v=1726244945139" cache-key="v" cache-version="1726244945139" main="@caliorg/a2jviewer/app"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
errRepURL: ''
}));
</script>
<script src="node_modules/steal/steal.production.js?v=1726244945139" cache-key="v" cache-version="1726244945139" main="@caliorg/a2jviewer/app"></script>
<script src="node_modules/steal/steal.production.js?v=1726264826982" cache-key="v" cache-version="1726264826982" main="@caliorg/a2jviewer/app"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/footer/footerVersion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const version = {
number: '8.1.7-10',
number: '8.1.7-11',
date: '2024-09-13'
}

Expand Down
47 changes: 47 additions & 0 deletions src/mobile/pages/pages-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/mobile/pages/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b47bf54

Please sign in to comment.