@@ -25,33 +25,30 @@ async function stateChange(state) {
2525 }
2626}
2727
28+ const questionnaryButtons = { } ;
2829async function setQuestionnaries ( ) {
29- const select = document . getElementById ( "select-questionnary" ) ;
30- const optionNull = document . createElement ( "option" ) ;
31- optionNull . text = '---' ;
32- optionNull . value = '' ;
33- select . add ( optionNull ) ;
30+ // -- on load
31+ const selectedQuestionnary = getQuestionnaryFromUrl ( ) ;
32+
33+
34+ const tbody = document . getElementById ( 'questionnary-table' ) . getElementsByTagName ( 'tbody' ) [ 0 ] ;
35+ // clear previous content
36+ while ( tbody . firstChild ) {
37+ tbody . removeChild ( tbody . firstChild ) ;
38+ }
3439
3540 const quests = await drLib . getQuestionnaires ( ) ;
3641 for ( const [ key , value ] of Object . entries ( quests ) ) {
37- const option = document . createElement ( "option" ) ;
38- option . text = value . title ;
39- option . value = key ;
40- select . add ( option ) ;
41- }
42-
43- // -- on change
44- select . onchange = function ( ) {
45- if ( select . value === '' ) {
46- showQuestionnary ( null ) ;
47- return ;
48- }
49- showQuestionnary ( select . value ) ;
50- }
51- // -- on load
52- const selectedQuestionnary = getQuestionnaryFromUrl ( ) ;
42+ const row = tbody . insertRow ( - 1 ) ;
43+ const cellQuestionnary = row . insertCell ( - 1 ) ;
44+ cellQuestionnary . innerHTML = `<button type="button" class="btn btn-secondary mb-sm">${ value . title } </button>` ;
45+ questionnaryButtons [ key ] = cellQuestionnary . getElementsByTagName ( 'button' ) [ 0 ] ;
46+ cellQuestionnary . onclick = function ( ) {
47+ showQuestionnary ( key ) ;
48+ } ;
49+ } ;
50+
5351 if ( selectedQuestionnary ) {
54- select . value = selectedQuestionnary ;
5552 showQuestionnary ( selectedQuestionnary ) ;
5653 }
5754}
@@ -63,7 +60,15 @@ function getQuestionnaryFromUrl() {
6360 return questionaryId
6461}
6562
63+ function highlightQuestionnaryButton ( questionaryId ) {
64+ for ( const [ key , button ] of Object . entries ( questionnaryButtons ) ) {
65+ const color = ( questionaryId === key ) ? "LightSeaGreen" : 'lightgrey' ;
66+ button . style . backgroundColor = color ;
67+ }
68+ }
69+
6670async function showQuestionnary ( questionaryId ) {
71+ highlightQuestionnaryButton ( questionaryId ) ;
6772 console . log ( '## showQuestionnary' , questionaryId ) ;
6873 if ( questionaryId == null ) {
6974 document . getElementById ( 'questionnary-view' ) . style . visibility = 'hidden' ;
0 commit comments