Skip to content

Commit

Permalink
use jquery for post and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasnteireho committed Sep 14, 2024
1 parent b47bf54 commit 64fb565
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 51 deletions.
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-11",
"version": "8.1.7-13",
"description": "A2J Viewer standalone and preview app.",
"main": "a2jviewer/app",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/footer/footerVersion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

export default version
66 changes: 32 additions & 34 deletions src/mobile/pages/pages-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default DefineMap.extend('PagesVM', {
* check is date is valid
*/
function isValidDate (date) {
console.log("date: " + date)
console.log('date: ' + date)
let dmy = date.split('/')
// js wants mdy or ymd
// while a2j dates are d/m/yyyy
Expand Down Expand Up @@ -251,26 +251,26 @@ export default DefineMap.extend('PagesVM', {

validator.set('Date', isValidDate)
validator.set('Number', isValidNumber)
if (validator.has(answer.type)){

if (validator.has(answer.type)) {
for (let i = 1; i < answer.values.length; i++) {
if (!validator.get(answer.type)(answer.values[i])) {
//delete answer.values[i]
// delete answer.values[i]
answer.values[i] = null
Object.defineProperty(answer, "invalid", "true")
Object.defineProperty(answer, 'invalid', 'true')
}
}
}

//answer.values[0] = answer.values.length
// answer.values[0] = answer.values.length

return answer
}

Object.keys(answers).forEach(function filter (name) {
let sanitizedAnswer = sanitizeAnswerValues(answers[name])
if (sanitizedAnswer.values.length === 1) {
//delete answers[name]
// delete answers[name]
answers[name] = null
} else {
answers[name] = sanitizedAnswer
Expand All @@ -280,7 +280,7 @@ export default DefineMap.extend('PagesVM', {
return answers
},

/**
/**
* @property {String} pages.ViewModel.prototype.answersString answersString
* @parent pages.ViewModel
*
Expand All @@ -289,18 +289,17 @@ export default DefineMap.extend('PagesVM', {
* 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()))
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
}
},

const parsed = this.validatedAnswers(this.answers.serialize())
return parsed
}
},

/**
/**
* @property {String} pages.ViewModel.prototype.answersString answersString
* @parent pages.ViewModel
*
Expand All @@ -309,22 +308,21 @@ export default DefineMap.extend('PagesVM', {
* 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()))
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]
}

})
let answers = this.answersValidated
Object.keys(answers).forEach(function filter (name) {
if (!answers[name].invalid) {
delete answers[name]
}
})

return answers
}
},
return answers
}
},

/**
* @property {String} pages.ViewModel.prototype.answersString answersString
Expand All @@ -337,8 +335,8 @@ export default DefineMap.extend('PagesVM', {
*/
answersANX: {
get () {
//console.log(this.answers.serialize())
//console.log(this.validatedAnswers(this.answers.serialize()))
// console.log(this.answers.serialize())
// console.log(this.validatedAnswers(this.answers.serialize()))
// const parsed = Parser.parseANX(this.answers.serialize())
const parsed = Parser.parseANX(this.validatedAnswers(this.answers.serialize()))
return parsed
Expand Down
20 changes: 8 additions & 12 deletions src/mobile/pages/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 @@ -113,10 +112,9 @@ export default Component.extend({
},

'button.save-answers click': function (el, ev) {

ev.preventDefault()

const button = new DefineMap({ next: constants.qIDSUCCESS })
const button = new Map({ next: constants.qIDSUCCESS })

const vm = this.viewModel
let postBody = {
Expand All @@ -129,19 +127,17 @@ export default Component.extend({
/***
* !!! 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"
}
// fetch('https://staging.a2jauthor.org/a2jauthor/bad-answer-alert.php', {
$.ajax({
url: 'https://staging.a2jauthor.org/a2jauthor/bad-answer-alert.php',
type: 'POST',
data: JSON.stringify(postBody),
dataType: 'json'
})
.then((response) => response.json())
.then((json) => console.log(json));

.then((json) => console.log(json))

vm.navigate(button, el, ev)

},

// This event is fired when the Exit, Success, or AssembleSuccess button is clicked,
Expand Down

0 comments on commit 64fb565

Please sign in to comment.