Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / data / ticket_items / copies.js
blob91e6acf475ddeafc719e53535df5c29632628fcb
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.
5 cr.define('print_preview.ticket_items', function() {
6 'use strict';
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.DestinationStore} destinationStore Destination store
13 * used determine if a destination has the copies capability.
14 * @constructor
15 * @extends {print_preview.ticket_items.TicketItem}
17 function Copies(destinationStore) {
18 print_preview.ticket_items.TicketItem.call(
19 this, null /*appState*/, null /*field*/, destinationStore);
22 Copies.prototype = {
23 __proto__: print_preview.ticket_items.TicketItem.prototype,
25 /** @override */
26 wouldValueBeValid: function(value) {
27 if (/[^\d]+/.test(value)) {
28 return false;
30 var copies = parseInt(value, 10);
31 if (copies > 999 || copies < 1) {
32 return false;
34 return true;
37 /** @override */
38 isCapabilityAvailable: function() {
39 return !!this.getCopiesCapability_();
42 /** @return {number} The number of copies indicated by the ticket item. */
43 getValueAsNumber: function() {
44 return parseInt(this.getValue(), 10);
47 /** @override */
48 getDefaultValueInternal: function() {
49 var cap = this.getCopiesCapability_();
50 return cap.hasOwnProperty('default') ? cap.default : '1';
53 /** @override */
54 getCapabilityNotAvailableValueInternal: function() {
55 return '1';
58 /**
59 * @return {Object} Copies capability of the selected destination.
60 * @private
62 getCopiesCapability_: function() {
63 var dest = this.getSelectedDestInternal();
64 return (dest &&
65 dest.capabilities &&
66 dest.capabilities.printer &&
67 dest.capabilities.printer.copies) ||
68 null;
72 // Export
73 return {
74 Copies: Copies
76 });