# Copyright 2012 United States Government, as represented by the Secretary of Defense, Under # Secretary of Defense (Personnel & Readiness). # # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except # in compliance with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express # or implied. See the License for the specific language governing permissions and limitations under # the License. ## The component representation of a lesson ## ## @name lesson.vwf ## @namespace --- extends: http://vwf.example.com/node.vwf properties: ## Index value for the instruction ## ## @name lesson.vwf#instructionIndex ## @property instructionIndex: 0 methods: ## Method to start the lesson ## ## @name lesson.vwf#begin ## @function ## ## @returns undefined begin: events: ## The event that is fired (usually from the view) when the user has clicked the Next button ## ## @name instruction.vwf#nextButtonClicked ## @event nextButtonClicked: ## The event that is fired when the lesson has been completed ## ## @name instruction.vwf#completed ## @event completed: scripts: - | var self = this; var instructions; var activeInstruction; this.begin = function() { // TODO: In actuality, I'll need to figure out how to test just the children, not all ancestors (one slash?) // Find lesson's children which are of type "instruction" instructions = this.find( ".//element(*,'http://vwf.example.com/instruction.vwf')" ) if ( instructions && instructions.length ) { this.instructionIndex = 0; this.activateInstruction(); } else console.warn( "This lesson has no instructions - add some as children to use it"); } this.activateInstruction = function() { // Remove event handlers from the instruction that just completed if ( activeInstruction ) activeInstruction.events.flush(); // Set up the new instruction activeInstruction = instructions[ this.instructionIndex ]; activeInstruction.exited = this.activateNext; activeInstruction.begin(); } this.activateNext = function() { self.instructionIndex++; if ( self.instructionIndex < self.instructions.length ) self.activateInstruction(); else self.completed(); } //@ sourceURL=lesson.vwf