Chromium Code Reviews| 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(context) { | |
| 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 * @return {boolean} true if we have not reached the end of the flow. | |
|
Bernhard Bauer
2014/09/01 10:16:23
What is the return value used for?
kcarattini
2014/09/02 04:37:23
Removed.
| |
| 42 */ | |
| 43 Flow.prototype.advanceStep = function() { | |
| 44 if (this.currentStepIndex_ >= 0) { | |
| 45 this.currentStepIndex_++; | |
| 46 if (this.currentStepIndex_ > this.currentFlow_.length) { | |
|
Bernhard Bauer
2014/09/01 10:16:23
No braces around single-line bodies.
kcarattini
2014/09/02 04:37:23
Done.
| |
| 47 return false; | |
| 48 } | |
| 49 } else { | |
| 50 this.currentStepIndex_ = 0; | |
|
Bernhard Bauer
2014/09/01 10:16:23
Are there other possible negative values than -1?
kcarattini
2014/09/02 04:37:23
Done.
| |
| 51 } | |
| 52 | |
| 53 showStep_.apply(this); | |
| 54 return true; | |
| 55 }; | |
| 56 | |
| 57 // ---- private methods: | |
| 58 | |
| 59 /** | |
| 60 * Gets the appropriate flow for the current configuration of settings. | |
| 61 * @private | |
| 62 */ | |
| 63 getFlowForSetting_ = function() { | |
| 64 // TODO(kcarattini): This should eventually return the correct flow for | |
| 65 // the current settings state. | |
| 66 return FLOWS.HOTWORD_AND_AUDIO_HISTORY; | |
| 67 }; | |
| 68 | |
| 69 /** | |
| 70 * Displays the current step. If the current step is not the first step. | |
|
Bernhard Bauer
2014/09/01 10:16:23
I think there should be a comma at the end here.
kcarattini
2014/09/02 04:37:23
Done.
| |
| 71 * also hides the previous step. | |
| 72 * @private | |
| 73 */ | |
| 74 showStep_ = function() { | |
| 75 var currentStep = this.currentFlow_[this.currentStepIndex_]; | |
| 76 var previousStep = null; | |
| 77 if (this.currentStepIndex_ > 0) | |
| 78 previousStep = this.currentFlow_[this.currentStepIndex_ - 1]; | |
| 79 | |
| 80 if (previousStep) | |
| 81 document.getElementById(previousStep).hidden = true; | |
| 82 | |
| 83 document.getElementById(currentStep).hidden = false; | |
| 84 }; | |
| 85 | |
| 86 window.Flow = Flow; | |
|
Bernhard Bauer
2014/09/01 10:16:23
Do you want to use |context| here? Or just leave t
kcarattini
2014/09/02 04:37:23
Done.
| |
| 87 })(window); | |
| OLD | NEW |