Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2038)

Unified Diff: chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js

Issue 540563002: Export vendor capabilities to the CJT ticket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js
diff --git a/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js b/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js
new file mode 100644
index 0000000000000000000000000000000000000000..d2acb1f780d2b50ba4ea35fe67f2e49cbbe452fa
--- /dev/null
+++ b/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js
@@ -0,0 +1,108 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('print_preview.ticket_items', function() {
+ 'use strict';
+
+ /**
+ * An object that represents a user modifiable item in a print ticket. Each
+ * ticket item has a value which can be set by the user. Ticket items can also
+ * be unavailable for modifying if the print destination doesn't support it or
+ * if other ticket item constraints are not met.
+ * @param {print_preview.AppState} appState Application state model to update
+ * when ticket items update.
+ * @param {print_preview.DestinationStore} destinationStore Used listen for
+ * changes in the currently selected destination's capabilities. Since
+ * this is a common dependency of ticket items, it's handled in the base
+ * class.
+ * @constructor
+ * @extends {cr.EventTarget}
+ */
+ function VendorItems(appState, destinationStore) {
+ cr.EventTarget.call(this);
+
+ /**
+ * Application state model to update when ticket items update.
+ * @private {print_preview.AppState}
+ */
+ this.appState_ = appState || null;
+
+ /**
+ * Used listen for changes in the currently selected destination's
+ * capabilities.
+ * @private {print_preview.DestinationStore}
+ */
+ this.destinationStore_ = destinationStore || null;
+
+ /**
+ * Vendor ticket items store, maps item id to the item value.
+ * @private {!Object.<string, string>}
+ */
+ this.items_ = {};
+ };
+
+ VendorItems.prototype = {
+ __proto__: cr.EventTarget.prototype,
+
+ /** @return {boolean} Whether vendor capabilities are available. */
+ isCapabilityAvailable: function() {
+ return !!this.capability;
+ },
+
+ /** @return {boolean} Whether the ticket item was modified by the user. */
+ isUserEdited: function() {
+ // If there's at least one ticket item stored in values, it was edited.
+ for (var key in values) {
+ if (values.hasOwnProperty(key))
+ return true;
+ }
+ return false;
+ },
+
+ /** @return {Object} Media size capability of the selected destination. */
+ get capability() {
+ var destination = this.destinationStore_ ?
+ this.destinationStore_.selectedDestination : null;
+ return (destination &&
+ destination.capabilities &&
+ destination.capabilities.printer &&
+ destination.capabilities.printer.vendor_capability) ||
+ null;
+ },
+
+ /**
+ * Vendor ticket items store, maps item id to the item value.
+ * @return {!Object.<string, string>}
+ */
+ get ticketItems() {
+ return this.items_;
+ },
+
+ /**
+ * @param {!Object.<string, string>} values Values to set as the values of
+ * vendor ticket items. Maps vendor item id to the value.
+ */
+ updateValue: function(values) {
+ this.items_ = {};
+ if (typeof values == 'object') {
+ for (var key in values) {
+ if (values.hasOwnProperty(key) && typeof values[key] == 'string') {
+ // Let's empirically limit each value at 2K.
+ this.items_[key] = values[key].substring(0, 2048);
+ }
+ }
+ }
+
+ if (this.appState_) {
+ this.appState_.persistField(
+ print_preview.AppState.Field.VENDOR_OPTIONS, this.items_);
+ }
+ }
+ };
+
+ // Export
+ return {
+ VendorItems: VendorItems
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698