Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / login / oobe_screen_reset.js
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
3 // found in the LICENSE file.
4
5 /**
6  * @fileoverview Device reset screen implementation.
7  */
8
9 login.createScreen('ResetScreen', 'reset', function() {
10   return {
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
21     EXTERNAL_API: [
22       'hideRollbackOption',
23       'showRollbackOption',
24       'updateViewOnRollbackCall'
25     ],
26
27     /** @override */
28     decorate: function() {
29       $('powerwash-help-link').addEventListener('click', function(event) {
30         chrome.send('resetOnLearnMore');
31       });
32     },
33
34     /**
35      * Header text of the screen.
36      * @type {string}
37      */
38     get header() {
39       return loadTimeData.getString('resetScreenTitle');
40     },
41
42     /**
43      * Buttons in oobe wizard's button strip.
44      * @type {array} Array of Buttons.
45      */
46     get 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.
58       var resetButton = this.ownerDocument.createElement('button');
59       resetButton.id = 'reset-button';
60       resetButton.textContent = loadTimeData.getString('resetButtonReset');
61       resetButton.addEventListener('click', function(e) {
62         chrome.send('powerwashOnReset', [$('reset').rollbackChecked]);
63         e.stopPropagation();
64       });
65       buttons.push(resetButton);
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
88       var cancelButton = this.ownerDocument.createElement('button');
89       cancelButton.id = 'reset-cancel-button';
90       cancelButton.textContent = loadTimeData.getString('cancelButton');
91       cancelButton.addEventListener('click', function(e) {
92         chrome.send('cancelOnReset');
93         e.stopPropagation();
94       });
95       buttons.push(cancelButton);
96
97       return buttons;
98     },
99
100     /**
101      * Returns a control which should receive an initial focus.
102      */
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');
112       return $('reset-button');
113     },
114
115     /**
116      * Cancels the reset and drops the user back to the login screen.
117      */
118     cancel: function() {
119       chrome.send('cancelOnReset');
120     },
121
122     /**
123      * Event handler that is invoked just before the screen in shown.
124      * @param {Object} data Screen init payload.
125      */
126     onBeforeShow: function(data) {
127       if (data === undefined)
128         return;
129
130       this.rollbackChecked = false;
131       this.rollbackAvailable = false;
132       this.isConfirmational = false;
133
134       if ('rollbackAvailable' in data)
135         this.rollbackAvailable = data['rollbackAvailable'];
136
137       if ('restartRequired' in data && data['restartRequired']) {
138         this.restartRequired = true;
139         this.setDialogView_(this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED);
140       } else {
141         this.restartRequired = false;
142         this.setDialogView_(this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL);
143       }
144     },
145
146     /**
147       * Sets css style for corresponding state of the screen.
148       * @param {string} state.
149       * @private
150       */
151     setDialogView_: function(state) {
152       this.classList.remove('revert-promise-view');
153       this.classList.remove('restart-required-view');
154       this.classList.remove('powerwash-proposal-view');
155       this.classList.remove('powerwash-confirm-view');
156       this.classList.remove('rollback-confirm-view');
157       if (state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE)
158         this.classList.add('revert-promise-view');
159       else if (state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED)
160         this.classList.add('restart-required-view');
161       else if (state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL)
162         this.classList.add('powerwash-proposal-view');
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.');
169     },
170
171     updateViewOnRollbackCall: function() {
172       this.setDialogView_(this.RESET_SCREEN_UI_STATE.REVERT_PROMISE);
173       announceAccessibleMessage(
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;
187     }
188   };
189 });