Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy library asset content before parsing it #2823

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion jsapp/js/stores.es6
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import Reflux from 'reflux';
import {Cookies} from 'react-cookie';
import clonedeep from 'lodash.clonedeep';
import dkobo_xlform from '../xlform/src/_xlform.init';
import {parsed, parseTags} from './assetParserUtils';
import {actions} from './actions';
Expand Down Expand Up @@ -275,8 +276,15 @@ var surveyCompanionStore = Reflux.createStore({
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, function(asset){
var _s = dkobo_xlform.model.Survey.loadDict(asset.content, survey)
// `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
let assetCopy = clonedeep(asset);
// `loadDict()` will mutate its first argument; see `inputParser.parse()`
let _s = dkobo_xlform.model.Survey.loadDict(assetCopy.content, survey)
survey.insertSurvey(_s, position, groupId);
});
}
Expand Down