Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: chrome/browser/resources/options/easy_unlock_turn_off_overlay.js

Issue 475483003: Wire easy unlock settings UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 var oldState = this.uiState_;
tbarzic 2014/08/14 17:43:23 you don't use oldState also, consider adding if (
xiyuan 2014/08/14 22:09:19 Done.
43 this.uiState_ = newUiState;
44 switch (this.uiState_) {
45 case UIState.OFFLINE:
46 this.setUpOfflineUI_();
47 break;
48 case UIState.IDLE:
49 this.setUpTurnOffUI_(false);
50 break;
51 case UIState.PENDING:
52 this.setUpTurnOffUI_(true);
53 break;
54 case UIState.SERVER_ERROR:
55 this.setUpServerErrorUI_();
56 break;
57 default:
58 console.error('Unknow Easy unlock turn off UI state: ' +
59 this.uiState_);
60 }
61 },
62
26 /** @override */ 63 /** @override */
27 initializePage: function() { 64 initializePage: function() {
28 Page.prototype.initializePage.call(this); 65 Page.prototype.initializePage.call(this);
29 66
30 $('easy-unlock-turn-off-dismiss').onclick = function(event) { 67 $('easy-unlock-turn-off-dismiss').onclick = function(event) {
31 EasyUnlockTurnOffOverlay.dismiss(); 68 EasyUnlockTurnOffOverlay.dismiss();
32 }; 69 };
33 $('easy-unlock-turn-off-confirm').onclick = function(event) { 70 $('easy-unlock-turn-off-confirm').onclick = function(event) {
34 $('easy-unlock-turn-off-confirm').disabled = true; 71 this.uiState = UIState.PENDING;
35 this.setSpinnerVisible_(true); 72 chrome.send('easyUnlockRequestTurnOff');
36
37 // TODO(xiyuan): Wire this up.
38 // chrome.send('turnOffEasyUnlock');
39 }.bind(this); 73 }.bind(this);
40 }, 74 },
41 75
42 /** @override */ 76 /** @override */
43 didShowPage: function() { 77 didShowPage: function() {
44 if (navigator.onLine) { 78 if (navigator.onLine) {
45 this.setUpTurnOffUI_(); 79 this.uiState = UIState.IDLE;
80 chrome.send('easyUnlockGetTurnOffFlowStatus');
46 } else { 81 } else {
47 this.setUpOfflineUI_(); 82 this.uiState = UIState.OFFLINE;
48 } 83 }
49 }, 84 },
50 85
86 /** @override */
87 didClosePage: function() {
88 chrome.send('easyUnlockTurnOffOverlayDismissed');
89 },
90
51 /** 91 /**
52 * Returns the button strip element. 92 * Returns the button strip element.
53 * @return {HTMLDivElement} The container div of action buttons. 93 * @return {HTMLDivElement} The container div of action buttons.
54 */ 94 */
55 get buttonStrip() { 95 get buttonStrip() {
56 return this.pageDiv.querySelector('.button-strip'); 96 return this.pageDiv.querySelector('.button-strip');
57 }, 97 },
58 98
59 /** 99 /**
60 * Set visibility of action buttons in button strip. 100 * Set visibility of action buttons in button strip.
(...skipping 23 matching lines...) Expand all
84 loadTimeData.getString('easyUnlockTurnOffOfflineTitle'); 124 loadTimeData.getString('easyUnlockTurnOffOfflineTitle');
85 $('easy-unlock-turn-off-messagee').textContent = 125 $('easy-unlock-turn-off-messagee').textContent =
86 loadTimeData.getString('easyUnlockTurnOffOfflineMessage'); 126 loadTimeData.getString('easyUnlockTurnOffOfflineMessage');
87 127
88 this.setActionButtonsVisible_(false); 128 this.setActionButtonsVisible_(false);
89 this.setSpinnerVisible_(false); 129 this.setSpinnerVisible_(false);
90 }, 130 },
91 131
92 /** 132 /**
93 * Set up UI for turning off Easy Unlock. 133 * Set up UI for turning off Easy Unlock.
134 * @param {boolean} pending Whether there is a pending turn-off call.
94 * @private 135 * @private
95 */ 136 */
96 setUpTurnOffUI_: function() { 137 setUpTurnOffUI_: function(pending) {
97 $('easy-unlock-turn-off-title').textContent = 138 $('easy-unlock-turn-off-title').textContent =
98 loadTimeData.getString('easyUnlockTurnOffTitle'); 139 loadTimeData.getString('easyUnlockTurnOffTitle');
99 $('easy-unlock-turn-off-messagee').textContent = 140 $('easy-unlock-turn-off-messagee').textContent =
100 loadTimeData.getString('easyUnlockTurnOffDescription'); 141 loadTimeData.getString('easyUnlockTurnOffDescription');
101 $('easy-unlock-turn-off-confirm').textContent = 142 $('easy-unlock-turn-off-confirm').textContent =
102 loadTimeData.getString('easyUnlockTurnOffButton'); 143 loadTimeData.getString('easyUnlockTurnOffButton');
103 144
104 this.setActionButtonsVisible_(true); 145 this.setActionButtonsVisible_(true);
105 this.setSpinnerVisible_(false); 146 this.setSpinnerVisible_(pending);
106 $('easy-unlock-turn-off-confirm').disabled = false; 147 $('easy-unlock-turn-off-confirm').disabled = pending;
107 $('easy-unlock-turn-off-dismiss').hidden = false; 148 $('easy-unlock-turn-off-dismiss').hidden = false;
108 }, 149 },
109 150
110 /** 151 /**
111 * Set up UI for showing server error. 152 * Set up UI for showing server error.
112 * @private 153 * @private
113 */ 154 */
114 setUpServerErrorUI_: function() { 155 setUpServerErrorUI_: function() {
115 $('easy-unlock-turn-off-title').textContent = 156 $('easy-unlock-turn-off-title').textContent =
116 loadTimeData.getString('easyUnlockTurnOffErrorTitle'); 157 loadTimeData.getString('easyUnlockTurnOffErrorTitle');
117 $('easy-unlock-turn-off-messagee').textContent = 158 $('easy-unlock-turn-off-messagee').textContent =
118 loadTimeData.getString('easyUnlockTurnOffErrorMessage'); 159 loadTimeData.getString('easyUnlockTurnOffErrorMessage');
119 $('easy-unlock-turn-off-confirm').textContent = 160 $('easy-unlock-turn-off-confirm').textContent =
120 loadTimeData.getString('easyUnlockTurnOffRetryButton'); 161 loadTimeData.getString('easyUnlockTurnOffRetryButton');
121 162
122 this.setActionButtonsVisible_(true); 163 this.setActionButtonsVisible_(true);
123 this.setSpinnerVisible_(false); 164 this.setSpinnerVisible_(false);
124 $('easy-unlock-turn-off-confirm').disabled = false; 165 $('easy-unlock-turn-off-confirm').disabled = false;
125 $('easy-unlock-turn-off-dismiss').hidden = true; 166 $('easy-unlock-turn-off-dismiss').hidden = true;
126 }, 167 },
127 }; 168 };
128 169
170 /**
171 * Closes the Easy unlock turn off overlay.
172 */
129 EasyUnlockTurnOffOverlay.dismiss = function() { 173 EasyUnlockTurnOffOverlay.dismiss = function() {
130 PageManager.closeOverlay(); 174 PageManager.closeOverlay();
131 }; 175 };
132 176
177 /**
178 * Update UI to reflect the turn off operation status.
179 * @param {string} newState The UIState string representing the new state.
180 */
181 EasyUnlockTurnOffOverlay.updateUIState = function(newState) {
182 EasyUnlockTurnOffOverlay.getInstance().uiState = newState;
183 };
184
133 // Export 185 // Export
134 return { 186 return {
135 EasyUnlockTurnOffOverlay: EasyUnlockTurnOffOverlay 187 EasyUnlockTurnOffOverlay: EasyUnlockTurnOffOverlay
136 }; 188 };
137 }); 189 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698