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 PageSettings object. This object encapsulates all settings and | 9 * Creates a PageSettings object. This object encapsulates all settings and |
10 * logic related to page selection. | 10 * logic related to page selection. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 this.previouslySelectedPages_.push(i + 1); | 170 this.previouslySelectedPages_.push(i + 1); |
171 } | 171 } |
172 | 172 |
173 if (!this.isPageSelectionValid()) | 173 if (!this.isPageSelectionValid()) |
174 this.onSelectedPagesTextfieldChanged(); | 174 this.onSelectedPagesTextfieldChanged(); |
175 }, | 175 }, |
176 | 176 |
177 /** | 177 /** |
178 * Updates |this.previouslySelectedPages_| with the currently selected | 178 * Updates |this.previouslySelectedPages_| with the currently selected |
179 * pages. | 179 * pages. |
180 * @private | |
181 */ | 180 */ |
182 updatePageSelection_: function() { | 181 updatePageSelection: function() { |
183 this.previouslySelectedPages_ = this.selectedPagesSet; | 182 this.previouslySelectedPages_ = this.selectedPagesSet; |
184 }, | 183 }, |
185 | 184 |
186 /** | 185 /** |
187 * @private | 186 * @private |
188 * @return {boolean} true if currently selected pages differ from | 187 * @return {boolean} true if currently selected pages differ from |
189 * |this.previouslySelectesPages_|. | 188 * |this.previouslySelectesPages_|. |
190 */ | 189 */ |
191 hasPageSelectionChanged_: function() { | 190 hasPageSelectionChanged_: function() { |
192 return !areArraysEqual(this.previouslySelectedPages_, | 191 return !areArraysEqual(this.previouslySelectedPages_, |
193 this.selectedPagesSet); | 192 this.selectedPagesSet); |
194 }, | 193 }, |
195 | 194 |
196 /** | 195 /** |
196 * Checks if the page selection has changed and is valid. | |
197 * @return {boolean} true if the page selection is changed and is valid. | |
198 */ | |
199 hasPageSelectionChangedAndIsValid: function() { | |
200 return this.isPageSelectionValid() && this.hasPageSelectionChanged_(); | |
201 }, | |
202 | |
203 /** | |
197 * Validates the contents of |this.selectedPagesTextfield|. | 204 * Validates the contents of |this.selectedPagesTextfield|. |
198 * | 205 * |
199 * @return {boolean} true if the text is valid. | 206 * @return {boolean} true if the text is valid. |
200 */ | 207 */ |
201 isPageSelectionValid: function() { | 208 isPageSelectionValid: function() { |
202 if (this.allPagesRadioButton_.checked || | 209 if (this.allPagesRadioButton_.checked || |
203 this.selectedPagesText.length == 0) { | 210 this.selectedPagesText.length == 0) { |
204 return true; | 211 return true; |
205 } | 212 } |
206 return isPageRangeTextValid(this.selectedPagesText, this.totalPageCount_); | 213 return isPageRangeTextValid(this.selectedPagesText, this.totalPageCount_); |
207 }, | 214 }, |
208 | 215 |
209 /** | 216 /** |
210 * Checks all page selection related settings and requests a new print | 217 * Checks all page selection related settings and requests a new print |
211 * previw if needed. | 218 * previw if needed. |
212 * @return {boolean} true if a new preview was requested. | 219 * @return {boolean} true if a new preview was requested. |
213 */ | 220 */ |
214 requestPrintPreviewIfNeeded: function() { | 221 requestPrintPreviewIfNeeded: function() { |
215 if (this.isPageSelectionValid() && this.hasPageSelectionChanged_()) { | 222 if (this.hasPageSelectionChangedAndIsValid()) { |
216 this.updatePageSelection_(); | 223 this.updatePageSelection(); |
217 requestPrintPreview(); | 224 requestPrintPreview(); |
218 return true; | 225 return true; |
219 } | 226 } |
220 if (!this.isPageSelectionValid()) | 227 if (!this.isPageSelectionValid()) |
221 this.onSelectedPagesTextfieldChanged(); | 228 this.onSelectedPagesTextfieldChanged(); |
222 return false; | 229 return false; |
223 }, | 230 }, |
224 | 231 |
225 /** | 232 /** |
226 * Validates the selected pages and updates the hint accordingly. | 233 * Validates the selected pages and updates the hint accordingly. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 this.onSelectedPagesTextfieldChanged(); | 274 this.onSelectedPagesTextfieldChanged(); |
268 | 275 |
269 // Toggling between "all pages"/"some pages" radio buttons while having an | 276 // Toggling between "all pages"/"some pages" radio buttons while having an |
270 // invalid entry in the page selection textfield still requires updating | 277 // invalid entry in the page selection textfield still requires updating |
271 // the print summary and print button. | 278 // the print summary and print button. |
272 if (!this.isPageSelectionValid() || !this.hasPageSelectionChanged_()) { | 279 if (!this.isPageSelectionValid() || !this.hasPageSelectionChanged_()) { |
273 cr.dispatchSimpleEvent(document, 'updateSummary'); | 280 cr.dispatchSimpleEvent(document, 'updateSummary'); |
274 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 281 cr.dispatchSimpleEvent(document, 'updatePrintButton'); |
275 return; | 282 return; |
276 } | 283 } |
277 this.previouslySelectedPages_ = this.selectedPagesSet; | |
vandebo (ex-Chrome)
2011/08/29 18:21:56
Do you want to call updatePageSelection here?
kmadhusu
2011/08/30 17:27:00
No. I do that in requestPrintPreview.
| |
278 requestPrintPreview(); | 284 requestPrintPreview(); |
279 }, | 285 }, |
280 | 286 |
281 /** | 287 /** |
282 * Whenever |this.selectedPagesTextfield| gains focus we add a timer to | 288 * Whenever |this.selectedPagesTextfield| gains focus we add a timer to |
283 * detect when the user stops typing in order to update the print preview. | 289 * detect when the user stops typing in order to update the print preview. |
284 * @private | 290 * @private |
285 */ | 291 */ |
286 addTimerToSelectedPagesTextfield_: function() { | 292 addTimerToSelectedPagesTextfield_: function() { |
287 this.timerId_ = window.setTimeout( | 293 this.timerId_ = window.setTimeout( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 clearTimeout(this.timerId_); | 359 clearTimeout(this.timerId_); |
354 this.onSelectedPagesMayHaveChanged_(); | 360 this.onSelectedPagesMayHaveChanged_(); |
355 }.bind(this); | 361 }.bind(this); |
356 } | 362 } |
357 }; | 363 }; |
358 | 364 |
359 return { | 365 return { |
360 PageSettings: PageSettings, | 366 PageSettings: PageSettings, |
361 }; | 367 }; |
362 }); | 368 }); |
OLD | NEW |