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

Refactored base question class with generic answer type.

Added error feedback.
Updated cachebuster.
Previous page now clears slide.
parent ac27e4fe
Branches
No related tags found
No related merge requests found
Showing
with 226 additions and 169 deletions
...@@ -91,7 +91,12 @@ export interface IQuestion ...@@ -91,7 +91,12 @@ export interface IQuestion
Id:string; Id:string;
Type: string; Type: string;
Input:any[]; Input:any[];
Output: any; Output: IOutput;
}
export interface IOutput
{
Events:IQuestionEvent[];
} }
export interface IQuestionEvent export interface IQuestionEvent
......
...@@ -21,7 +21,7 @@ class AudioInfo ...@@ -21,7 +21,7 @@ class AudioInfo
}); });
} }
public static Create(stimulus:Stimulus):AudioInfo public static Create(stimulus:IStimulus):AudioInfo
{ {
if (stimulus === null) return null; if (stimulus === null) return null;
return new AudioInfo([{ Type: stimulus.Type, Source: stimulus.URI }]); return new AudioInfo([{ Type: stimulus.Type, Source: stimulus.URI }]);
......
...@@ -15,9 +15,9 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", " ...@@ -15,9 +15,9 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.HasMedia = false; this.HasMedia = false;
this.Id = this.Model.Id; this.Id = this.Model.Id;
this.HeaderLabel = this.GetInstrumentFormatted("HeaderLabel"); this.HeaderLabel = this.GetInstrumentFormatted("HeaderLabel");
this._minNoOfSelections = this.GetInstrument("MinNoOfSelections"); this._minNoOfSelections = parseInt(this.GetInstrument("MinNoOfSelections"));
this._maxNoOfSelections = this.GetInstrument("MaxNoOfSelections"); this._maxNoOfSelections = parseInt(this.GetInstrument("MaxNoOfSelections"));
var stimulus = this.GetInstrument("Stimulus"); var stimulus = this.GetStimulusInstrument("Stimulus");
if (stimulus != null) { if (stimulus != null) {
this.AudioLabel = this.GetFormatted(stimulus.Label); this.AudioLabel = this.GetFormatted(stimulus.Label);
this.AudioInfo = new AudioInfo([{ Type: stimulus.Type, Source: stimulus.URI }]); this.AudioInfo = new AudioInfo([{ Type: stimulus.Type, Source: stimulus.URI }]);
...@@ -32,15 +32,19 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", " ...@@ -32,15 +32,19 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.AddHalfFillerItem = knockout.computed(function () { return _this.Items.length === 3; }); this.AddHalfFillerItem = knockout.computed(function () { return _this.Items.length === 3; });
this.AddFillerItem = knockout.computed(function () { return _this.AddOneFillerItem() || _this.AddHalfFillerItem(); }); this.AddFillerItem = knockout.computed(function () { return _this.AddOneFillerItem() || _this.AddHalfFillerItem(); });
if (this.HasAnswer()) { if (this.HasAnswer()) {
if (this.GetAsnwer()["Selections"]) if (this.GetAnswer()["Selections"])
this.Answer.push.apply(this.Answer, this.GetAsnwer()["Selections"]); this.Answer.push.apply(this.Answer, this.GetAnswer().Selections);
} }
else
this.SetAnswer({ Selections: [] });
this.Answer.subscribe(function (v) { this.Answer.subscribe(function (v) {
_this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v.join(",")); _this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v.join(","));
_this.SetAnswer({ Selections: v }); _this.SetAnswer({ Selections: v });
}); });
} }
CheckBoxGroup.prototype.HasValidAnswer = function (answer) { CheckBoxGroup.prototype.HasValidAnswer = function (answer) {
if (this._minNoOfSelections === 0)
return true;
if (!answer.Selections) if (!answer.Selections)
return false; return false;
return answer.Selections.length >= this._minNoOfSelections; return answer.Selections.length >= this._minNoOfSelections;
......
...@@ -6,7 +6,7 @@ import AudioInfo = require("Components/Players/Audio/AudioInfo"); ...@@ -6,7 +6,7 @@ import AudioInfo = require("Components/Players/Audio/AudioInfo");
type ItemInfo = { Id: string; Label: string; IsEnabled: KnockoutComputed<boolean>; }; type ItemInfo = { Id: string; Label: string; IsEnabled: KnockoutComputed<boolean>; };
type Item = { Label: string; Id: string; Selected: string }; type Item = { Label: string; Id: string; Selected: string };
class CheckBoxGroup extends QuestionBase class CheckBoxGroup extends QuestionBase<{Selections:string[]}>
{ {
private _minNoOfSelections: number; private _minNoOfSelections: number;
private _maxNoOfSelections: number; private _maxNoOfSelections: number;
...@@ -31,10 +31,10 @@ class CheckBoxGroup extends QuestionBase ...@@ -31,10 +31,10 @@ class CheckBoxGroup extends QuestionBase
this.Id = this.Model.Id; this.Id = this.Model.Id;
this.HeaderLabel = this.GetInstrumentFormatted("HeaderLabel"); this.HeaderLabel = this.GetInstrumentFormatted("HeaderLabel");
this._minNoOfSelections = this.GetInstrument("MinNoOfSelections"); this._minNoOfSelections = parseInt(this.GetInstrument("MinNoOfSelections"));
this._maxNoOfSelections = this.GetInstrument("MaxNoOfSelections"); this._maxNoOfSelections = parseInt(this.GetInstrument("MaxNoOfSelections"));
var stimulus = this.GetInstrument("Stimulus"); var stimulus = this.GetStimulusInstrument("Stimulus");
if (stimulus != null) if (stimulus != null)
{ {
this.AudioLabel = this.GetFormatted(stimulus.Label); this.AudioLabel = this.GetFormatted(stimulus.Label);
...@@ -57,9 +57,11 @@ class CheckBoxGroup extends QuestionBase ...@@ -57,9 +57,11 @@ class CheckBoxGroup extends QuestionBase
if (this.HasAnswer()) if (this.HasAnswer())
{ {
if (this.GetAsnwer()["Selections"]) if (this.GetAnswer()["Selections"])
this.Answer.push.apply(this.Answer, this.GetAsnwer()["Selections"]); this.Answer.push.apply(this.Answer, this.GetAnswer().Selections);
} }
else
this.SetAnswer({ Selections: [] });
this.Answer.subscribe(v => this.Answer.subscribe(v =>
{ {
...@@ -70,6 +72,7 @@ class CheckBoxGroup extends QuestionBase ...@@ -70,6 +72,7 @@ class CheckBoxGroup extends QuestionBase
protected HasValidAnswer(answer: any): boolean protected HasValidAnswer(answer: any): boolean
{ {
if (this._minNoOfSelections === 0) return true;
if (!answer.Selections) return false; if (!answer.Selections) return false;
return answer.Selections.length >= this._minNoOfSelections; return answer.Selections.length >= this._minNoOfSelections;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import QuestionBase = require("Components/Questions/QuestionBase"); import QuestionBase = require("Components/Questions/QuestionBase");
import QuestionModel = require("Models/Question"); import QuestionModel = require("Models/Question");
class EndOfExperiment extends QuestionBase class EndOfExperiment extends QuestionBase<any>
{ {
constructor(question: QuestionModel) constructor(question: QuestionModel)
{ {
......
...@@ -4,63 +4,19 @@ var __extends = this.__extends || function (d, b) { ...@@ -4,63 +4,19 @@ var __extends = this.__extends || function (d, b) {
__.prototype = b.prototype; __.prototype = b.prototype;
d.prototype = new __(); d.prototype = new __();
}; };
define(["require", "exports", "knockout", "Components/Questions/QuestionBase"], function (require, exports, knockout, QuestionBase) { define(["require", "exports", "Components/Questions/Freetext/FreetextBase"], function (require, exports, FreetextBase) {
var Freetext = (function (_super) { var Freetext = (function (_super) {
__extends(Freetext, _super); __extends(Freetext, _super);
function Freetext(question) { function Freetext() {
var _this = this; _super.apply(this, arguments);
_super.call(this, question);
this.Label = "";
this.Answer = knockout.observable(null);
this.LabelPosition = "left";
this.LabelPositionLeft = false;
this.LabelPositionTop = false;
this.LabelPositionRight = false;
this.LabelPositionBottom = false;
this.Id = this.Model.Id;
if (this.HasInstrument()) {
this.Label = this.GetInstrumentFormatted("Label");
var validation = this.GetInstrument("Validation");
if (validation)
this._validation = new RegExp(validation);
}
this.LabelPosition = this.GetInstrument("LabelPosition");
switch (this.LabelPosition) {
case "left":
this.LabelPositionLeft = true;
break;
case "top":
this.LabelPositionTop = true;
break;
case "right":
this.LabelPositionRight = true;
break;
case "bottom":
this.LabelPositionBottom = true;
break;
}
if (this.HasAnswer())
this.LoadAnswer(this.GetAsnwer());
this.Answer.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 200 } });
this.Answer.subscribe(function (v) {
_this.AddEvent("Change", "/Instrument", "Keyboard", v);
_this.SetAnswer(_this.SaveAnswerAnswer(v));
});
} }
Freetext.prototype.LoadAnswer = function (answer) { Freetext.prototype.LoadAnswer = function (answer) {
this.Answer(answer["Text"]); this.Answer(answer.Text ? answer.Text : "");
}; };
Freetext.prototype.SaveAnswerAnswer = function (answer) { Freetext.prototype.SaveAnswerAnswer = function (answer) {
return { Text: answer }; return { Text: answer };
}; };
Freetext.prototype.HasValidAnswer = function (answer) {
if (!this._validation)
return true;
if (answer === null)
answer = "";
return this._validation.test(answer);
};
return Freetext; return Freetext;
})(QuestionBase); })(FreetextBase);
return Freetext; return Freetext;
}); });
import knockout = require("knockout"); import FreetextBase = require("Components/Questions/Freetext/FreetextBase");
import QuestionBase = require("Components/Questions/QuestionBase");
import QuestionModel = require("Models/Question");
class Freetext extends QuestionBase type Answer = { Text: string };
{
public Id: string;
public Label: string = "";
public Answer: KnockoutObservable<string> = knockout.observable<string>(null);
public LabelPosition:string = "left";
public LabelPositionLeft:boolean = false;
public LabelPositionTop:boolean = false;
public LabelPositionRight:boolean = false;
public LabelPositionBottom:boolean = false;
private _validation: RegExp;
constructor(question: QuestionModel) class Freetext extends FreetextBase<Answer>
{ {
super(question); protected LoadAnswer(answer: Answer): void
this.Id = this.Model.Id;
if (this.HasInstrument())
{ {
this.Label = this.GetInstrumentFormatted("Label"); this.Answer(answer.Text ? answer.Text : "");
var validation = this.GetInstrument("Validation");
if (validation) this._validation = new RegExp(validation);
} }
this.LabelPosition = this.GetInstrument("LabelPosition"); protected SaveAnswerAnswer(answer: string): Answer
switch (this.LabelPosition)
{
case "left":
this.LabelPositionLeft = true;
break;
case "top":
this.LabelPositionTop = true;
break;
case "right":
this.LabelPositionRight = true;
break;
case "bottom":
this.LabelPositionBottom = true;
break;
}
if (this.HasAnswer()) this.LoadAnswer(this.GetAsnwer());
this.Answer.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 200 }});
this.Answer.subscribe(v =>
{
this.AddEvent("Change", "/Instrument", "Keyboard", v);
this.SetAnswer(this.SaveAnswerAnswer(v));
});
}
protected LoadAnswer(answer:any):void
{
this.Answer(answer["Text"]);
}
protected SaveAnswerAnswer(answer:string): any
{ {
return { Text: answer }; return { Text: answer };
} }
protected HasValidAnswer(answer: any): boolean
{
if (!this._validation) return true;
if (answer === null) answer = "";
return this._validation.test(answer);
}
} }
export = Freetext; export = Freetext;
\ No newline at end of file
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
define(["require", "exports", "knockout", "Components/Questions/QuestionBase"], function (require, exports, knockout, QuestionBase) {
var FreetextBase = (function (_super) {
__extends(FreetextBase, _super);
function FreetextBase(question) {
var _this = this;
_super.call(this, question);
this.Label = "";
this.Answer = knockout.observable(null);
this.LabelPosition = "left";
this.LabelPositionLeft = false;
this.LabelPositionTop = false;
this.LabelPositionRight = false;
this.LabelPositionBottom = false;
this.Id = this.Model.Id;
if (this.HasInstrument()) {
this.Label = this.GetInstrumentFormatted("Label");
var validation = this.GetInstrument("Validation");
if (validation)
this._validation = new RegExp(validation);
}
this.LabelPosition = this.GetInstrument("LabelPosition");
switch (this.LabelPosition) {
case "left":
this.LabelPositionLeft = true;
break;
case "top":
this.LabelPositionTop = true;
break;
case "right":
this.LabelPositionRight = true;
break;
case "bottom":
this.LabelPositionBottom = true;
break;
}
if (this.HasAnswer())
this.LoadAnswer(this.GetAnswer());
this.Answer.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 200 } });
this.Answer.subscribe(function (v) {
_this.AddEvent("Change", "/Instrument", "Keyboard", v);
_this.SetAnswer(_this.SaveAnswerAnswer(v));
});
}
FreetextBase.prototype.LoadAnswer = function (answer) {
throw new Error("Not implemented");
};
FreetextBase.prototype.SaveAnswerAnswer = function (answer) {
throw new Error("Not implemented");
};
FreetextBase.prototype.HasValidAnswer = function (answer) {
if (!this._validation)
return true;
if (answer === null)
answer = "";
return this._validation.test(answer);
};
return FreetextBase;
})(QuestionBase);
return FreetextBase;
});
import knockout = require("knockout");
import QuestionBase = require("Components/Questions/QuestionBase");
import QuestionModel = require("Models/Question");
class FreetextBase<T> extends QuestionBase<T>
{
public Id: string;
public Label: string = "";
public Answer: KnockoutObservable<string> = knockout.observable<string>(null);
public LabelPosition:string = "left";
public LabelPositionLeft:boolean = false;
public LabelPositionTop:boolean = false;
public LabelPositionRight:boolean = false;
public LabelPositionBottom:boolean = false;
private _validation: RegExp;
constructor(question: QuestionModel)
{
super(question);
this.Id = this.Model.Id;
if (this.HasInstrument())
{
this.Label = this.GetInstrumentFormatted("Label");
var validation = this.GetInstrument("Validation");
if (validation) this._validation = new RegExp(validation);
}
this.LabelPosition = this.GetInstrument("LabelPosition");
switch (this.LabelPosition)
{
case "left":
this.LabelPositionLeft = true;
break;
case "top":
this.LabelPositionTop = true;
break;
case "right":
this.LabelPositionRight = true;
break;
case "bottom":
this.LabelPositionBottom = true;
break;
}
if (this.HasAnswer())
this.LoadAnswer(this.GetAnswer());
this.Answer.extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 200 }});
this.Answer.subscribe(v =>
{
this.AddEvent("Change", "/Instrument", "Keyboard", v);
this.SetAnswer(this.SaveAnswerAnswer(v));
});
}
protected LoadAnswer(answer: T):void
{
throw new Error("Not implemented");
}
protected SaveAnswerAnswer(answer: string): T
{
throw new Error("Not implemented");
}
protected HasValidAnswer(answer: any): boolean
{
if (!this._validation) return true;
if (answer === null) answer = "";
return this._validation.test(answer);
}
}
export = FreetextBase;
\ No newline at end of file
...@@ -4,7 +4,7 @@ var __extends = this.__extends || function (d, b) { ...@@ -4,7 +4,7 @@ var __extends = this.__extends || function (d, b) {
__.prototype = b.prototype; __.prototype = b.prototype;
d.prototype = new __(); d.prototype = new __();
}; };
define(["require", "exports", "Components/Questions/Freetext/Freetext", "crypto-js"], function (require, exports, FreeText, CryptoJS) { define(["require", "exports", "Components/Questions/Freetext/FreetextBase", "crypto-js"], function (require, exports, FreetextBase, CryptoJS) {
var FreetextHash = (function (_super) { var FreetextHash = (function (_super) {
__extends(FreetextHash, _super); __extends(FreetextHash, _super);
function FreetextHash(question) { function FreetextHash(question) {
...@@ -17,6 +17,6 @@ define(["require", "exports", "Components/Questions/Freetext/Freetext", "crypto- ...@@ -17,6 +17,6 @@ define(["require", "exports", "Components/Questions/Freetext/Freetext", "crypto-
return { Value: CryptoJS.MD5(this._forceLowerCase ? answer.toLocaleLowerCase() : answer).toString(), Length: answer.length }; return { Value: CryptoJS.MD5(this._forceLowerCase ? answer.toLocaleLowerCase() : answer).toString(), Length: answer.length };
}; };
return FreetextHash; return FreetextHash;
})(FreeText); })(FreetextBase);
return FreetextHash; return FreetextHash;
}); });
import QuestionModel = require("Models/Question"); import QuestionModel = require("Models/Question");
import FreeText = require("Components/Questions/Freetext/Freetext"); import FreetextBase = require("Components/Questions/Freetext/FreetextBase");
import CryptoJS = require("crypto-js"); import CryptoJS = require("crypto-js");
class FreetextHash extends FreeText type Answer = { Value:string; Length:number };
class FreetextHash extends FreetextBase<Answer>
{ {
private _forceLowerCase:boolean; private _forceLowerCase:boolean;
...@@ -13,12 +15,12 @@ class FreetextHash extends FreeText ...@@ -13,12 +15,12 @@ class FreetextHash extends FreeText
this._forceLowerCase = this.GetInstrument("ForceLowerCase") === 1; this._forceLowerCase = this.GetInstrument("ForceLowerCase") === 1;
} }
protected LoadAnswer(answer: any): void protected LoadAnswer(answer: Answer): void
{ {
} }
protected SaveAnswerAnswer(answer: string): any protected SaveAnswerAnswer(answer: string): Answer
{ {
return { Value: CryptoJS.MD5(this._forceLowerCase ? answer.toLocaleLowerCase() : answer).toString(), Length: answer.length }; return { Value: CryptoJS.MD5(this._forceLowerCase ? answer.toLocaleLowerCase() : answer).toString(), Length: answer.length };
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import QuestionBase = require("Components/Questions/QuestionBase"); import QuestionBase = require("Components/Questions/QuestionBase");
import QuestionModel = require("Models/Question"); import QuestionModel = require("Models/Question");
class Header extends QuestionBase class Header extends QuestionBase<any>
{ {
constructor(question: QuestionModel) constructor(question: QuestionModel)
{ {
......
...@@ -18,7 +18,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", " ...@@ -18,7 +18,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.HasNoStimulus = this.Items.every(function (i) { return !i.HasStimulus; }); this.HasNoStimulus = this.Items.every(function (i) { return !i.HasStimulus; });
this.CanAnswer = this.WhenAllAudioHavePlayed(this.Items.map(function (i) { return i.AudioInfo; }), true); this.CanAnswer = this.WhenAllAudioHavePlayed(this.Items.map(function (i) { return i.AudioInfo; }), true);
if (this.HasAnswer()) if (this.HasAnswer())
this.Answer(this.GetAsnwer()["Id"]); this.Answer(this.GetAnswer().Id);
this.Answer.subscribe(function (v) { this.Answer.subscribe(function (v) {
_this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v); _this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v);
_this.SetAnswer({ Id: v }); _this.SetAnswer({ Id: v });
......
...@@ -4,9 +4,9 @@ import QuestionModel = require("Models/Question"); ...@@ -4,9 +4,9 @@ import QuestionModel = require("Models/Question");
import AudioInfo = require("Components/Players/Audio/AudioInfo"); 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 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:Stimulus }; type Item = { Id:string; ChoiceButton:{ Label:string; Selected:string }; Stimulus:IStimulus };
class KacPS extends QuestionBase class KacPS extends QuestionBase<{Id:string}>
{ {
public Id: string; public Id: string;
public HeaderLabel: string; public HeaderLabel: string;
...@@ -32,7 +32,7 @@ class KacPS extends QuestionBase ...@@ -32,7 +32,7 @@ class KacPS extends QuestionBase
this.CanAnswer = this.WhenAllAudioHavePlayed(this.Items.map(i => i.AudioInfo), true); this.CanAnswer = this.WhenAllAudioHavePlayed(this.Items.map(i => i.AudioInfo), true);
if (this.HasAnswer()) this.Answer(this.GetAsnwer()["Id"]); if (this.HasAnswer()) this.Answer(this.GetAnswer().Id);
this.Answer.subscribe(v => this.Answer.subscribe(v =>
{ {
this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v); this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v);
......
...@@ -32,7 +32,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", " ...@@ -32,7 +32,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.AnswerIsRequired = this.GetInstrument("MinNoOfScalings") !== "0"; this.AnswerIsRequired = this.GetInstrument("MinNoOfScalings") !== "0";
this.Items = this.GetItems(function (item) { return _this.ItemInfo(item); }); this.Items = this.GetItems(function (item) { return _this.ItemInfo(item); });
if (this.HasAnswer()) if (this.HasAnswer())
this.Answer(this.GetAsnwer()["Id"]); this.Answer(this.GetAnswer().Id);
this.Answer.subscribe(function (v) { this.Answer.subscribe(function (v) {
_this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v); _this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v);
_this.SetAnswer({ Id: v }); _this.SetAnswer({ Id: v });
......
...@@ -6,7 +6,7 @@ import AudioInfo = require("Components/Players/Audio/AudioInfo"); ...@@ -6,7 +6,7 @@ import AudioInfo = require("Components/Players/Audio/AudioInfo");
type ItemInfo = { Id: string; Label: string; }; type ItemInfo = { Id: string; Label: string; };
type Item = { Label:string; Id:string; Selected:string }; type Item = { Label:string; Id:string; Selected:string };
class LikertScale extends QuestionBase class LikertScale extends QuestionBase<{Id:string}>
{ {
public Id: string; public Id: string;
public HeaderLabel: string; public HeaderLabel: string;
...@@ -47,7 +47,7 @@ class LikertScale extends QuestionBase ...@@ -47,7 +47,7 @@ class LikertScale extends QuestionBase
this.Items = this.GetItems<Item, ItemInfo>(item => this.ItemInfo(item)); this.Items = this.GetItems<Item, ItemInfo>(item => this.ItemInfo(item));
if (this.HasAnswer()) this.Answer(this.GetAsnwer()["Id"]); if (this.HasAnswer()) this.Answer(this.GetAnswer().Id);
this.Answer.subscribe(v => this.Answer.subscribe(v =>
{ {
this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v); this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import QuestionBase = require("Components/Questions/QuestionBase"); import QuestionBase = require("Components/Questions/QuestionBase");
import QuestionModel = require("Models/Question"); import QuestionModel = require("Models/Question");
class Monitor extends QuestionBase class Monitor extends QuestionBase<{Context: {Type:string; Data:string}; TimeZone: {Offset: number}}>
{ {
constructor(question: QuestionModel) constructor(question: QuestionModel)
{ {
......
...@@ -25,7 +25,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", " ...@@ -25,7 +25,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.Y2Ticks = this.GetTicks("Y2AxisTicks"); this.Y2Ticks = this.GetTicks("Y2AxisTicks");
this.HasY1Ticks = this.Y1Ticks.length !== 0; this.HasY1Ticks = this.Y1Ticks.length !== 0;
this.HasY2Ticks = this.Y2Ticks.length !== 0; this.HasY2Ticks = this.Y2Ticks.length !== 0;
this.IsValueNotSet = knockout.computed(function () { return !(_this.HasAnswer() && _this.HasValidAnswer(_this.Answer())); }); this.IsValueNotSet = knockout.computed(function () { return !(_this.HasAnswer() && _this.HasValidAnswer()); });
var stimulus = this.GetInstrument("Stimulus"); var stimulus = this.GetInstrument("Stimulus");
if (stimulus != null) { if (stimulus != null) {
this.AudioLabel = this.GetFormatted(stimulus.Label); this.AudioLabel = this.GetFormatted(stimulus.Label);
...@@ -38,7 +38,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", " ...@@ -38,7 +38,7 @@ define(["require", "exports", "knockout", "Components/Questions/QuestionBase", "
this.IsStimuliBlockVisible = this._alignForStimuli || this.HasMedia; this.IsStimuliBlockVisible = this._alignForStimuli || this.HasMedia;
this.CanAnswer = this.WhenAllAudioHavePlayed(this.AudioInfo, true); this.CanAnswer = this.WhenAllAudioHavePlayed(this.AudioInfo, true);
if (this.HasAnswer()) if (this.HasAnswer())
this.Answer(this.GetAsnwer().Position); this.Answer(this.GetAnswer().Position);
this.Answer.subscribe(function (v) { this.Answer.subscribe(function (v) {
_this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v.toString()); _this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v.toString());
_this.SetAnswer({ Position: v }); _this.SetAnswer({ Position: v });
......
...@@ -6,7 +6,7 @@ import AudioInfo = require("Components/Players/Audio/AudioInfo"); ...@@ -6,7 +6,7 @@ import AudioInfo = require("Components/Players/Audio/AudioInfo");
type Tick = { Label: string; Position: number; RelativePosition:number; IsMinPosition:boolean; IsMaxPosition:boolean;} type Tick = { Label: string; Position: number; RelativePosition:number; IsMinPosition:boolean; IsMaxPosition:boolean;}
type TickData = {Label:string; Position:string;} type TickData = {Label:string; Position:string;}
class OneDScale extends QuestionBase class OneDScale extends QuestionBase<{Position:number}>
{ {
private static _positionMinValue: number = -1; private static _positionMinValue: number = -1;
private static _positionMaxValue: number = 1; private static _positionMaxValue: number = 1;
...@@ -50,7 +50,7 @@ class OneDScale extends QuestionBase ...@@ -50,7 +50,7 @@ class OneDScale extends QuestionBase
this.HasY1Ticks = this.Y1Ticks.length !== 0; this.HasY1Ticks = this.Y1Ticks.length !== 0;
this.HasY2Ticks = this.Y2Ticks.length !== 0; this.HasY2Ticks = this.Y2Ticks.length !== 0;
this.IsValueNotSet = knockout.computed(() => !(this.HasAnswer() && this.HasValidAnswer(this.Answer()))); this.IsValueNotSet = knockout.computed(() => !(this.HasAnswer() && this.HasValidAnswer()));
var stimulus = this.GetInstrument("Stimulus"); var stimulus = this.GetInstrument("Stimulus");
...@@ -68,7 +68,7 @@ class OneDScale extends QuestionBase ...@@ -68,7 +68,7 @@ class OneDScale extends QuestionBase
this.CanAnswer = this.WhenAllAudioHavePlayed(this.AudioInfo, true); this.CanAnswer = this.WhenAllAudioHavePlayed(this.AudioInfo, true);
if (this.HasAnswer()) this.Answer(this.GetAsnwer().Position); if (this.HasAnswer()) this.Answer(this.GetAnswer().Position);
this.Answer.subscribe(v => this.Answer.subscribe(v =>
{ {
this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v.toString()); this.AddEvent("Change", "/Instrument", "Mouse/Left/Down", v.toString());
......
...@@ -5,27 +5,23 @@ define(["require", "exports", "knockout", "Components/Players/Audio/AudioInfo", ...@@ -5,27 +5,23 @@ define(["require", "exports", "knockout", "Components/Players/Audio/AudioInfo",
if (requiresInput === void 0) { requiresInput = true; } if (requiresInput === void 0) { requiresInput = true; }
this.Model = question; this.Model = question;
this.Model.RequiresInput = requiresInput; this.Model.RequiresInput = requiresInput;
this.HasAnswer = knockout.computed(function () { return _this.Model.Answer() != null; }); this.HasAnswer = knockout.computed(function () { return _this.Model.Answer() != null && _this.HasNoneEventsProperty(_this.GetAnswer()); });
if (this.HasAnswer()) {
var answer = this.Model.Answer(); var answer = this.Model.Answer();
this._events = answer.Events ? answer.Events : new Array(); this._events = answer != null && answer.Events ? answer.Events : new Array();
}
else {
this._events = new Array();
}
setTimeout(function () { setTimeout(function () {
_this.UpdateIsAnswerValid(); _this.UpdateIsAnswerValid();
_this.Model.Loaded(); _this.Model.Loaded();
}, 0); }, 0);
} }
QuestionsBase.prototype.UpdateIsAnswerValid = function (answer) { QuestionsBase.prototype.UpdateIsAnswerValid = function (answer) {
answer = answer || this.GetAsnwer(); answer = answer || this.GetAnswer();
if (answer == null)
this.Model.HasValidAnswer(false);
else
this.Model.HasValidAnswer(this.HasValidAnswer(answer)); this.Model.HasValidAnswer(this.HasValidAnswer(answer));
}; };
QuestionsBase.prototype.HasValidAnswer = function (answer) { QuestionsBase.prototype.HasValidAnswer = function (answer) {
answer = answer || this.GetAnswer();
return this.HasNoneEventsProperty(answer);
};
QuestionsBase.prototype.HasNoneEventsProperty = function (answer) {
for (var key in answer) for (var key in answer)
if (key !== "Events") if (key !== "Events")
return true; return true;
...@@ -34,6 +30,9 @@ define(["require", "exports", "knockout", "Components/Players/Audio/AudioInfo", ...@@ -34,6 +30,9 @@ define(["require", "exports", "knockout", "Components/Players/Audio/AudioInfo",
QuestionsBase.prototype.GetFormatted = function (unformatted) { QuestionsBase.prototype.GetFormatted = function (unformatted) {
return (unformatted === null || unformatted === undefined) ? unformatted : TextFormatter.Format(unformatted); return (unformatted === null || unformatted === undefined) ? unformatted : TextFormatter.Format(unformatted);
}; };
QuestionsBase.prototype.GetStimulusInstrument = function (key) {
return this.GetInstrument(key);
};
QuestionsBase.prototype.GetInstrument = function (key) { QuestionsBase.prototype.GetInstrument = function (key) {
return this.GetIntrumentObject()[key]; return this.GetIntrumentObject()[key];
}; };
...@@ -64,13 +63,15 @@ define(["require", "exports", "knockout", "Components/Players/Audio/AudioInfo", ...@@ -64,13 +63,15 @@ define(["require", "exports", "knockout", "Components/Players/Audio/AudioInfo",
} }
return false; return false;
}; };
QuestionsBase.prototype.GetAsnwer = function () { QuestionsBase.prototype.GetAnswer = function () {
return this.HasAnswer() ? this.Model.Answer() : null; var answer = this.Model.Answer();
return answer ? answer : {};
}; };
QuestionsBase.prototype.SetAnswer = function (answer) { QuestionsBase.prototype.SetAnswer = function (answer) {
answer.Events = this._events;
this.UpdateIsAnswerValid(answer); this.UpdateIsAnswerValid(answer);
this.Model.Answer(answer); var output = answer;
output.Events = this._events;
this.Model.Answer(output);
}; };
QuestionsBase.prototype.GetArray = function (data) { QuestionsBase.prototype.GetArray = function (data) {
if (data instanceof Array) if (data instanceof Array)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment