| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * An object that represents a user modifiable item in a print ticket. Each | 9 * An object that represents a user modifiable item in a print ticket. Each |
| 10 * ticket item has a value which can be set by the user. Ticket items can also | 10 * ticket item has a value which can be set by the user. Ticket items can also |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Used listen for changes in the currently selected destination's | 32 * Used listen for changes in the currently selected destination's |
| 33 * capabilities. | 33 * capabilities. |
| 34 * @private {print_preview.DestinationStore} | 34 * @private {print_preview.DestinationStore} |
| 35 */ | 35 */ |
| 36 this.destinationStore_ = destinationStore || null; | 36 this.destinationStore_ = destinationStore || null; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Vendor ticket items store, maps item id to the item value. | 39 * Vendor ticket items store, maps item id to the item value. |
| 40 * @private {!Object.<string, string>} | 40 * @private {!Object<string, string>} |
| 41 */ | 41 */ |
| 42 this.items_ = {}; | 42 this.items_ = {}; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 VendorItems.prototype = { | 45 VendorItems.prototype = { |
| 46 __proto__: cr.EventTarget.prototype, | 46 __proto__: cr.EventTarget.prototype, |
| 47 | 47 |
| 48 /** @return {boolean} Whether vendor capabilities are available. */ | 48 /** @return {boolean} Whether vendor capabilities are available. */ |
| 49 isCapabilityAvailable: function() { | 49 isCapabilityAvailable: function() { |
| 50 return !!this.capability; | 50 return !!this.capability; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 71 return null; | 71 return null; |
| 72 } | 72 } |
| 73 return (destination.capabilities && | 73 return (destination.capabilities && |
| 74 destination.capabilities.printer && | 74 destination.capabilities.printer && |
| 75 destination.capabilities.printer.vendor_capability) || | 75 destination.capabilities.printer.vendor_capability) || |
| 76 null; | 76 null; |
| 77 }, | 77 }, |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Vendor ticket items store, maps item id to the item value. | 80 * Vendor ticket items store, maps item id to the item value. |
| 81 * @return {!Object.<string, string>} | 81 * @return {!Object<string, string>} |
| 82 */ | 82 */ |
| 83 get ticketItems() { | 83 get ticketItems() { |
| 84 return this.items_; | 84 return this.items_; |
| 85 }, | 85 }, |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @param {!Object.<string, string>} values Values to set as the values of | 88 * @param {!Object<string, string>} values Values to set as the values of |
| 89 * vendor ticket items. Maps vendor item id to the value. | 89 * vendor ticket items. Maps vendor item id to the value. |
| 90 */ | 90 */ |
| 91 updateValue: function(values) { | 91 updateValue: function(values) { |
| 92 this.items_ = {}; | 92 this.items_ = {}; |
| 93 if (typeof values == 'object') { | 93 if (typeof values == 'object') { |
| 94 for (var key in values) { | 94 for (var key in values) { |
| 95 if (values.hasOwnProperty(key) && typeof values[key] == 'string') { | 95 if (values.hasOwnProperty(key) && typeof values[key] == 'string') { |
| 96 // Let's empirically limit each value at 2K. | 96 // Let's empirically limit each value at 2K. |
| 97 this.items_[key] = values[key].substring(0, 2048); | 97 this.items_[key] = values[key].substring(0, 2048); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 if (this.appState_) { | 102 if (this.appState_) { |
| 103 this.appState_.persistField( | 103 this.appState_.persistField( |
| 104 print_preview.AppState.Field.VENDOR_OPTIONS, this.items_); | 104 print_preview.AppState.Field.VENDOR_OPTIONS, this.items_); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 // Export | 109 // Export |
| 110 return { | 110 return { |
| 111 VendorItems: VendorItems | 111 VendorItems: VendorItems |
| 112 }; | 112 }; |
| 113 }); | 113 }); |
| OLD | NEW |