| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var localStrings; | 5 var localStrings; |
| 6 var browserBridge; | 6 var browserBridge; |
| 7 | 7 |
| 8 // Class that keeps track of current burn process state. | 8 /** |
| 9 * Class that keeps track of current burn process state. |
| 10 * @param {Object} strings Localized state strings. |
| 11 * @constructor |
| 12 */ |
| 9 function State(strings) { | 13 function State(strings) { |
| 10 this.setStrings(strings); | 14 this.setStrings(strings); |
| 11 this.changeState(State.StatesEnum.DEVICE_NONE); | 15 this.changeState(State.StatesEnum.DEVICE_NONE); |
| 12 } | 16 } |
| 13 | 17 |
| 18 /** |
| 19 * State Enum object. |
| 20 */ |
| 14 State.StatesEnum = { | 21 State.StatesEnum = { |
| 15 DEVICE_NONE : { | 22 DEVICE_NONE: { |
| 16 cssState : "device-detected-none", | 23 cssState: 'device-detected-none', |
| 17 }, | 24 }, |
| 18 DEVICE_USB : { | 25 DEVICE_USB: { |
| 19 cssState : "device-detected-usb warning", | 26 cssState: 'device-detected-usb warning', |
| 20 }, | 27 }, |
| 21 DEVICE_SD : { | 28 DEVICE_SD: { |
| 22 cssState : "device-detected-sd warning", | 29 cssState: 'device-detected-sd warning', |
| 23 }, | 30 }, |
| 24 DEVICE_MUL : { | 31 DEVICE_MUL: { |
| 25 cssState: "device-detected-mul warning", | 32 cssState: 'device-detected-mul warning', |
| 26 }, | 33 }, |
| 27 ERROR_NO_NETWORK : { | 34 ERROR_NO_NETWORK: { |
| 28 cssState : "warning-no-conf", | 35 cssState: 'warning-no-conf', |
| 29 }, | 36 }, |
| 30 ERROR_DEVICE_TOO_SMALL : { | 37 ERROR_DEVICE_TOO_SMALL: { |
| 31 cssState : "warning-no-conf", | 38 cssState: 'warning-no-conf', |
| 32 }, | 39 }, |
| 33 PROGRESS_DOWNLOAD : { | 40 PROGRESS_DOWNLOAD: { |
| 34 cssState : "progress progress-canceble", | 41 cssState: 'progress progress-canceble', |
| 35 }, | 42 }, |
| 36 PROGRESS_UNZIP : { | 43 PROGRESS_UNZIP: { |
| 37 cssState : "progress progress-canceble", | 44 cssState: 'progress progress-canceble', |
| 38 }, | 45 }, |
| 39 PROGRESS_BURN : { | 46 PROGRESS_BURN: { |
| 40 cssState : "progress", | 47 cssState: 'progress', |
| 41 }, | 48 }, |
| 42 FAIL : { | 49 FAIL: { |
| 43 cssState : "error", | 50 cssState: 'error', |
| 44 }, | 51 }, |
| 45 SUCCESS : { | 52 SUCCESS: { |
| 46 cssState : "success", | 53 cssState: 'success', |
| 47 }, | 54 }, |
| 48 }; | 55 }; |
| 49 | 56 |
| 50 State.prototype = { | 57 State.prototype = { |
| 58 /** |
| 59 * Sets the state strings. |
| 60 * @param {Object} strings Localized state strings. |
| 61 */ |
| 51 setStrings: function(strings) { | 62 setStrings: function(strings) { |
| 52 State.StatesEnum.DEVICE_NONE.statusText = | 63 State.StatesEnum.DEVICE_NONE.statusText = |
| 53 strings.getString('statusDevicesNone'); | 64 strings.getString('statusDevicesNone'); |
| 54 State.StatesEnum.DEVICE_NONE.warningText = | 65 State.StatesEnum.DEVICE_NONE.warningText = |
| 55 strings.getString('warningDevicesNone'); | 66 strings.getString('warningDevicesNone'); |
| 56 State.StatesEnum.DEVICE_USB.statusText = | 67 State.StatesEnum.DEVICE_USB.statusText = |
| 57 strings.getString('statusDeviceUSB'); | 68 strings.getString('statusDeviceUSB'); |
| 58 State.StatesEnum.DEVICE_SD.statusText = strings.getString('statusDeviceSD'); | 69 State.StatesEnum.DEVICE_SD.statusText = strings.getString('statusDeviceSD'); |
| 59 State.StatesEnum.DEVICE_MUL.statusText = | 70 State.StatesEnum.DEVICE_MUL.statusText = |
| 60 strings.getString('statusDevicesMultiple'); | 71 strings.getString('statusDevicesMultiple'); |
| 61 State.StatesEnum.ERROR_NO_NETWORK.statusText = | 72 State.StatesEnum.ERROR_NO_NETWORK.statusText = |
| 62 strings.getString('statusNoConnection'); | 73 strings.getString('statusNoConnection'); |
| 63 State.StatesEnum.ERROR_NO_NETWORK.warningText = | 74 State.StatesEnum.ERROR_NO_NETWORK.warningText = |
| 64 strings.getString('warningNoConnection'); | 75 strings.getString('warningNoConnection'); |
| 65 State.StatesEnum.ERROR_DEVICE_TOO_SMALL.statusText = | 76 State.StatesEnum.ERROR_DEVICE_TOO_SMALL.statusText = |
| 66 strings.getString('statusNoSpace'); | 77 strings.getString('statusNoSpace'); |
| 67 State.StatesEnum.PROGRESS_DOWNLOAD.statusText = | 78 State.StatesEnum.PROGRESS_DOWNLOAD.statusText = |
| 68 strings.getString('statusDownloading'); | 79 strings.getString('statusDownloading'); |
| 69 State.StatesEnum.PROGRESS_UNZIP.statusText = | 80 State.StatesEnum.PROGRESS_UNZIP.statusText = |
| 70 strings.getString('statusUnzip'); | 81 strings.getString('statusUnzip'); |
| 71 State.StatesEnum.PROGRESS_BURN.statusText = strings.getString('statusBurn'); | 82 State.StatesEnum.PROGRESS_BURN.statusText = strings.getString('statusBurn'); |
| 72 State.StatesEnum.FAIL.statusText = strings.getString('statusError'); | 83 State.StatesEnum.FAIL.statusText = strings.getString('statusError'); |
| 73 State.StatesEnum.SUCCESS.statusText = strings.getString('statusSuccess'); | 84 State.StatesEnum.SUCCESS.statusText = strings.getString('statusSuccess'); |
| 74 State.StatesEnum.SUCCESS.warningText = strings.getString('warningSuccess'); | 85 State.StatesEnum.SUCCESS.warningText = strings.getString('warningSuccess'); |
| 75 }, | 86 }, |
| 76 | 87 |
| 88 /** |
| 89 * Changes the current state to new state. |
| 90 * @param {Object} newState Specifies the new state object. |
| 91 */ |
| 77 changeState: function(newState) { | 92 changeState: function(newState) { |
| 78 if (newState == this.state) | 93 if (newState == this.state) |
| 79 return; | 94 return; |
| 80 this.state = newState; | 95 this.state = newState; |
| 81 | 96 |
| 82 $('main-content').className = this.state.cssState; | 97 $('main-content').className = this.state.cssState; |
| 83 | 98 |
| 84 $('status-text').textContent = this.state.statusText; | 99 $('status-text').textContent = this.state.statusText; |
| 85 | 100 |
| 86 if (newState.warningText) { | 101 if (newState.warningText) |
| 87 $('warning-text').textContent = this.state.warningText; | 102 $('warning-text').textContent = this.state.warningText; |
| 88 } | |
| 89 | 103 |
| 90 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { | 104 if (this.isInitialState() && this.state != State.StatesEnum.DEVICE_NONE) { |
| 91 $('warning-button').textContent = localStrings.getString('confirmButton'); | 105 $('warning-button').textContent = localStrings.getString('confirmButton'); |
| 92 } else if (this.state == State.StatesEnum.FAIL) { | 106 } else if (this.state == State.StatesEnum.FAIL) { |
| 93 $('warning-button').textContent = | 107 $('warning-button').textContent = |
| 94 localStrings.getString('retryButton'); | 108 localStrings.getString('retryButton'); |
| 95 } | 109 } |
| 96 }, | 110 }, |
| 97 | 111 |
| 112 /** |
| 113 * Reset to initial state. |
| 114 * @param {number} deviceCount Device count information. |
| 115 */ |
| 98 gotoInitialState: function(deviceCount) { | 116 gotoInitialState: function(deviceCount) { |
| 99 if (deviceCount == 0) { | 117 if (deviceCount == 0) |
| 100 this.changeState(State.StatesEnum.DEVICE_NONE); | 118 this.changeState(State.StatesEnum.DEVICE_NONE); |
| 101 } else if (deviceCount == 1) { | 119 else if (deviceCount == 1) |
| 102 this.changeState(State.StatesEnum.DEVICE_USB); | 120 this.changeState(State.StatesEnum.DEVICE_USB); |
| 103 } else { | 121 else |
| 104 this.changeState(State.StatesEnum.DEVICE_MUL); | 122 this.changeState(State.StatesEnum.DEVICE_MUL); |
| 105 } | |
| 106 }, | 123 }, |
| 107 | 124 |
| 125 /** |
| 126 * Returns true if the device is in initial state. |
| 127 * @return {boolean} True if the device is in initial state else false. |
| 128 */ |
| 108 isInitialState: function() { | 129 isInitialState: function() { |
| 109 return (this.state == State.StatesEnum.DEVICE_NONE || | 130 return this.state == State.StatesEnum.DEVICE_NONE || |
| 110 this.state == State.StatesEnum.DEVICE_USB || | 131 this.state == State.StatesEnum.DEVICE_USB || |
| 111 this.state == State.StatesEnum.DEVICE_SD || | 132 this.state == State.StatesEnum.DEVICE_SD || |
| 112 this.state == State.StatesEnum.DEVICE_MUL); | 133 this.state == State.StatesEnum.DEVICE_MUL; |
| 113 }, | 134 }, |
| 114 | 135 |
| 136 /** |
| 137 * Returns true if device state matches the given state name. |
| 138 * @param {string} stateName Given state name. |
| 139 * @return {boolean} True if the device state matches the given state name. |
| 140 */ |
| 115 equals: function(stateName) { | 141 equals: function(stateName) { |
| 116 return this.state == stateName; | 142 return this.state == stateName; |
| 117 } | 143 } |
| 118 }; | 144 }; |
| 119 | 145 |
| 120 // Class that keeps track of available devices. | 146 /** |
| 147 * Class that keeps track of available devices. |
| 148 * @constructor |
| 149 */ |
| 121 function DeviceSelection() { | 150 function DeviceSelection() { |
| 122 this.deviceCount = 0; | 151 this.deviceCount = 0; |
| 123 }; | 152 } |
| 124 | 153 |
| 125 DeviceSelection.prototype = { | 154 DeviceSelection.prototype = { |
| 155 /** |
| 156 * Clears the given selection list. |
| 157 * @param {Array} list Device selection list. |
| 158 */ |
| 126 clearSelectList: function(list) { | 159 clearSelectList: function(list) { |
| 127 list.innerHtml = ''; | 160 list.innerHtml = ''; |
| 128 }, | 161 }, |
| 129 | 162 |
| 163 /** |
| 164 * Shows the currently selected device. |
| 165 * @return {number} Selected device count. |
| 166 */ |
| 130 showDeviceSelection: function() { | 167 showDeviceSelection: function() { |
| 131 if (this.deviceCount == 0) { | 168 if (this.deviceCount == 0) { |
| 132 this.selectedDevice = undefined; | 169 this.selectedDevice = undefined; |
| 133 } else { | 170 } else { |
| 134 var devices = document.getElementsByClassName('selection-element'); | 171 var devices = document.getElementsByClassName('selection-element'); |
| 135 this.selectDevice(devices[0].devicePath); | 172 this.selectDevice(devices[0].devicePath); |
| 136 } | 173 } |
| 137 return this.deviceCount; | 174 return this.deviceCount; |
| 138 }, | 175 }, |
| 139 | 176 |
| 177 /** |
| 178 * Handles device selected event. |
| 179 * @param {string} label Device label. |
| 180 * @param {string} filePath File path. |
| 181 * @param {string} devicePath Selected device path. |
| 182 */ |
| 140 onDeviceSelected: function(label, filePath, devicePath) { | 183 onDeviceSelected: function(label, filePath, devicePath) { |
| 141 $('warning-button').onclick = | 184 $('warning-button').onclick = |
| 142 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, | 185 browserBridge.sendBurnImageMessage.bind(browserBridge, filePath, |
| 143 devicePath); | 186 devicePath); |
| 144 | 187 |
| 145 this.selectedDevice = devicePath; | 188 this.selectedDevice = devicePath; |
| 146 | 189 |
| 147 $('warning-text').textContent = | 190 $('warning-text').textContent = |
| 148 localStrings.getStringF('warningDevices', label); | 191 localStrings.getStringF('warningDevices', label); |
| 149 }, | 192 }, |
| 150 | 193 |
| 194 /** |
| 195 * Selects the specified device based on the specified path. |
| 196 * @param {string} path Device path. |
| 197 */ |
| 151 selectDevice: function(path) { | 198 selectDevice: function(path) { |
| 152 var element = $('radio ' + path); | 199 var element = $('radio ' + path); |
| 153 element.checked = true; | 200 element.checked = true; |
| 154 element.onclick.apply(element); | 201 element.onclick.apply(element); |
| 155 }, | 202 }, |
| 156 | 203 |
| 204 /** |
| 205 * Creates a new device element. |
| 206 * @param {Object} device Specifies new device information. |
| 207 * @return {HTMLLIElement} New device element. |
| 208 */ |
| 157 createNewDeviceElement: function(device) { | 209 createNewDeviceElement: function(device) { |
| 158 var element = document.createElement('li'); | 210 var element = document.createElement('li'); |
| 159 var radioButton = document.createElement('input'); | 211 var radioButton = document.createElement('input'); |
| 160 radioButton.type = 'radio'; | 212 radioButton.type = 'radio'; |
| 161 radioButton.name = 'device'; | 213 radioButton.name = 'device'; |
| 162 radioButton.value = device.label; | 214 radioButton.value = device.label; |
| 163 radioButton.id = 'radio ' + device.devicePath; | 215 radioButton.id = 'radio ' + device.devicePath; |
| 164 radioButton.className = 'float-start'; | 216 radioButton.className = 'float-start'; |
| 165 var deviceLabelText = document.createElement('p'); | 217 var deviceLabelText = document.createElement('p'); |
| 166 deviceLabelText.textContent = device.label; | 218 deviceLabelText.textContent = device.label; |
| 167 deviceLabelText.className = 'select-option float-start'; | 219 deviceLabelText.className = 'select-option float-start'; |
| 168 var newLine = document.createElement('div'); | 220 var newLine = document.createElement('div'); |
| 169 newLine.className = 'new-line'; | 221 newLine.className = 'new-line'; |
| 170 element.appendChild(radioButton); | 222 element.appendChild(radioButton); |
| 171 element.appendChild(deviceLabelText); | 223 element.appendChild(deviceLabelText); |
| 172 element.appendChild(newLine); | 224 element.appendChild(newLine); |
| 173 element.id = 'select ' + device.devicePath; | 225 element.id = 'select ' + device.devicePath; |
| 174 element.devicePath = device.devicePath; | 226 element.devicePath = device.devicePath; |
| 175 element.className = 'selection-element'; | 227 element.className = 'selection-element'; |
| 176 radioButton.onclick = this.onDeviceSelected.bind(this, | 228 radioButton.onclick = this.onDeviceSelected.bind(this, |
| 177 device.label, device.filePath, device.devicePath); | 229 device.label, device.filePath, device.devicePath); |
| 178 return element; | 230 return element; |
| 179 }, | 231 }, |
| 180 | 232 |
| 233 /** |
| 234 * Updates the list of selected devices. |
| 235 * @param {Array} devices List of devices. |
| 236 * @return {number} Device count. |
| 237 */ |
| 181 getDevicesCallback: function(devices) { | 238 getDevicesCallback: function(devices) { |
| 182 var selectListDOM = $('device-selection'); | 239 var selectListDOM = $('device-selection'); |
| 183 this.clearSelectList(selectListDOM); | 240 this.clearSelectList(selectListDOM); |
| 184 this.deviceCount = devices.length; | 241 this.deviceCount = devices.length; |
| 185 if (devices.length > 0) { | 242 if (devices.length > 0) { |
| 186 for (var i = 0; i < devices.length; i++) { | 243 for (var i = 0; i < devices.length; i++) { |
| 187 var element = this.createNewDeviceElement(devices[i]); | 244 var element = this.createNewDeviceElement(devices[i]); |
| 188 selectListDOM.appendChild(element); | 245 selectListDOM.appendChild(element); |
| 189 } | 246 } |
| 190 this.selectDevice(devices[0].devicePath); | 247 this.selectDevice(devices[0].devicePath); |
| 191 } else { | 248 } else { |
| 192 this.selectedDevice = undefined; | 249 this.selectedDevice = undefined; |
| 193 } | 250 } |
| 194 return this.deviceCount; | 251 return this.deviceCount; |
| 195 }, | 252 }, |
| 196 | 253 |
| 254 /** |
| 255 * Handles device added event. |
| 256 * @param {Object} device Device information. |
| 257 * @param {boolean} allowSelect True to update the selected device info. |
| 258 * @return {number} Device count. |
| 259 */ |
| 197 deviceAdded: function(device, allowSelect) { | 260 deviceAdded: function(device, allowSelect) { |
| 198 var selectListDOM = $('device-selection'); | 261 var selectListDOM = $('device-selection'); |
| 199 selectListDOM.appendChild(this.createNewDeviceElement(device)); | 262 selectListDOM.appendChild(this.createNewDeviceElement(device)); |
| 200 this.deviceCount++; | 263 this.deviceCount++; |
| 201 if (allowSelect && this.deviceCount == 1) | 264 if (allowSelect && this.deviceCount == 1) |
| 202 this.selectDevice(device.devicePath); | 265 this.selectDevice(device.devicePath); |
| 203 return this.deviceCount; | 266 return this.deviceCount; |
| 204 }, | 267 }, |
| 205 | 268 |
| 269 /** |
| 270 * Handles device removed event. |
| 271 * @param {string} devicePath Selected device path. |
| 272 * @param {boolean} allowSelect True to update the selected device info. |
| 273 * @return {number} Device count. |
| 274 */ |
| 206 deviceRemoved: function(devicePath, allowSelect) { | 275 deviceRemoved: function(devicePath, allowSelect) { |
| 207 var deviceSelectElement = $('select ' + devicePath); | 276 var deviceSelectElement = $('select ' + devicePath); |
| 208 deviceSelectElement.parentNode.removeChild(deviceSelectElement); | 277 deviceSelectElement.parentNode.removeChild(deviceSelectElement); |
| 209 this.deviceCount--; | 278 this.deviceCount--; |
| 210 var devices = document.getElementsByClassName('selection-element'); | 279 var devices = document.getElementsByClassName('selection-element'); |
| 211 | 280 |
| 212 if (allowSelect) { | 281 if (allowSelect) { |
| 213 if (devices.length > 0) { | 282 if (devices.length > 0) { |
| 214 if (this.selectedDevice == devicePath) | 283 if (this.selectedDevice == devicePath) |
| 215 this.selectDevice(devices[0].devicePath); | 284 this.selectDevice(devices[0].devicePath); |
| 216 } else { | 285 } else { |
| 217 this.selectedDevice = undefined; | 286 this.selectedDevice = undefined; |
| 218 } | 287 } |
| 219 } | 288 } |
| 220 return this.deviceCount; | 289 return this.deviceCount; |
| 221 } | 290 } |
| 222 }; | 291 }; |
| 223 | 292 |
| 224 // Class that handles communication with chrome. | 293 /** |
| 294 * Class that handles communication with chrome. |
| 295 * @constructor |
| 296 */ |
| 225 function BrowserBridge() { | 297 function BrowserBridge() { |
| 226 this.currentState = new State(localStrings); | 298 this.currentState = new State(localStrings); |
| 227 this.devices = new DeviceSelection(); | 299 this.devices = new DeviceSelection(); |
| 228 // We will use these often so it makes sence making them class members to | 300 // We will use these often so it makes sence making them class members to |
| 229 // avoid frequent document.getElementById calls. | 301 // avoid frequent document.getElementById calls. |
| 230 this.progressElement = $('progress-div'); | 302 this.progressElement = $('progress-div'); |
| 231 this.progressText = $('progress-text'); | 303 this.progressText = $('progress-text'); |
| 232 this.progressTimeLeftText = $('pending-time'); | 304 this.progressTimeLeftText = $('pending-time'); |
| 233 }; | 305 } |
| 234 | 306 |
| 235 BrowserBridge.prototype = { | 307 BrowserBridge.prototype = { |
| 236 sendCancelMessage: function() { | 308 sendCancelMessage: function() { |
| 237 chrome.send("cancelBurnImage"); | 309 chrome.send('cancelBurnImage'); |
| 238 }, | 310 }, |
| 239 | 311 |
| 240 sendGetDevicesMessage: function() { | 312 sendGetDevicesMessage: function() { |
| 241 chrome.send("getDevices"); | 313 chrome.send('getDevices'); |
| 242 }, | 314 }, |
| 243 | 315 |
| 244 sendWebuiInitializedMessage: function() { | 316 sendWebuiInitializedMessage: function() { |
| 245 chrome.send("webuiInitialized"); | 317 chrome.send('webuiInitialized'); |
| 246 }, | 318 }, |
| 247 | 319 |
| 320 /** |
| 321 * Sends the burn image message to c++ code. |
| 322 * @param {string} filePath Specifies the file path. |
| 323 * @param {string} devicePath Specifies the device path. |
| 324 */ |
| 248 sendBurnImageMessage: function(filePath, devicePath) { | 325 sendBurnImageMessage: function(filePath, devicePath) { |
| 249 chrome.send('burnImage', [devicePath, filePath]); | 326 chrome.send('burnImage', [devicePath, filePath]); |
| 250 }, | 327 }, |
| 251 | 328 |
| 252 reportSuccess: function() { | 329 reportSuccess: function() { |
| 253 this.currentState.changeState(State.StatesEnum.SUCCESS); | 330 this.currentState.changeState(State.StatesEnum.SUCCESS); |
| 254 }, | 331 }, |
| 255 | 332 |
| 333 /** |
| 334 * Update the device state to report a failure and display an error message to |
| 335 * the user. |
| 336 * @param {string} errorMessage Specifies the warning text message. |
| 337 */ |
| 256 reportFail: function(errorMessage) { | 338 reportFail: function(errorMessage) { |
| 257 this.currentState.changeState(State.StatesEnum.FAIL); | 339 this.currentState.changeState(State.StatesEnum.FAIL); |
| 258 $('warning-text').textContent = errorMessage; | 340 $('warning-text').textContent = errorMessage; |
| 259 $('warning-button').onclick = this.onBurnRetry.bind(this); | 341 $('warning-button').onclick = this.onBurnRetry.bind(this); |
| 260 }, | 342 }, |
| 261 | 343 |
| 344 /** |
| 345 * Handles device added event. |
| 346 * @param {Object} device Device information. |
| 347 */ |
| 262 deviceAdded: function(device) { | 348 deviceAdded: function(device) { |
| 263 var inInitialState = this.currentState.isInitialState(); | 349 var inInitialState = this.currentState.isInitialState(); |
| 264 var deviceCount = this.devices.deviceAdded(device, inInitialState); | 350 var deviceCount = this.devices.deviceAdded(device, inInitialState); |
| 265 if (inInitialState) | 351 if (inInitialState) |
| 266 this.currentState.gotoInitialState(deviceCount); | 352 this.currentState.gotoInitialState(deviceCount); |
| 267 }, | 353 }, |
| 268 | 354 |
| 355 /** |
| 356 * Handles device removed event. |
| 357 * @param {Object} device Device information. |
| 358 */ |
| 269 deviceRemoved: function(device) { | 359 deviceRemoved: function(device) { |
| 270 var inInitialState = this.currentState.isInitialState(); | 360 var inInitialState = this.currentState.isInitialState(); |
| 271 var deviceCount = this.devices.deviceRemoved(device, inInitialState); | 361 var deviceCount = this.devices.deviceRemoved(device, inInitialState); |
| 272 if (inInitialState) | 362 if (inInitialState) |
| 273 this.currentState.gotoInitialState(deviceCount); | 363 this.currentState.gotoInitialState(deviceCount); |
| 274 }, | 364 }, |
| 275 | 365 |
| 366 /** |
| 367 * Gets device callbacks and update the current state. |
| 368 * @param {Array} devices List of devices. |
| 369 */ |
| 276 getDevicesCallback: function(devices) { | 370 getDevicesCallback: function(devices) { |
| 277 var deviceCount = this.devices.getDevicesCallback(devices); | 371 var deviceCount = this.devices.getDevicesCallback(devices); |
| 278 this.currentState.gotoInitialState(deviceCount); | 372 this.currentState.gotoInitialState(deviceCount); |
| 279 this.sendWebuiInitializedMessage(); | 373 this.sendWebuiInitializedMessage(); |
| 280 }, | 374 }, |
| 281 | 375 |
| 282 updateProgress: function(update_signal) { | 376 /** |
| 283 if (update_signal.progressType == 'download' && | 377 * Updates the progress information based on the signal received. |
| 378 * @param {Object} updateSignal Specifies the signal information. |
| 379 */ |
| 380 updateProgress: function(updateSignal) { |
| 381 if (updateSignal.progressType == 'download' && |
| 284 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { | 382 !this.currentState.equals(State.StatesEnum.PROGRESS_DOWNLOAD)) { |
| 285 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); | 383 this.currentState.changeState(State.StatesEnum.PROGRESS_DOWNLOAD); |
| 286 } else if (update_signal.progressType == 'unzip' && | 384 } else if (updateSignal.progressType == 'unzip' && |
| 287 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { | 385 !this.currentState.equals(State.StatesEnum.PROGRESS_UNZIP)) { |
| 288 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); | 386 this.currentState.changeState(State.StatesEnum.PROGRESS_UNZIP); |
| 289 } else if (update_signal.progressType == 'burn' && | 387 } else if (updateSignal.progressType == 'burn' && |
| 290 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { | 388 !this.currentState.equals(State.StatesEnum.PROGRESS_BURN)) { |
| 291 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); | 389 this.currentState.changeState(State.StatesEnum.PROGRESS_BURN); |
| 292 } | 390 } |
| 293 | 391 |
| 294 if (!(update_signal.amountTotal > 0)) { | 392 if (!(updateSignal.amountTotal > 0)) { |
| 295 this.progressElement.removeAttribute('value'); | 393 this.progressElement.removeAttribute('value'); |
| 296 } else { | 394 } else { |
| 297 this.progressElement.value = update_signal.amountFinished; | 395 this.progressElement.value = updateSignal.amountFinished; |
| 298 this.progressElement.max = update_signal.amountTotal; | 396 this.progressElement.max = updateSignal.amountTotal; |
| 299 } | 397 } |
| 300 | 398 |
| 301 this.progressText.textContent = update_signal.progressText; | 399 this.progressText.textContent = updateSignal.progressText; |
| 302 this.progressTimeLeftText.textContent = update_signal.timeLeftText; | 400 this.progressTimeLeftText.textContent = updateSignal.timeLeftText; |
| 303 }, | 401 }, |
| 304 | 402 |
| 305 reportNoNetwork: function() { | 403 reportNoNetwork: function() { |
| 306 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); | 404 this.currentState.changeState(State.StatesEnum.ERROR_NO_NETWORK); |
| 307 }, | 405 }, |
| 308 | 406 |
| 309 reportNetworkDetected: function() { | 407 reportNetworkDetected: function() { |
| 310 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { | 408 if (this.currentState.equals(State.StatesEnum.ERROR_NO_NETWORK)) { |
| 311 var deviceCount = this.devices.showDeviceSelection(); | 409 var deviceCount = this.devices.showDeviceSelection(); |
| 312 this.currentState.gotoInitialState(deviceCount); | 410 this.currentState.gotoInitialState(deviceCount); |
| 313 } | 411 } |
| 314 }, | 412 }, |
| 315 | 413 |
| 316 reportDeviceTooSmall: function(device_size) { | 414 /** |
| 415 * Updates the current state to report device too small error. |
| 416 * @param {number} deviceSize Received device size. |
| 417 */ |
| 418 reportDeviceTooSmall: function(deviceSize) { |
| 317 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); | 419 this.currentState.changeState(State.StatesEnum.ERROR_DEVICE_TOO_SMALL); |
| 318 $('warning-text').textContent = | 420 $('warning-text').textContent = |
| 319 localStrings.getStringF('warningNoSpace', device_size); | 421 localStrings.getStringF('warningNoSpace', deviceSize); |
| 320 }, | 422 }, |
| 321 | 423 |
| 322 // Processes click on "Retry" button in FAIL state. | 424 /** |
| 323 onBurnRetry: function () { | 425 * Processes click on 'Retry' button in FAIL state. |
| 426 */ |
| 427 onBurnRetry: function() { |
| 324 var deviceCount = this.devices.showDeviceSelection(); | 428 var deviceCount = this.devices.showDeviceSelection(); |
| 325 this.currentState.gotoInitialState(deviceCount); | 429 this.currentState.gotoInitialState(deviceCount); |
| 326 } | 430 } |
| 327 }; | 431 }; |
| 328 | 432 |
| 329 document.addEventListener('DOMContentLoaded', function() { | 433 document.addEventListener('DOMContentLoaded', function() { |
| 330 localStrings = new LocalStrings(); | 434 localStrings = new LocalStrings(); |
| 331 browserBridge = new BrowserBridge(); | 435 browserBridge = new BrowserBridge(); |
| 332 | 436 |
| 333 jstProcess(new JsEvalContext(templateData), $("more-info-link")); | 437 jstProcess(new JsEvalContext(templateData), $('more-info-link')); |
| 334 | 438 |
| 335 $('cancel-button').onclick = | 439 $('cancel-button').onclick = |
| 336 browserBridge.sendCancelMessage.bind(browserBridge); | 440 browserBridge.sendCancelMessage.bind(browserBridge); |
| 337 browserBridge.sendGetDevicesMessage(); | 441 browserBridge.sendGetDevicesMessage(); |
| 338 }); | 442 }); |
| OLD | NEW |