@@ -37,6 +37,7 @@ export default class SelectOne extends RunestoneBase {
3737 this . not_seen_ever = $ ( opts . orig ) . data ( "not_seen_ever" ) ;
3838 this . selector_id = $ ( opts . orig ) . first ( ) . attr ( "id" ) ;
3939 this . primaryOnly = $ ( opts . orig ) . data ( "primary" ) ;
40+ this . ABExperiment = $ ( opts . orig ) . data ( "ab" ) ;
4041 opts . orig . id = this . selector_id ;
4142 }
4243 /**
@@ -72,59 +73,52 @@ export default class SelectOne extends RunestoneBase {
7273 if ( this . primaryOnly ) {
7374 data . primary = this . primaryOnly ;
7475 }
76+ if ( this . ABExperiment ) {
77+ data . AB = this . ABExperiment ;
78+ }
7579 let opts = this . origOpts ;
7680 let selectorId = this . selector_id ;
77- let myPromise = new Promise (
78- function ( resolve , reject ) {
79- $ . getJSON (
80- "/runestone/ajax/get_question_source" ,
81- data ,
82- function ( htmlsrc ) {
83- if ( htmlsrc . indexOf ( "No preview" ) >= 0 ) {
84- alert (
85- `Error: Not able to find a question for ${ selectorId } based on the criteria`
86- ) ;
87- resolve ( "done" ) ;
88- return ;
89- }
90- let res ;
91- if ( opts . timed ) {
92- // timed components are not rendered immediately, only when the student
93- // starts the assessment and visits this particular entry.
94- res = createTimedComponent ( htmlsrc , {
95- timed : true ,
96- selector_id : selectorId ,
97- assessmentTaken : opts . assessmentTaken ,
98- } ) ;
99- // replace the entry in the timed assessment's list of components
100- // with the component created by createTimedComponent
101- for ( let component of opts . rqa ) {
102- if ( component . question == self ) {
103- component . question = res . question ;
104- break ;
105- }
106- }
107- self . realComponent = res . question ;
108- self . containerDiv = res . question . containerDiv ;
109- self . realComponent . selectorId = selectorId ;
110- } else {
111- // just render this component on the page in its usual place
112- res = renderRunestoneComponent (
113- htmlsrc ,
114- selectorId ,
115- {
116- selector_id : selectorId ,
117- useRunestoneServices : true ,
118- }
119- ) ;
120- }
121- console . log ( "resolving selectquestion" ) ;
122- resolve ( "done" ) ;
123- }
124- ) ;
125- } . bind ( this )
126- ) ;
127- return myPromise ;
81+ let request = new Request ( "/runestone/ajax/get_question_source" , {
82+ method : "POST" ,
83+ headers : this . jsonHeaders ,
84+ body : JSON . stringify ( data ) ,
85+ } ) ;
86+ let response = await fetch ( request ) ;
87+ let htmlsrc = await response . json ( ) ;
88+ if ( htmlsrc . indexOf ( "No preview" ) >= 0 ) {
89+ alert (
90+ `Error: Not able to find a question for ${ selectorId } based on the criteria`
91+ ) ;
92+ return response ;
93+ }
94+ let res ;
95+ if ( opts . timed ) {
96+ // timed components are not rendered immediately, only when the student
97+ // starts the assessment and visits this particular entry.
98+ res = createTimedComponent ( htmlsrc , {
99+ timed : true ,
100+ selector_id : selectorId ,
101+ assessmentTaken : opts . assessmentTaken ,
102+ } ) ;
103+ // replace the entry in the timed assessment's list of components
104+ // with the component created by createTimedComponent
105+ for ( let component of opts . rqa ) {
106+ if ( component . question == self ) {
107+ component . question = res . question ;
108+ break ;
109+ }
110+ }
111+ self . realComponent = res . question ;
112+ self . containerDiv = res . question . containerDiv ;
113+ self . realComponent . selectorId = selectorId ;
114+ } else {
115+ // just render this component on the page in its usual place
116+ res = renderRunestoneComponent ( htmlsrc , selectorId , {
117+ selector_id : selectorId ,
118+ useRunestoneServices : true ,
119+ } ) ;
120+ }
121+ return response ;
128122 }
129123}
130124
0 commit comments