Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Object used to get and persist the print preview application state. | 9 * Object used to get and persist the print preview application state. |
| 10 * @constructor | 10 * @constructor |
| 11 */ | 11 */ |
| 12 function AppState() { | 12 function AppState() { |
| 13 /** | 13 /** |
| 14 * Internal representation of application state. | 14 * Internal representation of application state. |
| 15 * @type {Object.<string: Object>} | 15 * @type {Object.<string,print_preview.ValueType>} |
|
Aleksey Shlyapnikov
2014/09/22 22:00:40
Space after comma.
Vitaly Pavlenko
2014/09/22 22:33:10
Done.
| |
| 16 * @private | 16 * @private |
| 17 */ | 17 */ |
| 18 this.state_ = {}; | 18 this.state_ = {}; |
| 19 this.state_[AppState.Field.VERSION] = AppState.VERSION_; | 19 this.state_[AppState.Field.VERSION] = AppState.VERSION_; |
| 20 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = true; | 20 this.state_[AppState.Field.IS_GCP_PROMO_DISMISSED] = true; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Whether the app state has been initialized. The app state will ignore all | 23 * Whether the app state has been initialized. The app state will ignore all |
| 24 * writes until it has been initialized. | 24 * writes until it has been initialized. |
| 25 * @type {boolean} | 25 * @type {boolean} |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 49 /** @return {?string} ID of the selected destination. */ | 49 /** @return {?string} ID of the selected destination. */ |
| 50 get selectedDestinationId() { | 50 get selectedDestinationId() { |
| 51 return this.state_[AppState.Field.SELECTED_DESTINATION_ID]; | 51 return this.state_[AppState.Field.SELECTED_DESTINATION_ID]; |
| 52 }, | 52 }, |
| 53 | 53 |
| 54 /** @return {?string} Account the selected destination is registered for. */ | 54 /** @return {?string} Account the selected destination is registered for. */ |
| 55 get selectedDestinationAccount() { | 55 get selectedDestinationAccount() { |
| 56 return this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT]; | 56 return this.state_[AppState.Field.SELECTED_DESTINATION_ACCOUNT]; |
| 57 }, | 57 }, |
| 58 | 58 |
| 59 /** @return {?string} Origin of the selected destination. */ | 59 /** |
| 60 * @return {?print_preview.Destination.Origin.<string>} Origin of the | |
| 61 * selected destination. | |
| 62 */ | |
| 60 get selectedDestinationOrigin() { | 63 get selectedDestinationOrigin() { |
| 61 return this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]; | 64 return this.state_[AppState.Field.SELECTED_DESTINATION_ORIGIN]; |
| 62 }, | 65 }, |
| 63 | 66 |
| 64 /** @return {?print_preview.Cdd} CDD of the selected destination. */ | 67 /** @return {?print_preview.Cdd} CDD of the selected destination. */ |
| 65 get selectedDestinationCapabilities() { | 68 get selectedDestinationCapabilities() { |
| 66 return this.state_[AppState.Field.SELECTED_DESTINATION_CAPABILITIES]; | 69 return this.state_[AppState.Field.SELECTED_DESTINATION_CAPABILITIES]; |
| 67 }, | 70 }, |
| 68 | 71 |
| 69 /** @return {?string} Name of the selected destination. */ | 72 /** @return {?string} Name of the selected destination. */ |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 80 * @param {!print_preview.AppState.Field} field App state field to check if | 83 * @param {!print_preview.AppState.Field} field App state field to check if |
| 81 * set. | 84 * set. |
| 82 * @return {boolean} Whether a field has been set in the app state. | 85 * @return {boolean} Whether a field has been set in the app state. |
| 83 */ | 86 */ |
| 84 hasField: function(field) { | 87 hasField: function(field) { |
| 85 return this.state_.hasOwnProperty(field); | 88 return this.state_.hasOwnProperty(field); |
| 86 }, | 89 }, |
| 87 | 90 |
| 88 /** | 91 /** |
| 89 * @param {!print_preview.AppState.Field} field App state field to get. | 92 * @param {!print_preview.AppState.Field} field App state field to get. |
| 90 * @return {Object} Value of the app state field. | 93 * @return {print_preview.ValueType} Value of the app state field. |
| 91 */ | 94 */ |
| 92 getField: function(field) { | 95 getField: function(field) { |
| 93 if (field == AppState.Field.CUSTOM_MARGINS) { | 96 if (field == AppState.Field.CUSTOM_MARGINS) { |
| 94 return this.state_[field] ? | 97 return this.state_[field] ? |
| 95 print_preview.Margins.parse(this.state_[field]) : null; | 98 print_preview.Margins.parse(this.state_[field]) : null; |
| 96 } else { | 99 } else { |
| 97 return this.state_[field]; | 100 return this.state_[field]; |
| 98 } | 101 } |
| 99 }, | 102 }, |
| 100 | 103 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 /** | 135 /** |
| 133 * Sets to initialized state. Now object will accept persist requests. | 136 * Sets to initialized state. Now object will accept persist requests. |
| 134 */ | 137 */ |
| 135 setInitialized: function() { | 138 setInitialized: function() { |
| 136 this.isInitialized_ = true; | 139 this.isInitialized_ = true; |
| 137 }, | 140 }, |
| 138 | 141 |
| 139 /** | 142 /** |
| 140 * Persists the given value for the given field. | 143 * Persists the given value for the given field. |
| 141 * @param {!print_preview.AppState.Field} field Field to persist. | 144 * @param {!print_preview.AppState.Field} field Field to persist. |
| 142 * @param {Object} value Value of field to persist. | 145 * @param {print_preview.ValueType} value Value of field to persist. |
| 143 */ | 146 */ |
| 144 persistField: function(field, value) { | 147 persistField: function(field, value) { |
| 145 if (!this.isInitialized_) | 148 if (!this.isInitialized_) |
| 146 return; | 149 return; |
| 147 if (field == AppState.Field.CUSTOM_MARGINS) { | 150 if (field == AppState.Field.CUSTOM_MARGINS) { |
| 148 this.state_[field] = value ? value.serialize() : null; | 151 this.state_[field] = value ? value.serialize() : null; |
| 149 } else { | 152 } else { |
| 150 this.state_[field] = value; | 153 this.state_[field] = value; |
| 151 } | 154 } |
| 152 this.persist_(); | 155 this.persist_(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 MARGINS_TYPE: 'marginsType', | 214 MARGINS_TYPE: 'marginsType', |
| 212 CUSTOM_MARGINS: 'customMargins', | 215 CUSTOM_MARGINS: 'customMargins', |
| 213 IS_COLOR_ENABLED: 'isColorEnabled', | 216 IS_COLOR_ENABLED: 'isColorEnabled', |
| 214 IS_DUPLEX_ENABLED: 'isDuplexEnabled', | 217 IS_DUPLEX_ENABLED: 'isDuplexEnabled', |
| 215 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', | 218 IS_HEADER_FOOTER_ENABLED: 'isHeaderFooterEnabled', |
| 216 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', | 219 IS_LANDSCAPE_ENABLED: 'isLandscapeEnabled', |
| 217 IS_COLLATE_ENABLED: 'isCollateEnabled', | 220 IS_COLLATE_ENABLED: 'isCollateEnabled', |
| 218 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled', | 221 IS_CSS_BACKGROUND_ENABLED: 'isCssBackgroundEnabled', |
| 219 VENDOR_OPTIONS: 'vendorOptions' | 222 VENDOR_OPTIONS: 'vendorOptions' |
| 220 }; | 223 }; |
| OLD | NEW |