| OLD | NEW |
| 1 // Copyright (c) 2012 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Class representing the host-list portion of the home screen UI. | 7 * Class representing the host-list portion of the home screen UI. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Create a host list consisting of the specified HTML elements, which should | 16 * Create a host list consisting of the specified HTML elements, which should |
| 17 * have a common parent that contains only host-list UI as it will be hidden | 17 * have a common parent that contains only host-list UI as it will be hidden |
| 18 * if the host-list is empty. | 18 * if the host-list is empty. |
| 19 * | 19 * |
| 20 * @constructor | 20 * @constructor |
| 21 * @param {Element} table The HTML <div> to contain host-list. | 21 * @param {Element} table The HTML <div> to contain host-list. |
| 22 * @param {Element} noHosts The HTML <div> containing the "no hosts" message. | 22 * @param {Element} noHosts The HTML <div> containing the "no hosts" message. |
| 23 * @param {Element} errorMsg The HTML <div> to display error messages. | 23 * @param {Element} errorMsg The HTML <div> to display error messages. |
| 24 * @param {Element} errorButton The HTML <button> to display the error | 24 * @param {Element} errorButton The HTML <button> to display the error |
| 25 * resolution action. | 25 * resolution action. |
| 26 * @param {HTMLElement} loadingIndicator The HTML <span> to update while the | 26 * @param {HTMLElement} loadingIndicator The HTML <span> to update while the |
| 27 * host list is being loaded. The first element of this span should be | 27 * host list is being loaded. The first element of this span should be |
| 28 * the reload button. | 28 * the reload button. |
| 29 * @param {function(!remoting.Error)} onError Function to call when an error |
| 30 * occurs. |
| 29 */ | 31 */ |
| 30 remoting.HostList = function(table, noHosts, errorMsg, errorButton, | 32 remoting.HostList = function(table, noHosts, errorMsg, errorButton, |
| 31 loadingIndicator) { | 33 loadingIndicator, onError) { |
| 32 /** @private {Element} */ | 34 /** @private {Element} */ |
| 33 this.table_ = table; | 35 this.table_ = table; |
| 34 /** | 36 /** |
| 35 * TODO(jamiewalch): This should be doable using CSS's sibling selector, | 37 * TODO(jamiewalch): This should be doable using CSS's sibling selector, |
| 36 * but it doesn't work right now (crbug.com/135050). | 38 * but it doesn't work right now (crbug.com/135050). |
| 37 * @private {Element} | 39 * @private {Element} |
| 38 */ | 40 */ |
| 39 this.noHosts_ = noHosts; | 41 this.noHosts_ = noHosts; |
| 40 /** @private {Element} */ | 42 /** @private {Element} */ |
| 41 this.errorMsg_ = errorMsg; | 43 this.errorMsg_ = errorMsg; |
| 42 /** @private {Element} */ | 44 /** @private {Element} */ |
| 43 this.errorButton_ = errorButton; | 45 this.errorButton_ = errorButton; |
| 44 /** @private {HTMLElement} */ | 46 /** @private {HTMLElement} */ |
| 45 this.loadingIndicator_ = loadingIndicator; | 47 this.loadingIndicator_ = loadingIndicator; |
| 48 this.onError_ = onError; |
| 49 |
| 46 /** @private {Array<remoting.HostTableEntry>} */ | 50 /** @private {Array<remoting.HostTableEntry>} */ |
| 47 this.hostTableEntries_ = []; | 51 this.hostTableEntries_ = []; |
| 48 /** @private {Array<remoting.Host>} */ | 52 /** @private {Array<remoting.Host>} */ |
| 49 this.hosts_ = []; | 53 this.hosts_ = []; |
| 50 /** @private {!remoting.Error} */ | 54 /** @private {!remoting.Error} */ |
| 51 this.lastError_ = remoting.Error.none(); | 55 this.lastError_ = remoting.Error.none(); |
| 52 /** @private {remoting.LocalHostSection} */ | 56 /** @private {remoting.LocalHostSection} */ |
| 53 this.localHostSection_ = new remoting.LocalHostSection( | 57 this.localHostSection_ = new remoting.LocalHostSection( |
| 54 /** @type {HTMLElement} */ (document.querySelector('.daemon-control')), | 58 /** @type {HTMLElement} */ (document.querySelector('.daemon-control')), |
| 55 new remoting.LocalHostSection.Controller( | 59 new remoting.LocalHostSection.Controller( |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 * @return {void} Nothing. | 292 * @return {void} Nothing. |
| 289 * @private | 293 * @private |
| 290 */ | 294 */ |
| 291 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { | 295 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { |
| 292 this.table_.removeChild(hostTableEntry.element()); | 296 this.table_.removeChild(hostTableEntry.element()); |
| 293 var index = this.hostTableEntries_.indexOf(hostTableEntry); | 297 var index = this.hostTableEntries_.indexOf(hostTableEntry); |
| 294 if (index != -1) { | 298 if (index != -1) { |
| 295 this.hostTableEntries_.splice(index, 1); | 299 this.hostTableEntries_.splice(index, 1); |
| 296 } | 300 } |
| 297 remoting.hostListApi.remove(hostTableEntry.host.hostId, base.doNothing, | 301 remoting.hostListApi.remove(hostTableEntry.host.hostId, base.doNothing, |
| 298 remoting.showErrorMessage); | 302 this.onError_); |
| 299 }; | 303 }; |
| 300 | 304 |
| 301 /** | 305 /** |
| 302 * Prepare a host for renaming by replacing its name with an edit box. | 306 * Prepare a host for renaming by replacing its name with an edit box. |
| 303 * @param {remoting.HostTableEntry} hostTableEntry The host to be renamed. | 307 * @param {remoting.HostTableEntry} hostTableEntry The host to be renamed. |
| 304 * @return {void} Nothing. | 308 * @return {void} Nothing. |
| 305 */ | 309 */ |
| 306 remoting.HostList.prototype.renameHost = function(hostTableEntry) { | 310 remoting.HostList.prototype.renameHost = function(hostTableEntry) { |
| 307 for (var i = 0; i < this.hosts_.length; ++i) { | 311 for (var i = 0; i < this.hosts_.length; ++i) { |
| 308 if (this.hosts_[i].hostId == hostTableEntry.host.hostId) { | 312 if (this.hosts_[i].hostId == hostTableEntry.host.hostId) { |
| 309 this.hosts_[i].hostName = hostTableEntry.host.hostName; | 313 this.hosts_[i].hostName = hostTableEntry.host.hostName; |
| 310 break; | 314 break; |
| 311 } | 315 } |
| 312 } | 316 } |
| 313 this.save_(); | 317 this.save_(); |
| 314 | 318 |
| 315 remoting.hostListApi.put(hostTableEntry.host.hostId, | 319 remoting.hostListApi.put(hostTableEntry.host.hostId, |
| 316 hostTableEntry.host.hostName, | 320 hostTableEntry.host.hostName, |
| 317 hostTableEntry.host.publicKey, | 321 hostTableEntry.host.publicKey, |
| 318 function() {}, | 322 function() {}, |
| 319 remoting.showErrorMessage); | 323 this.onError_); |
| 320 }; | 324 }; |
| 321 | 325 |
| 322 /** | 326 /** |
| 323 * Unregister a host. | 327 * Unregister a host. |
| 324 * @param {string} hostId The id of the host to be removed. | 328 * @param {string} hostId The id of the host to be removed. |
| 325 * @param {function(void)=} opt_onDone | 329 * @param {function(void)=} opt_onDone |
| 326 * @return {void} Nothing. | 330 * @return {void} Nothing. |
| 327 */ | 331 */ |
| 328 remoting.HostList.prototype.unregisterHostById = function(hostId, opt_onDone) { | 332 remoting.HostList.prototype.unregisterHostById = function(hostId, opt_onDone) { |
| 329 var that = this; | 333 var that = this; |
| 330 var onDone = opt_onDone || base.doNothing; | 334 var onDone = opt_onDone || base.doNothing; |
| 331 | 335 |
| 332 var host = this.getHostForId(hostId); | 336 var host = this.getHostForId(hostId); |
| 333 if (!host) { | 337 if (!host) { |
| 334 console.log('Skipping host un-registration as the host is not registered ' + | 338 console.log('Skipping host un-registration as the host is not registered ' + |
| 335 'under the current account'); | 339 'under the current account'); |
| 336 onDone(); | 340 onDone(); |
| 337 return; | 341 return; |
| 338 } | 342 } |
| 339 | 343 |
| 340 var onRemoved = function() { | 344 var onRemoved = function() { |
| 341 that.refresh(function() { | 345 that.refresh(function() { |
| 342 that.display(); | 346 that.display(); |
| 343 onDone(); | 347 onDone(); |
| 344 }); | 348 }); |
| 345 }; | 349 }; |
| 346 remoting.hostListApi.remove(hostId, onRemoved, remoting.showErrorMessage); | 350 remoting.hostListApi.remove(hostId, onRemoved, this.onError_); |
| 347 }; | 351 }; |
| 348 | 352 |
| 349 /** | 353 /** |
| 350 * Set the state of the local host and localHostId if any. | 354 * Set the state of the local host and localHostId if any. |
| 351 * | 355 * |
| 352 * @param {remoting.HostController.State} state State of the local host. | 356 * @param {remoting.HostController.State} state State of the local host. |
| 353 * @param {string?} hostId ID of the local host, or null. | 357 * @param {string?} hostId ID of the local host, or null. |
| 354 * @return {void} Nothing. | 358 * @return {void} Nothing. |
| 355 */ | 359 */ |
| 356 remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) { | 360 remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 419 } |
| 416 }; | 420 }; |
| 417 | 421 |
| 418 /** | 422 /** |
| 419 * Key name under which Me2Me hosts are cached. | 423 * Key name under which Me2Me hosts are cached. |
| 420 */ | 424 */ |
| 421 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 425 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
| 422 | 426 |
| 423 /** @type {remoting.HostList} */ | 427 /** @type {remoting.HostList} */ |
| 424 remoting.hostList = null; | 428 remoting.hostList = null; |
| OLD | NEW |