Chromium Code Reviews| 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 /** | |
| 9 * Creates a PageSettings object. This object encapsulates all settings and | |
| 10 * logic related to page selection. | |
| 11 * | |
| 12 * @param {print_preview.PrintTicketStore} printTicketStore Used to read and | |
| 13 * write page range settings. | |
| 14 * @constructor | |
| 15 * @extends {print_preview.Component} | |
| 16 */ | |
| 17 function PageSettings(printTicketStore) { | |
| 18 print_preview.Component.call(this); | |
| 19 | |
| 20 /** | |
| 21 * Used to read and write page range settings. | |
| 22 * @type {print_preview.PrintTicketStore} | |
| 23 * @private | |
| 24 */ | |
| 25 this.printTicketStore_ = printTicketStore; | |
| 26 | |
| 27 /** | |
| 28 * Timeout used to delay processing of the custom page range input. | |
| 29 * @type {Object} | |
| 30 * @private | |
| 31 */ | |
| 32 this.customInputTimeout_ = null; | |
| 33 }; | |
| 34 | |
| 35 /** | |
| 36 * CSS classes used by the page settings. | |
| 37 * @enum {string} | |
| 38 * @private | |
| 39 */ | |
| 40 PageSettings.Classes_ = { | |
| 41 ALL_RADIO: 'page-settings-all-radio', | |
| 42 CUSTOM_HINT: 'page-settings-custom-hint', | |
| 43 CUSTOM_INPUT: 'page-settings-custom-input', | |
| 44 CUSTOM_RADIO: 'page-settings-custom-radio' | |
| 45 }; | |
| 46 | |
| 47 /** | |
| 48 * Delay in milliseconds before processing custom page range input. | |
| 49 * @type {number} | |
| 50 * @private | |
| 51 */ | |
| 52 PageSettings.CUSTOM_INPUT_DELAY_ = 500; | |
| 53 | |
| 54 PageSettings.prototype = { | |
| 55 __proto__: print_preview.Component.prototype, | |
| 56 | |
| 57 set isEnabled(isEnabled) { | |
|
dpapad1
2012/04/26 16:04:44
I would name this setEnabled() instead of set isEn
Robert Toscano
2012/04/28 01:41:37
I wanted to model this after dom elements that hav
dpapad
2012/04/30 16:19:25
Ok, so I see two possible namings.
- If you prefe
Robert Toscano
2012/05/05 00:02:50
Done.
| |
| 58 this.customInput_.disabled = !isEnabled; | |
| 59 this.allRadio_.disabled = !isEnabled; | |
| 60 this.customRadio_.disabled = !isEnabled; | |
| 61 }, | |
| 62 | |
| 63 /** @override */ | |
| 64 enterDocument: function() { | |
| 65 print_preview.Component.prototype.enterDocument.call(this); | |
| 66 this.customHintEl_.textContent = localStrings.getStringF( | |
| 67 'pageRangeInstruction', | |
| 68 localStrings.getString('examplePageRangeText')); | |
| 69 this.tracker.add( | |
| 70 this.allRadio_, 'click', this.onAllRadioClick_.bind(this)); | |
| 71 this.tracker.add( | |
| 72 this.customRadio_, 'click', this.onCustomRadioClick_.bind(this)); | |
| 73 this.tracker.add( | |
| 74 this.customInput_, 'blur', this.onCustomInputBlur_.bind(this)); | |
| 75 this.tracker.add( | |
| 76 this.customInput_, 'keyup', this.onCustomInputKeyUp_.bind(this)); | |
| 77 this.tracker.add( | |
| 78 this.printTicketStore_, | |
| 79 print_preview.PrintTicketStore.Event.DOCUMENT_CHANGE, | |
| 80 this.onPrintTicketStoreChange_.bind(this)); | |
| 81 this.tracker.add( | |
| 82 this.printTicketStore_, | |
| 83 print_preview.PrintTicketStore.Event.TICKET_CHANGE, | |
| 84 this.onPrintTicketStoreChange_.bind(this)); | |
| 85 this.tracker.add( | |
| 86 this.printTicketStore_, | |
| 87 print_preview.PrintTicketStore.Event.CAPABILITIES_CHANGE, | |
| 88 this.onPrintTicketStoreChange_.bind(this)); | |
| 89 }, | |
| 90 | |
| 91 get customInput_() { | |
| 92 return this.getElement().getElementsByClassName( | |
| 93 PageSettings.Classes_.CUSTOM_INPUT)[0]; | |
| 94 }, | |
| 95 | |
| 96 get allRadio_() { | |
| 97 return this.getElement().getElementsByClassName( | |
| 98 PageSettings.Classes_.ALL_RADIO)[0]; | |
| 99 }, | |
| 100 | |
| 101 get customRadio_() { | |
| 102 return this.getElement().getElementsByClassName( | |
| 103 PageSettings.Classes_.CUSTOM_RADIO)[0]; | |
| 104 }, | |
| 105 | |
| 106 get customHintEl_() { | |
| 107 return this.getElement().getElementsByClassName( | |
| 108 PageSettings.Classes_.CUSTOM_HINT)[0]; | |
| 109 }, | |
| 110 | |
| 111 setInvalidStateVisible_: function(isVisible) { | |
| 112 if (isVisible) { | |
| 113 this.customInput_.classList.add('invalid'); | |
| 114 this.customHintEl_.setAttribute('aria-hidden', 'false'); | |
| 115 fadeInElement(this.customHintEl_); | |
| 116 } else { | |
| 117 this.customInput_.classList.remove('invalid'); | |
| 118 fadeOutElement(this.customHintEl_); | |
| 119 this.customHintEl_.setAttribute('aria-hidden', 'true'); | |
| 120 } | |
| 121 }, | |
| 122 | |
| 123 onAllRadioClick_: function() { | |
| 124 this.printTicketStore_.updatePageRange(''); | |
| 125 }, | |
| 126 | |
| 127 onCustomRadioClick_: function() { | |
| 128 this.customInput_.focus(); | |
| 129 this.printTicketStore_.updatePageRange(this.customInput_.value); | |
| 130 }, | |
| 131 | |
| 132 onCustomInputBlur_: function() { | |
| 133 if (this.customInput_.value == '') { | |
| 134 this.allRadio_.checked = true; | |
| 135 this.customRadio_.checked = false; | |
| 136 } | |
| 137 }, | |
| 138 | |
| 139 onCustomInputKeyUp_: function(evt) { | |
| 140 if (this.customInputTimeout_) { | |
| 141 clearTimeout(this.customInputTimeout_); | |
| 142 } | |
| 143 if (evt.keyIdentifier == 'Enter') { | |
| 144 this.printTicketStore_.updatePageRange(this.customInput_.value); | |
| 145 } else { | |
| 146 this.allRadio_.checked = false; | |
| 147 this.customRadio_.checked = true; | |
| 148 this.customInputTimeout_ = setTimeout( | |
| 149 this.onCustomInputTimeout_.bind(this), | |
| 150 PageSettings.CUSTOM_INPUT_DELAY_); | |
| 151 } | |
| 152 }, | |
| 153 | |
| 154 onCustomInputTimeout_: function() { | |
| 155 this.customInputTimeout_ = null; | |
| 156 if (this.customRadio_.checked) { | |
| 157 this.printTicketStore_.updatePageRange(this.customInput_.value); | |
| 158 } | |
| 159 }, | |
| 160 | |
| 161 onPrintTicketStoreChange_: function() { | |
| 162 if (this.printTicketStore_.hasPageRangeCapability()) { | |
| 163 var pageRangeStr = this.printTicketStore_.getPageRangeStr(); | |
| 164 if (pageRangeStr) { | |
| 165 // TODO There might be a bad case here where we overwrite what the | |
| 166 // user is typing. Also could be the case in copies. | |
| 167 this.customInput_.value = pageRangeStr; | |
| 168 this.customRadio_.checked = true; | |
| 169 this.allRadio_.checked = false; | |
| 170 this.setInvalidStateVisible_( | |
| 171 !this.printTicketStore_.isPageRangeValid()); | |
| 172 } else { | |
| 173 this.allRadio_.checked = true; | |
| 174 this.customRadio_.checked = false; | |
| 175 this.customInput_.value = ''; | |
| 176 this.setInvalidStateVisible_(false); | |
| 177 } | |
| 178 fadeInOption(this.getElement()); | |
| 179 } else { | |
| 180 fadeOutOption(this.getElement()); | |
| 181 } | |
| 182 } | |
| 183 }; | |
| 184 | |
| 185 // Export | |
| 186 return { | |
| 187 PageSettings: PageSettings | |
| 188 }; | |
| 189 }); | |
| OLD | NEW |