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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 clearElement(this.domElement); | 93 clearElement(this.domElement); |
94 } else { | 94 } else { |
95 this.domElement = document.createElement('div'); | 95 this.domElement = document.createElement('div'); |
96 this.deviceContainer().appendChild(this.domElement); | 96 this.deviceContainer().appendChild(this.domElement); |
97 } | 97 } |
98 | 98 |
99 this.registerButton = fillDeviceDescription( | 99 this.registerButton = fillDeviceDescription( |
100 this.domElement, | 100 this.domElement, |
101 this.info.human_readable_name, | 101 this.info.human_readable_name, |
102 this.info.description, | 102 this.info.description, |
| 103 this.info.type, |
103 loadTimeData.getString('serviceRegister'), | 104 loadTimeData.getString('serviceRegister'), |
104 this.showRegister.bind(this)); | 105 this.showRegister.bind(this)); |
105 | 106 |
106 this.setRegisterEnabled(this.registerEnabled); | 107 this.setRegisterEnabled(this.registerEnabled); |
107 }, | 108 }, |
108 | 109 |
109 /** | 110 /** |
110 * Return the correct container for the device. | 111 * Return the correct container for the device. |
111 * @param {boolean} is_mine Whether or not the device is in the 'Registered' | 112 * @param {boolean} is_mine Whether or not the device is in the 'Registered' |
112 * section. | 113 * section. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return loadTimeData.getStringF('printersOnNetworkMultiple', | 177 return loadTimeData.getStringF('printersOnNetworkMultiple', |
177 numberPrinters); | 178 numberPrinters); |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 /** | 182 /** |
182 * Fill device element with the description of a device. | 183 * Fill device element with the description of a device. |
183 * @param {HTMLElement} device_dom_element Element to be filled. | 184 * @param {HTMLElement} device_dom_element Element to be filled. |
184 * @param {string} name Name of device. | 185 * @param {string} name Name of device. |
185 * @param {string} description Description of device. | 186 * @param {string} description Description of device. |
| 187 * @param {string} type Type of device. |
186 * @param {string} button_text Text to appear on button. | 188 * @param {string} button_text Text to appear on button. |
187 * @param {function()} button_action Action for button. | 189 * @param {function()} button_action Action for button. |
188 * @return {HTMLElement} The button (for enabling/disabling/rebinding) | 190 * @return {HTMLElement} The button (for enabling/disabling/rebinding) |
189 */ | 191 */ |
190 function fillDeviceDescription(device_dom_element, | 192 function fillDeviceDescription(device_dom_element, |
191 name, | 193 name, |
192 description, | 194 description, |
193 button_text, | 195 type, |
194 button_action) { | 196 button_text, |
| 197 button_action) { |
195 device_dom_element.classList.add('device'); | 198 device_dom_element.classList.add('device'); |
196 device_dom_element.classList.add('printer'); | 199 if (type == 'printer') |
| 200 device_dom_element.classList.add('printer'); |
197 | 201 |
198 var deviceInfo = document.createElement('div'); | 202 var deviceInfo = document.createElement('div'); |
199 deviceInfo.className = 'device-info'; | 203 deviceInfo.className = 'device-info'; |
200 device_dom_element.appendChild(deviceInfo); | 204 device_dom_element.appendChild(deviceInfo); |
201 | 205 |
202 var deviceName = document.createElement('h3'); | 206 var deviceName = document.createElement('h3'); |
203 deviceName.className = 'device-name'; | 207 deviceName.className = 'device-name'; |
204 deviceName.textContent = name; | 208 deviceName.textContent = name; |
205 deviceInfo.appendChild(deviceName); | 209 deviceInfo.appendChild(deviceName); |
206 | 210 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 322 |
319 /** | 323 /** |
320 * Create the DOM for a cloud device described by the device section. | 324 * Create the DOM for a cloud device described by the device section. |
321 * @param {Array.<Object>} devices_list List of devices. | 325 * @param {Array.<Object>} devices_list List of devices. |
322 */ | 326 */ |
323 function createCloudDeviceDOM(device) { | 327 function createCloudDeviceDOM(device) { |
324 var devicesDomElement = document.createElement('div'); | 328 var devicesDomElement = document.createElement('div'); |
325 | 329 |
326 var description; | 330 var description; |
327 if (device.description == '') { | 331 if (device.description == '') { |
328 description = loadTimeData.getString('noDescription'); | 332 description = loadTimeData.getString('noDescription'); |
329 } else { | 333 } else { |
330 description = device.description; | 334 description = device.description; |
331 } | 335 } |
332 | 336 |
333 fillDeviceDescription(devicesDomElement, device.display_name, | 337 fillDeviceDescription(devicesDomElement, device.display_name, |
334 description, 'Manage' /*Localize*/, | 338 description, device.type, 'Manage' /*Localize*/, |
335 manageCloudDevice.bind(null, device.id)); | 339 manageCloudDevice.bind(null, device.id)); |
336 return devicesDomElement; | 340 return devicesDomElement; |
337 } | 341 } |
338 | 342 |
339 /** | 343 /** |
340 * Handle a list of cloud devices available to the user globally. | 344 * Handle a list of cloud devices available to the user globally. |
341 * @param {Array.<Object>} devices_list List of devices. | 345 * @param {Array.<Object>} devices_list List of devices. |
342 */ | 346 */ |
343 function onCloudDeviceListAvailable(devices_list) { | 347 function onCloudDeviceListAvailable(devices_list) { |
344 var devicesListLength = devices_list.length; | 348 var devicesListLength = devices_list.length; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 onCloudDeviceListAvailable: onCloudDeviceListAvailable, | 619 onCloudDeviceListAvailable: onCloudDeviceListAvailable, |
616 onCloudDeviceListUnavailable: onCloudDeviceListUnavailable, | 620 onCloudDeviceListUnavailable: onCloudDeviceListUnavailable, |
617 onDeviceCacheFlushed: onDeviceCacheFlushed, | 621 onDeviceCacheFlushed: onDeviceCacheFlushed, |
618 onRegistrationCanceledPrinter: onRegistrationCanceledPrinter, | 622 onRegistrationCanceledPrinter: onRegistrationCanceledPrinter, |
619 onRegistrationTimeout: onRegistrationTimeout, | 623 onRegistrationTimeout: onRegistrationTimeout, |
620 setUserLoggedIn: setUserLoggedIn, | 624 setUserLoggedIn: setUserLoggedIn, |
621 setupCloudPrintConnectorSection: setupCloudPrintConnectorSection, | 625 setupCloudPrintConnectorSection: setupCloudPrintConnectorSection, |
622 removeCloudPrintConnectorSection: removeCloudPrintConnectorSection | 626 removeCloudPrintConnectorSection: removeCloudPrintConnectorSection |
623 }; | 627 }; |
624 }); | 628 }); |
OLD | NEW |