createPrintTicket(destination) {
      assert(
          !destination.isLocal || destination.isPrivet ||
              destination.isExtension,
          'Trying to create a Google Cloud Print print ticket for a local ' +
              ' non-privet and non-extension destination');

      assert(
          destination.capabilities,
          'Trying to create a Google Cloud Print print ticket for a ' +
              'destination with no print capabilities');
      const cjt = {version: '1.0', print: {}};
      if (this.collate.isCapabilityAvailable() && this.collate.isUserEdited()) {
        cjt.print.collate = {collate: this.collate.getValue()};
      }
      if (this.color.isCapabilityAvailable() && this.color.isUserEdited()) {
        const selectedOption =
            destination.getSelectedColorOption(this.color.getValue());
        if (!selectedOption) {
          console.error('Could not find correct color option');
        } else {
          cjt.print.color = {type: selectedOption.type};
          if (selectedOption.hasOwnProperty('vendor_id')) {
            cjt.print.color.vendor_id = selectedOption.vendor_id;
          }
        }
      } else {
        // Always try setting the color in the print ticket, otherwise a
        // reasonable reader of the ticket will have to do more work, or process
        // the ticket sub-optimally, in order to safely handle the lack of a
        // color ticket item.
        const defaultOption = destination.defaultColorOption;
        if (defaultOption) {
          cjt.print.color = {type: defaultOption.type};
          if (defaultOption.hasOwnProperty('vendor_id')) {
            cjt.print.color.vendor_id = defaultOption.vendor_id;
          }
        }
      }

      if (this.copies.isCapabilityAvailable() && this.copies.isUserEdited()) {
        cjt.print.copies = {copies: this.copies.getValueAsNumber()};
      }
      if (this.duplex.isCapabilityAvailable() && this.duplex.isUserEdited()) {
        cjt.print.duplex = {
          type: this.duplex.getValue() ? 'LONG_EDGE' : 'NO_DUPLEX'
        };
      }
      if (this.mediaSize.isCapabilityAvailable()) {
        const mediaValue = this.mediaSize.getValue();
        cjt.print.media_size = {
          width_microns: mediaValue.width_microns,
          height_microns: mediaValue.height_microns,
          is_continuous_feed: mediaValue.is_continuous_feed,
          vendor_id: mediaValue.vendor_id
        };
      }
      if (!this.landscape.isCapabilityAvailable()) {
        // In this case "orientation" option is hidden from user, so user can't
        // adjust it for page content, see Landscape.isCapabilityAvailable().
        // We can improve results if we set AUTO here.
        if (this.landscape.hasOption('AUTO'))
          cjt.print.page_orientation = {type: 'AUTO'};
      } else if (this.landscape.isUserEdited()) {
        cjt.print.page_orientation = {
          type: this.landscape.getValue() ? 'LANDSCAPE' : 'PORTRAIT'
        };
      }
      if (this.dpi.isCapabilityAvailable()) {
        const dpiValue = this.dpi.getValue();
        cjt.print.dpi = {
          horizontal_dpi: dpiValue.horizontal_dpi,
          vertical_dpi: dpiValue.vertical_dpi,
          vendor_id: dpiValue.vendor_id
        };
      }
      if (this.vendorItems.isCapabilityAvailable() &&
          this.vendorItems.isUserEdited()) {
        const items = this.vendorItems.ticketItems;
        cjt.print.vendor_ticket_item = [];
        for (const itemId in items) {
          if (items.hasOwnProperty(itemId)) {
            cjt.print.vendor_ticket_item.push(
                {id: itemId, value: items[itemId]});
          }
        }
      }
      return JSON.stringify(cjt);
    }
/**
     * Creates an object that represents a Google Cloud Print print ticket.
     * @param {!print_preview.Destination} destination Destination to print to.
     * @return {string} Google Cloud Print print ticket.
     */
Creates an object that represents a Google Cloud Print print ticket.
@param {!print_preview.Destination} destination Destination to print to.
@return {string} Google Cloud Print print ticket.
Creates an object that represents a Google Cloud Print print ticket . @param { !print_preview . Destination } destination Destination to print to . @return { string } Google Cloud Print print ticket .
createPrintTicket(destination) {
      assert(
          !destination.isLocal || destination.isPrivet ||
              destination.isExtension,
          'Trying to create a Google Cloud Print print ticket for a local ' +
              ' non-privet and non-extension destination');
      assert(
          destination.capabilities,
          'Trying to create a Google Cloud Print print ticket for a ' +
              'destination with no print capabilities');
      const cjt = {version: '1.0', print: {}};
      if (this.collate.isCapabilityAvailable() && this.collate.isUserEdited()) {
        cjt.print.collate = {collate: this.collate.getValue()};
      }
      if (this.color.isCapabilityAvailable() && this.color.isUserEdited()) {
        const selectedOption =
            destination.getSelectedColorOption(this.color.getValue());
        if (!selectedOption) {
          console.error('Could not find correct color option');
        } else {
          cjt.print.color = {type: selectedOption.type};
          if (selectedOption.hasOwnProperty('vendor_id')) {
            cjt.print.color.vendor_id = selectedOption.vendor_id;
          }
        }
      } else {
        const defaultOption = destination.defaultColorOption;
        if (defaultOption) {
          cjt.print.color = {type: defaultOption.type};
          if (defaultOption.hasOwnProperty('vendor_id')) {
            cjt.print.color.vendor_id = defaultOption.vendor_id;
          }
        }
      }
      if (this.copies.isCapabilityAvailable() && this.copies.isUserEdited()) {
        cjt.print.copies = {copies: this.copies.getValueAsNumber()};
      }
      if (this.duplex.isCapabilityAvailable() && this.duplex.isUserEdited()) {
        cjt.print.duplex = {
          type: this.duplex.getValue() ? 'LONG_EDGE' : 'NO_DUPLEX'
        };
      }
      if (this.mediaSize.isCapabilityAvailable()) {
        const mediaValue = this.mediaSize.getValue();
        cjt.print.media_size = {
          width_microns: mediaValue.width_microns,
          height_microns: mediaValue.height_microns,
          is_continuous_feed: mediaValue.is_continuous_feed,
          vendor_id: mediaValue.vendor_id
        };
      }
      if (!this.landscape.isCapabilityAvailable()) {
        if (this.landscape.hasOption('AUTO'))
          cjt.print.page_orientation = {type: 'AUTO'};
      } else if (this.landscape.isUserEdited()) {
        cjt.print.page_orientation = {
          type: this.landscape.getValue() ? 'LANDSCAPE' : 'PORTRAIT'
        };
      }
      if (this.dpi.isCapabilityAvailable()) {
        const dpiValue = this.dpi.getValue();
        cjt.print.dpi = {
          horizontal_dpi: dpiValue.horizontal_dpi,
          vertical_dpi: dpiValue.vertical_dpi,
          vendor_id: dpiValue.vendor_id
        };
      }
      if (this.vendorItems.isCapabilityAvailable() &&
          this.vendorItems.isUserEdited()) {
        const items = this.vendorItems.ticketItems;
        cjt.print.vendor_ticket_item = [];
        for (const itemId in items) {
          if (items.hasOwnProperty(itemId)) {
            cjt.print.vendor_ticket_item.push(
                {id: itemId, value: items[itemId]});
          }
        }
      }
      return JSON.stringify(cjt);
    }
createPrintTicket ( destination ) { assert ( ! destination . isLocal || destination . isPrivet || destination . isExtension , 'Trying to create a Google Cloud Print print ticket for a local ' + ' non-privet and non-extension destination' ) ; assert ( destination . capabilities , 'Trying to create a Google Cloud Print print ticket for a ' + 'destination with no print capabilities' ) ; const cjt = { version : '1.0' , print : { } } ; if ( this . collate . isCapabilityAvailable ( ) && this . collate . isUserEdited ( ) ) { cjt . print . collate = { collate : this . collate . getValue ( ) } ; } if ( this . color . isCapabilityAvailable ( ) && this . color . isUserEdited ( ) ) { const selectedOption = destination . getSelectedColorOption ( this . color . getValue ( ) ) ; if ( ! selectedOption ) { console . error ( 'Could not find correct color option' ) ; } else { cjt . print . color = { type : selectedOption . type } ; if ( selectedOption . hasOwnProperty ( 'vendor_id' ) ) { cjt . print . color . vendor_id = selectedOption . vendor_id ; } } } else { const defaultOption = destination . defaultColorOption ; if ( defaultOption ) { cjt . print . color = { type : defaultOption . type } ; if ( defaultOption . hasOwnProperty ( 'vendor_id' ) ) { cjt . print . color . vendor_id = defaultOption . vendor_id ; } } } if ( this . copies . isCapabilityAvailable ( ) && this . copies . isUserEdited ( ) ) { cjt . print . copies = { copies : this . copies . getValueAsNumber ( ) } ; } if ( this . duplex . isCapabilityAvailable ( ) && this . duplex . isUserEdited ( ) ) { cjt . print . duplex = { type : this . duplex . getValue ( ) ? 'LONG_EDGE' : 'NO_DUPLEX' } ; } if ( this . mediaSize . isCapabilityAvailable ( ) ) { const mediaValue = this . mediaSize . getValue ( ) ; cjt . print . media_size = { width_microns : mediaValue . width_microns , height_microns : mediaValue . height_microns , is_continuous_feed : mediaValue . is_continuous_feed , vendor_id : mediaValue . vendor_id } ; } if ( ! this . landscape . isCapabilityAvailable ( ) ) { if ( this . landscape . hasOption ( 'AUTO' ) ) cjt . print . page_orientation = { type : 'AUTO' } ; } else if ( this . landscape . isUserEdited ( ) ) { cjt . print . page_orientation = { type : this . landscape . getValue ( ) ? 'LANDSCAPE' : 'PORTRAIT' } ; } if ( this . dpi . isCapabilityAvailable ( ) ) { const dpiValue = this . dpi . getValue ( ) ; cjt . print . dpi = { horizontal_dpi : dpiValue . horizontal_dpi , vertical_dpi : dpiValue . vertical_dpi , vendor_id : dpiValue . vendor_id } ; } if ( this . vendorItems . isCapabilityAvailable ( ) && this . vendorItems . isUserEdited ( ) ) { const items = this . vendorItems . ticketItems ; cjt . print . vendor_ticket_item = [ ] ; for ( const itemId in items ) { if ( items . hasOwnProperty ( itemId ) ) { cjt . print . vendor_ticket_item . push ( { id : itemId , value : items [ itemId ] } ) ; } } } return JSON . stringify ( cjt ) ; }
Creates an object that represents a Google Cloud Print print ticket.
Creates an object that represents a Google Cloud Print print ticket .
// Always try setting the color in the print ticket, otherwise a // reasonable reader of the ticket will have to do more work, or process // the ticket sub-optimally, in order to safely handle the lack of a // color ticket item. // In this case "orientation" option is hidden from user, so user can't // adjust it for page content, see Landscape.isCapabilityAvailable(). // We can improve results if we set AUTO here.