|
66 | 66 |
|
67 | 67 | button#paste, |
68 | 68 | button#submit, |
| 69 | + button#next, |
69 | 70 | button#exit, |
70 | 71 | button#add-answers, |
71 | 72 | button#remove-answers, |
|
96 | 97 |
|
97 | 98 | button#paste:hover, |
98 | 99 | button#submit:hover, |
| 100 | + button#next:hover, |
99 | 101 | button#exit:hover, |
100 | 102 | button#add-answers:hover, |
101 | 103 | button#remove-answers:hover, |
|
116 | 118 | margin-top: 0.5em; |
117 | 119 | } |
118 | 120 |
|
| 121 | + button#next, |
119 | 122 | button#exit { |
120 | 123 | display: none; |
121 | 124 | margin-top: 0.5em; |
|
252 | 255 | const loader = uploader.querySelector('#loader'); |
253 | 256 | if (loader) loader.classList.remove('active'); |
254 | 257 | }; |
255 | | - async function exit() { |
| 258 | + async function next() { |
256 | 259 | window.opener.postMessage('uploadSuccess', window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')); |
257 | 260 | setTimeout(() => { |
258 | 261 | window.close(); |
259 | 262 | }, 500); |
260 | 263 | }; |
| 264 | + async function exit() { |
| 265 | + window.opener.postMessage('exitToCourse', window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')); |
| 266 | + setTimeout(() => { |
| 267 | + window.close(); |
| 268 | + }, 500); |
| 269 | + }; |
261 | 270 | function createUploader(event = null, number = null) { |
262 | 271 | const isMultiple = document.querySelector('.uploader') && originalWindowWidth && originalWindowHeight && originalWindowY && originalWindowX; |
263 | 272 | if (isMultiple) { |
264 | 273 | window.resizeTo(originalWindowWidth, originalWindowHeight); |
265 | 274 | window.moveTo(originalWindowX, originalWindowY); |
266 | | - }; |
267 | | - if (isMultiple) { |
268 | 275 | startingQuestionId++; |
269 | 276 | startingQuestion = (number || startingQuestion).replace(/(\d+)([a-z]*)$/, (match, num, suffix) => { |
270 | 277 | return !suffix ? (parseInt(num, 10) + 1).toString() : ((suffix === 'z') ? ((parseInt(num, 10) + 1) + 'a') : (num + String.fromCharCode(suffix.charCodeAt(0) + 1))); |
271 | 278 | }); |
272 | 279 | } |
| 280 | + window.opener.postMessage(`${startingQuestionId};+;${startingQuestion}`, window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')); |
273 | 281 | const uploaderQuestionId = startingQuestionId; |
274 | 282 | const uploaderQuestion = startingQuestion; |
275 | | - window.opener.postMessage(`${startingQuestionId}+${startingQuestion}`, window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')); |
276 | 283 | var uploader = document.createElement('div'); |
277 | 284 | uploader.id = uploaderQuestionId; |
278 | 285 | uploader.classList.add('uploader'); |
|
309 | 316 | <div class="description"></div> |
310 | 317 | ${isMultiple ? '' : `${allowMultiple ? '<div id="submit-exit" class="input-group row">' : ''} |
311 | 318 | <button id="submit">Create</button> |
312 | | - <button id="exit">Close & Next Question</button> |
| 319 | + <button id="next">Next Question</button> |
| 320 | + <button id="exit">Exit</button> |
313 | 321 | ${allowMultiple ? '</div>' : ''}`} |
314 | 322 | `; |
315 | 323 | document.querySelector('.uploaders').appendChild(uploader); |
316 | | - uploader.querySelector('[data-question-number]').focus(); |
| 324 | + uploader.querySelector('[data-question-number]').select(); |
317 | 325 | const inputElement = uploader.querySelector('input[type="file"]'); |
318 | 326 | const questionElement = uploader.querySelector('input[type="file"]'); |
319 | 327 | const pond = FilePond.create(inputElement, { |
|
369 | 377 | uploader.querySelectorAll('.input-group').forEach(e => e.remove()); |
370 | 378 | uploader.querySelector('.description').remove(); |
371 | 379 | uploader.querySelector('#submit').remove(); |
| 380 | + uploader.querySelector('#next').remove(); |
372 | 381 | uploader.querySelector('#exit').remove(); |
373 | 382 | } else { |
374 | 383 | var textareaContainer = uploader.querySelector('.description') |
|
612 | 621 | uploader.querySelector('#copy')?.addEventListener('click', () => { |
613 | 622 | createUploader(null, uploader.querySelector('[data-question-number]').value || uploaderQuestion); |
614 | 623 | }); |
| 624 | + uploader.querySelector('#next')?.addEventListener('click', next); |
615 | 625 | uploader.querySelector('#exit')?.addEventListener('click', exit); |
616 | 626 | uploader.querySelector('#remove')?.addEventListener('click', () => { |
617 | 627 | if (confirm('Are you sure you want to remove this question? If it has unsaved data, all will be deleted.')) uploader.remove(); |
|
628 | 638 | }); |
629 | 639 | }; |
630 | 640 | async function submitAllUploaders() { |
| 641 | + document.querySelector('#submit').disabled = true; |
| 642 | + document.querySelector('#next').disabled = true; |
| 643 | + document.querySelector('#exit').disabled = true; |
631 | 644 | var submitSuccess = true; |
632 | 645 | document.querySelector('#submit').innerText = 'Submitting'; |
633 | 646 | for (const { uploader, pond, quill, uploaderQuestionId, uploaderQuestion } of uploaders) { |
|
659 | 672 | if (data.error) submitSuccess = false; |
660 | 673 | }); |
661 | 674 | }; |
| 675 | + document.querySelector('#submit').disabled = false; |
| 676 | + document.querySelector('#next').disabled = false; |
| 677 | + document.querySelector('#exit').disabled = false; |
662 | 678 | if (submitSuccess) { |
663 | 679 | document.querySelector('#submit').innerText = 'Success'; |
664 | 680 | document.querySelector('#submit').classList.add('success'); |
| 681 | + document.querySelector('#next').style.display = 'block'; |
665 | 682 | document.querySelector('#exit').style.display = 'block'; |
666 | 683 | setTimeout(() => { |
667 | 684 | document.querySelector('#submit').innerText = 'Save'; |
668 | 685 | document.querySelector('#submit').classList.remove('success'); |
669 | 686 | }, 2000); |
670 | 687 | } else { |
671 | | - document.querySelector('#exit').classList.add('error'); |
| 688 | + document.querySelector('#submit').classList.add('error'); |
672 | 689 | setTimeout(() => { |
673 | | - document.querySelector('#exit').classList.remove('error'); |
| 690 | + document.querySelector('#submit').classList.remove('error'); |
674 | 691 | }, 2000); |
675 | 692 | alert(data.error); |
676 | 693 | }; |
| 694 | + window.opener.postMessage('uploadSuccess', window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')); |
677 | 695 | } |
678 | 696 | window.onload = createUploader; |
679 | 697 | </script> |
|
0 commit comments