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

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

Issue 2304673002: [CUPS] Implelment Manufacturer and Model Dialog. (Closed)
Patch Set: Address michaelpg@'s comment. Rebase. 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.
11 * - 'add-printer-maually-dialog' is a dialog in which user can manually enter 11 * - 'add-printer-maually-dialog' is a dialog in which user can manually enter
12 * the information to set up a new printer. 12 * the information to set up a new printer.
13 * - 'add-printer-configuring-dialog' is the configuring-in-progress dialog. 13 * - 'add-printer-configuring-dialog' is the configuring-in-progress dialog.
14 * - 'add-printer-manufacturer-model-dialog' is a dialog in which the user can
15 * manually select the manufacture and model of the new printer.
14 */ 16 */
15 17
16 /** 18 /**
17 * Different dialogs in add printer flow. 19 * Different dialogs in add printer flow.
18 * @enum {string} 20 * @enum {string}
19 */ 21 */
20 var AddPrinterDialogs = { 22 var AddPrinterDialogs = {
21 DISCOVERY: 'add-printer-discovery-dialog', 23 DISCOVERY: 'add-printer-discovery-dialog',
22 MANUALLY: 'add-printer-maually-dialog', 24 MANUALLY: 'add-printer-maually-dialog',
23 CONFIGURING: 'add-printer-configuring-dialog', 25 CONFIGURING: 'add-printer-configuring-dialog',
26 MANUFACTURER: 'add-printer-manufacturer-model-dialog',
24 }; 27 };
25 28
26 Polymer({ 29 Polymer({
27 is: 'add-printer-discovery-dialog', 30 is: 'add-printer-discovery-dialog',
28 31
29 properties: { 32 properties: {
30 /** @type {!Array<!CupsPrinterInfo>} */ 33 /** @type {!Array<!CupsPrinterInfo>} */
31 discoveredPrinters: { 34 discoveredPrinters: {
32 type: Array, 35 type: Array,
33 }, 36 },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 this.$$('add-printer-dialog').close(); 94 this.$$('add-printer-dialog').close();
92 this.fire('open-discovery-printers-dialog'); 95 this.fire('open-discovery-printers-dialog');
93 }, 96 },
94 97
95 /** @private */ 98 /** @private */
96 onCancelTap_: function() { 99 onCancelTap_: function() {
97 this.$$('add-printer-dialog').close(); 100 this.$$('add-printer-dialog').close();
98 }, 101 },
99 102
100 /** @private */ 103 /** @private */
104 switchToManufacturerDialog_: function() {
105 this.$$('add-printer-dialog').close();
106 this.fire('open-manufacturer-model-dialog');
107 },
108
109 /** @private */
110 onAddressChanged_: function() {
111 this.$.searchInProgress.hidden = false;
112 this.$.searchFound.hidden = true;
113 this.$.searchNotFound.hidden = true;
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 },
151 });
152
153 Polymer({
154 is: 'add-printer-manufacturer-model-dialog',
155
156 properties: {
157 /** @type {!CupsPrinterInfo} */
158 newPrinter: {
159 type: Object,
160 notify: true,
161 },
162
163 /** @type {!Array<string>} */
164 manufacturerList: {
165 type: Array,
166 },
167
168 /** @type {!Array<string>} */
169 modelList: {
170 type: Array,
171 },
172 },
173
174 observers: [
175 'selectedManufacturerChanged_(newPrinter.printerManufacturer)',
176 ],
177
178 /** @override */
179 ready: function() {
180 // TODO(xdai): Get available manufacturerList after the API is ready.
181 },
182
183 /** @private */
184 selectedManufacturerChanged_: function() {
185 // TODO(xdai): Get available modelList for a selected manufacturer after
186 // the API is ready.
187 },
188
189 /** @private */
190 switchToManualAddDialog_: function() {
191 this.$$('add-printer-dialog').close();
192 this.fire('open-manually-add-printer-dialog');
193 },
194
195 /** @private */
196 onCancelTap_: function() {
197 this.$$('add-printer-dialog').close();
198 },
199
200 /** @private */
101 switchToConfiguringDialog_: function() { 201 switchToConfiguringDialog_: function() {
102 this.$$('add-printer-dialog').close(); 202 this.$$('add-printer-dialog').close();
103 this.fire('open-configuring-printer-dialog'); 203 this.fire('open-configuring-printer-dialog');
104 }, 204 },
105 }); 205 });
106 206
107 Polymer({ 207 Polymer({
108 is: 'add-printer-configuring-dialog', 208 is: 'add-printer-configuring-dialog',
109 209
110 properties: { 210 properties: {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 currentDialog_: String, 245 currentDialog_: String,
146 246
147 /** @private {boolean} */ 247 /** @private {boolean} */
148 showDiscoveryDialog_: Boolean, 248 showDiscoveryDialog_: Boolean,
149 249
150 /** @private {boolean} */ 250 /** @private {boolean} */
151 showManuallyAddDialog_: Boolean, 251 showManuallyAddDialog_: Boolean,
152 252
153 /** @private {boolean} */ 253 /** @private {boolean} */
154 showConfiguringDialog_: Boolean, 254 showConfiguringDialog_: Boolean,
255
256 /** @private {boolean} */
257 showManufacturerDialog_: Boolean,
155 }, 258 },
156 259
157 listeners: { 260 listeners: {
158 'configuring-dialog-closed': 'configuringDialogClosed_', 261 'configuring-dialog-closed': 'configuringDialogClosed_',
159 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_', 262 'open-manually-add-printer-dialog': 'openManuallyAddPrinterDialog_',
160 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_', 263 'open-configuring-printer-dialog': 'openConfiguringPrinterDialog_',
161 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_', 264 'open-discovery-printers-dialog': 'openDiscoveryPrintersDialog_',
265 'open-manufacturer-model-dialog': 'openManufacturerModelDialog_',
162 }, 266 },
163 267
164 /** Opens the Add printer discovery dialog. */ 268 /** Opens the Add printer discovery dialog. */
165 open: function() { 269 open: function() {
166 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_'); 270 this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_');
167 }, 271 },
168 272
169 /** @private */ 273 /** @private */
170 openManuallyAddPrinterDialog_: function() { 274 openManuallyAddPrinterDialog_: function() {
171 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY, 275 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY,
172 'showManuallyAddDialog_'); 276 'showManuallyAddDialog_');
173 }, 277 },
174 278
175 /** @private */ 279 /** @private */
176 openDiscoveryPrintersDialog_: function() { 280 openDiscoveryPrintersDialog_: function() {
177 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY, 281 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.DISCOVERY,
178 'showDiscoveryDialog_'); 282 'showDiscoveryDialog_');
179 }, 283 },
180 284
181 /** @private */ 285 /** @private */
182 openConfiguringPrinterDialog_: function() { 286 openConfiguringPrinterDialog_: function() {
183 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING, 287 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.CONFIGURING,
184 'showConfiguringDialog_'); 288 'showConfiguringDialog_');
185 }, 289 },
186 290
187 /** @private */ 291 /** @private */
292 openManufacturerModelDialog_: function() {
293 this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUFACTURER,
294 'showManufacturerDialog_');
295 },
296
297 /** @private */
188 configuringDialogClosed_: function() { 298 configuringDialogClosed_: function() {
189 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) { 299 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) {
190 this.switchDialog_( 300 this.switchDialog_(
191 this.currentDialog_, this.previousDialog_, 'showDiscoveryDialog_'); 301 this.currentDialog_, this.previousDialog_, 'showDiscoveryDialog_');
192 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) { 302 } else if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) {
193 this.switchDialog_( 303 this.switchDialog_(
194 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_'); 304 this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_');
305 } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
306 this.switchDialog_(
307 this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_');
195 } 308 }
196 }, 309 },
197 310
198 /** 311 /**
199 * Switch dialog from |fromDialog| to |toDialog|. 312 * Switch dialog from |fromDialog| to |toDialog|.
200 * @param {string} fromDialog 313 * @param {string} fromDialog
201 * @param {string} toDialog 314 * @param {string} toDialog
202 * @param {string} domIfBooleanName The name of the boolean variable 315 * @param {string} domIfBooleanName The name of the boolean variable
203 * corresponding to the |toDialog|. 316 * corresponding to the |toDialog|.
204 * @private 317 * @private
(...skipping 11 matching lines...) Expand all
216 }); 329 });
217 }, 330 },
218 331
219 /** 332 /**
220 * @return {string} The name of the current printer in configuration. 333 * @return {string} The name of the current printer in configuration.
221 * @private 334 * @private
222 */ 335 */
223 getConfiguringPrinterName_: function() { 336 getConfiguringPrinterName_: function() {
224 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) 337 if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY)
225 return this.selectedPrinter.printerName; 338 return this.selectedPrinter.printerName;
226 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) 339 if (this.previousDialog_ == AddPrinterDialogs.MANUALLY ||
340 this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
227 return this.newPrinter.printerName; 341 return this.newPrinter.printerName;
342 }
228 return ''; 343 return '';
229 }, 344 },
230 }); 345 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698