lesson.vwf.yaml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  2. # Secretary of Defense (Personnel & Readiness).
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. # in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under
  12. # the License.
  13. ## The component representation of a lesson
  14. ##
  15. ## @name lesson.vwf
  16. ## @namespace
  17. ---
  18. extends: http://vwf.example.com/node.vwf
  19. properties:
  20. ## Index value for the instruction
  21. ##
  22. ## @name lesson.vwf#instructionIndex
  23. ## @property
  24. instructionIndex: 0
  25. methods:
  26. ## Method to start the lesson
  27. ##
  28. ## @name lesson.vwf#begin
  29. ## @function
  30. ##
  31. ## @returns undefined
  32. begin:
  33. events:
  34. ## The event that is fired (usually from the view) when the user has clicked the Next button
  35. ##
  36. ## @name instruction.vwf#nextButtonClicked
  37. ## @event
  38. nextButtonClicked:
  39. ## The event that is fired when the lesson has been completed
  40. ##
  41. ## @name instruction.vwf#completed
  42. ## @event
  43. completed:
  44. scripts:
  45. - |
  46. var self = this;
  47. var instructions;
  48. var activeInstruction;
  49. this.begin = function() {
  50. // TODO: In actuality, I'll need to figure out how to test just the children, not all ancestors (one slash?)
  51. // Find lesson's children which are of type "instruction"
  52. instructions = this.find( ".//element(*,'http://vwf.example.com/instruction.vwf')" )
  53. if ( instructions && instructions.length ) {
  54. this.instructionIndex = 0;
  55. this.activateInstruction();
  56. }
  57. else
  58. console.warn( "This lesson has no instructions - add some as children to use it");
  59. }
  60. this.activateInstruction = function() {
  61. // Remove event handlers from the instruction that just completed
  62. if ( activeInstruction )
  63. activeInstruction.events.flush();
  64. // Set up the new instruction
  65. activeInstruction = instructions[ this.instructionIndex ];
  66. activeInstruction.exited = this.activateNext;
  67. activeInstruction.begin();
  68. }
  69. this.activateNext = function() {
  70. self.instructionIndex++;
  71. if ( self.instructionIndex < self.instructions.length )
  72. self.activateInstruction();
  73. else
  74. self.completed();
  75. } //@ sourceURL=lesson.vwf