-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathsurveyCompanionStore.js
26 lines (24 loc) · 1.06 KB
/
surveyCompanionStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import clonedeep from 'lodash.clonedeep'
import Reflux from 'reflux'
import { actions } from '#/actions'
import { stores } from '#/stores'
import dkobo_xlform from '../xlform/src/_xlform.init'
const surveyCompanionStore = Reflux.createStore({
init() {
this.listenTo(actions.survey.addExternalItemAtPosition, this.addExternalItemAtPosition)
},
addExternalItemAtPosition({ position, survey, uid, groupId }) {
// `survey` is what's currently open in the form builder
// `uid` identifies the library item being added to `survey`
stores.allAssets.whenLoaded(uid, (asset) => {
// `asset` is the library item being added to `survey`
// be careful not to mutate it, becuase it's kept in a store and not
// re-fetched from the server each time it's loaded
const assetCopy = clonedeep(asset)
// `loadDict()` will mutate its first argument; see `inputParser.parse()`
const _s = dkobo_xlform.model.Survey.loadDict(assetCopy.content, survey)
survey.insertSurvey(_s, position, groupId)
})
},
})
export default surveyCompanionStore