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.
5 cr.define('options', function() {
6 var Page = cr.ui.pageManager.Page;
7 var PageManager = cr.ui.pageManager.PageManager;
9 // UI state of the turn off overlay.
16 SERVER_ERROR: 'server-error',
20 * EasyUnlockTurnOffOverlay class
21 * Encapsulated handling of the Factory Reset confirmation overlay page.
24 function EasyUnlockTurnOffOverlay() {
25 Page.call(this, 'easyUnlockTurnOffOverlay',
26 loadTimeData.getString('easyUnlockTurnOffTitle'),
27 'easy-unlock-turn-off-overlay');
30 cr.addSingletonGetter(EasyUnlockTurnOffOverlay);
32 EasyUnlockTurnOffOverlay.prototype = {
33 // Inherit EasyUnlockTurnOffOverlay from Page.
34 __proto__: Page.prototype,
36 /** Current UI state */
37 uiState_: UIState.UNKNOWN,
41 set uiState(newUiState) {
42 if (newUiState == this.uiState_)
45 this.uiState_ = newUiState;
46 switch (this.uiState_) {
48 this.setUpOfflineUI_();
51 this.setUpTurnOffUI_(false);
54 this.setUpTurnOffUI_(true);
56 case UIState.SERVER_ERROR:
57 this.setUpServerErrorUI_();
60 console.error('Unknow Easy unlock turn off UI state: ' +
62 this.setUpTurnOffUI_(false);
68 initializePage: function() {
69 Page.prototype.initializePage.call(this);
71 $('easy-unlock-turn-off-dismiss').onclick = function(event) {
72 EasyUnlockTurnOffOverlay.dismiss();
74 $('easy-unlock-turn-off-confirm').onclick = function(event) {
75 this.uiState = UIState.PENDING;
76 chrome.send('easyUnlockRequestTurnOff');
81 didShowPage: function() {
82 if (navigator.onLine) {
83 this.uiState = UIState.IDLE;
84 chrome.send('easyUnlockGetTurnOffFlowStatus');
86 this.uiState = UIState.OFFLINE;
91 didClosePage: function() {
92 chrome.send('easyUnlockTurnOffOverlayDismissed');
96 * Returns the button strip element.
97 * @return {HTMLDivElement} The container div of action buttons.
100 return this.pageDiv.querySelector('.button-strip');
104 * Set visibility of action buttons in button strip.
107 setActionButtonsVisible_: function(visible) {
108 var buttons = this.buttonStrip.querySelectorAll('button');
109 for (var i = 0; i < buttons.length; ++i) {
110 buttons[i].hidden = !visible;
115 * Set visibility of spinner.
118 setSpinnerVisible_: function(visible) {
119 $('easy-unlock-turn-off-spinner').hidden = !visible;
123 * Set up UI for showing offline message.
126 setUpOfflineUI_: function() {
127 $('easy-unlock-turn-off-title').textContent =
128 loadTimeData.getString('easyUnlockTurnOffOfflineTitle');
129 $('easy-unlock-turn-off-messagee').textContent =
130 loadTimeData.getString('easyUnlockTurnOffOfflineMessage');
132 this.setActionButtonsVisible_(false);
133 this.setSpinnerVisible_(false);
137 * Set up UI for turning off Easy Unlock.
138 * @param {boolean} pending Whether there is a pending turn-off call.
141 setUpTurnOffUI_: function(pending) {
142 $('easy-unlock-turn-off-title').textContent =
143 loadTimeData.getString('easyUnlockTurnOffTitle');
144 $('easy-unlock-turn-off-messagee').textContent =
145 loadTimeData.getString('easyUnlockTurnOffDescription');
146 $('easy-unlock-turn-off-confirm').textContent =
147 loadTimeData.getString('easyUnlockTurnOffButton');
149 this.setActionButtonsVisible_(true);
150 this.setSpinnerVisible_(pending);
151 $('easy-unlock-turn-off-confirm').disabled = pending;
152 $('easy-unlock-turn-off-dismiss').hidden = false;
156 * Set up UI for showing server error.
159 setUpServerErrorUI_: function() {
160 $('easy-unlock-turn-off-title').textContent =
161 loadTimeData.getString('easyUnlockTurnOffErrorTitle');
162 $('easy-unlock-turn-off-messagee').textContent =
163 loadTimeData.getString('easyUnlockTurnOffErrorMessage');
164 $('easy-unlock-turn-off-confirm').textContent =
165 loadTimeData.getString('easyUnlockTurnOffRetryButton');
167 this.setActionButtonsVisible_(true);
168 this.setSpinnerVisible_(false);
169 $('easy-unlock-turn-off-confirm').disabled = false;
170 $('easy-unlock-turn-off-dismiss').hidden = true;
175 * Closes the Easy unlock turn off overlay.
177 EasyUnlockTurnOffOverlay.dismiss = function() {
178 PageManager.closeOverlay();
182 * Update UI to reflect the turn off operation status.
183 * @param {string} newState The UIState string representing the new state.
185 EasyUnlockTurnOffOverlay.updateUIState = function(newState) {
186 EasyUnlockTurnOffOverlay.getInstance().uiState = newState;
191 EasyUnlockTurnOffOverlay: EasyUnlockTurnOffOverlay