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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 printerAddress: '', | 78 printerAddress: '', |
79 printerDescription: '', | 79 printerDescription: '', |
80 printerId: '', | 80 printerId: '', |
81 printerManufacturer: '', | 81 printerManufacturer: '', |
82 printerModel: '', | 82 printerModel: '', |
83 printerName: '', | 83 printerName: '', |
84 printerPPDPath: '', | 84 printerPPDPath: '', |
85 printerProtocol: 'ipp', | 85 printerProtocol: 'ipp', |
86 printerQueue: '', | 86 printerQueue: '', |
87 printerStatus: '', | 87 printerStatus: '', |
88 printerPPDPath: '', | |
michaelpg
2016/09/21 19:13:23
duplicate
xdai1
2016/09/21 23:16:16
Removed it.
| |
88 }; | 89 }; |
89 }, | 90 }, |
90 }, | 91 }, |
91 }, | 92 }, |
92 | 93 |
93 /** @private */ | 94 /** @private */ |
94 switchToDiscoveryDialog_: function() { | 95 switchToDiscoveryDialog_: function() { |
95 this.$$('add-printer-dialog').close(); | 96 this.$$('add-printer-dialog').close(); |
96 this.fire('open-discovery-printers-dialog'); | 97 this.fire('open-discovery-printers-dialog'); |
97 }, | 98 }, |
98 | 99 |
99 /** @private */ | 100 /** @private */ |
100 onCancelTap_: function() { | 101 onCancelTap_: function() { |
101 this.$$('add-printer-dialog').close(); | 102 this.$$('add-printer-dialog').close(); |
102 }, | 103 }, |
103 | 104 |
104 /** @private */ | 105 /** @private */ |
105 switchToManufacturerDialog_: function() { | 106 switchToConfiguringDialog_: function() { |
106 this.$$('add-printer-dialog').close(); | 107 this.$$('add-printer-dialog').close(); |
107 this.fire('open-manufacturer-model-dialog'); | 108 this.fire('open-configuring-printer-dialog'); |
108 }, | 109 }, |
109 | 110 |
110 /** @private */ | 111 /** @private */ |
111 onAddressChanged_: function() { | 112 onAddressChanged_: function() { |
112 this.$.searchInProgress.hidden = false; | 113 // TODO(xdai): Check if the printer address exists and then show the |
113 this.$.searchFound.hidden = true; | 114 // corresponding message after the API is ready. |
114 this.$.searchNotFound.hidden = true; | 115 // The format of address is: ip-address-or-hostname:port-number. |
115 | |
116 var value = this.$.printerAddressInput.value; | |
117 if (this.isValidIpAddress_(value)) { | |
118 // TODO(xdai): Check if the printer address exists after the API is ready. | |
119 this.$.searchInProgress.hidden = true; | |
120 this.$.searchFound.hidden = false; | |
121 this.$.searchNotFound.hidden = true; | |
122 } else { | |
123 this.$.searchInProgress.hidden = true; | |
124 this.$.searchFound.hidden = true; | |
125 this.$.searchNotFound.hidden = false; | |
126 } | |
127 }, | |
128 | |
129 /** | |
130 * @param {string} ip | |
131 * @return {boolean} | |
132 * @private | |
133 */ | |
134 isValidIpAddress_: function(ip) { | |
135 var addressRegex = RegExp('^([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 '([01]?\\d\\d?|2[0-4]\\d|25[0-5])$'); | |
139 return addressRegex.test(ip); | |
140 }, | |
141 | |
142 /** | |
143 * @param {string} printerName | |
144 * @param {string} printerAddress | |
145 * @return {boolean} | |
146 * @private | |
147 */ | |
148 addPrinterNotAllowed_: function(printerName, printerAddress) { | |
149 return !printerName || !printerAddress || | |
150 !this.isValidIpAddress_(printerAddress); | |
151 }, | 116 }, |
152 }); | 117 }); |
153 | 118 |
154 Polymer({ | 119 Polymer({ |
155 is: 'add-printer-manufacturer-model-dialog', | 120 is: 'add-printer-manufacturer-model-dialog', |
156 | 121 |
157 properties: { | 122 properties: { |
158 /** @type {!CupsPrinterInfo} */ | 123 /** @type {!CupsPrinterInfo} */ |
159 newPrinter: { | 124 newPrinter: { |
160 type: Object, | 125 type: Object, |
161 notify: true, | 126 notify: true, |
162 }, | 127 }, |
163 | 128 |
164 /** @type {!Array<string>} */ | 129 /** @type {!Array<string>} */ |
165 manufacturerList: { | 130 manufacturerList: { |
166 type: Array, | 131 type: Array, |
167 }, | 132 }, |
168 | 133 |
169 /** @type {!Array<string>} */ | 134 /** @type {!Array<string>} */ |
170 modelList: { | 135 modelList: { |
171 type: Array, | 136 type: Array, |
172 }, | 137 }, |
138 | |
139 setupFailed: { | |
140 type: Boolean, | |
141 value: false, | |
142 }, | |
173 }, | 143 }, |
174 | 144 |
175 observers: [ | 145 observers: [ |
176 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', | 146 'selectedManufacturerChanged_(newPrinter.printerManufacturer)', |
177 ], | 147 ], |
178 | 148 |
179 /** @override */ | 149 /** @override */ |
180 ready: function() { | 150 ready: function() { |
181 // TODO(xdai): Get available manufacturerList after the API is ready. | 151 // TODO(xdai): Get available manufacturerList after the API is ready. |
182 }, | 152 }, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 attached: function() { | 210 attached: function() { |
241 this.$.configuringMessage.textContent = loadTimeData.getStringF( | 211 this.$.configuringMessage.textContent = loadTimeData.getStringF( |
242 'printerConfiguringMessage', this.printerName); | 212 'printerConfiguringMessage', this.printerName); |
243 }, | 213 }, |
244 | 214 |
245 /** @private */ | 215 /** @private */ |
246 onCancelConfiguringTap_: function() { | 216 onCancelConfiguringTap_: function() { |
247 this.$$('add-printer-dialog').close(); | 217 this.$$('add-printer-dialog').close(); |
248 this.fire('configuring-dialog-closed'); | 218 this.fire('configuring-dialog-closed'); |
249 }, | 219 }, |
220 | |
221 close: function() { | |
222 this.$$('add-printer-dialog').close(); | |
223 }, | |
250 }); | 224 }); |
251 | 225 |
252 Polymer({ | 226 Polymer({ |
253 is: 'settings-cups-add-printer-dialog', | 227 is: 'settings-cups-add-printer-dialog', |
254 | 228 |
229 behaviors: [WebUIListenerBehavior], | |
230 | |
255 properties: { | 231 properties: { |
256 /** @type {!CupsPrinterInfo} */ | 232 /** @type {!CupsPrinterInfo} */ |
257 selectedPrinter: { | 233 selectedPrinter: { |
258 type: Object, | 234 type: Object, |
259 }, | 235 }, |
260 | 236 |
261 /** @type {!CupsPrinterInfo} */ | 237 /** @type {!CupsPrinterInfo} */ |
262 newPrinter: { | 238 newPrinter: { |
263 type: Object, | 239 type: Object, |
264 }, | 240 }, |
265 | 241 |
242 /** @type {boolean} whether the new printer setup is failed. */ | |
243 setupFailed: { | |
244 type: Boolean, | |
245 value: false, | |
246 }, | |
247 | |
266 /** @private {string} */ | 248 /** @private {string} */ |
267 previousDialog_: String, | 249 previousDialog_: String, |
268 | 250 |
269 /** @private {string} */ | 251 /** @private {string} */ |
270 currentDialog_: String, | 252 currentDialog_: String, |
271 | 253 |
272 /** @private {boolean} */ | 254 /** @private {boolean} */ |
273 showDiscoveryDialog_: Boolean, | 255 showDiscoveryDialog_: Boolean, |
274 | 256 |
275 /** @private {boolean} */ | 257 /** @private {boolean} */ |
276 showManuallyAddDialog_: Boolean, | 258 showManuallyAddDialog_: Boolean, |
277 | 259 |
278 /** @private {boolean} */ | 260 /** @private {boolean} */ |
279 showConfiguringDialog_: Boolean, | 261 showConfiguringDialog_: Boolean, |
280 | 262 |
281 /** @private {boolean} */ | 263 /** @private {boolean} */ |
282 showManufacturerDialog_: Boolean, | 264 showManufacturerDialog_: Boolean, |
283 }, | 265 }, |
284 | 266 |
285 listeners: { | 267 listeners: { |
286 'configuring-dialog-closed': 'configuringDialogClosed_', | 268 'configuring-dialog-closed': 'configuringDialogClosed_', |
287 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', | 269 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', |
288 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', | 270 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', |
289 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', | 271 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', |
290 'open-manufacturer-model-dialog': 'openManufacturerModelDialog_', | 272 'open-manufacturer-model-dialog': 'openManufacturerModelDialog_', |
291 }, | 273 }, |
292 | 274 |
275 /** @override */ | |
276 ready: function() { | |
277 this.addWebUIListener('on-add-cups-printer', this.onAddPrinter_.bind(this)); | |
278 }, | |
279 | |
293 /** Opens the Add printer discovery dialog. */ | 280 /** Opens the Add printer discovery dialog. */ |
294 open: function() { | 281 open: function() { |
282 this.resetData_(); | |
295 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); | 283 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); |
296 }, | 284 }, |
297 | 285 |
286 /** | |
287 * Reset all the printer data in the Add printer flow. | |
288 * @private | |
289 */ | |
290 resetData_: function() { | |
291 if (this.selectedPrinter) | |
292 this.resetPrinterData_(this.selectedPrinter); | |
293 if (this.newPrinter) | |
294 this.resetPrinterData_(this.newPrinter); | |
295 this.setupFailed = false; | |
296 }, | |
297 | |
298 /** | |
299 * @param {!CupsPrinterInfo} printer | |
300 * @private | |
301 */ | |
302 resetPrinterData_: function(printer) { | |
303 printer.printerAddress = ''; | |
304 printer.printerDescription = ''; | |
305 printer.printerId = ''; | |
306 printer.printerManufacturer = ''; | |
307 printer.printerModel = ''; | |
308 printer.printerName = ''; | |
309 printer.printerProtocol = 'ipp'; | |
310 printer.printerQueue = ''; | |
311 printer.printerStatus = ''; | |
312 printer.printerPPDPath = ''; | |
313 }, | |
314 | |
298 /** @private */ | 315 /** @private */ |
299 openManuallyAddPrinterDialog_: function() { | 316 openManuallyAddPrinterDialog_: function() { |
300 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, | 317 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, |
301 'showManuallyAddDialog_'); | 318 'showManuallyAddDialog_'); |
302 }, | 319 }, |
303 | 320 |
304 /** @private */ | 321 /** @private */ |
305 openDiscoveryPrintersDialog_: function() { | 322 openDiscoveryPrintersDialog_: function() { |
306 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, | 323 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, |
307 'showDiscoveryDialog_'); | 324 'showDiscoveryDialog_'); |
308 }, | 325 }, |
309 | 326 |
310 /** @private */ | 327 /** @private */ |
311 openConfiguringPrinterDialog_: function() { | 328 openConfiguringPrinterDialog_: function() { |
312 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, | 329 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, |
313 'showConfiguringDialog_'); | 330 'showConfiguringDialog_'); |
331 settings.CupsPrintersBrowserProxyImpl.getInstance(). | |
332 addCupsPrinter(this.newPrinter); | |
314 }, | 333 }, |
315 | 334 |
316 /** @private */ | 335 /** @private */ |
317 openManufacturerModelDialog_: function() { | 336 openManufacturerModelDialog_: function() { |
318 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | 337 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, |
319 'showManufacturerDialog_'); | 338 'showManufacturerDialog_'); |
320 }, | 339 }, |
321 | 340 |
322 /** @private */ | 341 /** @private */ |
323 configuringDialogClosed_: function() { | 342 configuringDialogClosed_: function() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 */ | 379 */ |
361 getConfiguringPrinterName_: function() { | 380 getConfiguringPrinterName_: function() { |
362 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) | 381 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) |
363 return this.selectedPrinter.printerName; | 382 return this.selectedPrinter.printerName; |
364 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || | 383 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY || |
365 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { | 384 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) { |
366 return this.newPrinter.printerName; | 385 return this.newPrinter.printerName; |
367 } | 386 } |
368 return ''; | 387 return ''; |
369 }, | 388 }, |
389 | |
390 /** | |
391 * @param {boolean} success | |
392 * @param {string} printerName | |
393 * @private | |
394 */ | |
395 onAddPrinter_: function(success, printerName) { | |
396 this.$$('add-printer-configuring-dialog').close(); | |
397 if (success) | |
398 return; | |
399 | |
400 if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) | |
401 this.setupFailed = true; | |
402 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER, | |
403 'showManufacturerDialog_'); | |
404 }, | |
370 }); | 405 }); |
OLD | NEW |