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

New: _isLocked becomes a lockable attribute #585

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 12 additions & 4 deletions js/models/adaptModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export default class AdaptModel extends LockingModel {
};
}

lockedAttributes() {
return {
_isLocked: true
};
}

/**
* Fetch an array representing the relative location of the model to the nearest _trackingId
* @returns {Array<Number, Number>}
Expand Down Expand Up @@ -780,27 +786,27 @@ export default class AdaptModel extends LockingModel {
!previousChild.get('_isComplete') &&
!previousChild.get('_isOptional')
);
child.set('_isLocked', isLockedByPreviousChild);
child.set('_isLocked', isLockedByPreviousChild, { pluginName: 'adapt' });
}, false);
}

setUnlockFirstLocking() {
const children = this.getAvailableChildModels();
const firstChild = children.shift();
const isLockedByFirstChild = (!firstChild.get('_isComplete') && !firstChild.get('_isOptional'));
children.forEach(child => child.set('_isLocked', isLockedByFirstChild));
children.forEach(child => child.set('_isLocked', isLockedByFirstChild, { pluginName: 'adapt' }));
}

setLockLastLocking() {
const children = this.getAvailableChildModels();
const lastChild = children.pop();
const isLockedByChildren = children.some(child => (!child.get('_isComplete') && !child.get('_isOptional')));
lastChild.set('_isLocked', isLockedByChildren);
lastChild.set('_isLocked', isLockedByChildren, { pluginName: 'adapt' });
}

setCustomLocking() {
const children = this.getAvailableChildModels();
children.forEach(child => child.set('_isLocked', this.shouldLock(child)));
children.forEach(child => child.set('_isLocked', this.shouldLock(child), { pluginName: 'adapt' }));
}

shouldLock(child) {
Expand Down Expand Up @@ -850,6 +856,8 @@ export default class AdaptModel extends LockingModel {
const ModelClass = this.constructor;
// Clone the model
const clonedModel = new ModelClass(this.toJSON());
clonedModel._lockedAttributes = { ...this._lockedAttributes };
clonedModel._lockedAttributesValues = { ...this._lockedAttributesValues };
// Run the custom modifier on the clone
if (modifier) {
modifier(clonedModel, this);
Expand Down
4 changes: 3 additions & 1 deletion js/models/lockingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default class LockingModel extends Backbone.Model {
const isAttemptingToLock = (lockingValue === attrVal);

if (isAttemptingToLock) {
this.setLockState(attrName, true, { pluginName, skipcheck: true });
if (!isInitialDefault) {
this.setLockState(attrName, true, { pluginName, skipcheck: true });
}
newValues[attrName] = lockingValue;
continue;
}
Expand Down
7 changes: 6 additions & 1 deletion js/models/questionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class QuestionModel extends ComponentModel {
]);
}

lockedAttributes() {
return ComponentModel.resultExtend('lockedAttributes', {
_canSubmit: true
});
}

/**
* Returns a string of the model type group.
* @returns {string}
Expand All @@ -59,7 +65,6 @@ class QuestionModel extends ComponentModel {

init() {
this.setupDefaultSettings();
this.setLocking('_canSubmit', true);
this.updateRawScore();
super.init();
}
Expand Down