Chromium Code Reviews| 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.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Copies ticket item whose value is a {@code string} that indicates how many | 9 * Copies ticket item whose value is a {@code string} that indicates how many |
| 10 * copies of the document should be printed. The ticket item is backed by a | 10 * copies of the document should be printed. The ticket item is backed by a |
| 11 * string since the user can textually input the copies value. | 11 * string since the user can textually input the copies value. |
| 12 * @param {!print_preview.DestinationStore} destinationStore Destination store | 12 * @param {!print_preview.DestinationStore} destinationStore Destination store |
| 13 * used determine if a destination has the copies capability. | 13 * used determine if a destination has the copies capability. |
| 14 * @constructor | 14 * @constructor |
| 15 * @extends {print_preview.ticket_items.TicketItem} | 15 * @extends {print_preview.ticket_items.TicketItem} |
| 16 */ | 16 */ |
| 17 function Copies(destinationStore) { | 17 function Copies(destinationStore) { |
| 18 print_preview.ticket_items.TicketItem.call( | 18 print_preview.ticket_items.TicketItem.call( |
| 19 this, null /*appState*/, null /*field*/, destinationStore); | 19 this, null /*appState*/, null /*field*/, destinationStore); |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 Copies.prototype = { | 22 Copies.prototype = { |
| 23 __proto__: print_preview.ticket_items.TicketItem.prototype, | 23 __proto__: print_preview.ticket_items.TicketItem.prototype, |
| 24 | 24 |
| 25 /** @override */ | 25 /** @override */ |
| 26 wouldValueBeValid: function(value) { | 26 wouldValueBeValid: function(value) { |
| 27 if (/[^\d]+/.test(value)) { | 27 return value != ''; |
| 28 return false; | |
| 29 } | |
| 30 var copies = parseInt(value, 10); | |
| 31 if (copies > 999 || copies < 1) { | |
| 32 return false; | |
| 33 } | |
| 34 return true; | |
| 35 }, | 28 }, |
| 36 | 29 |
| 37 /** @override */ | 30 /** @override */ |
| 38 isCapabilityAvailable: function() { | 31 isCapabilityAvailable: function() { |
| 39 return !!this.getCopiesCapability_(); | 32 return !!this.getCopiesCapability_(); |
| 40 }, | 33 }, |
| 41 | 34 |
| 42 /** @return {number} The number of copies indicated by the ticket item. */ | 35 /** @return {number} The number of copies indicated by the ticket item. */ |
| 43 getValueAsNumber: function() { | 36 getValueAsNumber: function() { |
| 37 if (this.getValue() == '') | |
|
dpapad
2017/02/27 21:56:02
Nit (optional)
var value = this.getValue();
retur
rbpotter
2017/02/28 00:12:59
Done.
| |
| 38 return 0; | |
| 44 return parseInt(this.getValue(), 10); | 39 return parseInt(this.getValue(), 10); |
| 45 }, | 40 }, |
| 46 | 41 |
| 47 /** @override */ | 42 /** @override */ |
| 48 getDefaultValueInternal: function() { | 43 getDefaultValueInternal: function() { |
| 49 var cap = this.getCopiesCapability_(); | 44 var cap = this.getCopiesCapability_(); |
| 50 return cap.hasOwnProperty('default') ? cap.default : '1'; | 45 return cap.hasOwnProperty('default') ? cap.default : '1'; |
| 51 }, | 46 }, |
| 52 | 47 |
| 53 /** @override */ | 48 /** @override */ |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 67 dest.capabilities.printer.copies) || | 62 dest.capabilities.printer.copies) || |
| 68 null; | 63 null; |
| 69 } | 64 } |
| 70 }; | 65 }; |
| 71 | 66 |
| 72 // Export | 67 // Export |
| 73 return { | 68 return { |
| 74 Copies: Copies | 69 Copies: Copies |
| 75 }; | 70 }; |
| 76 }); | 71 }); |
| OLD | NEW |