OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 //<include src="../../../../ui/webui/resources/js/cr.js"> | 5 //<include src="../../../../ui/webui/resources/js/cr.js"> |
6 //<include src="../../../../ui/webui/resources/js/load_time_data.js"> | 6 //<include src="../../../../ui/webui/resources/js/load_time_data.js"> |
7 //<include src="../../../../ui/webui/resources/js/i18n_template_no_process.js"> | 7 //<include src="../../../../ui/webui/resources/js/i18n_template_no_process.js"> |
8 //<include src="../../../../ui/webui/resources/js/cr/event_target.js"> | 8 //<include src="../../../../ui/webui/resources/js/cr/event_target.js"> |
9 //<include src="../../../../ui/webui/resources/js/cr/ui/dialogs.js"> | 9 //<include src="../../../../ui/webui/resources/js/cr/ui/dialogs.js"> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 } | 33 } |
34 | 34 |
35 /** | 35 /** |
36 * Default strings. | 36 * Default strings. |
37 */ | 37 */ |
38 var defaultStrings = { | 38 var defaultStrings = { |
39 'language': 'en', | 39 'language': 'en', |
40 'LINK_TO_WEBSTORE': '[LOCALIZE ME] Learn more...', | 40 'LINK_TO_WEBSTORE': '[LOCALIZE ME] Learn more...', |
41 'INSTALLATION_FAILED_MESSAGE': '[LOCALIZE ME] Installation failed!', | 41 'INSTALLATION_FAILED_MESSAGE': '[LOCALIZE ME] Installation failed!', |
42 'OK_BUTTON': '[LOCALIZE ME] OK', | 42 'OK_BUTTON': '[LOCALIZE ME] OK', |
43 'TITLE_PRINTER_PROVIDERS': '[LOCALIZE ME] Select app for your printer' | 43 'TITLE_PRINTER_PROVIDERS': '[LOCALIZE ME] Select app for your printer', |
44 'DEFAULT_ERROR_MESSAGE': '[LOCALIZE ME] Failure' | |
44 }; | 45 }; |
45 | 46 |
46 | 47 |
47 /** | 48 /** |
48 * @param {string} id The string id. | 49 * @param {string} id The string id. |
49 * @return {string} | 50 * @return {string} |
50 */ | 51 */ |
51 function getString(id) { | 52 function getString(id) { |
52 return loadTimeData.getString(id) || defaultStrings[id] || ''; | 53 return loadTimeData.getString(id) || defaultStrings[id] || ''; |
53 } | 54 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 } | 116 } |
116 callback(token); | 117 callback(token); |
117 }); | 118 }); |
118 } | 119 } |
119 }; | 120 }; |
120 } | 121 } |
121 | 122 |
122 function initializeTopbarButtons() { | 123 function initializeTopbarButtons() { |
123 $('close-button').addEventListener('click', function(e) { | 124 $('close-button').addEventListener('click', function(e) { |
124 e.preventDefault(); | 125 e.preventDefault(); |
125 chrome.app.window.current().close(); | 126 close(); |
126 }); | 127 }); |
127 | 128 |
128 $('close-button').addEventListener('mousedown', function(e) { | 129 $('close-button').addEventListener('mousedown', function(e) { |
129 e.preventDefault(); | 130 e.preventDefault(); |
130 }); | 131 }); |
131 | 132 |
132 $('minimize-button').addEventListener('click', function(e) { | 133 $('minimize-button').addEventListener('click', function(e) { |
133 e.preventDefault(); | 134 e.preventDefault(); |
134 chrome.app.window.current().minimize(); | 135 chrome.app.window.current().minimize(); |
135 }); | 136 }); |
136 | 137 |
137 $('minimize-button').addEventListener('mousedown', function(e) { | 138 $('minimize-button').addEventListener('mousedown', function(e) { |
138 e.preventDefault(); | 139 e.preventDefault(); |
139 }); | 140 }); |
140 } | 141 } |
141 | 142 |
143 /** | |
144 * @param {!CWSWidgetContainer.Result} result The result reported by the widget. | |
145 */ | |
146 function showWidgetResult(result) { | |
147 // TODO(tbarzic): Add some UI to show on success. | |
148 if (result != CWSWidgetContainer.Result.FAILED) { | |
149 close(); | |
150 return; | |
151 } | |
152 | |
153 var dialog = new CWSWidgetContainerErrorDialog($('widget-container-root')); | |
154 dialog.show(getString('DEFAULT_ERROR_MESSAGE'), close, close); | |
155 } | |
156 | |
157 /** Closes the current app window. */ | |
158 function close() { | |
yoshiki
2015/05/12 13:57:15
nit: this overrides window.close() in this scope.
tbarzic
2015/05/12 20:38:51
Done.
| |
159 chrome.app.window.current().close(); | |
160 } | |
161 | |
142 window.addEventListener('DOMContentLoaded', function() { | 162 window.addEventListener('DOMContentLoaded', function() { |
143 initializeTopbarButtons(); | 163 initializeTopbarButtons(); |
144 | 164 |
145 chrome.webstoreWidgetPrivate.getStrings(function(strings) { | 165 chrome.webstoreWidgetPrivate.getStrings(function(strings) { |
146 loadTimeData.data = strings; | 166 loadTimeData.data = strings; |
147 i18nTemplate.process(document, loadTimeData); | 167 i18nTemplate.process(document, loadTimeData); |
148 | 168 |
149 cr.ui.dialogs.BaseDialog.OK_LABEL = getString('OK_BUTTON'); | 169 cr.ui.dialogs.BaseDialog.OK_LABEL = getString('OK_BUTTON'); |
150 | 170 |
151 document.title = getString('TITLE_PRINTER_PROVIDERS'); | 171 document.title = getString('TITLE_PRINTER_PROVIDERS'); |
(...skipping 18 matching lines...) Expand all Loading... | |
170 document, root, platformDelegate, {} /* state */); | 190 document, root, platformDelegate, {} /* state */); |
171 | 191 |
172 widgetContainer.ready() | 192 widgetContainer.ready() |
173 /** @return {!Promise.<CWSWidgetContainer.ResolveReason>} */ | 193 /** @return {!Promise.<CWSWidgetContainer.ResolveReason>} */ |
174 .then(function() { | 194 .then(function() { |
175 return widgetContainer.start(window.params.filter, | 195 return widgetContainer.start(window.params.filter, |
176 window.params.webstoreUrl); | 196 window.params.webstoreUrl); |
177 }) | 197 }) |
178 /** @param {!CWSWidgetContainer.ResolveReason} reason */ | 198 /** @param {!CWSWidgetContainer.ResolveReason} reason */ |
179 .then(function(reason) { | 199 .then(function(reason) { |
180 chrome.app.window.current().close(); | 200 if (reason != CWSWidgetContainer.ResolveReason.DONE) |
201 return; | |
202 | |
203 var result = widgetContainer.finalizeAndGetResult(); | |
204 showWidgetResult(result.result); | |
181 }) | 205 }) |
182 /** @param {*} error */ | 206 /** @param {*} error */ |
183 .catch(function(error) { | 207 .catch(function(error) { |
184 // TODO(tbarzic): Add error UI. | 208 showWidgetResult(CWSWidgetContainer.Result.FAILED); |
185 console.error(error); | |
186 }); | 209 }); |
187 }); | 210 }); |
188 }); | 211 }); |
189 })(); | 212 })(); |
OLD | NEW |