OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 'settings-cups-add-printer-dialog' includes multiple dialogs to | 6 * @fileoverview 'settings-cups-add-printer-dialog' includes multiple dialogs to |
7 * set up a new CUPS printer. | 7 * set up a new CUPS printer. |
8 * Subdialogs include: | 8 * Subdialogs include: |
9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on | 9 * - 'add-printer-discovery-dialog' is a dialog showing discovered printers on |
10 * the network that are available for setup. | 10 * the network that are available for setup. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 this.$$('add-printer-dialog').close(); | 94 this.$$('add-printer-dialog').close(); |
95 this.fire('open-discovery-printers-dialog'); | 95 this.fire('open-discovery-printers-dialog'); |
96 }, | 96 }, |
97 | 97 |
98 /** @private */ | 98 /** @private */ |
99 onCancelTap_: function() { | 99 onCancelTap_: function() { |
100 this.$$('add-printer-dialog').close(); | 100 this.$$('add-printer-dialog').close(); |
101 }, | 101 }, |
102 | 102 |
103 /** @private */ | 103 /** @private */ |
104 switchToManufacturerDialog_: function() { | 104 switchToConfiguringDialog_: function() { |
105 this.$$('add-printer-dialog').close(); | 105 this.$$('add-printer-dialog').close(); |
106 this.fire('open-manufacturer-model-dialog'); | 106 this.fire('open-configuring-printer-dialog'); |
107 }, | 107 }, |
108 | 108 |
109 /** @private */ | 109 /** @private */ |
110 onAddressChanged_: function() { | 110 onAddressChanged_: function() { |
111 this.$.searchInProgress.hidden = false; | 111 // TODO(xdai): Check if the printer address exists and then show the |
112 this.$.searchFound.hidden = true; | 112 // corresponding message after the API is ready. |
113 this.$.searchNotFound.hidden = true; | 113 // The format of address is: ip-address-or-hostname:port-number. |
114 | |
115 var value = this.$.printerAddressInput.value; | |
116 if (this.isValidIpAddress_(value)) { | |
117 // TODO(xdai): Check if the printer address exists after the API is ready. | |
118 this.$.searchInProgress.hidden = true; | |
119 this.$.searchFound.hidden = false; | |
120 this.$.searchNotFound.hidden = true; | |
121 } else { | |
122 this.$.searchInProgress.hidden = true; | |
123 this.$.searchFound.hidden = true; | |
124 this.$.searchNotFound.hidden = false; | |
125 } | |
126 }, | |
127 | |
128 /** | |
129 * @param {string} ip | |
130 * @return {boolean} | |
131 * @private | |
132 */ | |
133 isValidIpAddress_: function(ip) { | |
134 var addressRegex = RegExp('^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + | |
135 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + | |
136 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.' + | |
137 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])$'); | |
138 return addressRegex.test(ip); | |
139 }, | |
140 | |
141 /** | |
142 * @param {string} printerName | |
143 * @param {string} printerAddress | |
144 * @return {boolean} | |
145 * @private | |
146 */ | |
147 addPrinterNotAllowed_: function(printerName, printerAddress) { | |
148 return !printerName || !printerAddress || | |
149 !this.isValidIpAddress_(printerAddress); | |
150 }, | 114 }, |
151 }); | 115 }); |
152 | 116 |
153 Polymer({ | 117 Polymer({ |
154 is: 'add-printer-manufacturer-model-dialog', | 118 is: 'add-printer-manufacturer-model-dialog', |
155 | 119 |
156 properties: { | 120 properties: { |
157 /** @type {!CupsPrinterInfo} */ | 121 /** @type {!CupsPrinterInfo} */ |
158 newPrinter: { | 122 newPrinter: { |
159 type: Object, | 123 type: Object, |
160 notify: true, | 124 notify: true, |
161 }, | 125 }, |
162 | 126 |
163 /** @type {!Array<string>} */ | 127 /** @type {!Array<string>} */ |
164 manufacturerList: { | 128 manufacturerList: { |
165 type: Array, | 129 type: Array, |
166 }, | 130 }, |
167 | 131 |
168 /** @type {!Array<string>} */ | 132 /** @type {!Array<string>} */ |
169 modelList: { | 133 modelList: { |
170 type: Array, | 134 type: Array, |
171 }, | 135 }, |
136 | |
137 setupFailed: { | |
138 type: Boolean, | |
139 value: false, | |
140 }, | |
172 }, | 141 }, |
173 | 142 |
174 observers: [ | 143 observers: [ |
175 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', | 144 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', |
176 ], | 145 ], |
177 | 146 |
178 /** @override */ | 147 /** @override */ |
179 ready: function() { | 148 ready: function() { |
180 // TODO(xdai): Get available manufacturerList after the API is ready. | 149 // TODO(xdai): Get available manufacturerList after the API is ready. |
181 }, | 150 }, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 attached: function() { | 184 attached: function() { |
216 this.$.configuringMessage.textContent = loadTimeData.getStringF( | 185 this.$.configuringMessage.textContent = loadTimeData.getStringF( |
217 'printerConfiguringMessage', this.printerName); | 186 'printerConfiguringMessage', this.printerName); |
218 }, | 187 }, |
219 | 188 |
220 /** @private */ | 189 /** @private */ |
221 onCancelConfiguringTap_: function() { | 190 onCancelConfiguringTap_: function() { |
222 this.$$('add-printer-dialog').close(); | 191 this.$$('add-printer-dialog').close(); |
223 this.fire('configuring-dialog-closed'); | 192 this.fire('configuring-dialog-closed'); |
224 }, | 193 }, |
194 | |
195 close: function() { | |
196 this.$$('add-printer-dialog').close(); | |
197 }, | |
225 }); | 198 }); |
226 | 199 |
227 Polymer({ | 200 Polymer({ |
228 is: 'settings-cups-add-printer-dialog', | 201 is: 'settings-cups-add-printer-dialog', |
229 | 202 |
203 behaviors: [WebUIListenerBehavior], | |
204 | |
230 properties: { | 205 properties: { |
231 /** @type {!CupsPrinterInfo} */ | 206 /** @type {!CupsPrinterInfo} */ |
232 selectedPrinter: { | 207 selectedPrinter: { |
233 type: Object, | 208 type: Object, |
234 }, | 209 }, |
235 | 210 |
236 /** @type {!CupsPrinterInfo} */ | 211 /** @type {!CupsPrinterInfo} */ |
237 newPrinter: { | 212 newPrinter: { |
238 type: Object, | 213 type: Object, |
239 }, | 214 }, |
240 | 215 |
216 /** @type {boolean} whether the new printer setup is failed. */ | |
217 setupFailed: { | |
218 type: Boolean, | |
219 value: false, | |
220 }, | |
221 | |
241 /** @private {string} */ | 222 /** @private {string} */ |
242 previousDialog_: String, | 223 previousDialog_: String, |
243 | 224 |
244 /** @private {string} */ | 225 /** @private {string} */ |
245 currentDialog_: String, | 226 currentDialog_: String, |
246 | 227 |
247 /** @private {boolean} */ | 228 /** @private {boolean} */ |
248 showDiscoveryDialog_: Boolean, | 229 showDiscoveryDialog_: Boolean, |
249 | 230 |
250 /** @private {boolean} */ | 231 /** @private {boolean} */ |
251 showManuallyAddDialog_: Boolean, | 232 showManuallyAddDialog_: Boolean, |
252 | 233 |
253 /** @private {boolean} */ | 234 /** @private {boolean} */ |
254 showConfiguringDialog_: Boolean, | 235 showConfiguringDialog_: Boolean, |
255 | 236 |
256 /** @private {boolean} */ | 237 /** @private {boolean} */ |
257 showManufacturerDialog_: Boolean, | 238 showManufacturerDialog_: Boolean, |
258 }, | 239 }, |
259 | 240 |
260 listeners: { | 241 listeners: { |
261 'configuring-dialog-closed': 'configuringDialogClosed_', | 242 'configuring-dialog-closed': 'configuringDialogClosed_', |
262 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', | 243 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', |
263 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', | 244 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', |
264 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', | 245 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', |
265 'open-manufacturer-model-dialog': 'openManufacturerModelDialog_', | 246 'open-manufacturer-model-dialog': 'openManufacturerModelDialog_', |
266 }, | 247 }, |
267 | 248 |
249 /** @override */ | |
250 ready: function() { | |
251 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); | |
252 }, | |
253 | |
268 /** Opens the Add printer discovery dialog. */ | 254 /** Opens the Add printer discovery dialog. */ |
269 open: function() { | 255 open: function() { |
256 this.resetData_(); | |
270 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); | 257 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
271 }, | 258 }, |
272 | 259 |
260 /** | |
261 * Reset all the printer data in the Add printer flow. | |
262 * @private | |
263 */ | |
264 resetData_: function() { | |
265 if (this.selectedPrinter) | |
266 this.resetPrinterData_(this.selectedPrinter); | |
michaelpg
2016/09/20 20:58:42
This doesn't notify Polymer of these changes. How
xdai1
2016/09/21 17:40:19
Actually it works. For example, this.resetPrinterD
michaelpg
2016/09/21 19:13:23
No: https://jsfiddle.net/jdysdxey/
See https://ww
xdai1
2016/09/21 23:16:16
Thanks! You're right. But then I'm confused why it
| |
267 if (this.newPrinter) | |
268 this.resetPrinterData_(this.newPrinter); | |
269 this.setupFailed = false; | |
270 }, | |
271 | |
272 /** | |
273 * @param {!CupsPrinterInfo} printer | |
274 * @private | |
275 */ | |
276 resetPrinterData_: function(printer) { | |
277 printer.printerAddress = ''; | |
278 printer.printerDescription = ''; | |
279 printer.printerId = ''; | |
280 printer.printerManufacturer = ''; | |
281 printer.printerModel = ''; | |
282 printer.printerName = ''; | |
283 printer.printerProtocol = 'ipp'; | |
284 printer.printerQueue = ''; | |
285 printer.printerStatus = ''; | |
286 }, | |
287 | |
273 /** @private */ | 288 /** @private */ |
274 openManuallyAddPrinterDialog_: function() { | 289 openManuallyAddPrinterDialog_: function() { |
275 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, | 290 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
276 'showManuallyAddDialog_'); | 291 'showManuallyAddDialog_'); |
277 }, | 292 }, |
278 | 293 |
279 /** @private */ | 294 /** @private */ |
280 openDiscoveryPrintersDialog_: function() { | 295 openDiscoveryPrintersDialog_: function() { |
281 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 296 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
282 'showDiscoveryDialog_'); | 297 'showDiscoveryDialog_'); |
283 }, | 298 }, |
284 | 299 |
285 /** @private */ | 300 /** @private */ |
286 openConfiguringPrinterDialog_: function() { | 301 openConfiguringPrinterDialog_: function() { |
287 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 302 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
288 'showConfiguringDialog_'); | 303 'showConfiguringDialog_'); |
304 settings.CupsPrintersBrowserProxyImpl.getInstance(). | |
305 addCupsPrinter(this.newPrinter); | |
289 }, | 306 }, |
290 | 307 |
291 /** @private */ | 308 /** @private */ |
292 openManufacturerModelDialog_: function() { | 309 openManufacturerModelDialog_: function() { |
293 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 310 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
294 'showManufacturerDialog_'); | 311 'showManufacturerDialog_'); |
295 }, | 312 }, |
296 | 313 |
297 /** @private */ | 314 /** @private */ |
298 configuringDialogClosed_: function() { | 315 configuringDialogClosed_: function() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 */ | 352 */ |
336 getConfiguringPrinterName_: function() { | 353 getConfiguringPrinterName_: function() { |
337 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | 354 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) |
338 return this.selectedPrinter.printerName; | 355 return this.selectedPrinter.printerName; |
339 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | 356 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || |
340 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 357 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
341 return this.newPrinter.printerName; | 358 return this.newPrinter.printerName; |
342 } | 359 } |
343 return ''; | 360 return ''; |
344 }, | 361 }, |
362 | |
363 /** | |
364 * @param {boolean} success | |
365 * @param {string} printerName | |
366 * @private | |
367 */ | |
368 onAddPrinter_: function(success, printerName) { | |
369 this.$$('add-printer-configuring-dialog').close(); | |
370 if (success) | |
371 return; | |
372 | |
373 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) | |
michaelpg
2016/09/20 20:58:42
I'm having trouble following the flow here. When w
xdai1
2016/09/21 17:40:19
This is the flow https://folio.googleplex.com/chro
michaelpg
2016/09/21 19:13:23
Is this just because you haven't implemented the 0
xdai1
2016/09/21 23:16:16
Actually based on the discussion I had with the PM
| |
374 this.setupFailed = true; | |
375 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | |
376 'showManufacturerDialog_'); | |
377 }, | |
345 }); | 378 }); |
OLD | NEW |