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', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Base class for the printer option element visualizing the generic selection | 9 * Base class for the printer option element visualizing the generic selection |
10 * based option. | 10 * based option. |
(...skipping 23 matching lines...) Expand all Loading... |
34 }, | 34 }, |
35 | 35 |
36 /** @override */ | 36 /** @override */ |
37 set isEnabled(isEnabled) { | 37 set isEnabled(isEnabled) { |
38 this.select_.disabled = !isEnabled; | 38 this.select_.disabled = !isEnabled; |
39 }, | 39 }, |
40 | 40 |
41 /** @override */ | 41 /** @override */ |
42 enterDocument: function() { | 42 enterDocument: function() { |
43 print_preview.SettingsSection.prototype.enterDocument.call(this); | 43 print_preview.SettingsSection.prototype.enterDocument.call(this); |
44 this.tracker.add(assert(this.select_), | 44 this.tracker.add( |
45 'change', | 45 assert(this.select_), 'change', this.onSelectChange_.bind(this)); |
46 this.onSelectChange_.bind(this)); | 46 this.tracker.add( |
47 this.tracker.add(this.ticketItem_, | 47 this.ticketItem_, |
48 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 48 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
49 this.onTicketItemChange_.bind(this)); | 49 this.onTicketItemChange_.bind(this)); |
50 }, | 50 }, |
51 | 51 |
52 /** | 52 /** |
53 * @return {HTMLSelectElement} Select element containing option items. | 53 * @return {HTMLSelectElement} Select element containing option items. |
54 * @private | 54 * @private |
55 */ | 55 */ |
56 get select_() { | 56 get select_() { |
57 return this.getElement().querySelector('.settings-select'); | 57 return this.getElement().querySelector('.settings-select'); |
58 }, | 58 }, |
59 | 59 |
(...skipping 13 matching lines...) Expand all Loading... |
73 this.ticketItem_.capability.option.length == select.length && | 73 this.ticketItem_.capability.option.length == select.length && |
74 this.ticketItem_.capability.option.every(function(option, index) { | 74 this.ticketItem_.capability.option.every(function(option, index) { |
75 return select.options[index].value == JSON.stringify(option); | 75 return select.options[index].value == JSON.stringify(option); |
76 }); | 76 }); |
77 var indexToSelect = select.selectedIndex; | 77 var indexToSelect = select.selectedIndex; |
78 if (!sameContent) { | 78 if (!sameContent) { |
79 select.innerHTML = ''; | 79 select.innerHTML = ''; |
80 this.ticketItem_.capability.option.forEach(function(option, index) { | 80 this.ticketItem_.capability.option.forEach(function(option, index) { |
81 var selectOption = document.createElement('option'); | 81 var selectOption = document.createElement('option'); |
82 selectOption.text = this.getCustomDisplayName_(option) || | 82 selectOption.text = this.getCustomDisplayName_(option) || |
83 this.getDefaultDisplayName_(option); | 83 this.getDefaultDisplayName_(option); |
84 selectOption.value = JSON.stringify(option); | 84 selectOption.value = JSON.stringify(option); |
85 select.appendChild(selectOption); | 85 select.appendChild(selectOption); |
86 if (option.is_default) | 86 if (option.is_default) |
87 indexToSelect = index; | 87 indexToSelect = index; |
88 }, this); | 88 }, this); |
89 } | 89 } |
90 // Try to select current ticket item. | 90 // Try to select current ticket item. |
91 var valueToSelect = JSON.stringify(this.ticketItem_.getValue()); | 91 var valueToSelect = JSON.stringify(this.ticketItem_.getValue()); |
92 for (var i = 0, option; (option = select.options[i]); i++) { | 92 for (var i = 0, option; (option = select.options[i]); i++) { |
93 if (option.value == valueToSelect) { | 93 if (option.value == valueToSelect) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 * select option. | 137 * select option. |
138 * @private | 138 * @private |
139 */ | 139 */ |
140 onTicketItemChange_: function() { | 140 onTicketItemChange_: function() { |
141 this.updateSelect_(); | 141 this.updateSelect_(); |
142 this.updateUiStateInternal(); | 142 this.updateUiStateInternal(); |
143 } | 143 } |
144 }; | 144 }; |
145 | 145 |
146 // Export | 146 // Export |
147 return { | 147 return {SettingsSectionSelect: SettingsSectionSelect}; |
148 SettingsSectionSelect: SettingsSectionSelect | |
149 }; | |
150 }); | 148 }); |
OLD | NEW |