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 * Creates a ColorSettings object. This object encapsulates all settings and | 9 * Creates a ColorSettings object. This object encapsulates all settings and |
10 * logic related to color selection (color/bw). | 10 * logic related to color selection (color/bw). |
11 * @param {!print_preview.ticket_item.Color} colorTicketItem Used for writing | 11 * @param {!print_preview.ticket_item.Color} colorTicketItem Used for writing |
12 * and reading color value. | 12 * and reading color value. |
13 * @constructor | 13 * @constructor |
14 * @extends {print_preview.Component} | 14 * @extends {print_preview.SettingsSection} |
15 */ | 15 */ |
16 function ColorSettings(colorTicketItem) { | 16 function ColorSettings(colorTicketItem) { |
17 print_preview.Component.call(this); | 17 print_preview.SettingsSection.call(this); |
18 | 18 |
19 /** | 19 /** |
20 * Used for reading/writing the color value. | 20 * Used for reading/writing the color value. |
21 * @type {!print_preview.ticket_items.Color} | 21 * @type {!print_preview.ticket_items.Color} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.colorTicketItem_ = colorTicketItem; | 24 this.colorTicketItem_ = colorTicketItem; |
25 }; | 25 }; |
26 | 26 |
27 ColorSettings.prototype = { | 27 ColorSettings.prototype = { |
28 __proto__: print_preview.Component.prototype, | 28 __proto__: print_preview.SettingsSection.prototype, |
29 | 29 |
| 30 /** @override */ |
| 31 isAvailable: function() { |
| 32 return this.colorTicketItem_.isCapabilityAvailable(); |
| 33 }, |
| 34 |
| 35 /** @override */ |
| 36 hasCollapsibleContent: function() { |
| 37 return false; |
| 38 }, |
| 39 |
| 40 /** @override */ |
30 set isEnabled(isEnabled) { | 41 set isEnabled(isEnabled) { |
31 this.getChildElement('.color-option').disabled = !isEnabled; | 42 this.getChildElement('.color-option').disabled = !isEnabled; |
32 this.getChildElement('.bw-option').disabled = !isEnabled; | 43 this.getChildElement('.bw-option').disabled = !isEnabled; |
33 }, | 44 }, |
34 | 45 |
35 /** @override */ | 46 /** @override */ |
36 enterDocument: function() { | 47 enterDocument: function() { |
37 print_preview.Component.prototype.enterDocument.call(this); | 48 print_preview.SettingsSection.prototype.enterDocument.call(this); |
38 fadeOutOption(this.getElement(), true); | |
39 this.tracker.add( | 49 this.tracker.add( |
40 this.getChildElement('.color-option'), | 50 this.getChildElement('.color-option'), |
41 'click', | 51 'click', |
42 this.colorTicketItem_.updateValue.bind(this.colorTicketItem_, true)); | 52 this.colorTicketItem_.updateValue.bind(this.colorTicketItem_, true)); |
43 this.tracker.add( | 53 this.tracker.add( |
44 this.getChildElement('.bw-option'), | 54 this.getChildElement('.bw-option'), |
45 'click', | 55 'click', |
46 this.colorTicketItem_.updateValue.bind(this.colorTicketItem_, false)); | 56 this.colorTicketItem_.updateValue.bind(this.colorTicketItem_, false)); |
47 this.tracker.add( | 57 this.tracker.add( |
48 this.colorTicketItem_, | 58 this.colorTicketItem_, |
49 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 59 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
50 this.updateState_.bind(this)); | 60 this.updateState_.bind(this)); |
51 }, | 61 }, |
52 | 62 |
53 /** | 63 /** |
54 * Updates state of the widget. | 64 * Updates state of the widget. |
55 * @private | 65 * @private |
56 */ | 66 */ |
57 updateState_: function() { | 67 updateState_: function() { |
58 var isColorCapAvailable = this.colorTicketItem_.isCapabilityAvailable(); | 68 if (this.isAvailable()) { |
59 if (isColorCapAvailable) { | |
60 fadeInOption(this.getElement()); | |
61 var isColorEnabled = this.colorTicketItem_.getValue(); | 69 var isColorEnabled = this.colorTicketItem_.getValue(); |
62 this.getChildElement('.color-option').checked = isColorEnabled; | 70 this.getChildElement('.color-option').checked = isColorEnabled; |
63 this.getChildElement('.bw-option').checked = !isColorEnabled; | 71 this.getChildElement('.bw-option').checked = !isColorEnabled; |
64 } else { | |
65 fadeOutOption(this.getElement()); | |
66 } | 72 } |
67 this.getElement().setAttribute('aria-hidden', !isColorCapAvailable); | 73 this.updateUiStateInternal(); |
68 } | 74 } |
69 }; | 75 }; |
70 | 76 |
71 // Export | 77 // Export |
72 return { | 78 return { |
73 ColorSettings: ColorSettings | 79 ColorSettings: ColorSettings |
74 }; | 80 }; |
75 }); | 81 }); |
OLD | NEW |