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

Send translation settings with saved rows to question library #2742

Merged
merged 3 commits into from Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 34 additions & 14 deletions jsapp/js/models/surveyScope.es6
Expand Up @@ -2,31 +2,51 @@ import {actions} from '../actions';
import {
notify,
t,
unnullifyTranslations,
} from '../utils';

class SurveyScope {
constructor ({survey}) {
this.survey = survey;
}
add_row_to_question_library (row) {
add_row_to_question_library (row, assetContent) {
if (row.constructor.kls === 'Row') {
var rowJSON = row.toJSON2();
let content;
var surv = this.survey.toFlatJSON();
/*
* Apply translations "hack" again for saving single questions to library
* Since `unnullifyTranslations` requires the whole survey, we need to
* fish out the saved row and its translation settings out of the unnullified return
*/
duvld marked this conversation as resolved.
Show resolved Hide resolved
var unnullifiedContent = JSON.parse(unnullifyTranslations(JSON.stringify(surv), assetContent));
var settings_obj = unnullifiedContent.settings;
var survey_obj = unnullifiedContent.survey;
duvld marked this conversation as resolved.
Show resolved Hide resolved
if (rowJSON.type === 'select_one' || rowJSON.type === 'select_multiple') {
var surv = this.survey.toFlatJSON();
var choices = surv.choices.filter(s => s.list_name === rowJSON.select_from_list_name);
content = JSON.stringify({
survey: [
row.toJSON2()
],
choices: choices || undefined
});
var choices = unnullifiedContent.choices.filter(s => s.list_name === rowJSON.select_from_list_name);
for (var i in survey_obj) {
if (survey_obj[i].$kuid == row.toJSON2().$kuid) {
content = JSON.stringify({
survey: [
survey_obj[i]
],
choices: choices || undefined,
settings: settings_obj || undefined
duvld marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
} else {
content = JSON.stringify({
survey: [
row.toJSON2()
]
});
for (var j in survey_obj) {
if (survey_obj[j].$kuid == row.toJSON2().$kuid) {
content = JSON.stringify({
survey: [
survey_obj[j]
],
choices: choices || undefined,
settings: settings_obj || undefined
});
}
}
}
actions.resources.createResource.triggerAsync({
asset_type: 'question',
Expand Down
2 changes: 1 addition & 1 deletion jsapp/xlform/src/view.row.coffee
Expand Up @@ -139,7 +139,7 @@ module.exports = do ->

add_row_to_question_library: (evt) =>
evt.stopPropagation()
@ngScope?.add_row_to_question_library @model
@ngScope?.add_row_to_question_library @model, @model.collection._parent._initialParams

class GroupView extends BaseRowView
className: "survey__row survey__row--group xlf-row-view xlf-row-view--depr"
Expand Down