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

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

Issue 9148043: Rename webapp_it2me to remoting_webapp and move it from webapp/me2mom to webapp/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add webapp_it2me back Created 8 years, 11 months 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
« no previous file with comments | « remoting/webapp/me2mom/host_session.js ('k') | remoting/webapp/me2mom/l10n.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * Class representing an entry in the host-list portion of the home screen.
8 */
9
10 'use strict';
11
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
14
15 /**
16 * The deserialized form of the chromoting host as returned by Apiary.
17 * Note that the object has more fields than are detailed below--these
18 * are just the ones that we refer to directly.
19 * @constructor
20 */
21 remoting.Host = function() {
22 /** @type {string} */
23 this.hostName = '';
24 /** @type {string} */
25 this.hostId = '';
26 /** @type {string} */
27 this.status = '';
28 /** @type {string} */
29 this.jabberId = '';
30 /** @type {string} */
31 this.publicKey = '';
32 };
33
34 /**
35 * An entry in the host table.
36 * @constructor
37 */
38 remoting.HostTableEntry = function() {
39 /** @type {remoting.Host} */
40 this.host = null;
41 /** @type {Element} */
42 this.tableRow = null;
43 /** @type {Element} @private */
44 this.hostNameCell_ = null;
45 /** @type {function(remoting.HostTableEntry):void} @private */
46 this.onRename_ = function(hostId) {};
47 /** @type {function():void} @private */
48 this.onBlurReference_ = function() {};
49 };
50
51 /**
52 * Create the HTML elements for this entry.
53 * @param {remoting.Host} host The host, as obtained from Apiary.
54 * @param {function(remoting.HostTableEntry):void} onRename Callback for
55 * rename operations.
56 * @param {function(remoting.HostTableEntry):void} onDelete Callback for
57 * delete operations.
58 */
59 remoting.HostTableEntry.prototype.init = function(host, onRename, onDelete) {
60 this.host = host;
61 this.onRename_ = onRename;
62
63 /** @type {remoting.HostTableEntry} */
64 var that = this;
65
66 this.tableRow = document.createElement('tr');
67 addClass(this.tableRow, 'host-list-row');
68
69 // Create the host icon cell.
70 var hostIcon = document.createElement('td');
71 addClass(hostIcon, 'host-list-row-start');
72 var hostIconImage = document.createElement('img');
73 hostIconImage.src = 'icon_host.png';
74 addClass(hostIconImage, 'host-list-main-icon');
75 hostIcon.appendChild(hostIconImage);
76 this.tableRow.appendChild(hostIcon);
77
78 // Create the host name cell.
79 this.hostNameCell_ = document.createElement('td');
80 addClass(this.hostNameCell_, 'mode-select-label');
81 this.hostNameCell_.appendChild(
82 document.createTextNode(host.hostName));
83 this.hostNameCell_.ondblclick = function() { that.beginRename_(); };
84 this.tableRow.appendChild(this.hostNameCell_);
85
86 // Create the host status cell.
87 var hostStatus = document.createElement('td');
88 if (host.status == 'ONLINE') {
89 var hostUrl = chrome.extension.getURL('choice.html') +
90 '?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); };
95 connectButton.addEventListener('click', startMe2Me, false);
96 connectButton.innerHTML =
97 chrome.i18n.getMessage(/*i18n-content*/'CONNECT_BUTTON');
98 hostStatus.appendChild(connectButton);
99 } else {
100 addClass(this.tableRow, 'host-offline');
101 hostStatus.innerHTML = chrome.i18n.getMessage(/*i18n-content*/'OFFLINE');
102 }
103 hostStatus.className = 'host-list-row-end';
104 this.tableRow.appendChild(hostStatus);
105
106 // Create the host rename cell.
107 var editButton = document.createElement('td');
108 editButton.onclick = function() { that.beginRename_(); };
109 addClass(editButton, 'clickable');
110 addClass(editButton, 'host-list-edit');
111 var penImage = document.createElement('img');
112 penImage.src = 'icon_pencil.png';
113 addClass(penImage, 'host-list-rename-icon');
114 editButton.appendChild(penImage);
115 this.tableRow.appendChild(editButton);
116
117 // Create the host delete cell.
118 var deleteButton = document.createElement('td');
119 deleteButton.onclick = function() { onDelete(that); }
120 addClass(deleteButton, 'clickable');
121 addClass(deleteButton, 'host-list-edit');
122 var crossImage = document.createElement('img');
123 crossImage.src = 'icon_cross.png';
124 addClass(crossImage, 'host-list-remove-icon');
125 deleteButton.appendChild(crossImage);
126 this.tableRow.appendChild(deleteButton);
127 };
128
129 /**
130 * Prepare the host for renaming by replacing its name with an edit box.
131 * @return {void} Nothing.
132 * @private
133 */
134 remoting.HostTableEntry.prototype.beginRename_ = function() {
135 var editBox = /** @type {HTMLInputElement} */ document.createElement('input');
136 editBox.type = 'text';
137 editBox.value = this.host.hostName;
138 this.hostNameCell_.innerHTML = '';
139 this.hostNameCell_.appendChild(editBox);
140 editBox.select();
141
142 /** @type {remoting.HostTableEntry} */
143 var that = this;
144 // Keep a reference to the blur event handler so that we can remove it later.
145 this.onBlurReference_ = function() { that.commitRename_(); };
146 editBox.addEventListener('blur', this.onBlurReference_, false);
147
148 /** @param {Event} event The keydown event. */
149 var onKeydown = function(event) { that.onKeydown_(event); }
150 editBox.addEventListener('keydown', onKeydown, false);
151 };
152
153 /**
154 * Accept the hostname entered by the user.
155 * @return {void} Nothing.
156 * @private
157 */
158 remoting.HostTableEntry.prototype.commitRename_ = function() {
159 var editBox = this.hostNameCell_.querySelector('input');
160 if (editBox) {
161 if (this.host.hostName != editBox.value) {
162 this.host.hostName = editBox.value;
163 this.onRename_(this);
164 }
165 this.removeEditBox_();
166 }
167 };
168
169 /**
170 * Remove the edit box corresponding to the specified host, and reset its name.
171 * @return {void} Nothing.
172 * @private
173 */
174 remoting.HostTableEntry.prototype.removeEditBox_ = function() {
175 var editBox = this.hostNameCell_.querySelector('input');
176 if (editBox) {
177 // onblur will fire when the edit box is removed, so remove the hook.
178 editBox.removeEventListener('blur', this.onBlurReference_, false);
179 }
180 this.hostNameCell_.innerHTML = ''; // Remove the edit box.
181 this.hostNameCell_.appendChild(document.createTextNode(this.host.hostName));
182 };
183
184 /**
185 * Handle a key event while the user is typing a host name
186 * @param {Event} event The keyboard event.
187 * @return {void} Nothing.
188 * @private
189 */
190 remoting.HostTableEntry.prototype.onKeydown_ = function(event) {
191 if (event.which == 27) { // Escape
192 this.removeEditBox_();
193 } else if (event.which == 13) { // Enter
194 this.commitRename_();
195 }
196 };
OLDNEW
« no previous file with comments | « remoting/webapp/me2mom/host_session.js ('k') | remoting/webapp/me2mom/l10n.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698