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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 this.onRename_ = function(host) {}; | 46 this.onRename_ = function(host) {}; |
47 /** @type {undefined|function(remoting.HostTableEntry):void} @private */ | 47 /** @type {undefined|function(remoting.HostTableEntry):void} @private */ |
48 this.onDelete_ = function(host) {}; | 48 this.onDelete_ = function(host) {}; |
49 // References to event handlers so that they can be removed. | 49 // References to event handlers so that they can be removed. |
50 /** @type {function():void} @private */ | 50 /** @type {function():void} @private */ |
51 this.onBlurReference_ = function() {}; | 51 this.onBlurReference_ = function() {}; |
52 /** @type {function():void} @private */ | 52 /** @type {function():void} @private */ |
53 this.onConfirmDeleteReference_ = function() {}; | 53 this.onConfirmDeleteReference_ = function() {}; |
54 /** @type {function():void} @private */ | 54 /** @type {function():void} @private */ |
55 this.onCancelDeleteReference_ = function() {}; | 55 this.onCancelDeleteReference_ = function() {}; |
56 /** @type {function():void} @private */ | 56 /** @type {function():void?} @private */ |
57 this.onConnectReference_ = function() {}; | 57 this.onConnectReference_ = null; |
58 }; | 58 }; |
59 | 59 |
60 /** | 60 /** |
61 * Create the HTML elements for this entry and set up event handlers. | 61 * Create the HTML elements for this entry and set up event handlers. |
62 * @param {remoting.Host} host The host, as obtained from Apiary. | 62 * @param {remoting.Host} host The host, as obtained from Apiary. |
63 * @param {function(remoting.HostTableEntry):void} onRename Callback for | 63 * @param {function(remoting.HostTableEntry):void} onRename Callback for |
64 * rename operations. | 64 * rename operations. |
65 * @param {function(remoting.HostTableEntry):void} onDelete Callback for | 65 * @param {function(remoting.HostTableEntry):void} onDelete Callback for |
66 * delete operations. | 66 * delete operations. |
67 * @return {void} Nothing. | 67 * @return {void} Nothing. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 }; | 138 }; |
139 editButton.addEventListener('click', beginRename, true); | 139 editButton.addEventListener('click', beginRename, true); |
140 if (opt_deleteButton) { | 140 if (opt_deleteButton) { |
141 /** @param {Event} event The click event. */ | 141 /** @param {Event} event The click event. */ |
142 var confirmDelete = function(event) { | 142 var confirmDelete = function(event) { |
143 that.showDeleteConfirmation_(); | 143 that.showDeleteConfirmation_(); |
144 event.stopPropagation(); | 144 event.stopPropagation(); |
145 }; | 145 }; |
146 opt_deleteButton.addEventListener('click', confirmDelete, false); | 146 opt_deleteButton.addEventListener('click', confirmDelete, false); |
147 } | 147 } |
148 var hostUrl = chrome.extension.getURL('main.html') + | |
149 '?mode=me2me&hostId=' + encodeURIComponent(host.hostId); | |
150 this.onConnectReference_ = function() { window.location.assign(hostUrl); }; | |
151 | |
152 this.updateStatus(); | 148 this.updateStatus(); |
153 }; | 149 }; |
154 | 150 |
155 /** | 151 /** |
156 * Update the row to reflect the current status of the host (online/offline and | 152 * Update the row to reflect the current status of the host (online/offline and |
157 * clickable/unclickable). | 153 * clickable/unclickable). |
158 * | 154 * |
159 * @param {boolean=} opt_forEdit True if the status is being updated in order | 155 * @param {boolean=} opt_forEdit True if the status is being updated in order |
160 * to allow the host name to be edited. | 156 * to allow the host name to be edited. |
161 * @return {void} Nothing. | 157 * @return {void} Nothing. |
162 */ | 158 */ |
163 remoting.HostTableEntry.prototype.updateStatus = function(opt_forEdit) { | 159 remoting.HostTableEntry.prototype.updateStatus = function(opt_forEdit) { |
164 var clickToConnect = this.host.status == 'ONLINE' && !opt_forEdit; | 160 var clickToConnect = this.host.status == 'ONLINE' && !opt_forEdit; |
165 if (clickToConnect) { | 161 if (clickToConnect) { |
166 this.tableRow.addEventListener('click', this.onConnectReference_, false); | 162 if (!this.onConnectReference_) { |
| 163 /** @type {remoting.HostTableEntry} */ |
| 164 var that = this; |
| 165 this.onConnectReference_ = function() { |
| 166 var hostUrl = chrome.extension.getURL('main.html') + |
| 167 '?mode=me2me&hostId=' + encodeURIComponent(that.host.hostId); |
| 168 window.location.assign(hostUrl); |
| 169 }; |
| 170 this.tableRow.addEventListener('click', this.onConnectReference_, false); |
| 171 } |
167 this.tableRow.classList.add('clickable'); | 172 this.tableRow.classList.add('clickable'); |
168 this.tableRow.title = chrome.i18n.getMessage( | 173 this.tableRow.title = chrome.i18n.getMessage( |
169 /*i18n-content*/'TOOLTIP_CONNECT', this.host.hostName); | 174 /*i18n-content*/'TOOLTIP_CONNECT', this.host.hostName); |
170 } else { | 175 } else { |
171 this.tableRow.removeEventListener('click', this.onConnectReference_, false); | 176 if (this.onConnectReference_) { |
| 177 this.tableRow.removeEventListener('click', this.onConnectReference_, |
| 178 false); |
| 179 this.onConnectReference_ = null; |
| 180 } |
172 this.tableRow.classList.remove('clickable'); | 181 this.tableRow.classList.remove('clickable'); |
173 this.tableRow.title = ''; | 182 this.tableRow.title = ''; |
174 } | 183 } |
175 var showOffline = this.host.status != 'ONLINE'; | 184 var showOffline = this.host.status != 'ONLINE'; |
176 if (showOffline) { | 185 if (showOffline) { |
177 this.tableRow.classList.remove('host-online'); | 186 this.tableRow.classList.remove('host-online'); |
178 this.tableRow.classList.add('host-offline'); | 187 this.tableRow.classList.add('host-offline'); |
179 } else { | 188 } else { |
180 this.tableRow.classList.add('host-online'); | 189 this.tableRow.classList.add('host-online'); |
181 this.tableRow.classList.remove('host-offline'); | 190 this.tableRow.classList.remove('host-offline'); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 * @return {void} Nothing. | 326 * @return {void} Nothing. |
318 * @private | 327 * @private |
319 */ | 328 */ |
320 remoting.HostTableEntry.prototype.onKeydown_ = function(event) { | 329 remoting.HostTableEntry.prototype.onKeydown_ = function(event) { |
321 if (event.which == 27) { // Escape | 330 if (event.which == 27) { // Escape |
322 this.removeEditBox_(); | 331 this.removeEditBox_(); |
323 } else if (event.which == 13) { // Enter | 332 } else if (event.which == 13) { // Enter |
324 this.commitRename_(); | 333 this.commitRename_(); |
325 } | 334 } |
326 }; | 335 }; |
OLD | NEW |