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('print_preview', function() { |
| 6 'use strict'; |
| 7 |
| 8 // TODO Maybe clear print ticket when destination changes. Or better yet, |
| 9 // carry over any print ticket state that is possible. I.e. if destination |
| 10 // changes, the new destination might not support duplex anymore, so we should |
| 11 // clear the ticket's isDuplexEnabled state. |
| 12 |
| 13 /** |
| 14 * Storage of the print ticket and document statistics. Dispatches events when |
| 15 * the contents of the print ticket or document statistics change. Also |
| 16 * handles validation of the print ticket against destination capabilities and |
| 17 * against the document. |
| 18 * @constructor |
| 19 * @extends {cr.EventTarget} |
| 20 */ |
| 21 function PrintTicketStore() { |
| 22 cr.EventTarget.call(this); |
| 23 |
| 24 // Create the document info with some initial settings. Actual |
| 25 // page-related information won't be set until preview generation occurs, |
| 26 // so we'll use some defaults until then. This way, the print ticket store |
| 27 // will be valid even if no preview can be generated. |
| 28 var initialPageSize = new print_preview.Size(612, 792); // 8.5"x11" |
| 29 |
| 30 /** |
| 31 * Information about the document to print. |
| 32 * @type {!print_preview.DocumentInfo} |
| 33 * @private |
| 34 */ |
| 35 this.documentInfo_ = new print_preview.DocumentInfo( |
| 36 true /*isModifiable*/, |
| 37 1 /*pageCount*/, |
| 38 initialPageSize, |
| 39 new print_preview.PrintableArea( |
| 40 new print_preview.Coordinate2d(0, 0), initialPageSize)); |
| 41 |
| 42 /** |
| 43 * Printing capabilities of Chromium and the currently selected destination. |
| 44 * @type {!print_preview.CapabilitiesHolder} |
| 45 * @private |
| 46 */ |
| 47 this.capabilitiesHolder_ = new print_preview.CapabilitiesHolder( |
| 48 new print_preview.ChromiumCapabilities( |
| 49 true /*hasCopiesCapability*/, |
| 50 '1' /*defaultCopiesStr*/, |
| 51 true /*hasCollateCapability*/, |
| 52 true /*defaultIsCollateEnabled*/, |
| 53 true /*hasDuplexCapability*/, |
| 54 true /*defaultIsDuplexEnabled*/, |
| 55 true /*hasOrientationCapability*/, |
| 56 false /*defaultIsLandscapeEnabled*/, |
| 57 true /*hasColorCapability*/, |
| 58 true /*defaultIsColorEnabled*/)); |
| 59 |
| 60 /** |
| 61 * Current measurement system. Used to work with margin measurements. |
| 62 * @type {!print_preview.MeasurementSystem} |
| 63 * @private |
| 64 */ |
| 65 this.measurementSystem_ = new print_preview.MeasurementSystem( |
| 66 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL); |
| 67 |
| 68 /** |
| 69 * Collate ticket item. |
| 70 * @type {!print_preview.ticket_items.Collate} |
| 71 * @private |
| 72 */ |
| 73 this.collate_ = |
| 74 new print_preview.ticket_items.Collate(this.capabilitiesHolder_); |
| 75 |
| 76 /** |
| 77 * Color ticket item. |
| 78 * @type {!print_preview.ticket_items.Color} |
| 79 * @private |
| 80 */ |
| 81 this.color_ = |
| 82 new print_preview.ticket_items.Color(this.capabilitiesHolder_); |
| 83 |
| 84 /** |
| 85 * Copies ticket item. |
| 86 * @type {!print_preview.ticket_items.Copies} |
| 87 * @private |
| 88 */ |
| 89 this.copies_ = |
| 90 new print_preview.ticket_items.Copies(this.capabilitiesHolder_); |
| 91 |
| 92 /** |
| 93 * Duplex ticket item. |
| 94 * @type {!print_preview.ticket_items.Duplex} |
| 95 * @private |
| 96 */ |
| 97 this.duplex_ = |
| 98 new print_preview.ticket_items.Duplex(this.capabilitiesHolder_); |
| 99 |
| 100 /** |
| 101 * Landscape ticket item. |
| 102 * @type {!print_preview.ticket_items.Landscape} |
| 103 * @private |
| 104 */ |
| 105 this.landscape_ = new print_preview.ticket_items.Landscape( |
| 106 this.capabilitiesHolder_, this.documentInfo_); |
| 107 |
| 108 /** |
| 109 * Page range ticket item. |
| 110 * @type {!print_preview.ticket_items.PageRange} |
| 111 * @private |
| 112 */ |
| 113 this.pageRange_ = |
| 114 new print_preview.ticket_items.PageRange(this.documentInfo_); |
| 115 |
| 116 /** |
| 117 * Margins type ticket item. |
| 118 * @type {!print_preview.ticket_items.MarginsType} |
| 119 * @private |
| 120 */ |
| 121 this.marginsType_ = |
| 122 new print_preview.ticket_items.MarginsType(this.documentInfo_); |
| 123 |
| 124 /** |
| 125 * Custom margins ticket item. |
| 126 * @type {!print_preview.ticket_items.CustomMargins} |
| 127 * @private |
| 128 */ |
| 129 this.customMargins_ = new print_preview.ticket_items.CustomMargins( |
| 130 this.documentInfo_, this.measurementSystem_); |
| 131 |
| 132 /** |
| 133 * Header-footer ticket item. |
| 134 * @type {!print_preview.ticket_items.HeaderFooter} |
| 135 * @private |
| 136 */ |
| 137 this.headerFooter_ = new print_preview.ticket_items.HeaderFooter( |
| 138 this.documentInfo_, this.marginsType_, this.customMargins_); |
| 139 }; |
| 140 |
| 141 /** |
| 142 * Event types dispatched by the print ticket store. |
| 143 * @enum {string} |
| 144 */ |
| 145 PrintTicketStore.EventType = { |
| 146 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE', |
| 147 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE', |
| 148 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE', |
| 149 TICKET_CHANGE: 'print_preview.PrintTicketStore.TICKET_CHANGE' |
| 150 }; |
| 151 |
| 152 PrintTicketStore.prototype = { |
| 153 __proto__: cr.EventTarget.prototype, |
| 154 |
| 155 /** @return {boolean} Whether the document is modifiable. */ |
| 156 get isDocumentModifiable() { |
| 157 return this.documentInfo_.isModifiable; |
| 158 }, |
| 159 |
| 160 /** @return {number} Number of pages in the document. */ |
| 161 get pageCount() { |
| 162 return this.documentInfo_.pageCount; |
| 163 }, |
| 164 |
| 165 /** |
| 166 * @param {number} pageCount New number of pages in the document. |
| 167 * Dispatches a DOCUMENT_CHANGE event if the value changes. |
| 168 */ |
| 169 updatePageCount: function(pageCount) { |
| 170 if (this.documentInfo_.pageCount != pageCount) { |
| 171 this.documentInfo_.pageCount = pageCount; |
| 172 cr.dispatchSimpleEvent( |
| 173 this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
| 174 } |
| 175 }, |
| 176 |
| 177 /** |
| 178 * @return {!print_preview.PrintableArea} Printable area of the document in |
| 179 * points. |
| 180 */ |
| 181 get printableArea() { |
| 182 return this.documentInfo_.printableArea; |
| 183 }, |
| 184 |
| 185 /** |
| 186 * @param {!print_preview.PrintableArea} printableArea New printable area of |
| 187 * the document in points. Dispatches a DOCUMENT_CHANGE event if the |
| 188 * value changes. |
| 189 */ |
| 190 updatePrintableArea: function(printableArea) { |
| 191 if (!this.documentInfo_.printableArea.equals(printableArea)) { |
| 192 this.documentInfo_.printableArea = printableArea; |
| 193 cr.dispatchSimpleEvent( |
| 194 this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
| 195 } |
| 196 }, |
| 197 |
| 198 /** @return {!print_preview.Size} Size of the document in points. */ |
| 199 get pageSize() { |
| 200 return this.documentInfo_.pageSize; |
| 201 }, |
| 202 |
| 203 /** |
| 204 * @param {!print_preview.Size} pageSize New size of the document. |
| 205 * Dispatches a DOCUMENT_CHANGE event if the value changes. |
| 206 */ |
| 207 updatePageSize: function(pageSize) { |
| 208 if (!this.documentInfo_.pageSize.equals(pageSize)) { |
| 209 this.documentInfo_.pageSize = pageSize; |
| 210 cr.dispatchSimpleEvent( |
| 211 this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
| 212 } |
| 213 }, |
| 214 |
| 215 /** |
| 216 * @return {!print_preview.MeasurementSystem} Measurement system of the |
| 217 * local system. |
| 218 */ |
| 219 get measurementSystem() { |
| 220 return this.measurementSystem_; |
| 221 }, |
| 222 |
| 223 /** |
| 224 * Initializes the print ticket store. Dispatches an INITIALIZE event. |
| 225 * @param {boolean} isDocumentModifiable Whether the document to print is |
| 226 * modifiable (i.e. can be re-flowed by Chromium). |
| 227 * @param {?boolean} isDuplexEnabled Previous duplex setting. |
| 228 * @param {?boolean} isHeaderFooterEnabled Previous header-footer setting. |
| 229 * @param {?print_preview.ticket_items.MarginsType.Value} marginsType |
| 230 * Previous margins type. |
| 231 * @param {print_preview.Margins} customMargins Previous custom margins. |
| 232 */ |
| 233 initialize: function( |
| 234 isDocumentModifiable, |
| 235 isDuplexEnabled, |
| 236 isHeaderFooterEnabled, |
| 237 marginsType, |
| 238 customMargins, |
| 239 thousandsDelimeter, |
| 240 decimalDelimeter, |
| 241 unitType) { |
| 242 |
| 243 this.documentInfo_.isModifiable = isDocumentModifiable; |
| 244 this.measurementSystem_.setSystem( |
| 245 thousandsDelimeter, decimalDelimeter, unitType); |
| 246 |
| 247 // Initialize ticket with user's previous values. |
| 248 if (isDuplexEnabled != null) { |
| 249 this.duplex_.updateValue(isDuplexEnabled); |
| 250 } |
| 251 if (isHeaderFooterEnabled != null) { |
| 252 this.headerFooter_.updateValue(isHeaderFooterEnabled); |
| 253 } |
| 254 if (marginsType != null) { |
| 255 this.marginsType_.updateValue(marginsType); |
| 256 } |
| 257 if (customMargins != null) { |
| 258 this.customMargins_.updateValueInPts(customMargins); |
| 259 } |
| 260 |
| 261 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); |
| 262 }, |
| 263 |
| 264 /** |
| 265 * Updates the capabilities of the destination the print ticket is for. |
| 266 * Dispatches a CAPABILITIES_CHANGE event. |
| 267 * @param {!print_preview.ChromiumCapabilities} caps New capabilities. |
| 268 */ |
| 269 updateDestinationCapabilities: function(caps) { |
| 270 this.capabilitiesHolder_.set(caps); |
| 271 cr.dispatchSimpleEvent( |
| 272 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); |
| 273 }, |
| 274 |
| 275 |
| 276 /** @return {boolean} Whether the ticket store has the copies capability. */ |
| 277 hasCopiesCapability: function() { |
| 278 return this.copies_.isCapabilityAvailable(); |
| 279 }, |
| 280 |
| 281 /** |
| 282 * @return {boolean} Whether the string representation of the copies value |
| 283 * currently in the ticket store is valid. |
| 284 */ |
| 285 isCopiesValid: function() { |
| 286 return this.copies_.isValid(); |
| 287 }, |
| 288 |
| 289 isCopiesValidForValue: function(value) { |
| 290 return this.copies_.wouldValueBeValid(value); |
| 291 }, |
| 292 |
| 293 /** @return {number} Number of copies to print. */ |
| 294 getCopies: function() { |
| 295 return this.copies_.getValueAsNumber(); |
| 296 }, |
| 297 |
| 298 /** |
| 299 * @return {string} String representation of the number of copies to print. |
| 300 */ |
| 301 getCopiesStr: function() { |
| 302 return this.copies_.getValue(); |
| 303 }, |
| 304 |
| 305 /** |
| 306 * Updates the string representation of the number of copies to print. |
| 307 * Dispatches a TICKET_CHANGE event if the string value has changed. |
| 308 * @param {string} New string representation of the number of copies to |
| 309 * print. |
| 310 */ |
| 311 updateCopies: function(copies) { |
| 312 if (this.copies_.getValue() != copies) { |
| 313 this.copies_.updateValue(copies); |
| 314 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 315 } |
| 316 }, |
| 317 |
| 318 /** @return {boolean} Whether the ticket store has a collate capability. */ |
| 319 hasCollateCapability: function() { |
| 320 return this.collate_.isCapabilityAvailable(); |
| 321 }, |
| 322 |
| 323 /** @return {boolean} Whether collate is enabled. */ |
| 324 isCollateEnabled: function() { |
| 325 return this.collate_.getValue(); |
| 326 }, |
| 327 |
| 328 /** |
| 329 * Updates whether collate is enabled. Dispatches a TICKET_CHANGE event if |
| 330 * collate has changed. |
| 331 * @param {boolean} isCollateEnabled Whether collate is enabled. |
| 332 */ |
| 333 updateCollate: function(isCollateEnabled) { |
| 334 if (this.collate_.getValue() != isCollateEnabled) { |
| 335 this.collate_.updateValue(isCollateEnabled); |
| 336 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 337 } |
| 338 }, |
| 339 |
| 340 /** |
| 341 * @return {boolean} Whether the ticket store has color printing capability. |
| 342 */ |
| 343 hasColorCapability: function() { |
| 344 return this.color_.isCapabilityAvailable(); |
| 345 }, |
| 346 |
| 347 /** @return {boolean} Whether color printing is enabled. */ |
| 348 isColorEnabled: function() { |
| 349 return this.color_.getValue(); |
| 350 }, |
| 351 |
| 352 /** |
| 353 * Updates whether color printing is enabled. Dispatches a TICKET_CHANGE if |
| 354 * color has changed. |
| 355 * @param {boolean} isColorEnabled Whether the color printing is enabled. |
| 356 */ |
| 357 updateColor: function(isColorEnabled) { |
| 358 if (this.color_.getValue() != isColorEnabled) { |
| 359 this.color_.updateValue(isColorEnabled); |
| 360 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 361 } |
| 362 }, |
| 363 |
| 364 /** @return {boolean} Whether the header-footer capability is available. */ |
| 365 hasHeaderFooterCapability: function() { |
| 366 return this.headerFooter_.isCapabilityAvailable(); |
| 367 }, |
| 368 |
| 369 /** @return {boolean} Whether the header-footer setting is enabled. */ |
| 370 isHeaderFooterEnabled: function() { |
| 371 return this.headerFooter_.getValue(); |
| 372 }, |
| 373 |
| 374 /** |
| 375 * Updates the whether the header-footer setting is enabled. Dispatches a |
| 376 * TICKET_CHANGE event if the setting changed. |
| 377 * @param {boolean} isHeaderFooterEnabled Whether the header-footer setting |
| 378 * is enabled. |
| 379 */ |
| 380 updateHeaderFooter: function(isHeaderFooterEnabled) { |
| 381 if (this.headerFooter_.getValue() != isHeaderFooterEnabled) { |
| 382 this.headerFooter_.updateValue(isHeaderFooterEnabled); |
| 383 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 384 } |
| 385 }, |
| 386 |
| 387 /** |
| 388 * @return {boolean} Whether the page orientation capability is available. |
| 389 */ |
| 390 hasOrientationCapability: function() { |
| 391 return this.landscape_.isCapabilityAvailable(); |
| 392 }, |
| 393 |
| 394 /** |
| 395 * @return {boolean} Whether the document should be printed in landscape. |
| 396 */ |
| 397 isLandscapeEnabled: function() { |
| 398 return this.landscape_.getValue(); |
| 399 }, |
| 400 |
| 401 /** |
| 402 * Updates whether the document should be printed in landscape. Dispatches |
| 403 * a TICKET_CHANGE event if the setting changes. |
| 404 * @param {boolean} isLandscapeEnabled Whether the document should be |
| 405 * printed in landscape. |
| 406 */ |
| 407 updateOrientation: function(isLandscapeEnabled) { |
| 408 if (this.landscape_.getValue() != isLandscapeEnabled) { |
| 409 this.landscape_.updateValue(isLandscapeEnabled); |
| 410 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 411 } |
| 412 }, |
| 413 |
| 414 /** @return {boolean} Whether the duplexing capability is available. */ |
| 415 hasDuplexCapability: function() { |
| 416 return this.duplex_.isCapabilityAvailable(); |
| 417 }, |
| 418 |
| 419 /** @return {boolean} Whether the document should be printed in duplex. */ |
| 420 isDuplexEnabled: function() { |
| 421 return this.duplex_.getValue(); |
| 422 }, |
| 423 |
| 424 /** |
| 425 * Updates the duplexing setting. Dispatches a TICKET_CHANGE event if the |
| 426 * value changes. |
| 427 * @param {boolean} isDuplexEnabled Whether the document should be printed |
| 428 * in duplex. |
| 429 */ |
| 430 updateDuplex: function(isDuplexEnabled) { |
| 431 if (this.duplex_.getValue() != isDuplexEnabled) { |
| 432 this.duplex_.updateValue(isDuplexEnabled); |
| 433 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 434 } |
| 435 }, |
| 436 |
| 437 /** @return {boolean} Whether the margins capability is available. */ |
| 438 hasMarginsCapability: function() { |
| 439 return this.marginsType_.isCapabilityAvailable(); |
| 440 }, |
| 441 |
| 442 /** |
| 443 * @return {print_preview.ticket_items.MarginsType.Value} Type of predefined |
| 444 * margins. |
| 445 */ |
| 446 getMarginsType: function() { |
| 447 return this.marginsType_.getValue(); |
| 448 }, |
| 449 |
| 450 /** |
| 451 * Updates the type of predefined margins. Dispatches a TICKET_CHANGE event |
| 452 * if the margins type changes. |
| 453 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Type of |
| 454 * predefined margins. |
| 455 */ |
| 456 updateMarginsType: function(marginsType) { |
| 457 if (this.marginsType_.getValue() != marginsType) { |
| 458 this.marginsType_.updateValue(marginsType); |
| 459 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 460 } |
| 461 }, |
| 462 |
| 463 /** @return {boolean} Whether all of the custom margins are valid. */ |
| 464 isCustomMarginsValid: function() { |
| 465 return this.customMargins_.isValid(); |
| 466 }, |
| 467 |
| 468 /** |
| 469 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 470 * Specifies the margin to check if parseable. |
| 471 * @return {boolean} Whether the specified margin is parseable. |
| 472 */ |
| 473 isCustomMarginParseable: function(orientation) { |
| 474 return this.customMargins_.isMarginParseable(orientation); |
| 475 }, |
| 476 |
| 477 /** @return {!print_preview.Margins} Custom margins of the document. */ |
| 478 getCustomMarginsInPts: function() { |
| 479 return this.customMargins_.getValueInPts(); |
| 480 }, |
| 481 |
| 482 /** |
| 483 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 484 * Specifies the margin to get the maximum value for. |
| 485 * @return {number} Maximum value in points of the specified margin. |
| 486 */ |
| 487 getCustomMarginMaxInPts: function(orientation) { |
| 488 return this.customMargins_.getMarginMaxInPts(orientation); |
| 489 }, |
| 490 |
| 491 /** |
| 492 * @return {!print_preview.ticket_items.StringMargins} Custom margins as |
| 493 * strings in the local measurement system. |
| 494 */ |
| 495 getCustomMargins: function() { |
| 496 return this.customMargins_.getValue(); |
| 497 }, |
| 498 |
| 499 /** |
| 500 * Updates the custom margins of the document. Dispatches a TICKET_CHANGE |
| 501 * event if the margins have changed. |
| 502 * @param {!print_preview.Margins} marginsInPts New document page margins. |
| 503 */ |
| 504 updateCustomMarginsInPts: function(marginsInPts) { |
| 505 if (!this.isCustomMarginsValid() || |
| 506 !marginsInPts.equals(this.getCustomMarginsInPts())) { |
| 507 this.customMargins_.updateValueInPts(marginsInPts); |
| 508 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 509 } |
| 510 }, |
| 511 |
| 512 /** |
| 513 * Updates a single custom margin's value as a string in the local |
| 514 * measurement system. |
| 515 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 516 * Specifies the margin to update. |
| 517 * @param {string} value Updated string value in the local measurement |
| 518 * system. |
| 519 */ |
| 520 updateCustomMargin: function(orientation, value) { |
| 521 if (this.customMargins_.getValue().get(orientation) != value) { |
| 522 this.customMargins_.updateMargin(orientation, value); |
| 523 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 524 } |
| 525 }, |
| 526 |
| 527 /** |
| 528 * Updates a single custom margin's value in points. |
| 529 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 530 * Specifies the margin to update. |
| 531 * @param {number} New value in points of the specified margin. |
| 532 */ |
| 533 updateCustomMarginInPts: function(orientation, valueInPts) { |
| 534 if (!this.isCustomMarginsValid() || |
| 535 this.getCustomMarginsInPts().get(orientation) != valueInPts) { |
| 536 this.customMargins_.updateMarginInPts(orientation, valueInPts); |
| 537 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 538 } |
| 539 }, |
| 540 |
| 541 /** |
| 542 * Updates the default value of the custom margins. This value is used if |
| 543 * the user has not edited the custom margins ticket item. |
| 544 * @param {!print_preview.Margins} margins Updated margins value. |
| 545 */ |
| 546 updateDefaultCustomMarginsInPts: function(margins) { |
| 547 this.customMargins_.updateDefaultValueInPts(margins); |
| 548 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 549 }, |
| 550 |
| 551 /** |
| 552 * Serializes a value in points to a string in the local measurement system. |
| 553 * @param {number} marginInPts Margin value in points. |
| 554 * @return {string} Serialized representation of the given value in the |
| 555 * local measurement system. |
| 556 */ |
| 557 serializeMarginFromPts: function(marginInPts) { |
| 558 return this.customMargins_.serializeMarginFromPts(marginInPts); |
| 559 }, |
| 560 |
| 561 /** @return {boolean} Whether the page range capability is available. */ |
| 562 hasPageRangeCapability: function() { |
| 563 return this.pageRange_.isCapabilityAvailable(); |
| 564 }, |
| 565 |
| 566 /** |
| 567 * @return {boolean} Whether the current page range string is defines a |
| 568 * valid page number set. |
| 569 */ |
| 570 isPageRangeValid: function() { |
| 571 return this.pageRange_.isValid(); |
| 572 }, |
| 573 |
| 574 /** @return {string} String representation of the page range. */ |
| 575 getPageRangeStr: function() { |
| 576 return this.pageRange_.getValue(); |
| 577 }, |
| 578 |
| 579 /** |
| 580 * @return {!print_preview.PageNumberSet} Page number set specified by the |
| 581 * string representation of the page range string. |
| 582 */ |
| 583 getPageNumberSet: function() { |
| 584 return this.pageRange_.getPageNumberSet(); |
| 585 }, |
| 586 |
| 587 /** |
| 588 * Updates the page range string. Dispatches a TICKET_CHANGE if the string |
| 589 * changed. |
| 590 * @param {string} pageRangeStr New page range string. |
| 591 */ |
| 592 updatePageRange: function(pageRangeStr) { |
| 593 if (this.pageRange_.getValue() != pageRangeStr) { |
| 594 this.pageRange_.updateValue(pageRangeStr); |
| 595 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 596 } |
| 597 }, |
| 598 |
| 599 /** |
| 600 * @return {boolean} {@code true} if the stored print ticket is valid, |
| 601 * {@code false} otherwise. |
| 602 */ |
| 603 isTicketValid: function() { |
| 604 return (!this.hasCopiesCapability() || this.isCopiesValid()) && |
| 605 (!this.hasPageRangeCapability() || this.isPageRangeValid()) && |
| 606 (!this.hasMarginsCapability() || |
| 607 this.getMarginsType() != |
| 608 print_preview.ticket_items.MarginsType.Value.CUSTOM || |
| 609 this.isCustomMarginsValid()); |
| 610 } |
| 611 }; |
| 612 |
| 613 // Export |
| 614 return { |
| 615 PrintTicketStore: PrintTicketStore |
| 616 }; |
| 617 }); |
OLD | NEW |