Example #1
0
exports.Experiment = ContextualizableComponent.specialize( /** @lends Experiment# */ {

	_currentStimulus: {
		value: null
	},

	_currentTestBlock: {
		value: null
	},

	_currentStimulusIndex: {
		value: null
	},

	_currentTestBlockIndex: {
		value: null
	},

	constructor: {
		value: function Experiment() {
			this.super();
			this.application.audioPlayer = new AudioPlayer();

		}
	},

	iconSrc: {
		value: "../../assets/img/blank.png"
	},

	loadDesign: {
		value: function(designToForceIncludeInMop) {
			if (!this.experimentalDesignSrc) {
				throw "Experimential design source file is undefined, not loading the experiment";
			}
			var self = this;

			// console.log(" Loaded in the experimental Design." + designToForceIncludeInMop);
			// self.experimentalDesign = JSON.parse(designToForceIncludeInMop);
			self.experimentalDesign = designToForceIncludeInMop;

			self.iconSrc = self.experimentalDesign.iconSrc;
			console.log("iconSrc" + self.iconSrc);
			this.experimentalDesign.congratulationsImageSrc = this.experimentalDesign.imageAssetsPath + "/" +this.experimentalDesign.congratulationsImageSrc;
			this.gamify = true;
			this.tutorialMode = false;
			this.currentlyPlaying = false;
			this.resultsReportMode = false;

			/* This makes essentially a slideshow of images, useful for debugging and reviewing */
			this.autoPlaySlideshowOfStimuli = false;
			// this.application.audioPlayer.play("assets/gammatone.wav");


		}
	},

	draw: {
		value: function() {
			this.super();
			var self = this;
			window.setTimeout(function() {
				/* hack to make the tutorial mode seem like its working */
				if (!self.currentlyPlaying) {
					self.confirm(this.application.contextualizer.localize("prompt_show_tutorial")).then(function() {
						console.log("Showing tutorial mode");
						self.toggleTutorialArea();
					}, function(reason) {
						console.log("Not showing tutorial");
					});
				}
			}, 30000);
		}
	},
	/**
	 *  Shows a dialog box with the message, returns a promise which will resolve
	 *  if the user gives a positive repsonse, and reject if the user gives a negative response
	 *
	 *
	 * @param {String} confirmChoicePrompt A message to be shown to the user
	 * @type {Promise}
	 */
	confirm: {
		value: function(confirmChoicePrompt) {
			var promiseForConfirm = Promise.defer();
			if (confirmChoicePrompt) {
				var options = {
					iconSrc: this.iconSrc,
					message: confirmChoicePrompt
					// okLabel: "Continue",
					// cancelLabel: "Pause"
				};
				Confirm.show(options, function() {
					promiseForConfirm.resolve();
				}, function() {
					console.log("The user clicked cancel.");

					promiseForConfirm.reject("The user clicked cancel.");
					// [Q] Unhandled rejection reasons (should be empty): ["(no stack) The user clicked cancel."] 
					// https://github.com/kriskowal/q/issues/292
					// https://github.com/kriskowal/q/issues/238 TODO seems to be nothing i can do about it...
				});
			} else {
				Promise.nextTick(function() {
					promiseForConfirm.resolve();
				});
			}
			return promiseForConfirm.promise;
		}
	},

	/*
	 * Machinery for Recording stimuli responses.
	 *
	 * Inspired by the digit video reel:
	 * https://github.com/montagejs/digit/tree/master/ui/video.reel
	 */
	enterDocument: {
		value: function(firstTime) {
			if (firstTime) {
				this.currentlyPlaying = false;
				this.experimentDisplayTimeStart = Date.now();

				this.application.addEventListener("changeinterfaceLocale", this);
				this.application.addEventListener("changeCurrentAudience", this);
			}

			this.super(firstTime);
		}
	},

	toggleTutorialArea: {
		value: function() {
			this.tutorialMode = !this.tutorialMode;
			console.log("Show tutorial: " + this.tutorialMode);
		}
	},

	run: {
		value: function() {
			console.log("currentlyPlaying: " + this.currentlyPlaying);

			this.experimentalDesign.jsonType = "experiment";
			this.experimentalDesign.experimentType = this.experimentType;
			var self = this;
			this.confirm(this.application.contextualizer.localize("plug_in_headphones")).then(function() {

				self.currentlyPlaying = true;
				self.experimentalDesign.timestamp = Date.now();

				self._currentStimulus = self.templateObjects.currentStimulus;
				self._currentStimulus.imageAssetsPath = self.experimentalDesign.imageAssetsPath;
				self._currentStimulus.audioAssetsPath = self.experimentalDesign.audioAssetsPath;
				// self.templateObjects.currentStimulus.templateObjects.reinforcement = self.templateObjects.reinforcement;
				self.loadTestBlock(0);

				self.templateObjects.tutorial.playInstructions();

			}, function(reason) {
				console.log("Waiting for user to plug in head phones");
			});

		}
	},


	autoPlaySlideshowOfStimuli: {
		value: null
	},

	/**
	 * 
	 *
	 * var example = {
			"auditoryStimulus": "practice_1_auditory_stimuli",
			"audioFile": "1.wav",
			"primeImage": "animal1.png",
			"targetImage": "practice1.png",
			"distractorImages": ["distractor1.png", "distractor2.png", "distractor3.png"],
			"response": {
				"reactionTimeAudioOffset": -234,
				"reactionTimeAudioOnset": 123,
				"x": 43,
				"y": 23
			}
		}
	 */
	nextStimulus: {
		value: function() {
			if (this.canBeResumed) {
				this.currentlyPlaying = true;
			}
			var self = this;

			if (!this._currentTestBlock || !this._currentTestBlock.trials || !this._currentTestBlock.trials.length) {
				console.warn("Something is wrong, there are no stimuli so I can't go to the next. ");
				return;
			}
			if (this._currentStimulusIndex >= this._currentTestBlock.trials.length - 1) {
				this.templateObjects.reinforcement.showLast();
				this.loadTestBlock(this._currentTestBlockIndex + 1);
				return;
			}

			this._currentStimulusIndex++;
			console.log("Showing stimulus " + this._currentStimulusIndex + " of block " + this._currentTestBlockIndex);

			if (!this._currentTestBlock.trials[this._currentStimulusIndex]) {
				console.warn("Something is wrong, there was no stimulus.");
				return;
			}
			this.templateObjects.reinforcement.next();
			this._currentTestBlock.trials[this._currentStimulusIndex].id = this._currentTestBlock.label + "_" + this._currentStimulusIndex;
			this._currentStimulus.load(this._currentTestBlock.trials[this._currentStimulusIndex]);

			if (this.autoPlaySlideshowOfStimuli) {
				window.setTimeout(function() {
					console.log("Slideshow play...");
					self.nextStimulus();
				}, 5000);
			}
		}
	},

	replayStimulus: {
		value: function() {
			console.log("Replaying stimulus");
			// this.application.audioPlayer.play();
			this._currentStimulus.load(this._currentTestBlock.trials[this._currentStimulusIndex]);
		}
	},

	pauseStimulus: {
		value: function() {
			console.log("Pausing stimulus");
			// this.templateObjects.currentStimulus.pauseAudio();
			this.application.audioPlayer.togglePause();
		}
	},

	previousStimulus: {
		value: function() {

			if (!this._currentTestBlock || !this._currentTestBlock.trials || !this._currentTestBlock.trials.length) {
				console.warn("Something is wrong, there are no stimuli so I can't go to the next. ");
				return;
			}
			if (this._currentStimulusIndex === 0) {
				this.loadTestBlock(this._currentTestBlockIndex - 1, "finalIndex");
				return;
			}

			this._currentStimulusIndex--;
			console.log("Showing stimulus " + this._currentStimulusIndex + " of block " + this._currentTestBlockIndex);

			this.templateObjects.reinforcement.previous();
			this._currentStimulus.load(this._currentTestBlock.trials[this._currentStimulusIndex]);
		}
	},

	loadTestBlock: {
		value: function(blockIndexToLoad, finalIndex) {

			if (!this.experimentalDesign || !this.experimentalDesign.subexperiments || blockIndexToLoad === undefined) {
				console.warn("Something is wrong, there are no subexperiments so I can't go to the next. ");
				return;
			}
			if (blockIndexToLoad < 0) {
				this.confirm("At the beginning!").then(function() {
					console.log("Doing nothing");
				}, function(reason) {
					console.log("Doing nothing");
				});
				return;
			}
			if (blockIndexToLoad >= this.experimentalDesign.subexperiments.length) {
				this.experimentCompleted();
				return;
			}
			if (!this.experimentalDesign.subexperiments[blockIndexToLoad]) {
				console.warn("Something is wrong, there are no test bock so I can't go to the next. ");
				return;
			}

			this._currentTestBlockIndex = blockIndexToLoad;
			this._currentTestBlock = this.experimentalDesign.subexperiments[blockIndexToLoad];
			console.log("Loaded block " + blockIndexToLoad);
			this.experimentBlockLoaded(finalIndex);
		}
	},

	/**
	 * By default when an experiment block is loaded,
	 * it prompts the user if they are ready,
	 * and then shows the first stimulus.
	 *
	 * This can be customized by experiements by overriding the experimentBlockLoaded function.
	 */
	experimentBlockLoaded: {
		value: function(finalIndex) {
			var self = this;
			console.log("experimentBlockLoaded");
			
			if (finalIndex) {
				this._currentStimulusIndex = this._currentTestBlock.trials.length - 1;
			} else {
				this._currentStimulusIndex = -1;
			}

			if (this._currentTestBlock.reinforcementCounter) {
				this.reinforcementCounter = [];
				for (var stimulus = 0; stimulus < this._currentTestBlock.trials.length; stimulus++) {
					this.reinforcementCounter.push({
						incompleteImageFile: "../../../" + this.experimentalDesign.imageAssetsPath + "/" + this._currentTestBlock.reinforcementCounter.before,
						completedImageFile: "../../../" + this.experimentalDesign.imageAssetsPath + "/" + this._currentTestBlock.reinforcementCounter.after
					});
				}
			} else if (this._currentTestBlock.reinforcementAnimation) {
				for (var frame = 0; frame < this._currentTestBlock.reinforcementAnimation.animationImages.length; frame++) {
					if (this._currentTestBlock.reinforcementAnimation.animationImages[frame].incompleteImageFile) {
						this._currentTestBlock.reinforcementAnimation.animationImages[frame].incompleteImageFile = "../../../" + this.experimentalDesign.imageAssetsPath + "/" + this._currentTestBlock.reinforcementAnimation.animationImages[frame].incompleteImageFile;
					}
					if (this._currentTestBlock.reinforcementAnimation.animationImages[frame].currentImageFile) {
						this._currentTestBlock.reinforcementAnimation.animationImages[frame].currentImageFile = "../../../" + this.experimentalDesign.imageAssetsPath + "/" + this._currentTestBlock.reinforcementAnimation.animationImages[frame].currentImageFile;
					}
					if (this._currentTestBlock.reinforcementAnimation.animationImages[frame].completedImageFile) {
						this._currentTestBlock.reinforcementAnimation.animationImages[frame].completedImageFile = "../../../" + this.experimentalDesign.imageAssetsPath + "/" + this._currentTestBlock.reinforcementAnimation.animationImages[frame].completedImageFile;
					}
				}
			}
			this.templateObjects.reinforcement.showFirst();

			if (this._currentTestBlock.promptUserBeforeContinuing) {
				this.confirm(this.application.contextualizer.localize(this._currentTestBlock.promptUserBeforeContinuing.text)).then(function() {
					self.nextStimulus();
				}).fail(function(reason) {
					console.log("TODO add a button for resume?");
					self.currentlyPlaying = false;
					self.canBeResumed = true;
					self.application.audioPlayer.stop();
				});
			} else {
				this.nextStimulus();
			}
		}
	},

	resumePreviousGame:{
		value: function(){
			console.log("TODO show a list of previous games, let the user select one, then go through the game design, find the stimulus that wasnt completed, and display all the trials and stimuli to the test administarator so they can choose where to resume.");
		}
	},

	experimentCompleted: {
		value: function() {
			var self = this;

			this.experimentalDesign.timestamp = Date.now();
			Database.databaseUrl = this.experimentalDesign.database;
			Database.set(this.experimentalDesign.experimentType + this.experimentalDesign.timestamp, this.experimentalDesign);


			this.confirm(this.application.contextualizer.localize(this.experimentalDesign.end_instructions.for_child)).then(function() {
				console.log("Experiment is complete.");
				self.currentlyPlaying = false;
				self.canBeResumed = false;
				self.showResultReport();
			}, function(reason) {
				console.log("TODO add a button for resume?");
			});
		}
	},

	showResultReport: {
		value: function() {
			this.resultsReportMode = !this.resultsReportMode;
			console.log("resultsReportMode " + this.resultsReportMode);
			if (this.templateObjects.resultReport) {
				this.templateObjects.resultReport.calculateScore();
			}
		}
	},


	pause: {
		value: function() {}
	},

	handleLocaleChange: {
		value: function(now, previous) {
			console.log("handleLocaleChange");
			if (!now || now.length === 0 || !now[0]) {
				return;
			}
			console.log("Locale changed from: " + (previous[0] ? previous[0].label : "nothing") + " -> " + (now[0] ? now[0].label : "nothing"));
		}
	},

	handleChangeinterfaceLocale: {
		value: function() {
			if (this.application && this.application.interfaceLocale) {
				console.log("handleChangeinterfaceLocale", this.application.interfaceLocale);
				this.contextualizer.currentLocale = this.application.interfaceLocale.iso;
				this.needsDraw = true;
				this.setContextualizedText("description");
				this.setContextualizedText("instructions");
				this.setTitle();
			} else {
				console.log("Not setting the experiments contextualizer locale");
			}
		}
	},

	handleChangeCurrentAudience: {
		value: function() {
			this.handleChangeinterfaceLocale();
		}
	},

	getTextFor: {
		value: function(key, audience, dialect) {
			console.log("getTextFor", key, audience, dialect);
			return this[key];
		}
	},

	/*
	TODO change the labelPropertyName to use an FRB contingent on gamify
	*/
	gamify: {
		value: null
	},

	description: {
		value: null
	},
	setContextualizedText: {
		value: function(key) {
			var contextualizedKey = "";
			if (!this.experimentalDesign || !this.experimentalDesign[key]) {
				return key;
			}
			if (this.application && this.application.currentAudience) {
				var context = this.application.currentAudience.key;
				if (this.gamify && this.application.currentAudience.gamifiedKey) {
					context = this.application.currentAudience.gamifiedKey;
				}
				contextualizedKey = this.experimentalDesign[key]["for_" + context];
				console.log("Contextualizing key for " + key);
			}
			if (!contextualizedKey) {
				contextualizedKey = this.experimentalDesign[key]["default"] || "";
			}

			var localized = this.contextualizer.localize(contextualizedKey);
			if (key === "instructions") {
				this.instructionsAudioDetails = this.contextualizer.audio(contextualizedKey);
				this.instructionsAudioDetails.path = this.experimentalDesign.audioAssetsPath;
			}
			this[key] = localized;
			return localized;
		}
	},

	title: {
		value: null
	},
	setTitle: {
		value: function() {
			var title = "";
			if (!this.experimentalDesign || !this.experimentalDesign.title) {
				return title;
			}
			if (this.gamify) {
				title = this.experimentalDesign.title["gamified_title"] || ""; //jshint ignore:line
			}
			if (!title) {
				title = this.experimentalDesign.title["default"] || "";
			}
			var localized = this.contextualizer.localize(title);
			this.title = localized;
			return localized;
		}
	}
});
exports.AbstractStimulus = ContextualizableComponent.specialize( /** @lends Stimulus# */ {
	constructor: {
		value: function Stimulus() {
			this.super();
		}
	},

	currentReinforcementImageSrc: {
		value: "../../assets/img/blank.png"
	},

	/**
	 *  dont draw automatically refs: http://montagejs.github.io/mfiddle/#!/7932746
	 * @type {Object}
	 */
	// willDraw: {
	//        value: function() {
	//			console.log("Stimulus does not draw automatically, instead it is drawn in steps by its child classes.");
	//        }
	//    },

	responsesController: {
		value: null
	},

	responses: {
		value: null
	},
	pauseAudioWhenConfirmingResponse: {
		value: null
	},
	addResponse: {
		value: function(responseEvent, chosenImage) {
			if (!responseEvent) {
				throw "Cannot add response without the x y information found in the touch/click responseEvent";
			}
			this.audioPlayStartTime = 0;
			if (this.application.audioPlayer.src && this.application.audioPlayer.src === this.model.audioFile) {
				this.audioPlayStartTime = this.application.audioPlayer.audioPlayStartTime;
			} else {
				this.audioPlayStartTime = 0;
			}
			var reactionTimeEnd = Date.now();
			var audioDuration = this.application.audioPlayer.getDuration(this.model.audioFile) || 0;
			if (audioDuration) {
				audioDuration = audioDuration * 1000;
			} else {
				console.log("The audio has no duration.. This is strange.");
			}
			if (this.pauseAudioWhenConfirmingResponse) {
				this.pauseAudio();
			}

			var self = this;
			var continueToNextStimulus = Promise.defer();
			if (this.confirmResponseChoiceMessage) {
				this.contextualizer.currentLocale = this.application.interfaceLocale;
				var confirmChoicePrompt = this.contextualizer.localize(this.confirmResponseChoiceMessage, this.application.experiment.experimentalDesign.stimuliDialect);
				var options = {
					iconSrc: self.ownerComponent.iconSrc,
					message: confirmChoicePrompt
				};
				Confirm.show(options, function() {
					continueToNextStimulus.resolve();
				}, function() {
					continueToNextStimulus.reject(new Error("The x prevented the cancel?"));
				});
			} else {
				continueToNextStimulus.resolve();
			}
			continueToNextStimulus.promise.then(function() {
				// self.ownerComponent.templateObjects.reinforcement.next();
				self.stopAudio();
				self.ownerComponent.nextStimulus();
			}, function(reason) {
				console.log("Not continuing to next stimulus");
				if (this.pauseAudioWhenConfirmingResponse) {
					self.playAudio();
				}
			});
			var choice = {};
			if (chosenImage) {
				console.info("===== = For " + this.model.target.utterance + " the user clicked on " + chosenImage + " the target image was " + this.model.target.visualChoice);
				if (this.model.target.visualChoice === chosenImage) {
					choice = this.model.target;
				} else {
					this.model.distractors.map(function(distractor) {
						if (distractor.visualChoice === chosenImage) {
							choice = distractor;
						}
					});
				}
			}
			var response = {
				"reactionTimeAudioOffset": reactionTimeEnd - this.audioPlayStartTime - audioDuration,
				"reactionTimeAudioOnset": reactionTimeEnd - this.audioPlayStartTime,
				"reactionTimeVisualOffset": reactionTimeEnd - this.reactionTimeStart,
				"reactionTimeVisualOnset": reactionTimeEnd - this.reactionTimeStart,
				"x": responseEvent.x,
				"y": responseEvent.y,
				"pageX": responseEvent.pageX,
				"pageY": responseEvent.pageY,
				// "prime": {
				// 	utterance: this.model.prime.utterance,
				// 	orthography: this.model.prime.orthography,
				// 	imageFile: this.model.prime.imageFile
				// },
				"choice": choice,
				// "target": this.model.target,
				"score": this.scoreResponse(this.model.target, choice)
			};
			this.model.responses.push(response);
			console.log("Recorded response", JSON.stringify(response));
		}
	},

	addOralResponse: {
		value: function(choice, dontAutoAdvance) {
			var reactionTimeEnd = Date.now();
			var audioDuration = this.application.audioPlayer.getDuration(this.model.audioFile) || 0;
			if (audioDuration) {
				audioDuration = audioDuration * 1000;
			} else {
				console.log("The audio has no duration.. This is strange.");
			}
			if (this.pauseAudioWhenConfirmingResponse) {
				this.pauseAudio();
			}

			var self = this;
			var continueToNextStimulus = Promise.defer();
			if (this.confirmResponseChoiceMessage) {
				this.contextualizer.currentLocale = this.application.interfaceLocale;
				var confirmChoicePrompt = this.contextualizer.localize(this.confirmResponseChoiceMessage);
				var options = {
					iconSrc: self.ownerComponent.iconSrc,
					message: confirmChoicePrompt
				};
				Confirm.show(options, function() {
					continueToNextStimulus.resolve();
				}, function() {
					continueToNextStimulus.reject(new Error("The x prevented the cancel?"));
				});
			} else {
				if (!dontAutoAdvance) {
					continueToNextStimulus.resolve();
				}
			}
			continueToNextStimulus.promise.then(function() {
				// self.ownerComponent.templateObjects.reinforcement.next();
				self.stopAudio();
				self.ownerComponent.nextStimulus();
			}, function(reason) {
				console.log("Not continuing to next stimulus");
				if (this.pauseAudioWhenConfirmingResponse) {
					self.playAudio();
				}
			});

			var response = {
				"reactionTimeAudioOffset": reactionTimeEnd - this.reactionTimeStart - audioDuration,
				"reactionTimeAudioOnset": reactionTimeEnd - this.reactionTimeStart,
				"x": 0,
				"y": 0,
				"pageX": 0,
				"pageY": 0,
				"choice": choice,
				"score": choice.score
			};
			this.model.responses = this.model.responses || [];
			this.model.responses.push(response);
			console.log("Recorded response", JSON.stringify(response));
		}
	},

	scoreResponse: {
		value: function(expectedResponse, actualResponse) {
			if (!actualResponse.utterance) {
				return "error";
			}
			if (actualResponse.utterance === expectedResponse.utterance) {
				return 1;
			} else {
				return 0;
			}
		}
	},

	addNonResponse: {
		value: function(responseEvent) {
			if (!responseEvent) {
				throw "Cannot add response without the x y information found in the touch/click responseEvent";
			}
			var reactionTimeEnd = Date.now();
			var response = {
				"reactionTimeAudioOffset": reactionTimeEnd - this.reactionTimeStart,
				"reactionTimeAudioOnset": reactionTimeEnd - this.reactionTimeStart,
				"x": responseEvent.x,
				"y": responseEvent.y,
				"pageX": responseEvent.pageX,
				"pageY": responseEvent.pageY,
				"chosenVisualStimulus": "none",
				"responseScore": -1
			};
			this.model.responses = this.model.responses || [];
			this.model.nonResponses.push(response);
			console.log("Recorded non-response, the user is confused or not playing the game.", JSON.stringify(response));
		}
	},

	/*
	 * Machinery for Recording stimuli responses.
	 *
	 * Inspired by the digit video reel:
	 * https://github.com/montagejs/digit/tree/master/ui/video.reel
	 */
	enterDocument: {
		value: function(firstTime) {
			this.super();

			if (firstTime) {
				this.setupFirstPlay();
				this.addOwnPropertyChangeListener("src", this);
			}
		}
	},

	handlePress: {
		value: function(touchEvent) {
			// console.log("event " + JSON.stringify(touchEvent.event));
			// console.log("targetElement " + JSON.stringify(touchEvent.targetElement));
			console.log("The stimulus has been pressed: ");
			if (touchEvent && touchEvent.targetElement && touchEvent.targetElement.dataset && touchEvent.targetElement.dataset.montageId && touchEvent.targetElement.classList.contains("Stimulus-record-touch-response")) {
				this.addResponse(touchEvent.event, touchEvent.targetElement.dataset.montageId);
			} else {
				this.addNonResponse(touchEvent.event);
			}
		}
	},

	handleAction: {
		value: function(touchEvent) {
			console.log("The stimulus has been actioned: ");
			this.handlePress(touchEvent);
		}
	},

	handleTouchup: {
		value: function(touchEvent) {
			console.log("The stimulus has been touchuped: ");
			this.handlePress(touchEvent);
		}
	},

	handlePressStart: {
		value: function(touchEvent) {
			console.log("The stimulus has been pressStarted: ");
		}
	},

	handleLongAction: {
		value: function(touchEvent) {
			console.log("The stimulus has been longActioned: ");
		}
	},

	handleLongPress: {
		value: function(touchEvent) {
			console.log("The stimulus has been handleLongPress: ");
			this.handlePress(touchEvent);
		}
	},

	prepareForActivationEvents: {
		value: function() {
			// this._pressComposer.addEventListener("pressStart", this, false);
			this._pressComposer.addEventListener("press", this, false);
			this._pressComposer.addEventListener("touchup", this, false);
			this._pressComposer.addEventListener("action", this, false);
			this._pressComposer.addEventListener("longAction", this, false);
			this._pressComposer.addEventListener("longPress", this, false);
			// this._pressComposer.addEventListener("pressCancel", this, false);
		}
	},

	setupFirstPlay: {
		value: function() {
			// this.element.removeEventListener("touchstart", this, false);
			// this.element.removeEventListener("mousedown", this, false);

			this._pressComposer = PressComposer.create();
			this._pressComposer.identifier = "stimulus";
			this.addComposerForElement(this._pressComposer, this.element);
		}
	},

	/**
	 *  TODO try using a media controller later montage/ui/controller/media-controller
	 * @type {Object}
	 */
	playAudio: {
		value: function(delay) {
			this.application.audioPlayer.play(this.model.audioFile, delay);
		}
	},

	pauseAudio: {
		value: function() {
			this.application.audioPlayer.pause(this.model.audioFile);
		}
	},

	stopAudio: {
		value: function() {
			this.application.audioPlayer.stop(this.model.audioFile);
		}
	},

	load: {
		value: function(model) {
			this.model = model || {};

			if (!this.model.responses) {
				this.model.responses = [];
			}
			if (!this.model.nonResponses) {
				this.model.nonResponses = [];
			}

			this.itemNumberInExperiment = model.itemNumberInExperiment;
			this.subexperimentLabel = model.subexperimentLabel;

			this.responsesController = new RangeController().initWithContent(this.model.responses);
			this.experimenterId = this.application.experiment.experimenter.id;
			this.participantId = this.application.experiment.participant.id;
			// Not playing audio by default, child must call it.
			// this.playAudio(2000);
			this.reactionTimeStart = Date.now();

		}
	}
});
 */
exports.Main = ContextualizableComponent.specialize( /** @lends Main# */ {
	constructor: {
		value: function Main() {
			// localStorage.setItem("montage_locale", "fr");
			this.super();

			FieldDB.FieldDBObject.warn = function() {
				//dont warn
			};
			FieldDB.FieldDBObject.todo = function() {
				//dont todo
			};
			FieldDB.FieldDBObject.bug = function(message) {
				console.warn(message);
			};

			FieldDB.Database.prototype.BASE_DB_URL = "https://corpusdev.example.org";
			FieldDB.Database.prototype.BASE_AUTH_URL = "https://authdev.example.org";
			FieldDB.AudioVideo.prototype.BASE_SPEECH_URL = "https://speechdev.example.org";
			FieldDB.FieldDBObject.application = this.application;

			if (!this.application.contextualizer) {
				this.application.contextualizer = this.application.contextualizer || new Contextualizer();
				this.application.contextualizer.addMessagesToContextualizedStrings("en", enLocales);
				this.application.contextualizer.addMessagesToContextualizedStrings("fr", frLocales);
			}

		}
	}
});
Example #4
0
/**
 * @module ui/main.reel
 * @requires core/contextualizable-component
 */
var ContextualizableComponent = require("core/contextualizable-component").ContextualizableComponent,
	Contextualizer = require("core/contextualizer").Contextualizer;

/**
 * @class Main
 * @extends ContextualizableComponent
 */
exports.Main = ContextualizableComponent.specialize( /** @lends Main# */ {
	constructor: {
		value: function Main() {
			// localStorage.setItem("montage_locale", "fr");
			this.super();
			var globalContextualizer = new Contextualizer();
		}
	}
});