OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CopiesSettings object. | 9 * Creates a CopiesSettings object. |
10 * @constructor | 10 * @constructor |
11 */ | 11 */ |
12 function CopiesSettings() { | 12 function CopiesSettings() { |
| 13 this.copiesOption_ = $('copies-option'); |
13 this.textfield_ = $('copies'); | 14 this.textfield_ = $('copies'); |
14 this.incrementButton_ = $('increment'); | 15 this.incrementButton_ = $('increment'); |
15 this.decrementButton_ = $('decrement'); | 16 this.decrementButton_ = $('decrement'); |
16 // Minimum allowed value for number of copies. | 17 // Minimum allowed value for number of copies. |
17 this.minValue_ = 1; | 18 this.minValue_ = 1; |
18 // Maximum allowed value for number of copies. | 19 // Maximum allowed value for number of copies. |
19 this.maxValue_ = 999; | 20 this.maxValue_ = 999; |
20 this.collateOption_ = $('collate-option'); | 21 this.collateOption_ = $('collate-option'); |
| 22 this.collateCheckbox_ = $('collate'); |
21 this.hint_ = $('copies-hint'); | 23 this.hint_ = $('copies-hint'); |
22 this.twoSidedCheckbox_ = $('two-sided'); | 24 this.twoSidedCheckbox_ = $('two-sided'); |
23 } | 25 } |
24 | 26 |
25 cr.addSingletonGetter(CopiesSettings); | 27 cr.addSingletonGetter(CopiesSettings); |
26 | 28 |
27 CopiesSettings.prototype = { | 29 CopiesSettings.prototype = { |
28 /** | 30 /** |
29 * The number of copies represented by the contents of |this.textfield_|. | 31 * The number of copies represented by the contents of |this.textfield_|. |
30 * If the text is not valid returns |this.minValue_|. | 32 * If the text is not valid returns |this.minValue_|. |
(...skipping 16 matching lines...) Expand all Loading... |
47 | 49 |
48 /** | 50 /** |
49 * Getter method for |twoSidedCheckbox_|. | 51 * Getter method for |twoSidedCheckbox_|. |
50 * @type {HTMLInputElement} | 52 * @type {HTMLInputElement} |
51 */ | 53 */ |
52 get twoSidedCheckbox() { | 54 get twoSidedCheckbox() { |
53 return this.twoSidedCheckbox_; | 55 return this.twoSidedCheckbox_; |
54 }, | 56 }, |
55 | 57 |
56 /** | 58 /** |
| 59 * Gets the duplex mode for printing. |
| 60 * @return {number} duplex mode. |
| 61 */ |
| 62 get duplexMode() { |
| 63 // Constant values matches printing::DuplexMode enum. Not using const |
| 64 // keyword because it is not allowed by JS strict mode. |
| 65 var SIMPLEX = 0; |
| 66 var LONG_EDGE = 1; |
| 67 return !this.twoSidedCheckbox_.checked ? SIMPLEX : LONG_EDGE; |
| 68 }, |
| 69 |
| 70 /** |
57 * @return {boolean} true if |this.textfield_| is empty, or represents a | 71 * @return {boolean} true if |this.textfield_| is empty, or represents a |
58 * positive integer value. | 72 * positive integer value. |
59 */ | 73 */ |
60 isValid: function() { | 74 isValid: function() { |
61 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); | 75 return !this.textfield_.value || isPositiveInteger(this.textfield_.value); |
62 }, | 76 }, |
63 | 77 |
64 /** | 78 /** |
| 79 * Checks whether the preview collate setting value is set or not. |
| 80 * @return {boolean} true if collate option is enabled and checked. |
| 81 */ |
| 82 isCollated: function() { |
| 83 return !this.collateOption_.hidden && this.collateCheckbox_.checked; |
| 84 }, |
| 85 |
| 86 /** |
65 * Resets |this.textfield_| to |this.minValue_|. | 87 * Resets |this.textfield_| to |this.minValue_|. |
66 * @private | 88 * @private |
67 */ | 89 */ |
68 reset_: function() { | 90 reset_: function() { |
69 this.textfield_.value = this.minValue_; | 91 this.textfield_.value = this.minValue_; |
70 }, | 92 }, |
71 | 93 |
72 /** | 94 /** |
73 * Listener function to execute whenever the increment/decrement buttons are | 95 * Listener function to execute whenever the increment/decrement buttons are |
74 * clicked. | 96 * clicked. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 addEventListeners: function() { | 135 addEventListeners: function() { |
114 this.textfield_.oninput = this.onTextfieldChanged_.bind(this); | 136 this.textfield_.oninput = this.onTextfieldChanged_.bind(this); |
115 this.incrementButton_.onclick = this.onIncrementButtonClicked_.bind(this); | 137 this.incrementButton_.onclick = this.onIncrementButtonClicked_.bind(this); |
116 this.decrementButton_.onclick = this.onDecrementButtonClicked_.bind(this); | 138 this.decrementButton_.onclick = this.onDecrementButtonClicked_.bind(this); |
117 this.twoSidedCheckbox_.onclick = function() { | 139 this.twoSidedCheckbox_.onclick = function() { |
118 if (!hasPendingPreviewRequest) | 140 if (!hasPendingPreviewRequest) |
119 updatePrintSummary(); | 141 updatePrintSummary(); |
120 } | 142 } |
121 document.addEventListener('PDFLoaded', | 143 document.addEventListener('PDFLoaded', |
122 this.updateButtonsState_.bind(this)); | 144 this.updateButtonsState_.bind(this)); |
| 145 document.addEventListener('printerCapabilitiesUpdated', |
| 146 this.onPrinterCapabilitiesUpdated_.bind(this)); |
123 }, | 147 }, |
124 | 148 |
125 /** | 149 /** |
| 150 * Listener triggered when a printerCapabilitiesUpdated event occurs. |
| 151 * @private |
| 152 */ |
| 153 onPrinterCapabilitiesUpdated_: function(e) { |
| 154 if (e.printerCapabilities.disableCopiesOption) { |
| 155 fadeOutElement(this.copiesOption_); |
| 156 $('hr-before-copies').classList.remove('invisible'); |
| 157 } else { |
| 158 fadeInElement(this.copiesOption_); |
| 159 $('hr-before-copies').classList.add('invisible'); |
| 160 } |
| 161 this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault; |
| 162 }, |
| 163 |
| 164 /** |
126 * Listener triggered when |incrementButton_| is clicked. | 165 * Listener triggered when |incrementButton_| is clicked. |
127 * @private | 166 * @private |
128 */ | 167 */ |
129 onIncrementButtonClicked_: function() { | 168 onIncrementButtonClicked_: function() { |
130 this.onButtonClicked_(1); | 169 this.onButtonClicked_(1); |
131 }, | 170 }, |
132 | 171 |
133 /** | 172 /** |
134 * Listener triggered when |decrementButton_| is clicked. | 173 * Listener triggered when |decrementButton_| is clicked. |
135 * @private | 174 * @private |
(...skipping 27 matching lines...) Expand all Loading... |
163 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; | 202 this.decrementButton_.disabled = this.numberOfCopies == this.minValue_; |
164 fadeOutElement(this.hint_); | 203 fadeOutElement(this.hint_); |
165 } | 204 } |
166 } | 205 } |
167 }; | 206 }; |
168 | 207 |
169 return { | 208 return { |
170 CopiesSettings: CopiesSettings, | 209 CopiesSettings: CopiesSettings, |
171 }; | 210 }; |
172 }); | 211 }); |
OLD | NEW |