OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview.ticket_items', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 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 |
| 11 * string since the user can textually input the copies value. |
| 12 * @param {!print_preview.CapabilitiesHolder} capabilitiesHolder Capabilities |
| 13 * holder used to determine the default number of copies and if the copies |
| 14 * capability is available. |
| 15 * @constructor |
| 16 * @extends {print_preview.ticket_items.TicketItem} |
| 17 */ |
| 18 function Copies(capabilitiesHolder) { |
| 19 print_preview.ticket_items.TicketItem.call(this); |
| 20 |
| 21 /** |
| 22 * Capabilities holder used to determine the default number of copies and if |
| 23 * the copies capability is available. |
| 24 * @type {!print_preview.CapabilitiesHolder} |
| 25 * @private |
| 26 */ |
| 27 this.capabilitiesHolder_ = capabilitiesHolder; |
| 28 }; |
| 29 |
| 30 Copies.prototype = { |
| 31 __proto__: print_preview.ticket_items.TicketItem.prototype, |
| 32 |
| 33 /** @override */ |
| 34 wouldValueBeValid: function(value) { |
| 35 if (/[^\d]+/.test(value)) { |
| 36 return false; |
| 37 } |
| 38 var copies = parseInt(value); |
| 39 if (copies > 999 || copies < 1) { |
| 40 return false; |
| 41 } |
| 42 return true; |
| 43 }, |
| 44 |
| 45 /** @override */ |
| 46 isCapabilityAvailable: function() { |
| 47 return this.capabilitiesHolder_.get().hasCopiesCapability; |
| 48 }, |
| 49 |
| 50 /** @return {number} The number of copies indicated by the ticket item. */ |
| 51 getValueAsNumber: function() { |
| 52 return parseInt(this.getValue()); |
| 53 }, |
| 54 |
| 55 /** @override */ |
| 56 getDefaultValueInternal: function() { |
| 57 return this.capabilitiesHolder_.get().defaultCopiesStr; |
| 58 }, |
| 59 |
| 60 /** @override */ |
| 61 getCapabilityNotAvailableValueInternal: function() { |
| 62 return '1'; |
| 63 } |
| 64 }; |
| 65 |
| 66 // Export |
| 67 return { |
| 68 Copies: Copies |
| 69 }; |
| 70 }); |
OLD | NEW |