Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1189)

Side by Side Diff: remoting/webapp/me2mom/host_list.js

Issue 8830001: Pass table entry to rename and delete callbacks, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 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';
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 * Refresh the host list with up-to-date details. 110 * Refresh the host list with up-to-date details.
111 * @param {Array.<remoting.Host>} hosts The new host list. 111 * @param {Array.<remoting.Host>} hosts The new host list.
112 * @return {void} Nothing. 112 * @return {void} Nothing.
113 * @private 113 * @private
114 */ 114 */
115 remoting.HostList.prototype.setHosts_ = function(hosts) { 115 remoting.HostList.prototype.setHosts_ = function(hosts) {
116 this.table_.innerHTML = ''; 116 this.table_.innerHTML = '';
117 this.showError_(null); 117 this.showError_(null);
118 this.hostTableEntries_ = []; 118 this.hostTableEntries_ = [];
119 119
120 /** @type {remoting.HostList} */ 120 /**
121 * @type {remoting.HostList}
122 */
121 var that = this; 123 var that = this;
124 /**
125 * @param {remoting.HostTableEntry} hostTableEntry The entry being renamed.
126 */
127 var onRename = function(hostTableEntry) { that.renameHost_(hostTableEntry); }
128 /**
129 * @param {remoting.HostTableEntry} hostTableEntry The entry beign deleted.
130 */
131 var onDelete = function(hostTableEntry) { that.deleteHost_(hostTableEntry); }
132
122 for (var i = 0; i < hosts.length; ++i) { 133 for (var i = 0; i < hosts.length; ++i) {
123 /** @type {remoting.Host} */ 134 /** @type {remoting.Host} */
124 var host = hosts[i]; 135 var host = hosts[i];
125 // Validate the entry to make sure it has all the fields we expect. 136 // Validate the entry to make sure it has all the fields we expect.
126 if (host.hostName && host.hostId && host.status && host.jabberId && 137 if (host.hostName && host.hostId && host.status && host.jabberId &&
127 host.publicKey) { 138 host.publicKey) {
128 var onRename = function() { that.renameHost_(host.hostId); }
129 var onDelete = function() { that.deleteHost_(host.hostId); }
130 var hostTableEntry = new remoting.HostTableEntry(); 139 var hostTableEntry = new remoting.HostTableEntry();
131 hostTableEntry.init(host, onRename, onDelete); 140 hostTableEntry.init(host, onRename, onDelete);
132 this.hostTableEntries_[i] = hostTableEntry; 141 this.hostTableEntries_[i] = hostTableEntry;
133 this.table_.appendChild(hostTableEntry.tableRow); 142 this.table_.appendChild(hostTableEntry.tableRow);
134 } 143 }
135 } 144 }
136 145
137 this.showOrHide_(this.hostTableEntries_.length != 0); 146 this.showOrHide_(this.hostTableEntries_.length != 0);
138 }; 147 };
139 148
(...skipping 26 matching lines...) Expand all
166 if (show) { 175 if (show) {
167 parent.style.height = parent.scrollHeight + 'px'; 176 parent.style.height = parent.scrollHeight + 'px';
168 removeClass(parent, remoting.HostList.COLLAPSED_); 177 removeClass(parent, remoting.HostList.COLLAPSED_);
169 } else { 178 } else {
170 addClass(parent, remoting.HostList.COLLAPSED_); 179 addClass(parent, remoting.HostList.COLLAPSED_);
171 } 180 }
172 }; 181 };
173 182
174 /** 183 /**
175 * Remove a host from the list, and deregister it. 184 * Remove a host from the list, and deregister it.
176 * @param {string} hostId The id of the host to be removed. 185 * @param {remoting.HostTableEntry} hostTableEntry The host to be removed.
177 * @return {void} Nothing. 186 * @return {void} Nothing.
178 * @private 187 * @private
179 */ 188 */
180 remoting.HostList.prototype.deleteHost_ = function(hostId) { 189 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) {
181 /** @type {remoting.HostTableEntry} */
182 var hostTableEntry = this.getHostForId(hostId);
183 if (!hostTableEntry) {
184 console.error('No host registered for id ' + hostId);
185 return;
186 }
187
188 this.table_.removeChild(hostTableEntry.tableRow); 190 this.table_.removeChild(hostTableEntry.tableRow);
189 var index = this.hostTableEntries_.indexOf(hostTableEntry); 191 var index = this.hostTableEntries_.indexOf(hostTableEntry);
190 if (index != -1) { // Since we've just found it, index must be >= 0 192 if (index != -1) {
191 this.hostTableEntries_.splice(index, 1); 193 this.hostTableEntries_.splice(index, 1);
192 } 194 }
193 195
194 /** @param {string} token */ 196 /** @param {string} token */
195 var deleteHost = function(token) { 197 var deleteHost = function(token) {
196 var headers = { 'Authorization': 'OAuth ' + token }; 198 var headers = { 'Authorization': 'OAuth ' + token };
197 remoting.xhr.remove( 199 remoting.xhr.remove(
198 'https://www.googleapis.com/chromoting/v1/@me/hosts/' + hostId, 200 'https://www.googleapis.com/chromoting/v1/@me/hosts/' +
201 hostTableEntry.host.hostId,
199 function() {}, '', headers); 202 function() {}, '', headers);
200 } 203 }
201 remoting.oauth2.callWithToken(deleteHost); 204 remoting.oauth2.callWithToken(deleteHost);
202 205
203 this.showOrHide_(this.hostTableEntries_.length != 0); 206 this.showOrHide_(this.hostTableEntries_.length != 0);
204 }; 207 };
205 208
206 /** 209 /**
207 * Prepare a host for renaming by replacing its name with an edit box. 210 * Prepare a host for renaming by replacing its name with an edit box.
208 * @param {string} hostId The id of the host to be renamed. 211 * @param {remoting.HostTableEntry} hostTableEntry The host to be renamed.
209 * @return {void} Nothing. 212 * @return {void} Nothing.
210 * @private 213 * @private
211 */ 214 */
212 remoting.HostList.prototype.renameHost_ = function(hostId) { 215 remoting.HostList.prototype.renameHost_ = function(hostTableEntry) {
213 /** @type {remoting.HostTableEntry} */
214 var hostTableEntry = this.getHostForId(hostId);
215 if (!hostTableEntry) {
216 console.error('No host registered for id ' + hostId);
217 return;
218 }
219 /** @param {string} token */ 216 /** @param {string} token */
220 var renameHost = function(token) { 217 var renameHost = function(token) {
221 var headers = { 218 var headers = {
222 'Authorization': 'OAuth ' + token, 219 'Authorization': 'OAuth ' + token,
223 'Content-type' : 'application/json; charset=UTF-8' 220 'Content-type' : 'application/json; charset=UTF-8'
224 }; 221 };
225 var newHostDetails = { data: { 222 var newHostDetails = { data: {
226 hostId: hostTableEntry.host.hostId, 223 hostId: hostTableEntry.host.hostId,
227 hostName: hostTableEntry.host.hostName, 224 hostName: hostTableEntry.host.hostName,
228 publicKey: hostTableEntry.host.publicKey 225 publicKey: hostTableEntry.host.publicKey
229 } }; 226 } };
230 remoting.xhr.put( 227 remoting.xhr.put(
231 'https://www.googleapis.com/chromoting/v1/@me/hosts/' + hostId, 228 'https://www.googleapis.com/chromoting/v1/@me/hosts/' +
229 hostTableEntry.host.hostId,
232 function(xhr) {}, 230 function(xhr) {},
233 JSON.stringify(newHostDetails), 231 JSON.stringify(newHostDetails),
234 headers); 232 headers);
235 } 233 }
236 remoting.oauth2.callWithToken(renameHost); 234 remoting.oauth2.callWithToken(renameHost);
237 }; 235 };
238 236
239 /** 237 /**
240 * Class name for the host list when it is collapsed. 238 * Class name for the host list when it is collapsed.
241 * @private 239 * @private
242 */ 240 */
243 remoting.HostList.COLLAPSED_ = 'collapsed'; 241 remoting.HostList.COLLAPSED_ = 'collapsed';
244 242
245 /** @type {remoting.HostList} */ 243 /** @type {remoting.HostList} */
246 remoting.hostList = null; 244 remoting.hostList = null;
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/me2mom/host_table_entry.js » ('j') | remoting/webapp/me2mom/host_table_entry.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698