| 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 an entry in the host-list portion of the home screen. | 7 * Class representing an entry in the host-list portion of the home screen. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 this.onRename_ = onRename; | 61 this.onRename_ = onRename; |
| 62 | 62 |
| 63 /** @type {remoting.HostTableEntry} */ | 63 /** @type {remoting.HostTableEntry} */ |
| 64 var that = this; | 64 var that = this; |
| 65 | 65 |
| 66 this.tableRow = document.createElement('tr'); | 66 this.tableRow = document.createElement('tr'); |
| 67 addClass(this.tableRow, 'host-list-row'); | 67 addClass(this.tableRow, 'host-list-row'); |
| 68 | 68 |
| 69 // Create the host icon cell. | 69 // Create the host icon cell. |
| 70 var hostIcon = document.createElement('td'); | 70 var hostIcon = document.createElement('td'); |
| 71 addClass(hostIcon, 'host-list-row-start'); | |
| 72 var hostIconImage = document.createElement('img'); | 71 var hostIconImage = document.createElement('img'); |
| 73 hostIconImage.src = 'icon_host.png'; | 72 hostIconImage.src = 'icon_host.png'; |
| 74 addClass(hostIconImage, 'host-list-main-icon'); | 73 addClass(hostIcon, 'host-list-main-icon'); |
| 75 hostIcon.appendChild(hostIconImage); | 74 hostIcon.appendChild(hostIconImage); |
| 76 this.tableRow.appendChild(hostIcon); | 75 this.tableRow.appendChild(hostIcon); |
| 77 | 76 |
| 78 // Create the host name cell. | 77 // Create the host name cell. |
| 79 this.hostNameCell_ = document.createElement('td'); | 78 this.hostNameCell_ = document.createElement('td'); |
| 80 addClass(this.hostNameCell_, 'mode-select-label'); | 79 this.setHostName_(); |
| 81 this.hostNameCell_.appendChild( | |
| 82 document.createTextNode(host.hostName)); | |
| 83 this.hostNameCell_.ondblclick = function() { that.beginRename_(); }; | |
| 84 this.tableRow.appendChild(this.hostNameCell_); | 80 this.tableRow.appendChild(this.hostNameCell_); |
| 85 | 81 |
| 86 // Create the host status cell. | 82 // Create the host status cell. |
| 87 var hostStatus = document.createElement('td'); | 83 var hostStatus = document.createElement('td'); |
| 88 if (host.status == 'ONLINE') { | 84 if (host.status == 'ONLINE') { |
| 89 var hostUrl = chrome.extension.getURL('main.html') + | 85 var hostUrl = chrome.extension.getURL('main.html') + |
| 90 '?mode=me2me&hostId=' + encodeURIComponent(host.hostId); | 86 '?mode=me2me&hostId=' + encodeURIComponent(host.hostId); |
| 91 var connectButton = document.createElement('button'); | |
| 92 connectButton.setAttribute('class', 'mode-select-button'); | |
| 93 connectButton.setAttribute('type', 'button'); | |
| 94 var startMe2Me = function() { window.location.replace(hostUrl); }; | 87 var startMe2Me = function() { window.location.replace(hostUrl); }; |
| 95 connectButton.addEventListener('click', startMe2Me, false); | 88 this.hostNameCell_.addEventListener('click', startMe2Me, false); |
| 96 connectButton.innerHTML = | 89 hostIcon.addEventListener('click', startMe2Me, false); |
| 97 chrome.i18n.getMessage(/*i18n-content*/'CONNECT_BUTTON'); | 90 hostStatus.addEventListener('click', startMe2Me, false); |
| 98 hostStatus.appendChild(connectButton); | 91 addClass(this.tableRow, 'clickable'); |
| 99 } else { | 92 } else { |
| 100 addClass(this.tableRow, 'host-offline'); | 93 addClass(this.tableRow, 'host-offline'); |
| 101 hostStatus.innerHTML = chrome.i18n.getMessage(/*i18n-content*/'OFFLINE'); | 94 hostStatus.innerHTML = chrome.i18n.getMessage(/*i18n-content*/'OFFLINE'); |
| 102 } | 95 } |
| 103 hostStatus.className = 'host-list-row-end'; | 96 hostStatus.className = 'host-list-label'; |
| 104 this.tableRow.appendChild(hostStatus); | 97 this.tableRow.appendChild(hostStatus); |
| 105 | 98 |
| 106 // Create the host rename cell. | 99 // Create the host rename cell. |
| 107 var editButton = document.createElement('td'); | 100 var editButton = document.createElement('td'); |
| 108 editButton.onclick = function() { that.beginRename_(); }; | 101 var beginRename = function() { that.beginRename_(); }; |
| 102 editButton.addEventListener('click', beginRename, true); |
| 109 addClass(editButton, 'clickable'); | 103 addClass(editButton, 'clickable'); |
| 110 addClass(editButton, 'host-list-edit'); | 104 addClass(editButton, 'host-list-edit'); |
| 111 var penImage = document.createElement('img'); | 105 var penImage = document.createElement('img'); |
| 112 penImage.src = 'icon_pencil.png'; | 106 penImage.src = 'icon_pencil.png'; |
| 113 addClass(penImage, 'host-list-rename-icon'); | 107 addClass(penImage, 'host-list-rename-icon'); |
| 114 editButton.appendChild(penImage); | 108 editButton.appendChild(penImage); |
| 115 this.tableRow.appendChild(editButton); | 109 this.tableRow.appendChild(editButton); |
| 116 | 110 |
| 117 // Create the host delete cell. | 111 // Create the host delete cell. |
| 118 var deleteButton = document.createElement('td'); | 112 var deleteButton = document.createElement('td'); |
| 119 deleteButton.onclick = function() { onDelete(that); } | 113 deleteButton.addEventListener('click', function() { onDelete(that); }, false); |
| 120 addClass(deleteButton, 'clickable'); | 114 addClass(deleteButton, 'clickable'); |
| 121 addClass(deleteButton, 'host-list-edit'); | 115 addClass(deleteButton, 'host-list-edit'); |
| 122 var crossImage = document.createElement('img'); | 116 var crossImage = document.createElement('img'); |
| 123 crossImage.src = 'icon_cross.png'; | 117 crossImage.src = 'icon_cross.png'; |
| 124 addClass(crossImage, 'host-list-remove-icon'); | 118 addClass(crossImage, 'host-list-remove-icon'); |
| 125 deleteButton.appendChild(crossImage); | 119 deleteButton.appendChild(crossImage); |
| 126 this.tableRow.appendChild(deleteButton); | 120 this.tableRow.appendChild(deleteButton); |
| 127 }; | 121 }; |
| 128 | 122 |
| 129 /** | 123 /** |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 * @return {void} Nothing. | 165 * @return {void} Nothing. |
| 172 * @private | 166 * @private |
| 173 */ | 167 */ |
| 174 remoting.HostTableEntry.prototype.removeEditBox_ = function() { | 168 remoting.HostTableEntry.prototype.removeEditBox_ = function() { |
| 175 var editBox = this.hostNameCell_.querySelector('input'); | 169 var editBox = this.hostNameCell_.querySelector('input'); |
| 176 if (editBox) { | 170 if (editBox) { |
| 177 // onblur will fire when the edit box is removed, so remove the hook. | 171 // onblur will fire when the edit box is removed, so remove the hook. |
| 178 editBox.removeEventListener('blur', this.onBlurReference_, false); | 172 editBox.removeEventListener('blur', this.onBlurReference_, false); |
| 179 } | 173 } |
| 180 this.hostNameCell_.innerHTML = ''; // Remove the edit box. | 174 this.hostNameCell_.innerHTML = ''; // Remove the edit box. |
| 181 this.hostNameCell_.appendChild(document.createTextNode(this.host.hostName)); | 175 this.setHostName_(); |
| 176 }; |
| 177 |
| 178 remoting.HostTableEntry.prototype.setHostName_ = function() { |
| 179 var hostNameNode = document.createElement('span'); |
| 180 hostNameNode.innerText = this.host.hostName; |
| 181 addClass(hostNameNode, 'host-list-label'); |
| 182 this.hostNameCell_.appendChild(hostNameNode); |
| 182 }; | 183 }; |
| 183 | 184 |
| 184 /** | 185 /** |
| 185 * Handle a key event while the user is typing a host name | 186 * Handle a key event while the user is typing a host name |
| 186 * @param {Event} event The keyboard event. | 187 * @param {Event} event The keyboard event. |
| 187 * @return {void} Nothing. | 188 * @return {void} Nothing. |
| 188 * @private | 189 * @private |
| 189 */ | 190 */ |
| 190 remoting.HostTableEntry.prototype.onKeydown_ = function(event) { | 191 remoting.HostTableEntry.prototype.onKeydown_ = function(event) { |
| 191 if (event.which == 27) { // Escape | 192 if (event.which == 27) { // Escape |
| 192 this.removeEditBox_(); | 193 this.removeEditBox_(); |
| 193 } else if (event.which == 13) { // Enter | 194 } else if (event.which == 13) { // Enter |
| 194 this.commitRename_(); | 195 this.commitRename_(); |
| 195 } | 196 } |
| 196 }; | 197 }; |
| OLD | NEW |