|
2 | 2 |
|
3 | 3 | {{ define "body" }} |
4 | 4 |
|
5 | | -<body onbeforeunload='resetDropdowns();'> |
| 5 | +<body onbeforeunload="resetDropdowns();" onload="retrieveSchemaName();retrieveResponseId();"> |
6 | 6 | <h1>Launch a survey</h1> |
7 | 7 | <div> |
8 | 8 | <form action="" method="POST" xmlns="http://www.w3.org/1999/html" onsubmit="validateForm()"> |
@@ -90,6 +90,7 @@ <h3>Required Data</h3> |
90 | 90 | <input id="response_id" name="response_id" type="text" class="qa-response_id"> |
91 | 91 | <img class="field-container__img" onclick="numericId()" src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iNTEycHgiIGlkPSJMYXllcl8xIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgdmVyc2lvbj0iMS4xIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiIgd2lkdGg9IjUxMnB4IiB4bWw6c3BhY2U9InByZXNlcnZlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48Zz48cGF0aCBkPSJNMjU2LDM4NC4xYy03MC43LDAtMTI4LTU3LjMtMTI4LTEyOC4xYzAtNzAuOCw1Ny4zLTEyOC4xLDEyOC0xMjguMVY4NGw5Niw2NGwtOTYsNTUuN3YtNTUuOCAgIGMtNTkuNiwwLTEwOC4xLDQ4LjUtMTA4LjEsMTA4LjFjMCw1OS42LDQ4LjUsMTA4LjEsMTA4LjEsMTA4LjFTMzY0LjEsMzE2LDM2NC4xLDI1NkgzODRDMzg0LDMyNywzMjYuNywzODQuMSwyNTYsMzg0LjF6Ii8+PC9nPjwvc3ZnPg=="> |
92 | 92 | </span> |
| 93 | + <input type="button" value="Load Previous Value" class="btn--hidden" id="response-id-btn" onclick="loadResponseId()"/> |
93 | 94 | </div> |
94 | 95 |
|
95 | 96 | <div class="field-container"> |
@@ -145,8 +146,9 @@ <h3>Runner Data</h3> |
145 | 146 | </div> |
146 | 147 |
|
147 | 148 | <div class="field-container"> |
148 | | - <input type="submit" name="action_launch" value="Open Survey" class="qa-btn-submit-dev btn btn--hidden" id="submit-btn"/> |
| 149 | + <input type="submit" name="action_launch" value="Open Survey" class="qa-btn-submit-dev btn btn--hidden" id="submit-btn" onclick="saveResponseId()"/> |
149 | 150 | <input type="submit" name="action_flush" value="Flush Survey Data" class="qa-btn-submit-dev btn btn--hidden" id="flush-btn"/> |
| 151 | + <input type="button" value="Clear Local Storage" class="qa-btn-submit-dev btn btn--hidden" id="local-storage-btn" onclick="clearLocalStorage()"/> |
150 | 152 | </div> |
151 | 153 |
|
152 | 154 | </form> |
@@ -247,16 +249,16 @@ <h3>Runner Data</h3> |
247 | 249 | } |
248 | 250 |
|
249 | 251 | function loadMetadataForSchemaName() { |
250 | | - let schema_name = document.querySelector("#schema_name").value |
| 252 | + let schemaName = document.querySelector("#schema_name").value; |
| 253 | + localStorage.setItem("schema_name", schemaName); |
251 | 254 |
|
252 | | - if (schema_name !== "Select Schema") { |
253 | | - clearAndDisableSchemaUrlSelection() |
| 255 | + if (schemaName !== "Select Schema") { |
| 256 | + clearAndDisableSchemaUrlSelection(); |
254 | 257 |
|
255 | | - const schemaName = document.querySelector("#schema_name").value |
256 | | - const surveyType = document.querySelector(`#schema_name option[value="${schemaName}"]`).dataset.surveyType |
| 258 | + const surveyType = document.querySelector(`#schema_name option[value="${schemaName}"]`).dataset.surveyType; |
257 | 259 |
|
258 | | - loadSurveyMetadata(schemaName, surveyType) |
259 | | - loadSchemaMetadata(schemaName, null) |
| 260 | + loadSurveyMetadata(schemaName, surveyType); |
| 261 | + loadSchemaMetadata(schemaName, null); |
260 | 262 | } |
261 | 263 | } |
262 | 264 |
|
@@ -460,6 +462,54 @@ <h3>Runner Data</h3> |
460 | 462 | document.getElementById('schema-url-survey-type').selectedIndex = -1; |
461 | 463 | } |
462 | 464 |
|
| 465 | + function retrieveSchemaName() { |
| 466 | + const availableSchemas = [...document.querySelector("#schema_name").options].map(x => x.value) |
| 467 | + let schemaName = localStorage.getItem("schema_name"); |
| 468 | + let localStorageButton = document.querySelector("#local-storage-btn") |
| 469 | + |
| 470 | + if (schemaName && availableSchemas.includes(schemaName)) { |
| 471 | + document.querySelector("#schema_name").value = schemaName; |
| 472 | + |
| 473 | + toggleSubmitFlushButtons("show"); |
| 474 | + clearAndDisableSchemaUrlSelection(); |
| 475 | + |
| 476 | + const surveyType = document.querySelector(`#schema_name option[value="${schemaName}"]`).dataset.surveyType; |
| 477 | + |
| 478 | + loadSurveyMetadata(schemaName, surveyType); |
| 479 | + loadSchemaMetadata(schemaName, null); |
| 480 | + localStorageButton.classList.remove("btn--hidden"); |
| 481 | + } |
| 482 | + else { |
| 483 | + localStorageButton.classList.add("btn--hidden"); |
| 484 | + } |
| 485 | + } |
| 486 | + |
| 487 | + function retrieveResponseId() { |
| 488 | + let responseId = localStorage.getItem("response_id"); |
| 489 | + let responseIdButton = document.querySelector("#response-id-btn"); |
| 490 | + |
| 491 | + if (responseId) { |
| 492 | + responseIdButton.classList.remove("btn--hidden"); |
| 493 | + } |
| 494 | + else { |
| 495 | + responseIdButton.classList.add("btn--hidden"); |
| 496 | + } |
| 497 | + } |
| 498 | + |
| 499 | + function loadResponseId() { |
| 500 | + document.querySelector("#response_id").value = localStorage.getItem("response_id"); |
| 501 | + } |
| 502 | + |
| 503 | + function saveResponseId() { |
| 504 | + localStorage.setItem("response_id", document.querySelector("#response_id").value); |
| 505 | + } |
| 506 | + |
| 507 | + function clearLocalStorage() { |
| 508 | + localStorage.removeItem("response_id"); |
| 509 | + localStorage.removeItem("schema_name"); |
| 510 | + location.reload(); |
| 511 | + } |
| 512 | + |
463 | 513 | uuid('collection_exercise_sid'); |
464 | 514 | uuid('case_id'); |
465 | 515 | numericId(); |
|
0 commit comments