OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 (function() { |
| 6 |
| 7 // Correspond to steps in the hotword opt-in flow. |
| 8 /** @const */ var HOTWORD_AUDIO_HISTORY = 'hotword-audio-history-container'; |
| 9 /** @const */ var HOTWORD_ONLY_START = 'hotword-only-container'; |
| 10 /** @const */ var AUDIO_HISTORY_START = 'audio-history-container'; |
| 11 /** @const */ var SPEECH_TRAINING = 'speech-training-container'; |
| 12 /** @const */ var FINISHED = 'finished-container'; |
| 13 |
| 14 /** @const */ var FLOWS = { |
| 15 HOTWORD_AND_AUDIO_HISTORY: [ |
| 16 HOTWORD_AUDIO_HISTORY, SPEECH_TRAINING, FINISHED], |
| 17 HOTWORD_ONLY: [HOTWORD_ONLY_START, SPEECH_TRAINING, FINISHED], |
| 18 AUDIO_HISTORY_ONLY: [AUDIO_HISTORY_START] |
| 19 }; |
| 20 |
| 21 /** |
| 22 * Class to control the page flow of the always-on hotword and |
| 23 * Audio History opt-in process. |
| 24 * @constructor |
| 25 */ |
| 26 function Flow() { |
| 27 this.currentStepIndex_ = -1; |
| 28 this.currentFlow_ = []; |
| 29 } |
| 30 |
| 31 /** |
| 32 * Gets the appropriate flow and displays its first page. |
| 33 */ |
| 34 Flow.prototype.startFlow = function() { |
| 35 this.currentFlow_ = getFlowForSetting_.apply(this); |
| 36 this.advanceStep(); |
| 37 }; |
| 38 |
| 39 /** |
| 40 * Advances the current step. |
| 41 */ |
| 42 Flow.prototype.advanceStep = function() { |
| 43 this.currentStepIndex_++; |
| 44 if (this.currentStepIndex_ < this.currentFlow_.length) |
| 45 showStep_.apply(this); |
| 46 }; |
| 47 |
| 48 // ---- private methods: |
| 49 |
| 50 /** |
| 51 * Gets the appropriate flow for the current configuration of settings. |
| 52 * @private |
| 53 */ |
| 54 getFlowForSetting_ = function() { |
| 55 // TODO(kcarattini): This should eventually return the correct flow for |
| 56 // the current settings state. |
| 57 return FLOWS.HOTWORD_AND_AUDIO_HISTORY; |
| 58 }; |
| 59 |
| 60 /** |
| 61 * Displays the current step. If the current step is not the first step, |
| 62 * also hides the previous step. |
| 63 * @private |
| 64 */ |
| 65 showStep_ = function() { |
| 66 var currentStep = this.currentFlow_[this.currentStepIndex_]; |
| 67 var previousStep = null; |
| 68 if (this.currentStepIndex_ > 0) |
| 69 previousStep = this.currentFlow_[this.currentStepIndex_ - 1]; |
| 70 |
| 71 if (previousStep) |
| 72 document.getElementById(previousStep).hidden = true; |
| 73 |
| 74 document.getElementById(currentStep).hidden = false; |
| 75 }; |
| 76 |
| 77 window.Flow = Flow; |
| 78 })(); |
OLD | NEW |