OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 24 matching lines...) Expand all Loading... |
35 * An entry in the host table. | 35 * An entry in the host table. |
36 * @constructor | 36 * @constructor |
37 */ | 37 */ |
38 remoting.HostTableEntry = function() { | 38 remoting.HostTableEntry = function() { |
39 /** @type {remoting.Host} */ | 39 /** @type {remoting.Host} */ |
40 this.host = null; | 40 this.host = null; |
41 /** @type {Element} */ | 41 /** @type {Element} */ |
42 this.tableRow = null; | 42 this.tableRow = null; |
43 /** @type {Element} @private */ | 43 /** @type {Element} @private */ |
44 this.hostNameCell_ = null; | 44 this.hostNameCell_ = null; |
45 /** @type {function():void} @private */ | 45 /** @type {function(remoting.HostTableEntry):void} @private */ |
46 this.onRename_ = function() {}; | 46 this.onRename_ = function(hostId) {}; |
47 }; | 47 }; |
48 | 48 |
49 /** | 49 /** |
50 * Create the HTML elements for this entry. | 50 * Create the HTML elements for this entry. |
51 * @param {remoting.Host} host The host, as obtained from Apiary. | 51 * @param {remoting.Host} host The host, as obtained from Apiary. |
52 * @param {function():void} onRename Callback for rename operations. | 52 * @param {function(remoting.HostTableEntry):void} onRename Callback for |
53 * @param {function():void} onDelete Callback for delete operations. | 53 * rename operations. |
| 54 * @param {function(remoting.HostTableEntry):void} onDelete Callback for |
| 55 * delete operations. |
54 */ | 56 */ |
55 remoting.HostTableEntry.prototype.init = function(host, onRename, onDelete) { | 57 remoting.HostTableEntry.prototype.init = function(host, onRename, onDelete) { |
56 this.host = host; | 58 this.host = host; |
57 this.onRename_ = onRename; | 59 this.onRename_ = onRename; |
58 | 60 |
59 /** @type {remoting.HostTableEntry} */ | 61 /** @type {remoting.HostTableEntry} */ |
60 var that = this; | 62 var that = this; |
61 | 63 |
62 this.tableRow = document.createElement('tr'); | 64 this.tableRow = document.createElement('tr'); |
63 addClass(this.tableRow, 'host-list-row'); | 65 addClass(this.tableRow, 'host-list-row'); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 editButton.onclick = function() { that.beginRename_(); }; | 109 editButton.onclick = function() { that.beginRename_(); }; |
108 addClass(editButton, 'clickable'); | 110 addClass(editButton, 'clickable'); |
109 addClass(editButton, 'host-list-edit'); | 111 addClass(editButton, 'host-list-edit'); |
110 var penImage = document.createElement('img'); | 112 var penImage = document.createElement('img'); |
111 penImage.src = 'icon_pencil.png'; | 113 penImage.src = 'icon_pencil.png'; |
112 addClass(penImage, 'host-list-rename-icon'); | 114 addClass(penImage, 'host-list-rename-icon'); |
113 editButton.appendChild(penImage); | 115 editButton.appendChild(penImage); |
114 this.tableRow.appendChild(editButton); | 116 this.tableRow.appendChild(editButton); |
115 | 117 |
116 // Create the host delete cell. | 118 // Create the host delete cell. |
117 var removeButton = document.createElement('td'); | 119 var deleteButton = document.createElement('td'); |
118 removeButton.onclick = onDelete; | 120 deleteButton.onclick = function() { onDelete(that); } |
119 addClass(removeButton, 'clickable'); | 121 addClass(deleteButton, 'clickable'); |
120 addClass(removeButton, 'host-list-edit'); | 122 addClass(deleteButton, 'host-list-edit'); |
121 var crossImage = document.createElement('img'); | 123 var crossImage = document.createElement('img'); |
122 crossImage.src = 'icon_cross.png'; | 124 crossImage.src = 'icon_cross.png'; |
123 addClass(crossImage, 'host-list-remove-icon'); | 125 addClass(crossImage, 'host-list-remove-icon'); |
124 removeButton.appendChild(crossImage); | 126 deleteButton.appendChild(crossImage); |
125 this.tableRow.appendChild(removeButton); | 127 this.tableRow.appendChild(deleteButton); |
126 }; | 128 }; |
127 | 129 |
128 /** | 130 /** |
129 * Prepare the host for renaming by replacing its name with an edit box. | 131 * Prepare the host for renaming by replacing its name with an edit box. |
130 * @return {void} Nothing. | 132 * @return {void} Nothing. |
131 * @private | 133 * @private |
132 */ | 134 */ |
133 remoting.HostTableEntry.prototype.beginRename_ = function() { | 135 remoting.HostTableEntry.prototype.beginRename_ = function() { |
134 var editBox = /** @type {HTMLInputElement} */ document.createElement('input'); | 136 var editBox = /** @type {HTMLInputElement} */ document.createElement('input'); |
135 editBox.type = 'text'; | 137 editBox.type = 'text'; |
(...skipping 14 matching lines...) Expand all Loading... |
150 /** | 152 /** |
151 * Accept the hostname entered by the user. | 153 * Accept the hostname entered by the user. |
152 * @return {void} Nothing. | 154 * @return {void} Nothing. |
153 * @private | 155 * @private |
154 */ | 156 */ |
155 remoting.HostTableEntry.prototype.commitRename_ = function() { | 157 remoting.HostTableEntry.prototype.commitRename_ = function() { |
156 var editBox = this.hostNameCell_.querySelector('input'); | 158 var editBox = this.hostNameCell_.querySelector('input'); |
157 if (editBox) { | 159 if (editBox) { |
158 if (this.host.hostName != editBox.value) { | 160 if (this.host.hostName != editBox.value) { |
159 this.host.hostName = editBox.value; | 161 this.host.hostName = editBox.value; |
160 this.onRename_(); | 162 this.onRename_(this); |
161 } | 163 } |
162 this.removeEditBox_(); | 164 this.removeEditBox_(); |
163 } | 165 } |
164 }; | 166 }; |
165 | 167 |
166 /** | 168 /** |
167 * Remove the edit box corresponding to the specified host, and reset its name. | 169 * Remove the edit box corresponding to the specified host, and reset its name. |
168 * @return {void} Nothing. | 170 * @return {void} Nothing. |
169 * @private | 171 * @private |
170 */ | 172 */ |
(...skipping 13 matching lines...) Expand all Loading... |
184 * @return {void} Nothing. | 186 * @return {void} Nothing. |
185 * @private | 187 * @private |
186 */ | 188 */ |
187 remoting.HostTableEntry.prototype.onKeydown_ = function(event) { | 189 remoting.HostTableEntry.prototype.onKeydown_ = function(event) { |
188 if (event.which == 27) { // Escape | 190 if (event.which == 27) { // Escape |
189 this.removeEditBox_(); | 191 this.removeEditBox_(); |
190 } else if (event.which == 13) { // Enter | 192 } else if (event.which == 13) { // Enter |
191 this.commitRename_(); | 193 this.commitRename_(); |
192 } | 194 } |
193 }; | 195 }; |
OLD | NEW |