OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @fileoverview Device reset screen implementation. | 6 * @fileoverview Device reset screen implementation. |
7 */ | 7 */ |
8 | 8 |
9 login.createScreen('ResetScreen', 'reset', function() { | 9 login.createScreen('ResetScreen', 'reset', function() { |
10 return { | 10 return { |
11 | 11 |
| 12 /* Possible UI states of the reset screen. */ |
| 13 RESET_SCREEN_UI_STATE: { |
| 14 REVERT_PROMISE: 'ui-state-revert-promise', |
| 15 RESTART_REQUIRED: 'ui-state-restart-required', |
| 16 POWERWASH_PROPOSAL: 'ui-state-powerwash-proposal', |
| 17 POWERWASH_CONFIRM: 'ui-state-powerwash-confirm', |
| 18 ROLLBACK_CONFIRM: 'ui-state-rollback-confirm' |
| 19 }, |
| 20 |
12 EXTERNAL_API: [ | 21 EXTERNAL_API: [ |
| 22 'hideRollbackOption', |
| 23 'showRollbackOption', |
13 'updateViewOnRollbackCall' | 24 'updateViewOnRollbackCall' |
14 ], | 25 ], |
15 | 26 |
16 /** @override */ | 27 /** @override */ |
17 decorate: function() { | 28 decorate: function() { |
18 $('reset-powerwash-help-link-on-rollback').addEventListener( | 29 $('powerwash-help-link').addEventListener('click', function(event) { |
19 'click', function(event) { | |
20 chrome.send('resetOnLearnMore'); | |
21 }); | |
22 $('powerwash-help-link').addEventListener( | |
23 'click', function(event) { | |
24 chrome.send('resetOnLearnMore'); | 30 chrome.send('resetOnLearnMore'); |
25 }); | 31 }); |
26 }, | 32 }, |
27 | 33 |
28 /** | 34 /** |
29 * Header text of the screen. | 35 * Header text of the screen. |
30 * @type {string} | 36 * @type {string} |
31 */ | 37 */ |
32 get header() { | 38 get header() { |
33 return loadTimeData.getString('resetScreenTitle'); | 39 return loadTimeData.getString('resetScreenTitle'); |
34 }, | 40 }, |
35 | 41 |
36 /** | 42 /** |
37 * Buttons in oobe wizard's button strip. | 43 * Buttons in oobe wizard's button strip. |
38 * @type {array} Array of Buttons. | 44 * @type {array} Array of Buttons. |
39 */ | 45 */ |
40 get buttons() { | 46 get buttons() { |
41 var buttons = []; | 47 var buttons = []; |
| 48 var restartButton = this.ownerDocument.createElement('button'); |
| 49 restartButton.id = 'reset-restart-button'; |
| 50 restartButton.textContent = loadTimeData.getString('resetButtonRestart'); |
| 51 restartButton.addEventListener('click', function(e) { |
| 52 chrome.send('restartOnReset'); |
| 53 e.stopPropagation(); |
| 54 }); |
| 55 buttons.push(restartButton); |
| 56 |
| 57 // Button that initiates actual powerwash or powerwash with rollback. |
42 var resetButton = this.ownerDocument.createElement('button'); | 58 var resetButton = this.ownerDocument.createElement('button'); |
43 resetButton.id = 'reset-button'; | 59 resetButton.id = 'reset-button'; |
44 resetButton.textContent = ''; | 60 resetButton.textContent = loadTimeData.getString('resetButtonReset'); |
45 resetButton.addEventListener('click', function(e) { | 61 resetButton.addEventListener('click', function(e) { |
46 if ($('reset').needRestart) | 62 chrome.send('powerwashOnReset', [$('reset').rollbackChecked]); |
47 chrome.send('restartOnReset', [$('reset-rollback-checkbox').checked]); | |
48 else | |
49 chrome.send('powerwashOnReset', | |
50 [$('reset-rollback-checkbox').checked]); | |
51 e.stopPropagation(); | 63 e.stopPropagation(); |
52 }); | 64 }); |
53 buttons.push(resetButton); | 65 buttons.push(resetButton); |
54 | 66 |
| 67 // Button that leads to confirmation dialog. |
| 68 var toConfirmButton = this.ownerDocument.createElement('button'); |
| 69 toConfirmButton.id = 'reset-toconfirm-button'; |
| 70 toConfirmButton.textContent = |
| 71 loadTimeData.getString('resetButtonPowerwash'); |
| 72 toConfirmButton.addEventListener('click', function(e) { |
| 73 // change view to confirmational |
| 74 var resetScreen = $('reset'); |
| 75 resetScreen.isConfirmational = true; |
| 76 if (resetScreen.rollbackChecked && resetScreen.rollbackAvailable) { |
| 77 resetScreen.setDialogView_( |
| 78 resetScreen.RESET_SCREEN_UI_STATE.ROLLBACK_CONFIRM); |
| 79 } else { |
| 80 resetScreen.setDialogView_( |
| 81 resetScreen.RESET_SCREEN_UI_STATE.POWERWASH_CONFIRM); |
| 82 } |
| 83 chrome.send('showConfirmationOnReset'); |
| 84 e.stopPropagation(); |
| 85 }); |
| 86 buttons.push(toConfirmButton); |
| 87 |
55 var cancelButton = this.ownerDocument.createElement('button'); | 88 var cancelButton = this.ownerDocument.createElement('button'); |
56 cancelButton.id = 'reset-cancel-button'; | 89 cancelButton.id = 'reset-cancel-button'; |
57 cancelButton.textContent = loadTimeData.getString('cancelButton'); | 90 cancelButton.textContent = loadTimeData.getString('cancelButton'); |
58 cancelButton.addEventListener('click', function(e) { | 91 cancelButton.addEventListener('click', function(e) { |
59 chrome.send('cancelOnReset'); | 92 chrome.send('cancelOnReset'); |
60 e.stopPropagation(); | 93 e.stopPropagation(); |
61 }); | 94 }); |
62 buttons.push(cancelButton); | 95 buttons.push(cancelButton); |
63 | 96 |
64 return buttons; | 97 return buttons; |
65 }, | 98 }, |
66 | 99 |
67 /** | 100 /** |
68 * Returns a control which should receive an initial focus. | 101 * Returns a control which should receive an initial focus. |
69 */ | 102 */ |
70 get defaultControl() { | 103 get defaultControl() { |
| 104 // choose |
| 105 if (this.needRestart) |
| 106 return $('reset-restart-button'); |
| 107 if (this.isConfirmational) |
| 108 if (this.rollbackChecked) |
| 109 return $('reset-button'); |
| 110 else |
| 111 return $('reset-toconfirm-button'); |
71 return $('reset-button'); | 112 return $('reset-button'); |
72 }, | 113 }, |
73 | 114 |
74 /** | 115 /** |
75 * Cancels the reset and drops the user back to the login screen. | 116 * Cancels the reset and drops the user back to the login screen. |
76 */ | 117 */ |
77 cancel: function() { | 118 cancel: function() { |
78 chrome.send('cancelOnReset'); | 119 chrome.send('cancelOnReset'); |
79 }, | 120 }, |
80 | 121 |
81 /** | 122 /** |
82 * Event handler that is invoked just before the screen in shown. | 123 * Event handler that is invoked just before the screen in shown. |
83 * @param {Object} data Screen init payload. | 124 * @param {Object} data Screen init payload. |
84 */ | 125 */ |
85 onBeforeShow: function(data) { | 126 onBeforeShow: function(data) { |
86 if (data === undefined) | 127 if (data === undefined) |
87 return; | 128 return; |
88 this.classList.remove('revert-promise'); | |
89 if ('showRestartMsg' in data) | |
90 this.setRestartMsg_(data['showRestartMsg']); | |
91 if ('showRollbackOption' in data) | |
92 this.setRollbackAvailable_(data['showRollbackOption']); | |
93 if ('simpleConfirm' in data) { | |
94 this.isConfirmational = data['simpleConfirm']; | |
95 this.confirmRollback = false; | |
96 } | |
97 if ('rollbackConfirm' in data) { | |
98 this.isConfirmational = data['rollbackConfirm']; | |
99 this.confirmRollback = true; | |
100 } | |
101 | 129 |
102 if (this.isConfirmational) { | 130 this.rollbackChecked = false; |
103 // Exec after reboot initiated by reset screen. | 131 this.rollbackAvailable = false; |
104 // Confirmational form of screen. | 132 this.isConfirmational = false; |
105 $('reset-button').textContent = loadTimeData.getString( | 133 |
106 'resetButtonReset'); | 134 if ('rollbackAvailable' in data) |
107 if (this.confirmRollback) { | 135 this.rollbackAvailable = data['rollbackAvailable']; |
108 $('reset-warning-msg').textContent = loadTimeData.getString( | 136 |
109 'resetAndRollbackWarningTextConfirmational'); | 137 if ('restartRequired' in data && data['restartRequired']) { |
110 $('reset-warning-details').textContent = loadTimeData.getString( | 138 this.restartRequired = true; |
111 'resetAndRollbackWarningDetailsConfirmational'); | 139 this.setDialogView_(this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED); |
112 } else { | |
113 $('reset-warning-msg').textContent = loadTimeData.getString( | |
114 'resetWarningTextConfirmational'); | |
115 $('reset-warning-details').textContent = loadTimeData.getString( | |
116 'resetWarningDetailsConfirmational'); | |
117 } | |
118 } else { | 140 } else { |
119 $('reset-warning-msg').textContent = loadTimeData.getString( | 141 this.restartRequired = false; |
120 'resetWarningTextInitial'); | 142 this.setDialogView_(this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL); |
121 $('reset-warning-details').textContent = loadTimeData.getString( | |
122 'resetWarningDetailsInitial'); | |
123 if (this.needRestart) { | |
124 $('reset-button').textContent = loadTimeData.getString( | |
125 'resetButtonRelaunch'); | |
126 } else { | |
127 $('reset-button').textContent = loadTimeData.getString( | |
128 'resetButtonPowerwash'); | |
129 } | |
130 } | 143 } |
131 }, | 144 }, |
132 | 145 |
133 /** | 146 /** |
134 * Sets restart necessity for the screen. | 147 * Sets css style for corresponding state of the screen. |
135 * @param {bool} need_restart. If restart required before reset. | 148 * @param {string} state. |
136 * @private | 149 * @private |
137 */ | 150 */ |
138 setRestartMsg_: function(need_restart) { | 151 setDialogView_: function(state) { |
139 this.classList.toggle('norestart', !need_restart); | 152 this.classList.remove('revert-promise-view'); |
140 this.needRestart = need_restart; | 153 this.classList.remove('restart-required-view'); |
141 }, | 154 this.classList.remove('powerwash-proposal-view'); |
142 | 155 this.classList.remove('powerwash-confirm-view'); |
143 /** | 156 this.classList.remove('rollback-confirm-view'); |
144 * Sets rollback availability for the screen. | 157 if (state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE) |
145 * @param {bool} can_rollback. If Rollback is available on reset screen. | 158 this.classList.add('revert-promise-view'); |
146 * @private | 159 else if (state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED) |
147 */ | 160 this.classList.add('restart-required-view'); |
148 setRollbackAvailable_: function(show_rollback) { | 161 else if (state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL) |
149 this.classList.toggle('norollback', !show_rollback); | 162 this.classList.add('powerwash-proposal-view'); |
150 this.showRollback = show_rollback; | 163 else if (state == this.RESET_SCREEN_UI_STATE.POWERWASH_CONFIRM) |
| 164 this.classList.add('powerwash-confirm-view'); |
| 165 else if (state == this.RESET_SCREEN_UI_STATE.ROLLBACK_CONFIRM) |
| 166 this.classList.add('rollback-confirm-view'); |
| 167 else // error |
| 168 console.error('State ' + state + ' is not supported by setDialogView.'); |
151 }, | 169 }, |
152 | 170 |
153 updateViewOnRollbackCall: function() { | 171 updateViewOnRollbackCall: function() { |
154 this.classList.add('revert-promise'); | 172 this.setDialogView_(this.RESET_SCREEN_UI_STATE.REVERT_PROMISE); |
155 announceAccessibleMessage( | 173 announceAccessibleMessage( |
156 loadTimeData.getString('resetRevertSpinnerMessage')); | 174 loadTimeData.getString('resetRevertSpinnerMessage')); |
| 175 }, |
| 176 |
| 177 showRollbackOption: function() { |
| 178 $('reset-toconfirm-button').textContent = loadTimeData.getString( |
| 179 'resetButtonPowerwashAndRollback'); |
| 180 this.rollbackChecked = true; |
| 181 }, |
| 182 |
| 183 hideRollbackOption: function() { |
| 184 $('reset-toconfirm-button').textContent = loadTimeData.getString( |
| 185 'resetButtonPowerwash'); |
| 186 this.rollbackChecked = false; |
157 } | 187 } |
158 }; | 188 }; |
159 }); | 189 }); |
OLD | NEW |