Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit d02be47

Browse files
committed
last getJSON removed!
1 parent 3ee5b31 commit d02be47

1 file changed

Lines changed: 41 additions & 51 deletions

File tree

runestone/selectquestion/js/selectone.js

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,57 +74,47 @@ export default class SelectOne extends RunestoneBase {
7474
}
7575
let opts = this.origOpts;
7676
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;
77+
let request = new Request("/runestone/ajax/get_question_source", {
78+
method: "POST",
79+
headers: this.jsonHeaders,
80+
body: JSON.stringify(data),
81+
});
82+
let response = await fetch(request);
83+
let htmlsrc = await response.json();
84+
if (htmlsrc.indexOf("No preview") >= 0) {
85+
alert(
86+
`Error: Not able to find a question for ${selectorId} based on the criteria`
87+
);
88+
return response;
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(htmlsrc, selectorId, {
113+
selector_id: selectorId,
114+
useRunestoneServices: true,
115+
});
116+
}
117+
return response;
128118
}
129119
}
130120

0 commit comments

Comments
 (0)