| 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 * Encapsulates all settings and logic related to the media size selection UI. | 9 * Encapsulates all settings and logic related to the media size selection UI. |
| 10 * @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and | 10 * @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // TODO: Better heuristics for the display name and options grouping. | 70 // TODO: Better heuristics for the display name and options grouping. |
| 71 this.ticketItem_.capability.option.forEach(function(option, index) { | 71 this.ticketItem_.capability.option.forEach(function(option, index) { |
| 72 var selectOption = document.createElement('option'); | 72 var selectOption = document.createElement('option'); |
| 73 selectOption.text = option.custom_display_name || option.name; | 73 selectOption.text = option.custom_display_name || option.name; |
| 74 selectOption.value = JSON.stringify(option); | 74 selectOption.value = JSON.stringify(option); |
| 75 select.add(selectOption); | 75 select.add(selectOption); |
| 76 if (option.is_default) { | 76 if (option.is_default) { |
| 77 indexToSelect = index; | 77 indexToSelect = index; |
| 78 } | 78 } |
| 79 }); | 79 }); |
| 80 } else { | 80 } |
| 81 var valueToSelect = JSON.stringify(this.ticketItem_.getValue()); | 81 // Try to select current ticket item. |
| 82 for (var i = 0, option; option = select.options[i]; i++) { | 82 var valueToSelect = JSON.stringify(this.ticketItem_.getValue()); |
| 83 if (option.value == valueToSelect) { | 83 for (var i = 0, option; option = select.options[i]; i++) { |
| 84 indexToSelect = i; | 84 if (option.value == valueToSelect) { |
| 85 break; | 85 indexToSelect = i; |
| 86 } | 86 break; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 select.selectedIndex = indexToSelect; | 89 select.selectedIndex = indexToSelect; |
| 90 this.onSelectChange_(); |
| 90 }, | 91 }, |
| 91 | 92 |
| 92 /** | 93 /** |
| 93 * Called when the select element is changed. Updates the print ticket. | 94 * Called when the select element is changed. Updates the print ticket. |
| 94 * @private | 95 * @private |
| 95 */ | 96 */ |
| 96 onSelectChange_: function() { | 97 onSelectChange_: function() { |
| 97 var select = this.select_; | 98 var select = this.select_; |
| 98 var mediaSize = JSON.parse(select.options[select.selectedIndex].value); | 99 var mediaSize = JSON.parse(select.options[select.selectedIndex].value); |
| 99 this.ticketItem_.updateValue(mediaSize); | 100 this.ticketItem_.updateValue(mediaSize); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 fadeOutOption(this.getElement()); | 113 fadeOutOption(this.getElement()); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 // Export | 118 // Export |
| 118 return { | 119 return { |
| 119 MediaSizeSettings: MediaSizeSettings | 120 MediaSizeSettings: MediaSizeSettings |
| 120 }; | 121 }; |
| 121 }); | 122 }); |
| OLD | NEW |