Skip to content

Commit

Permalink
Added text markdown to consent survey
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed Apr 10, 2024
1 parent 9e36eeb commit a7f0e08
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/data/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ export interface ResponseAttrsUpdate {
exp_data?: DataCollection[];
completed?: boolean;
survey_consent?: boolean;
completed_consent_frame?:boolean;
}
12 changes: 2 additions & 10 deletions packages/surveys/src/consent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import data from "@lookit/data";
import { TrialType } from "jspsych";
import { Model } from "survey-jquery";
import SurveyPlugin from "../../../../jsPsych/packages/plugin-survey/dist";
import { consent_survey_function as survey_function } from "./utils";

const info = <const>{
...SurveyPlugin.info,
Expand All @@ -10,19 +9,12 @@ const info = <const>{
type Info = typeof info;
type Trial = TrialType<Info>;

function survey_function(survey: Model) {
survey.onComplete.add(async () => {
await data.updateResponse(window.chs.response.id, { survey_consent: true });
});
return survey;
}

export class ConsentSurveyPlugin extends SurveyPlugin {
static readonly info = info;
trial(display_element: HTMLElement, trial: Trial) {
super.trial(display_element, {
...trial,
survey_function,
survey_function: survey_function(trial.survey_function),
});
}
}
4 changes: 2 additions & 2 deletions packages/surveys/src/exit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ParameterType, TrialType } from "jspsych";
import SurveyPlugin from "../../../../jsPsych/packages/plugin-survey/dist";
import surveyJSON from "./survey.json";
import { exit_survey_function } from "./utils";
import { exit_survey_function as survey_function } from "./utils";

const info = <const>{
...SurveyPlugin.info,
Expand Down Expand Up @@ -105,7 +105,7 @@ export class ExitSurveyPlugin extends SurveyPlugin {
super.trial(display_element, {
...trial,
survey_json: surveyParameters(trial),
survey_function: exit_survey_function,
survey_function
});
}
}
24 changes: 22 additions & 2 deletions packages/surveys/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Data from "@lookit/data";
import DOMPurify from "dompurify";
import { marked } from "marked";
import { Model } from "survey-jquery";
Expand All @@ -7,7 +8,7 @@ const CONFIG = <const>{
dompurify: { USE_PROFILES: { html: true } },
};

export function survey_function(survey: Model) {
function text_markdown_survey_function(survey: Model) {
survey.onTextMarkdown.add((_sender, options) => {
// We can set the type as "string" because async is false.
options.html = DOMPurify.sanitize(
Expand All @@ -19,7 +20,7 @@ export function survey_function(survey: Model) {
}

export function exit_survey_function(survey: Model) {
survey_function(survey);
text_markdown_survey_function(survey);
// For the withdrawal checkbox question, this takes the boolean response value out of an array
// and saves it as a single value (since there is always only one checkbox).
// We went with the checkbox question type rather than boolean with "renderAs: checkbox" because the
Expand All @@ -31,3 +32,22 @@ export function exit_survey_function(survey: Model) {
});
return survey;
}

export function consent_survey_function(userfn?: (x: Model) => Model) {
return function (survey: Model) {
text_markdown_survey_function(survey);

survey.onComplete.add(async () => {
await Data.updateResponse(window.chs.response.id, {
survey_consent: true,
completed_consent_frame:true
});
});

if (typeof userfn === "function") {
userfn(survey);
}

return survey;
};
}

0 comments on commit a7f0e08

Please sign in to comment.