Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Body text not updating on revisit with linked confidence sliders (fixes #101) #104

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion js/ConfidenceSliderModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export default class ConfidenceSliderModel extends SliderModel {
super.init();
if (!this.get('_linkedToId')) return;
this.set('originalBody', this.get('body'));
this._setupLinkedModel();
this.setupEventListeners();
}

setupEventListeners() {
this.listenToOnce(Adapt, 'adapt:initialize', this._setupLinkedModel);
}

/* override */
Expand Down Expand Up @@ -111,6 +115,19 @@ export default class ConfidenceSliderModel extends SliderModel {
return feedbackString;
}

onLinkedSubmittedChanged(linkedModel) {
this.set('body', this.get('originalBody'));
this.set('_isEnabled', (linkedModel.get('_isSubmitted') === true));
this.set('_linkedModelSelectedIndex', linkedModel.get('_selectedItem').index);
this.checkCanSubmit();
}

_listenToLinkedModel() {
this.listenTo(this.linkedModel, {
'change:_isSubmitted': this.onLinkedSubmittedChanged
});
}
joe-allen-89 marked this conversation as resolved.
Show resolved Hide resolved

_setupLinkedModel() {
this.linkedModel = Adapt.components.findWhere({ _id: this.get('_linkedToId') });
if (!this.linkedModel) {
Expand All @@ -129,6 +146,13 @@ export default class ConfidenceSliderModel extends SliderModel {
_scaleStart: this.linkedModel.get('_scaleStart'),
_scaleEnd: this.linkedModel.get('_scaleEnd')
});
this._listenToLinkedModel();
if (!this.linkedModel.get('_isSubmitted')) {
this.set('_isEnabled', false);
this.set('body', this.get('disabledBody'));
} else {
this.set('_linkedModelSelectedIndex', this.linkedModel.get('_selectedItem').index);
}
joe-allen-89 marked this conversation as resolved.
Show resolved Hide resolved
if (this.get('_attempts') < 0) this.linkedModel.set('_attempts', 1);
}

Expand Down
22 changes: 0 additions & 22 deletions js/ConfidenceSliderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,7 @@ class ConfidenceSliderView extends SliderView {
super.setupQuestion();
}

_listenToLinkedModel() {
this.listenTo(this.model.linkedModel, {
'change:_isSubmitted': this.onLinkedSubmittedChanged
});
}

onQuestionRendered() {
if (this.model.linkedModel) {
this._listenToLinkedModel();
if (!this.model.linkedModel.get('_isSubmitted')) {
this.model.set('_isEnabled', false);
this.model.set('body', this.model.get('disabledBody'));
} else {
this.model.set('_linkedModelSelectedIndex', this.model.linkedModel.get('_selectedItem').index);
}
}
if (!(this.model.get('_isSubmitted') && this.model.has('_userAnswer'))) return;
this.model.set({
feedbackTitle: this.model.get('title'),
Expand All @@ -56,13 +41,6 @@ class ConfidenceSliderView extends SliderView {
super.onNumberSelected(value);
}

onLinkedSubmittedChanged(linkedModel) {
this.model.set('body', this.model.get('originalBody'));
this.model.set('_isEnabled', (linkedModel.get('_isSubmitted') === true));
this.model.set('_linkedModelSelectedIndex', linkedModel.get('_selectedItem').index);
this.model.checkCanSubmit();
}

}

ConfidenceSliderView.template = 'confidenceSlider.jsx';
Expand Down