| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 5 /** |
| 6 * Javascript for local_discovery.html, served from chrome://devices/ | 6 * Javascript for local_discovery.html, served from chrome://devices/ |
| 7 * This is used to show discoverable devices near the user as well as | 7 * This is used to show discoverable devices near the user as well as |
| 8 * cloud devices registered to them. | 8 * cloud devices registered to them. |
| 9 * | 9 * |
| 10 * The object defined in this javascript file listens for callbacks from the | 10 * The object defined in this javascript file listens for callbacks from the |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 devices[name] = new Device(info); | 200 devices[name] = new Device(info); |
| 201 devices[name].renderDevice(); | 201 devices[name].renderDevice(); |
| 202 } | 202 } |
| 203 } else { | 203 } else { |
| 204 if (devices.hasOwnProperty(name)) { | 204 if (devices.hasOwnProperty(name)) { |
| 205 devices[name].removeDevice(); | 205 devices[name].removeDevice(); |
| 206 delete devices[name]; | 206 delete devices[name]; |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 var numberPrinters = $('register-device-list').children.length; | 210 updateUIToReflectNumberOfLocalDevices(); |
| 211 $('printer-num').textContent = generateNumberPrintersAvailableText( | |
| 212 numberPrinters); | |
| 213 | |
| 214 if (numberPrinters == 0) { | |
| 215 $('register-message').textContent = loadTimeData.getString( | |
| 216 'noPrintersOnNetworkExplanation'); | |
| 217 } else { | |
| 218 $('register-message').textContent = loadTimeData.getString( | |
| 219 'registerConfirmMessage'); | |
| 220 } | |
| 221 } | 211 } |
| 222 | 212 |
| 223 /** | 213 /** |
| 224 * Handle a list of cloud devices available to the user globally. | 214 * Handle a list of cloud devices available to the user globally. |
| 225 * @param {Array.<Object>} devices_list List of devices. | 215 * @param {Array.<Object>} devices_list List of devices. |
| 226 */ | 216 */ |
| 227 function onCloudDeviceListAvailable(devices_list) { | 217 function onCloudDeviceListAvailable(devices_list) { |
| 228 var devicesListLength = devices_list.length; | 218 var devicesListLength = devices_list.length; |
| 229 var devicesContainer = $('cloud-devices'); | 219 var devicesContainer = $('cloud-devices'); |
| 230 | 220 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 241 } else { | 231 } else { |
| 242 description = devices_list[i].description; | 232 description = devices_list[i].description; |
| 243 } | 233 } |
| 244 | 234 |
| 245 fillDeviceDescription(devicesDomElement, devices_list[i].display_name, | 235 fillDeviceDescription(devicesDomElement, devices_list[i].display_name, |
| 246 description, 'Manage' /*Localize*/, | 236 description, 'Manage' /*Localize*/, |
| 247 manageCloudDevice.bind(null, devices_list[i].id)); | 237 manageCloudDevice.bind(null, devices_list[i].id)); |
| 248 } | 238 } |
| 249 } | 239 } |
| 250 | 240 |
| 241 function onDeviceCacheFlushed() { |
| 242 for (var deviceName in devices) { |
| 243 devices[deviceName].removeDevice(); |
| 244 delete devices[deviceName]; |
| 245 } |
| 246 |
| 247 updateUIToReflectNumberOfLocalDevices(); |
| 248 } |
| 249 |
| 250 function updateUIToReflectNumberOfLocalDevices() { |
| 251 var numberPrinters = $('register-device-list').children.length; |
| 252 $('printer-num').textContent = generateNumberPrintersAvailableText( |
| 253 numberPrinters); |
| 254 |
| 255 if (numberPrinters == 0) { |
| 256 $('register-message').textContent = loadTimeData.getString( |
| 257 'noPrintersOnNetworkExplanation'); |
| 258 } else { |
| 259 $('register-message').textContent = loadTimeData.getString( |
| 260 'registerConfirmMessage'); |
| 261 } |
| 262 } |
| 263 |
| 251 | 264 |
| 252 /** | 265 /** |
| 253 * Announce that a registration succeeeded. | 266 * Announce that a registration succeeeded. |
| 254 */ | 267 */ |
| 255 function onRegistrationSuccess() { | 268 function onRegistrationSuccess() { |
| 256 hideRegisterOverlay(); | 269 hideRegisterOverlay(); |
| 257 requestPrinterList(); | 270 requestPrinterList(); |
| 258 } | 271 } |
| 259 | 272 |
| 260 /** | 273 /** |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 337 |
| 325 chrome.send('start'); | 338 chrome.send('start'); |
| 326 requestPrinterList(); | 339 requestPrinterList(); |
| 327 }); | 340 }); |
| 328 | 341 |
| 329 return { | 342 return { |
| 330 onRegistrationSuccess: onRegistrationSuccess, | 343 onRegistrationSuccess: onRegistrationSuccess, |
| 331 onRegistrationFailed: onRegistrationFailed, | 344 onRegistrationFailed: onRegistrationFailed, |
| 332 onUnregisteredDeviceUpdate: onUnregisteredDeviceUpdate, | 345 onUnregisteredDeviceUpdate: onUnregisteredDeviceUpdate, |
| 333 onRegistrationConfirmedOnPrinter: onRegistrationConfirmedOnPrinter, | 346 onRegistrationConfirmedOnPrinter: onRegistrationConfirmedOnPrinter, |
| 334 onCloudDeviceListAvailable: onCloudDeviceListAvailable | 347 onCloudDeviceListAvailable: onCloudDeviceListAvailable, |
| 348 onDeviceCacheFlushed: onDeviceCacheFlushed |
| 335 }; | 349 }; |
| 336 }); | 350 }); |
| OLD | NEW |