| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 var Page = cr.ui.pageManager.Page; | 6 var Page = cr.ui.pageManager.Page; |
| 7 var PageManager = cr.ui.pageManager.PageManager; | 7 var PageManager = cr.ui.pageManager.PageManager; |
| 8 | 8 |
| 9 // UI state of the turn off overlay. |
| 10 // @enum {string} |
| 11 var UIState = { |
| 12 UNKNOWN: 'unknown', |
| 13 OFFLINE: 'offline', |
| 14 IDLE: 'idle', |
| 15 PENDING: 'pending', |
| 16 SERVER_ERROR: 'server-error', |
| 17 }; |
| 18 |
| 9 /** | 19 /** |
| 10 * EasyUnlockTurnOffOverlay class | 20 * EasyUnlockTurnOffOverlay class |
| 11 * Encapsulated handling of the Factory Reset confirmation overlay page. | 21 * Encapsulated handling of the Factory Reset confirmation overlay page. |
| 12 * @class | 22 * @class |
| 13 */ | 23 */ |
| 14 function EasyUnlockTurnOffOverlay() { | 24 function EasyUnlockTurnOffOverlay() { |
| 15 Page.call(this, 'easyUnlockTurnOffOverlay', | 25 Page.call(this, 'easyUnlockTurnOffOverlay', |
| 16 loadTimeData.getString('easyUnlockTurnOffTitle'), | 26 loadTimeData.getString('easyUnlockTurnOffTitle'), |
| 17 'easy-unlock-turn-off-overlay'); | 27 'easy-unlock-turn-off-overlay'); |
| 18 } | 28 } |
| 19 | 29 |
| 20 cr.addSingletonGetter(EasyUnlockTurnOffOverlay); | 30 cr.addSingletonGetter(EasyUnlockTurnOffOverlay); |
| 21 | 31 |
| 22 EasyUnlockTurnOffOverlay.prototype = { | 32 EasyUnlockTurnOffOverlay.prototype = { |
| 23 // Inherit EasyUnlockTurnOffOverlay from Page. | 33 // Inherit EasyUnlockTurnOffOverlay from Page. |
| 24 __proto__: Page.prototype, | 34 __proto__: Page.prototype, |
| 25 | 35 |
| 36 /** Current UI state */ |
| 37 uiState_: UIState.UNKNKOWN, |
| 38 get uiState() { |
| 39 return this.uiState_; |
| 40 }, |
| 41 set uiState(newUiState) { |
| 42 if (newUiState == this.uiState_) |
| 43 return; |
| 44 |
| 45 this.uiState_ = newUiState; |
| 46 switch (this.uiState_) { |
| 47 case UIState.OFFLINE: |
| 48 this.setUpOfflineUI_(); |
| 49 break; |
| 50 case UIState.IDLE: |
| 51 this.setUpTurnOffUI_(false); |
| 52 break; |
| 53 case UIState.PENDING: |
| 54 this.setUpTurnOffUI_(true); |
| 55 break; |
| 56 case UIState.SERVER_ERROR: |
| 57 this.setUpServerErrorUI_(); |
| 58 break; |
| 59 default: |
| 60 console.error('Unknow Easy unlock turn off UI state: ' + |
| 61 this.uiState_); |
| 62 this.setUpTurnOffUI_(false); |
| 63 break; |
| 64 } |
| 65 }, |
| 66 |
| 26 /** @override */ | 67 /** @override */ |
| 27 initializePage: function() { | 68 initializePage: function() { |
| 28 Page.prototype.initializePage.call(this); | 69 Page.prototype.initializePage.call(this); |
| 29 | 70 |
| 30 $('easy-unlock-turn-off-dismiss').onclick = function(event) { | 71 $('easy-unlock-turn-off-dismiss').onclick = function(event) { |
| 31 EasyUnlockTurnOffOverlay.dismiss(); | 72 EasyUnlockTurnOffOverlay.dismiss(); |
| 32 }; | 73 }; |
| 33 $('easy-unlock-turn-off-confirm').onclick = function(event) { | 74 $('easy-unlock-turn-off-confirm').onclick = function(event) { |
| 34 $('easy-unlock-turn-off-confirm').disabled = true; | 75 this.uiState = UIState.PENDING; |
| 35 this.setSpinnerVisible_(true); | 76 chrome.send('easyUnlockRequestTurnOff'); |
| 36 | |
| 37 // TODO(xiyuan): Wire this up. | |
| 38 // chrome.send('turnOffEasyUnlock'); | |
| 39 }.bind(this); | 77 }.bind(this); |
| 40 }, | 78 }, |
| 41 | 79 |
| 42 /** @override */ | 80 /** @override */ |
| 43 didShowPage: function() { | 81 didShowPage: function() { |
| 44 if (navigator.onLine) { | 82 if (navigator.onLine) { |
| 45 this.setUpTurnOffUI_(); | 83 this.uiState = UIState.IDLE; |
| 84 chrome.send('easyUnlockGetTurnOffFlowStatus'); |
| 46 } else { | 85 } else { |
| 47 this.setUpOfflineUI_(); | 86 this.uiState = UIState.OFFLINE; |
| 48 } | 87 } |
| 49 }, | 88 }, |
| 50 | 89 |
| 90 /** @override */ |
| 91 didClosePage: function() { |
| 92 chrome.send('easyUnlockTurnOffOverlayDismissed'); |
| 93 }, |
| 94 |
| 51 /** | 95 /** |
| 52 * Returns the button strip element. | 96 * Returns the button strip element. |
| 53 * @return {HTMLDivElement} The container div of action buttons. | 97 * @return {HTMLDivElement} The container div of action buttons. |
| 54 */ | 98 */ |
| 55 get buttonStrip() { | 99 get buttonStrip() { |
| 56 return this.pageDiv.querySelector('.button-strip'); | 100 return this.pageDiv.querySelector('.button-strip'); |
| 57 }, | 101 }, |
| 58 | 102 |
| 59 /** | 103 /** |
| 60 * Set visibility of action buttons in button strip. | 104 * Set visibility of action buttons in button strip. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 84 loadTimeData.getString('easyUnlockTurnOffOfflineTitle'); | 128 loadTimeData.getString('easyUnlockTurnOffOfflineTitle'); |
| 85 $('easy-unlock-turn-off-messagee').textContent = | 129 $('easy-unlock-turn-off-messagee').textContent = |
| 86 loadTimeData.getString('easyUnlockTurnOffOfflineMessage'); | 130 loadTimeData.getString('easyUnlockTurnOffOfflineMessage'); |
| 87 | 131 |
| 88 this.setActionButtonsVisible_(false); | 132 this.setActionButtonsVisible_(false); |
| 89 this.setSpinnerVisible_(false); | 133 this.setSpinnerVisible_(false); |
| 90 }, | 134 }, |
| 91 | 135 |
| 92 /** | 136 /** |
| 93 * Set up UI for turning off Easy Unlock. | 137 * Set up UI for turning off Easy Unlock. |
| 138 * @param {boolean} pending Whether there is a pending turn-off call. |
| 94 * @private | 139 * @private |
| 95 */ | 140 */ |
| 96 setUpTurnOffUI_: function() { | 141 setUpTurnOffUI_: function(pending) { |
| 97 $('easy-unlock-turn-off-title').textContent = | 142 $('easy-unlock-turn-off-title').textContent = |
| 98 loadTimeData.getString('easyUnlockTurnOffTitle'); | 143 loadTimeData.getString('easyUnlockTurnOffTitle'); |
| 99 $('easy-unlock-turn-off-messagee').textContent = | 144 $('easy-unlock-turn-off-messagee').textContent = |
| 100 loadTimeData.getString('easyUnlockTurnOffDescription'); | 145 loadTimeData.getString('easyUnlockTurnOffDescription'); |
| 101 $('easy-unlock-turn-off-confirm').textContent = | 146 $('easy-unlock-turn-off-confirm').textContent = |
| 102 loadTimeData.getString('easyUnlockTurnOffButton'); | 147 loadTimeData.getString('easyUnlockTurnOffButton'); |
| 103 | 148 |
| 104 this.setActionButtonsVisible_(true); | 149 this.setActionButtonsVisible_(true); |
| 105 this.setSpinnerVisible_(false); | 150 this.setSpinnerVisible_(pending); |
| 106 $('easy-unlock-turn-off-confirm').disabled = false; | 151 $('easy-unlock-turn-off-confirm').disabled = pending; |
| 107 $('easy-unlock-turn-off-dismiss').hidden = false; | 152 $('easy-unlock-turn-off-dismiss').hidden = false; |
| 108 }, | 153 }, |
| 109 | 154 |
| 110 /** | 155 /** |
| 111 * Set up UI for showing server error. | 156 * Set up UI for showing server error. |
| 112 * @private | 157 * @private |
| 113 */ | 158 */ |
| 114 setUpServerErrorUI_: function() { | 159 setUpServerErrorUI_: function() { |
| 115 $('easy-unlock-turn-off-title').textContent = | 160 $('easy-unlock-turn-off-title').textContent = |
| 116 loadTimeData.getString('easyUnlockTurnOffErrorTitle'); | 161 loadTimeData.getString('easyUnlockTurnOffErrorTitle'); |
| 117 $('easy-unlock-turn-off-messagee').textContent = | 162 $('easy-unlock-turn-off-messagee').textContent = |
| 118 loadTimeData.getString('easyUnlockTurnOffErrorMessage'); | 163 loadTimeData.getString('easyUnlockTurnOffErrorMessage'); |
| 119 $('easy-unlock-turn-off-confirm').textContent = | 164 $('easy-unlock-turn-off-confirm').textContent = |
| 120 loadTimeData.getString('easyUnlockTurnOffRetryButton'); | 165 loadTimeData.getString('easyUnlockTurnOffRetryButton'); |
| 121 | 166 |
| 122 this.setActionButtonsVisible_(true); | 167 this.setActionButtonsVisible_(true); |
| 123 this.setSpinnerVisible_(false); | 168 this.setSpinnerVisible_(false); |
| 124 $('easy-unlock-turn-off-confirm').disabled = false; | 169 $('easy-unlock-turn-off-confirm').disabled = false; |
| 125 $('easy-unlock-turn-off-dismiss').hidden = true; | 170 $('easy-unlock-turn-off-dismiss').hidden = true; |
| 126 }, | 171 }, |
| 127 }; | 172 }; |
| 128 | 173 |
| 174 /** |
| 175 * Closes the Easy unlock turn off overlay. |
| 176 */ |
| 129 EasyUnlockTurnOffOverlay.dismiss = function() { | 177 EasyUnlockTurnOffOverlay.dismiss = function() { |
| 130 PageManager.closeOverlay(); | 178 PageManager.closeOverlay(); |
| 131 }; | 179 }; |
| 132 | 180 |
| 181 /** |
| 182 * Update UI to reflect the turn off operation status. |
| 183 * @param {string} newState The UIState string representing the new state. |
| 184 */ |
| 185 EasyUnlockTurnOffOverlay.updateUIState = function(newState) { |
| 186 EasyUnlockTurnOffOverlay.getInstance().uiState = newState; |
| 187 }; |
| 188 |
| 133 // Export | 189 // Export |
| 134 return { | 190 return { |
| 135 EasyUnlockTurnOffOverlay: EasyUnlockTurnOffOverlay | 191 EasyUnlockTurnOffOverlay: EasyUnlockTurnOffOverlay |
| 136 }; | 192 }; |
| 137 }); | 193 }); |
| OLD | NEW |