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() {
9 * Color ticket item whose value is a {@code boolean} that indicates whether
10 * the document should be printed in color.
11 * @param {!print_preview.AppState} appState App state persistence object to
12 * save the state of the color selection.
13 * @param {!print_preview.DestinationStore} destinationStore Used to determine
14 * whether color printing should be available.
16 * @extends {print_preview.ticket_items.TicketItem}
18 function Color(appState, destinationStore) {
19 print_preview.ticket_items.TicketItem.call(
22 print_preview.AppState.Field.IS_COLOR_ENABLED,
27 * @private {!Array.<string>} List of capability types considered color.
30 Color.COLOR_TYPES_ = ['STANDARD_COLOR', 'CUSTOM_COLOR'];
33 * @private {!Array.<string>} List of capability types considered monochrome.
36 Color.MONOCHROME_TYPES_ = ['STANDARD_MONOCHROME', 'CUSTOM_MONOCHROME'];
39 __proto__: print_preview.ticket_items.TicketItem.prototype,
42 wouldValueBeValid: function(value) {
47 isCapabilityAvailable: function() {
48 var capability = this.capability;
53 var hasMonochrome = false;
54 capability.option.forEach(function(option) {
55 hasColor = hasColor || (Color.COLOR_TYPES_.indexOf(option.type) >= 0);
56 hasMonochrome = hasMonochrome ||
57 (Color.MONOCHROME_TYPES_.indexOf(option.type) >= 0);
59 return hasColor && hasMonochrome;
62 /** @return {Object} Color capability of the selected destination. */
64 var dest = this.getSelectedDestInternal();
67 dest.capabilities.printer &&
68 dest.capabilities.printer.color) ||
72 /** @return {Object} Color option corresponding to the current value. */
73 getSelectedOption: function() {
74 var capability = this.capability;
75 var options = capability ? capability.option : null;
78 this.getValue() ? Color.COLOR_TYPES_ : Color.MONOCHROME_TYPES_;
79 for (var i = 0; i < typesToLookFor.length; i++) {
80 var matchingOptions = options.filter(function(option) {
81 return option.type == typesToLookFor[i];
83 if (matchingOptions.length > 0) {
84 return matchingOptions[0];
92 getDefaultValueInternal: function() {
93 var capability = this.capability;
94 var defaultOption = capability ?
95 this.getDefaultColorOption_(capability.option) : null;
96 return defaultOption &&
97 (Color.COLOR_TYPES_.indexOf(defaultOption.type) >= 0);
101 getCapabilityNotAvailableValueInternal: function() {
102 // TODO(rltoscano): Get rid of this check based on destination ID. These
103 // destinations should really update their CDDs to have only one color
104 // option that has type 'STANDARD_COLOR'.
105 var dest = this.getSelectedDestInternal();
107 if (dest.id == print_preview.Destination.GooglePromotedId.DOCS ||
108 dest.id == print_preview.Destination.GooglePromotedId.FEDEX ||
109 dest.type == print_preview.Destination.Type.MOBILE) {
113 return this.getDefaultValueInternal();
117 * @param {!Array.<!Object.<{type: string=, is_default: boolean=}>>} options
118 * @return {Object.<{type: string=, is_default: boolean=}>} Default color
119 * option of the given list.
122 getDefaultColorOption_: function(options) {
123 var defaultOptions = options.filter(function(option) {
124 return option.is_default;
126 return (defaultOptions.length == 0) ? null : defaultOptions[0];