|
3 | 3 | // this file contained the code only used by viewer.html. The code here is |
4 | 4 | // mostly for the lforms version menu, and it includes app.js. |
5 | 5 |
|
6 | | -import {loadLForms} from './lformsLoader.js' |
7 | | -import semverSort from 'semver/functions/rsort'; |
| 6 | +import {loadLForms, getSupportedLFormsVersions, changeLFormsVersion} from 'lforms-loader' |
8 | 7 | import * as app from './app.js'; |
9 | 8 |
|
10 | 9 | let params = new URL(document.location).searchParams; |
@@ -39,43 +38,18 @@ function showHeader() { |
39 | 38 | */ |
40 | 39 | function initLFormsVersionMenu() { |
41 | 40 | // Get the list of lforms versions |
42 | | - fetch('https://clinicaltables.nlm.nih.gov/lforms-versions').then(response=>{ |
43 | | - // https://clinicaltables.nlm.nih.gov/lforms-versions contains output like: |
44 | | - // <span class="name">lforms-9.0.2.zip</span> |
45 | | - if (response.ok) { // otherwise, don't show the menu |
46 | | - response.text().then(pageText=>{ |
47 | | - const versions = |
48 | | - [...pageText.matchAll(/<span class="name">lforms-(.*)\.zip<\/span>/g)].map( |
49 | | - m=>m[1]).filter(v=>v.split('.')[0]>=29); |
50 | | - semverSort(versions); |
51 | | - const ac = new LForms.Def.Autocompleter.Prefetch('lformsVersion', versions, |
52 | | - {defaultValue: LForms.lformsVersion, matchListValue: true, addSeqNum: false}); |
53 | | - ac.setFieldToListValue(LForms.lformsVersion); |
54 | | - $('#lformsVersionMenu')[0].style.display='inline'; |
55 | | - LForms.Def.Autocompleter.Event.observeListSelections('lformsVersion', (data)=>{ |
56 | | - if (data.final_val && data.on_list && data.final_val != LForms.lformsVersion) |
57 | | - changeLFormsVersion(data.final_val); |
58 | | - }); |
59 | | - }); |
60 | | - } |
| 41 | + getSupportedLFormsVersions().then(versions=>{ |
| 42 | + const ac = new LForms.Def.Autocompleter.Prefetch('lformsVersion', versions, |
| 43 | + {defaultValue: LForms.lformsVersion, matchListValue: true, addSeqNum: false}); |
| 44 | + ac.setFieldToListValue(LForms.lformsVersion); |
| 45 | + document.getElementById('lformsVersionMenu').style.display='inline'; |
| 46 | + LForms.Def.Autocompleter.Event.observeListSelections('lformsVersion', (data)=>{ |
| 47 | + if (data.final_val && data.on_list && data.final_val != LForms.lformsVersion) |
| 48 | + changeLFormsVersion(data.final_val); |
| 49 | + }); |
61 | 50 | }); |
62 | 51 | } |
63 | 52 |
|
64 | | -/** |
65 | | - * Handles a selection of a new LForms version. |
66 | | - * @param newLFormsVersion the new version to switch to (assumed valid) |
67 | | - */ |
68 | | -function changeLFormsVersion(newLFormsVersion) { |
69 | | - // We need to reload the page. |
70 | | - // The menu only shows if parameters were not set for the questionnaire, so |
71 | | - // we can't preserve any field values the user might have filled in for the |
72 | | - // questionnaire. |
73 | | - let pageURL = window.location.origin + window.location.pathname; |
74 | | - const params = new URLSearchParams(window.location.search); |
75 | | - params.set('lfv', newLFormsVersion); |
76 | | - window.location = pageURL + '?' + params; |
77 | | -} |
78 | | - |
79 | 53 |
|
80 | 54 | /** |
81 | 55 | * Initializes the app after everything has loaded. |
|
0 commit comments