@@ -16,34 +16,35 @@ async function connect (apiEndpoint, questionaryId) {
1616// ---------------- form content ---------------- //
1717
1818
19- // local copy of formProfileContent + actual values
20- let formProfileData = null ;
21- async function getFormContent ( formKey ) {
22- if ( formKey === 'profile' ) {
23- return getFormProfileContent ( ) ;
19+
20+ async function getFormContent ( questionaryId , formKey ) {
21+ const form = dataDefs . questionnaires [ questionaryId ] . forms [ formKey ] ;
22+ console . log ( '## getFormContent' , form ) ;
23+ if ( form . type === 'permanent' ) {
24+ return getFormPermanentContent ( form ) ;
2425 }
25- if ( formKey === 'historical ' ) {
26- return getFormHistoricalContent ( ) ;
26+ if ( formKey === 'recurring ' ) {
27+ return getFormRecurringContent ( form ) ;
2728 }
2829 return [ ] ;
2930}
3031
31- async function getFormHistoricalContent ( ) {
32- console . log ( '## getFormHistoricalContent' ) ;
33- const formHistoricalData = structuredClone ( dataDefs . formHistoricalContent ) ;
34- formHistoricalData . forEach ( field => {
32+ async function getFormRecurringContent ( form ) {
33+ const formReccuringData = structuredClone ( form . content ) ;
34+ formReccuringData . forEach ( field => {
3535 field . id = 'field-historical-' + field . dataFieldKey ;
3636 } ) ;
37- return formHistoricalData ;
37+ return formReccuringData ;
3838}
3939
40-
41- async function getFormProfileContent ( ) {
42- if ( formProfileData ) { return formProfileData ; }
43- formProfileData = structuredClone ( dataDefs . formProfileContent ) ;
40+ // local copy of formProfileContent + actual values
41+ let formPermanentData = null ;
42+ async function getFormPermanentContent ( form ) {
43+ if ( formPermanentData ) { return formPermanentData ; }
44+ formPermanentData = structuredClone ( form . content ) ;
4445
4546 // get the values from the API
46- const apiCalls = formProfileData . map ( field => ( {
47+ const apiCalls = formPermanentData . map ( field => ( {
4748 method : 'events.get' ,
4849 params : {
4950 streams : [ field . streamId ] ,
@@ -55,7 +56,7 @@ async function getFormProfileContent () {
5556 const res = await connection . api ( apiCalls ) ;
5657 for ( let i = 0 ; i < res . length ; i ++ ) {
5758 const e = res [ i ] ;
58- const field = formProfileData [ i ] ;
59+ const field = formPermanentData [ i ] ;
5960 field . id = 'field-profile-' + field . dataFieldKey ;
6061 console . log ( '## getFormContent ' + i , e ) ;
6162 if ( e . events && e . events . length > 0 ) {
@@ -75,7 +76,7 @@ async function getFormProfileContent () {
7576 field . eventId = event . id ; // will allow t track if the event is to be updated
7677 }
7778 }
78- return formProfileData ;
79+ return formPermanentData ;
7980} ;
8081
8182// ---------------- create / update data ---------------- //
@@ -104,9 +105,9 @@ function parseValue (value, type) {
104105 return value ;
105106}
106107
107- async function handleFormSubmit ( formKey , values ) {
108+ async function handleFormSubmit ( questionaryId , formKey , values ) {
108109 const apiCalls = [ ] ;
109- for ( const field of formProfileData ) {
110+ for ( const field of formPermanentData ) {
110111 const streamId = field . streamId ;
111112 const eventType = field . eventType ;
112113 const eventId = field . eventId ;
0 commit comments