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

Unified Diff: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js

Issue 2825153002: Update CUPS settings UI to allow USB printers to be added via discovery. (Closed)
Patch Set: One more round of xdai comments. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js
diff --git a/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js b/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js
index d2270f7c1a2fe01b487d5cc35d01b936cc3ae8d7..eeaff4f8dbb9bd067db62cd3a4c4889463b1371d 100644
--- a/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js
+++ b/chrome/browser/resources/settings/printing_page/cups_add_printer_dialog.js
@@ -33,6 +33,25 @@ var AddPrinterDialogs = {
*/
var kPrinterListFullHeight = 350;
+/**
+ * Return a reset CupsPrinterInfo object.
+ * @return {!CupsPrinterInfo}
+ */
+function getEmptyPrinter_() {
+ return {
+ printerAddress: '',
+ printerDescription: '',
+ printerId: '',
+ printerManufacturer: '',
+ printerModel: '',
+ printerName: '',
+ printerPPDPath: '',
+ printerProtocol: 'ipp',
+ printerQueue: '',
+ printerStatus: '',
+ };
+}
+
Polymer({
is: 'add-printer-discovery-dialog',
@@ -99,6 +118,9 @@ Polymer({
/** @private */
switchToManualAddDialog_: function() {
this.stopDiscoveringPrinters_();
+ // We're abandoning discovery in favor of manual specification, so
+ // drop the selection if one exists.
+ this.selectedPrinter = getEmptyPrinter_();
this.$$('add-printer-dialog').close();
this.fire('open-manually-add-printer-dialog');
},
@@ -110,10 +132,16 @@ Polymer({
},
/** @private */
- switchToConfiguringDialog_: function() {
+ switchToManufacturerDialog_: function() {
this.stopDiscoveringPrinters_();
+ // If we're switching to the manufacturer/model dialog, clear the existing
+ // data we have about the PPD (if any), as we're dropping that in favor of
+ // user selections.
+ this.selectedPrinter.printerManufacturer = '';
+ this.selectedPrinter.printerModel = '';
+ this.selectedPrinter.printerPPDPath = '';
this.$$('add-printer-dialog').close();
- this.fire('open-configuring-printer-dialog');
+ this.fire('open-manufacturer-model-dialog');
},
});
@@ -125,20 +153,7 @@ Polymer({
newPrinter: {
type: Object,
notify: true,
- value: function() {
- return {
- printerAddress: '',
- printerDescription: '',
- printerId: '',
- printerManufacturer: '',
- printerModel: '',
- printerName: '',
- printerPPDPath: '',
- printerProtocol: 'ipp',
- printerQueue: '',
- printerStatus: '',
- };
- },
+ value: getEmptyPrinter_
},
},
@@ -199,6 +214,9 @@ Polymer({
type: Array,
},
+ /** @type {string} */
+ previousDialog: String,
+
setupFailed: {
type: Boolean,
value: false,
@@ -263,9 +281,13 @@ Polymer({
},
/** @private */
- switchToManualAddDialog_: function() {
+ switchToPreviousDialog_: function() {
this.$$('add-printer-dialog').close();
- this.fire('open-manually-add-printer-dialog');
+ if (this.previousDialog == AddPrinterDialogs.DISCOVERY) {
+ this.fire('open-discovery-printers-dialog');
+ } else if (this.previousDialog == AddPrinterDialogs.MANUALLY) {
+ this.fire('open-manually-add-printer-dialog');
+ }
},
/** @private */
@@ -320,11 +342,6 @@ Polymer({
behaviors: [WebUIListenerBehavior],
properties: {
- /** @type {!CupsPrinterInfo} */
- selectedPrinter: {
- type: Object,
- },
-
/** @type {!CupsPrinterInfo} */
newPrinter: {
type: Object,
@@ -338,8 +355,8 @@ Polymer({
configuringDialogTitle: String,
- /** @private {string} */
- previousDialog_: String,
+ /** @type {string} */
+ previousDialog: String,
/** @private {string} */
currentDialog_: String,
@@ -373,8 +390,7 @@ Polymer({
/** Opens the Add printer discovery dialog. */
open: function() {
this.resetData_();
- this.switchDialog_(
- '', AddPrinterDialogs.MANUALLY, 'showManuallyAddDialog_');
+ this.switchDialog_('', AddPrinterDialogs.DISCOVERY, 'showDiscoveryDialog_');
},
/**
@@ -382,32 +398,11 @@ Polymer({
* @private
*/
resetData_: function() {
- if (this.selectedPrinter)
- this.selectedPrinter = this.getEmptyPrinter_();
if (this.newPrinter)
- this.newPrinter = this.getEmptyPrinter_();
+ this.newPrinter = getEmptyPrinter_();
this.setupFailed = false;
},
- /**
- * @return {!CupsPrinterInfo}
- * @private
- */
- getEmptyPrinter_: function() {
- return {
- printerAddress: '',
- printerDescription: '',
- printerId: '',
- printerManufacturer: '',
- printerModel: '',
- printerName: '',
- printerPPDPath: '',
- printerProtocol: 'ipp',
- printerQueue: '',
- printerStatus: '',
- };
- },
-
/** @private */
openManuallyAddPrinterDialog_: function() {
this.switchDialog_(this.currentDialog_, AddPrinterDialogs.MANUALLY,
@@ -425,12 +420,12 @@ Polymer({
this.switchDialog_(
this.currentDialog_, AddPrinterDialogs.CONFIGURING,
'showConfiguringDialog_');
- if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY) {
+ if (this.previousDialog == AddPrinterDialogs.DISCOVERY) {
this.configuringDialogTitle =
loadTimeData.getString('addPrintersNearbyTitle');
settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
this.selectedPrinter);
- } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
+ } else if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
this.configuringDialogTitle =
loadTimeData.getString('addPrintersManuallyTitle');
settings.CupsPrintersBrowserProxyImpl.getInstance().addCupsPrinter(
@@ -446,12 +441,21 @@ Polymer({
/** @private */
configuringDialogClosed_: function() {
- if (this.previousDialog_ == AddPrinterDialogs.MANUALLY) {
+ // If the configuring dialog is closed, we want to return whence we came.
+ //
+ // TODO(justincarlson) - This shouldn't need to be a conditional;
+ // clean up the way we switch dialogs so we don't have to supply
+ // redundant information and can just return to the previous
+ // dialog.
+ if (this.previousDialog == AddPrinterDialogs.DISCOVERY) {
this.switchDialog_(
- this.currentDialog_, this.previousDialog_, 'showManuallyAddDialog_');
- } else if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
+ this.currentDialog_, this.previousDialog, 'showDiscoveryDialog_');
+ } else if (this.previousDialog == AddPrinterDialogs.MANUALLY) {
this.switchDialog_(
- this.currentDialog_, this.previousDialog_, 'showManufacturerDialog_');
+ this.currentDialog_, this.previousDialog, 'showManuallyAddDialog_');
+ } else if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
+ this.switchDialog_(
+ this.currentDialog_, this.previousDialog, 'showManufacturerDialog_');
}
},
@@ -464,7 +468,7 @@ Polymer({
* @private
*/
switchDialog_: function(fromDialog, toDialog, domIfBooleanName) {
- this.previousDialog_ = fromDialog;
+ this.previousDialog = fromDialog;
this.currentDialog_ = toDialog;
this.set(domIfBooleanName, true);
@@ -476,20 +480,6 @@ Polymer({
});
},
- /**
- * @return {string} The name of the current printer in configuration.
- * @private
- */
- getConfiguringPrinterName_: function() {
- if (this.previousDialog_ == AddPrinterDialogs.DISCOVERY)
- return this.selectedPrinter.printerName;
- if (this.previousDialog_ == AddPrinterDialogs.MANUALLY ||
- this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
- return this.newPrinter.printerName;
- }
- return '';
- },
-
/**
* @param {boolean} success
* @param {string} printerName
@@ -500,7 +490,7 @@ Polymer({
if (success)
return;
- if (this.previousDialog_ == AddPrinterDialogs.MANUFACTURER) {
+ if (this.previousDialog == AddPrinterDialogs.MANUFACTURER) {
this.setupFailed = true;
}
},

Powered by Google App Engine
This is Rietveld 408576698