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

Side by Side Diff: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js

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

Powered by Google App Engine
This is Rietveld 408576698