Skip to content
Snippets Groups Projects
Commit 41e0f0b6 authored by Jacob Poul Richardt's avatar Jacob Poul Richardt
Browse files

Added support for active on KacPS.

parent 19c297e1
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@
<div class="Filler"><button class="btn btn-default"><span class="glyphicon glyphicon-play" aria-hidden="true"></span></button></div>
<!-- /ko -->
<input type="radio" data-bind="checked: $parent.Answer, attr: {id: UniqueId, name: $parent.Id}, value: Id, enable: $parent.CanAnswer" />
<label class="btn btn-default" data-bind="attr: {for: UniqueId}, css: {active: IsSelected, disabled: !$parent.CanAnswer()}, html: Label, Element: ButtonElement, style: { width: $parent.MaxButtonWidth() ? $parent.MaxButtonWidth() + 'px' : null }">
<label data-bind="attr: {for: UniqueId}, css: {active: IsSelected, disabled: !$parent.CanAnswer(), btn: IsActive, 'btn-default': IsActive}, html: Label, Element: ButtonElement, style: { width: $parent.MaxButtonWidth() ? $parent.MaxButtonWidth() + 'px' : null }">
</label>
</div>
</div>
......
......@@ -15,6 +15,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.Items = this.GetItems(function (v) { return _this.CreateItemInfo(v); });
this.MaxButtonWidth = knockout.computed(function () { return _this.Items.map(function (i) { return i.ButtonElement() == null ? null : i.ButtonElement().offsetWidth; }).reduce(function (p, c) { return p == null || c == null ? null : Math.max(p, c); }, 0); });
this.HasNoStimulus = this.Items.every(function (i) { return !i.HasStimulus; });
this._hasActives = this.Items.some(function (i) { return i.IsActive; });
this.CanAnswer = this.WhenAllAudioHavePlayed(this.Items.map(function (i) { return i.AudioInfo; }), true);
if (this.HasAnswer())
this.Answer(this.GetAnswer().Id);
......@@ -24,7 +25,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
});
}
KacPS.prototype.HasValidAnswer = function (answer) {
return answer.Id != undefined && answer.Id != null;
return !this._hasActives || (answer.Id != undefined && answer.Id != null);
};
KacPS.prototype.CreateItemInfo = function (data) {
var _this = this;
......@@ -39,6 +40,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
Label: this.GetFormatted(data.ChoiceButton.Label),
AudioInfo: audioInfo,
IsSelected: knockout.computed(function () { return _this.Answer() === data.Id; }),
IsActive: data.ChoiceButton.Active == undefined || data.ChoiceButton.Active,
HasStimulus: data.Stimulus !== null,
ButtonElement: knockout.observable(null)
};
......
......@@ -3,8 +3,8 @@ import QuestionBase = require("Components/Questions/QuestionBase");
import QuestionModel = require("Models/Question");
import AudioInfo = require("Components/Players/Audio/AudioInfo");
type ItemInfo = { Id: string; UniqueId: string; Label: string; AudioInfo: AudioInfo; HasStimulus: boolean; IsSelected: KnockoutComputed<boolean>; ButtonElement:KnockoutObservable<HTMLElement> };
type Item = { Id:string; ChoiceButton:{ Label:string; Selected:string }; Stimulus:IStimulus };
type ItemInfo = { Id: string; UniqueId: string; Label: string; AudioInfo: AudioInfo; HasStimulus: boolean; IsActive:boolean; IsSelected: KnockoutComputed<boolean>; ButtonElement:KnockoutObservable<HTMLElement> };
type Item = { Id: string; ChoiceButton: { Label: string; Selected: string; Active?:boolean }; Stimulus:IStimulus };
class KacPS extends QuestionBase<{Id:string}>
{
......@@ -17,6 +17,8 @@ class KacPS extends QuestionBase<{Id:string}>
public HasNoStimulus: boolean;
public MaxButtonWidth: KnockoutComputed<number>;
private _hasActives:boolean;
constructor(question: QuestionModel)
{
super(question);
......@@ -29,6 +31,7 @@ class KacPS extends QuestionBase<{Id:string}>
this.MaxButtonWidth = knockout.computed(() => this.Items.map(i => i.ButtonElement() == null ? null : i.ButtonElement().offsetWidth).reduce((p, c) => p == null || c == null ? null : Math.max(p, c), 0));
this.HasNoStimulus = this.Items.every(i => !i.HasStimulus);
this._hasActives = this.Items.some(i => i.IsActive);
this.CanAnswer = this.WhenAllAudioHavePlayed(this.Items.map(i => i.AudioInfo), true);
......@@ -42,7 +45,7 @@ class KacPS extends QuestionBase<{Id:string}>
protected HasValidAnswer(answer: any): boolean
{
return answer.Id != undefined && answer.Id != null;
return !this._hasActives || (answer.Id != undefined && answer.Id != null);
}
private CreateItemInfo(data: Item): ItemInfo
......@@ -61,6 +64,7 @@ class KacPS extends QuestionBase<{Id:string}>
Label: this.GetFormatted(data.ChoiceButton.Label),
AudioInfo: audioInfo,
IsSelected: knockout.computed(() => this.Answer() === data.Id),
IsActive: data.ChoiceButton.Active == undefined || data.ChoiceButton.Active,
HasStimulus: data.Stimulus !== null,
ButtonElement: knockout.observable(null)
};
......
......@@ -5,7 +5,7 @@
<meta charset="utf-8" />
<title>Cockpit Experiments</title>
<script type="text/javascript">
var CacheBuster = 32;
var CacheBuster = 33;
</script>
</head>
<body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment