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('cloudprint', function() { |
| 6 'use strict'; |
| 7 |
| 8 function CloudDestinationParser() {}; |
| 9 |
| 10 /** |
| 11 * Enumeration of cloud destination field names. |
| 12 * @enum {string} |
| 13 * @private |
| 14 */ |
| 15 CloudDestinationParser.Field_ = { |
| 16 CAPABILITIES: 'capabilities', |
| 17 DISPLAY_NAME: 'displayName', |
| 18 ID: 'id', |
| 19 TAGS: 'tags' |
| 20 }; |
| 21 |
| 22 /** |
| 23 * Special tag that denotes whether the destination has been recently used. |
| 24 * @type {string} |
| 25 * @private |
| 26 */ |
| 27 CloudDestinationParser.RECENT_TAG_ = '^recent'; |
| 28 |
| 29 /** |
| 30 * Parses a destination from JSON from a Google Cloud Print search or printer |
| 31 * response. |
| 32 * @return {!print_preview.Destination} Parsed destination. |
| 33 */ |
| 34 CloudDestinationParser.parse = function(json) { |
| 35 // TODO Error handling. |
| 36 var isRecent = arrayContains( |
| 37 json[CloudDestinationParser.Field_.TAGS], |
| 38 CloudDestinationParser.RECENT_TAG_); |
| 39 var cloudDest = new print_preview.Destination( |
| 40 json[CloudDestinationParser.Field_.ID], |
| 41 json[CloudDestinationParser.Field_.DISPLAY_NAME], |
| 42 isRecent, |
| 43 false /*isLocal*/, |
| 44 json[CloudDestinationParser.Field_.TAGS]); |
| 45 if (json.hasOwnProperty(CloudDestinationParser.Field_.CAPABILITIES)) { |
| 46 cloudDest.capabilities = CloudCapabilitiesParser.parse( |
| 47 json[CloudDestinationParser.Field_.CAPABILITIES]); |
| 48 } |
| 49 return cloudDest; |
| 50 }; |
| 51 |
| 52 function CloudCapabilitiesParser() {}; |
| 53 |
| 54 CloudCapabilitiesParser.parse = function(json) { |
| 55 var caps = new print_preview.ChromiumCapabilities(); |
| 56 caps.hasPageRangeCapability = true; |
| 57 caps.defaultPageRangeStr = ''; |
| 58 caps.hasCopiesCapability = false; // TODO |
| 59 caps.defaultCopiesStr = '1'; |
| 60 caps.hasCollateCapability = false; // TODO |
| 61 caps.defaultIsCollateEnabled = false; |
| 62 caps.hasDuplexCapability = false; // TODO |
| 63 caps.defaultIsDuplexEnabled = false; |
| 64 caps.hasOrientationCapability = true; // TODO |
| 65 caps.defaultIsLandscapeEnabled = false; |
| 66 caps.hasColorCapability = false; // TODO |
| 67 caps.defaultIsColorEnabled = false; |
| 68 caps.hasMarginsCapability = true; |
| 69 caps.defaultMarginType = print_preview.Margins.Type.DEFAULT; |
| 70 caps.hasHeaderFooterCapability = true; |
| 71 caps.defaultIsHeaderFooterEnabled = true; |
| 72 return caps; |
| 73 }; |
| 74 |
| 75 // Export |
| 76 return { |
| 77 CloudCapabilitiesParser: CloudCapabilitiesParser, |
| 78 CloudDestinationParser: CloudDestinationParser |
| 79 }; |
| 80 }); |
| 81 |
OLD | NEW |