Skip to content

Commit

Permalink
Merge pull request #455 from episphere/main
Browse files Browse the repository at this point in the history
Dev -> Stage Sync (July 2024)
  • Loading branch information
anthonypetersen authored Jul 29, 2024
2 parents 9428778 + 5a79f24 commit 9145d46
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 380 deletions.
79 changes: 5 additions & 74 deletions buildGrid.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { translate } from "./common.js";

export const grid_replace_regex = /\|grid(\!|\?)*\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|/g;

Expand Down Expand Up @@ -113,17 +114,17 @@ function buildHtmlTable(grid_obj){
grid_html += `</tr>`;
});

grid_html+=`</tbody></table>
grid_html += `</tbody></table>
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-12">
<button type="submit" class="previous w-100" aria-label="Back to the previous section" data-click-type="previous">Back</button>
<button type="submit" class="previous w-100" aria-label="Back to the previous section" data-click-type="previous">${translate("backButton")}</button>
</div>
<div class="col-md-6 col-sm-12">
<button type="submit" class="reset w-100" aria-label="Reset answer for this question" data-click-type="reset">Reset Answer</button>
<button type="submit" class="reset w-100" aria-label="Reset answer for this question" data-click-type="reset">${translate("resetAnswerButton")}</button>
</div>
<div class="col-md-3 col-sm-12">
<button type="submit" class="next w-100" aria-label="Go to the next section" data-click-type="next">Next</button>
<button type="submit" class="next w-100" aria-label="Go to the next section" data-click-type="next">${translate("nextButton")}</button>
</div>
</div>
</div>
Expand All @@ -132,76 +133,6 @@ function buildHtmlTable(grid_obj){
return grid_html;
}

function buildHtml_og(grid_obj) {
let grid_head =
'<div class="d-flex align-items-center border"><div class="col">Select an answer for each row below:</div>';
grid_obj.responses.forEach((resp) => {
grid_head += `<div class="col-1">${resp.text}</div>`;
});
grid_head += "</div>";
let grid_table_body = "";
grid_obj.questions.forEach((question) =>
{
// check for row-level display if
let displayif = question.displayif ? ` displayif="${question.displayif}"` : '';

// check for displayif inside row text
let question_text = grid_text_displayif(question.question_text)

grid_table_body += `<div id="${question.id}" ${displayif} data-gridrow=true class="d-flex align-items-stretch"><div class="col d-flex align-items-left justify-content-left border"><span>${question_text}<span></div>`;
grid_obj.responses.forEach((resp, resp_indx) => {
grid_table_body += `<div class="col-1 d-flex align-items-center justify-content-center border"><input gridcell type="${resp.type}" name="${question.id}" id="${question.id}_${resp_indx}" value="${resp.value}" grid class="grid-input-element show-button"/></div>`;
});
grid_table_body += "</div>";
});

let small_format = "";
grid_obj.questions.forEach((question) => {
let displayif = question.displayif ? ` displayif="${question.displayif}"` : '';
// check for displayif inside question text
let question_text = grid_text_displayif(question.question_text)
small_format += `<div id="${question.id}_sm" ${displayif}><div class="pt-4">${question_text}</div>`;
grid_obj.responses.forEach((resp, resp_indx) => {
small_format += `<div class="response text-center"><input data-is-small-grid-cell="1" type="${resp.type}" class="d-none grid-input-element" name="${question.id}_sm" id="${question.id}_sm_${resp_indx}" value="${resp.value}" aria-label='(${question.question_text}, ${resp.text})'/><label class="w-100" for="${question.id}_sm_${resp_indx}">${resp.text}</label></div>`;
});
small_format += "</div>";
});
let gridPrompt = "hardedit='false' softedit='false'";

if (grid_obj.prompt) {
if (grid_obj.prompt === '!') {
gridPrompt = "hardedit='true' softedit='false'";
}
else if (grid_obj.prompt === '?') {
gridPrompt = "hardedit='false' softedit='true'";
}
}
//remove , from display if for form if it exists
grid_obj.args = grid_obj.args.replace(",displayif", " displayif");
let shared_text = grid_text_displayif(grid_obj.shared_text)
shared_text = grid_replace_piped_variables(shared_text)
let html_text = `<form ${grid_obj.args} class="container question" grid ${gridPrompt}>
${shared_text}<div class="d-none d-lg-block" data-grid="large" style="background-color: rgb(193,225,236)">
${grid_head}${grid_table_body}</div><div class="d-lg-none" data-grid="small">${small_format}</div>
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-12">
<input type='submit' class='previous w-100' value='BACK'/>
</div>
<div class="col-md-6 col-sm-12">
<input type='submit' class='reset w-100' value='RESET ANSWER'/>
</div>
<div class="col-md-3 col-sm-12">
<input type='submit' class='next w-100' value='NEXT'/>
</div>
</div>
</div>
</form>`;

//for some reason spacing needs to be removed
return html_text.replace(/(\r\n|\n|\r)/gm, "");;
}

// note the text should contain the entirity of ONE grid!
// the regex for a grid is /\|grid\|([^|]*?)\|([^|]*?)\|([^|]*?)\|
// you can use the /g and then pass it to the function one at a time...
Expand Down
111 changes: 111 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { moduleParams } from "./questionnaire.js";

export const translate = (key, replacements = []) => {

let translation = moduleParams.i18n[key];

replacements.forEach((value, index) => {
translation = translation.replace(new RegExp(`\\{${index}\\}`, 'g'), value);
});

return translation;
}

export const responseRequestedModal = () => {

return `
<div class="modal" id="softModal" tabindex="-1" role="dialog" aria-labelledby="softModalTitle" aria-modal="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="softModalTitle" tabindex="-1">${translate('responseRequestedLabel')}</h5>
<button type="button" class="close" data-dismiss="modal" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div id="modalBody" class="modal-body" aria-describedby="modalBodyText">
<p id="modalBodyText"></p>
</div>
<div id="softModalFooter" class="modal-footer">
<button type="button" id=modalContinueButton class="btn btn-light" data-dismiss="modal" data-bs-dismiss="modal">${translate('continueWithoutAnsweringButton')}</button>
<button type="button" id=modalCloseButton class="btn btn-light" data-dismiss="modal" data-bs-dismiss="modal">${translate('answerQuestionButton')}</button>
</div>
</div>
</div>
</div>
`;
}

export const responseRequiredModal = () => {

return `
<div class="modal" id="hardModal" tabindex="-1" role="dialog" aria-labelledby="hardModalLabel" aria-modal="true" aria-describedby="hardModalBodyText">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="hardModalLabel">${translate('responseRequiredLabel')}</h5>
<button type="button" class="close" data-dismiss="modal" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p id="hardModalBodyText"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal" data-bs-dismiss="modal">${translate('answerQuestionButton')}</button>
</div>
</div>
</div>
</div>
`;
}

export const responseErrorModal = () => {

return `
<div class="modal" id="softModalResponse" tabindex="-1" role="dialog" aria-labelledby="softModalResponseTitle" aria-modal="true" aria-describedby="softModalResponseBody">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="softModalResponseTitle">${translate('responseErrorLabel')}</h5>
<button type="button" class="close" data-dismiss="modal" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div id="modalResponseBody" class="modal-body">
<p>${translate('responseErrorBody')}</p>
</div>
<div id="softModalResponseFooter" class="modal-footer">
<button type="button" id=modalResponseContinueButton class="btn btn-success" data-dismiss="modal" data-bs-dismiss="modal">${translate('correctButton')}</button>
<button type="button" id=modalResponseCloseButton class="btn btn-danger" data-dismiss="modal" data-bs-dismiss="modal">${translate('incorrectButton')}</button>
</div>
</div>
</div>
</div>
`;
}

export const submitModal = () => {

return `
<div class="modal" id="submitModal" tabindex="-1" role="dialog" aria-labelledby="submitModalLabel" aria-modal="true" aria-describedby="submitModalBodyText">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="submitModalLabel">${translate('submitLabel')}</h5>
<button type="button" class="close" data-dismiss="modal" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p id="submitModalBodyText">${translate('submitBody')}</p>
</div>
<div class="modal-footer">
<button type="button" id="submitModalButton" class="btn btn-success" data-dismiss="modal" data-bs-dismiss="modal">${translate('submitButton')}</button>
<button type="button" id="cancelModal" class="btn btn-danger" data-dismiss="modal" data-bs-dismiss="modal">${translate('cancelButton')}</button>
</div>
</div>
</div>
</div>
`;
}
61 changes: 61 additions & 0 deletions i18n/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const en = {
"language": "en",

"backButton": "Back",
"resetAnswerButton": "Reset Answer",
"submitSurveyButton": "Submit Survey",
"nextButton": "Next",
"responseRequestedLabel": "Response Requested",
"responseRequiredLabel": "Response Required",
"responseErrorLabel": "Response Requested",
"responseErrorBody": "There is an error with this response. Is this correct?",
"submitLabel": "Submit Answers",
"submitBody": "Are you sure you want to submit your answers?",
"continueWithoutAnsweringButton": "Continue Without Answering",
"answerQuestionButton": "Answer the Question",
"correctButton": "Correct",
"incorrectButton": "Incorrect",
"submitButton": "Submit",
"cancelButton": "Cancel",

"yes": "Yes",
"no": "No",
"preferNotToAnswer": "Prefer not to answer",

"yesNo": "(1) Yes (0) No",
"yesNoPrefer": "(1) Yes (0) No (99) Prefer not to answer",

"chooseState": "Choose a State",

"basePrompt": " There {0} {1} question{2} unanswered on this page.",
"softPrompt": " Would you like to continue?",
"hardPrompt": " Please answer the question{0}.",

"validationInputEmptyField": "Please fill out this field",
"validationNumberGreaterThan": "Value must be greater than or equal to {0}",
"validationNumberLessThan": "Value must be less than or equal to {0}",
"validationMonthFormat": "Format should match YYYY-MM",
"validationMonthInvalid": "Invalid month or year",
"validationMonthAfter": "Date must be after {0}-{1}",
"validationMonthBefore": "Date must be before {0}-{1}",
"validationDateAfter": "Date must be after {0}/{1}/{2}",
"validationDateBefore": "Date must be before {0}/{1}/{2}",
"validationEmailAddress": "Please enter an email address in this format: [email protected]",
"validationPhoneNumber": "Please enter a phone number in this format: 999-999-9999",
"validationSocialFull": "Please enter a valid Social Security Number in this format: 999-99-9999",
"validationSocialPartial": "Please enter the last four digits of a Social Security Number in this format: 9999",
"validationTextShortExact": "Entered text is too short (should have {0} characters)",
"validationTextLongExact": "Entered text is too long (should have {0} characters)",
"validationTextShort": "Entered text is too short (should have at least {0} characters)",
"validationTextLong": "Entered text is too long (should have at most {0} characters)",
"validationMismatch": "Values do not match",
"validationCountMore": "You have selected {0} items. Please select at least {1}",
"validationCountLess": "You have selected {0} items. Please select no more than {1}",

"months": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],

"example": "Example",
"enterValue": "Enter a value"
}

export default en;
61 changes: 61 additions & 0 deletions i18n/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const es = {
"language": "es",

"backButton": "Atrás",
"resetAnswerButton": "Restablecer Respuesta",
"submitSurveyButton": "Enviar Encuesta",
"nextButton": "Siguiente",
"responseRequestedLabel": "Respuesta Solicitada",
"responseRequiredLabel": "Respuesta Requerida",
"responseErrorLabel": "Respuesta Solicitada",
"responseErrorBody": "Hay un error en esta respuesta. ¿Es correcta?",
"submitLabel": "Enviar Respuestas",
"submitBody": "¿Está seguro de que desea enviar sus respuestas?",
"continueWithoutAnsweringButton": "Continuar Sin Responder",
"answerQuestionButton": "Responder La Pregunta",
"correctButton": "Correcto",
"incorrectButton": "Incorrecto",
"submitButton": "Enviar",
"cancelButton": "Cancelar",

"yes": "Sí",
"no": "No",
"preferNotToAnswer": "Prefiero no responder",

"yesNo": "(1) Sí (0) No",
"yesNoPrefer": "(1) Sí (0) No (99) Prefiero no responder",

"chooseState": "Elija un Estado",

"basePrompt": " Hay {1} pregunta{2} sin responder en esta página.",
"softPrompt": " ¿Desea continuar?",
"hardPrompt": " Responda las pregunta{0}.",

"validationInputEmptyField": "Sírvase completar este campo",
"validationNumberGreaterThan": "El valor debe ser mayor o igual a {0}",
"validationNumberLessThan": "El valor debe ser menor o igual a {0}",
"validationMonthFormat": "Debe tener el formato AAAA-MM",
"validationMonthInvalid": "Mes o año no válido",
"validationMonthAfter": "La fecha debe ser posterior al {0}-{1}",
"validationMonthBefore": "La fecha debe ser anterior al {0}-{1}",
"validationDateAfter": "La fecha debe ser posterior al {0}/{1}/{2}",
"validationDateBefore": "La fecha debe ser anterior al {0}/{1}/{2}",
"validationEmailAddress": "Ingrese una dirección de correo electrónico con este formato: [email protected]",
"validationPhoneNumber": "Ingrese un número de teléfono con este formato: 999-999-9999",
"validationSocialFull": "Ingrese un número de Seguro Social válido con este formato: 999-99-9999",
"validationSocialPartial": "Ingrese los últimos cuatro dígitos de un número de Seguro Social con este formato: 9999",
"validationTextShortExact": "El texto ingresado es demasiado corto (debe tener {0} caracteres)",
"validationTextLongExact": "El texto ingresado es demasiado largo (debe tener {0} caracteres)",
"validationTextShort": "El texto ingresado es demasiado corto (debe tener al menos {0} caracteres)",
"validationTextLong": "El texto ingresado es demasiado largo (debe tener como máximo {0} caracteres)",
"validationMismatch": "Los valores no coinciden",
"validationCountMore": "Ha seleccionado {0} elementos. Seleccione al menos {1}",
"validationCountLess": "Ha seleccionado {0} elementos. Seleccione no más de {1}",

"months": ["Ene", "Feb", "Mar", "Abr", "Mayo", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],

"example": "Ejemplo",
"enterValue": "Introduzca un valor"
}

export default es;
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,17 @@ <h3>Questionnaire Options</h3>
<input class="form-check-input" type="checkbox" role="switch" id="hide-markup">
</label>
</div>
<div>
<label for="langSelect">Language:</label>
<div class="input-group mb-3">
<select id="langSelect" class="form-select" aria-label="quest-locale">
<option value="en" selected>en-US</option>
<option value="es">en-MX</option>
</select>
</div>
</div>
</form>

<div class="border flex-grow-1 p-1">
<h3>Previous Results</h3>
<textarea id="json_input" aria-label="json input" style="width: 100%; height:150px"></textarea>
Expand Down
1 change: 1 addition & 0 deletions quest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function startUp() {
transform.render(
{
text: ta.value,
lang: document.getElementById("langSelect").value
},
"rendering",
previousResults
Expand Down
Loading

0 comments on commit 9145d46

Please sign in to comment.