From 061bd6888725399361281baaf9bddc31806f726f Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Wed, 25 Sep 2024 10:19:03 +0100 Subject: [PATCH 1/3] New: _isLocked becomes a lockable attribute --- js/models/adaptModel.js | 14 ++++++++++---- js/models/questionModel.js | 7 ++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/models/adaptModel.js b/js/models/adaptModel.js index 6e852c97..c191c38b 100644 --- a/js/models/adaptModel.js +++ b/js/models/adaptModel.js @@ -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} @@ -780,7 +786,7 @@ export default class AdaptModel extends LockingModel { !previousChild.get('_isComplete') && !previousChild.get('_isOptional') ); - child.set('_isLocked', isLockedByPreviousChild); + child.set('_isLocked', isLockedByPreviousChild, { pluginName: 'adapt' }); }, false); } @@ -788,19 +794,19 @@ export default class AdaptModel extends LockingModel { 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) { diff --git a/js/models/questionModel.js b/js/models/questionModel.js index 75989c85..44e4e452 100644 --- a/js/models/questionModel.js +++ b/js/models/questionModel.js @@ -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} @@ -59,7 +65,6 @@ class QuestionModel extends ComponentModel { init() { this.setupDefaultSettings(); - this.setLocking('_canSubmit', true); this.updateRawScore(); super.init(); } From 90ad1c122915ebf10ccf906ef8d2a2e427890366 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Wed, 25 Sep 2024 11:03:20 +0100 Subject: [PATCH 2/3] Do not lock when setting initial default --- js/models/lockingModel.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/models/lockingModel.js b/js/models/lockingModel.js index d990e61b..81f434c1 100644 --- a/js/models/lockingModel.js +++ b/js/models/lockingModel.js @@ -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; } From 6c57883a6f1b976761d6c02b7d3a9953deb2d02f Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Wed, 25 Sep 2024 11:14:59 +0100 Subject: [PATCH 3/3] Ensure locked attributes remain locked after deepClone --- js/models/adaptModel.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/models/adaptModel.js b/js/models/adaptModel.js index c191c38b..e97387de 100644 --- a/js/models/adaptModel.js +++ b/js/models/adaptModel.js @@ -856,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);