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

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

Issue 23441022: Add a reload button to host list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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/resources/reload.webp ('k') | remoting/webapp/main.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * Create a host list consisting of the specified HTML elements, which should 16 * Create a host list consisting of the specified HTML elements, which should
17 * have a common parent that contains only host-list UI as it will be hidden 17 * have a common parent that contains only host-list UI as it will be hidden
18 * if the host-list is empty. 18 * if the host-list is empty.
19 * 19 *
20 * @constructor 20 * @constructor
21 * @param {Element} table The HTML <div> to contain host-list. 21 * @param {Element} table The HTML <div> to contain host-list.
22 * @param {Element} noHosts The HTML <div> containing the "no hosts" message. 22 * @param {Element} noHosts The HTML <div> containing the "no hosts" message.
23 * @param {Element} errorMsg The HTML <div> to display error messages. 23 * @param {Element} errorMsg The HTML <div> to display error messages.
24 * @param {Element} errorButton The HTML <button> to display the error 24 * @param {Element} errorButton The HTML <button> to display the error
25 * resolution action. 25 * resolution action.
26 * @param {HTMLElement} loadingIndicator The HTML <span> to update while the
27 * host list is being loaded. The first element of this span should be
28 * the reload button.
26 */ 29 */
27 remoting.HostList = function(table, noHosts, errorMsg, errorButton) { 30 remoting.HostList = function(table, noHosts, errorMsg, errorButton,
31 loadingIndicator) {
28 /** 32 /**
29 * @type {Element} 33 * @type {Element}
30 * @private 34 * @private
31 */ 35 */
32 this.table_ = table; 36 this.table_ = table;
33 /** 37 /**
34 * @type {Element} 38 * @type {Element}
35 * @private 39 * @private
36 * TODO(jamiewalch): This should be doable using CSS's sibling selector, 40 * TODO(jamiewalch): This should be doable using CSS's sibling selector,
37 * but it doesn't work right now (crbug.com/135050). 41 * but it doesn't work right now (crbug.com/135050).
38 */ 42 */
39 this.noHosts_ = noHosts; 43 this.noHosts_ = noHosts;
40 /** 44 /**
41 * @type {Element} 45 * @type {Element}
42 * @private 46 * @private
43 */ 47 */
44 this.errorMsg_ = errorMsg; 48 this.errorMsg_ = errorMsg;
45 /** 49 /**
46 * @type {Element} 50 * @type {Element}
47 * @private 51 * @private
48 */ 52 */
49 this.errorButton_ = errorButton; 53 this.errorButton_ = errorButton;
50 /** 54 /**
55 * @type {HTMLElement}
56 * @private
57 */
58 this.loadingIndicator_ = loadingIndicator;
59 /**
51 * @type {Array.<remoting.HostTableEntry>} 60 * @type {Array.<remoting.HostTableEntry>}
52 * @private 61 * @private
53 */ 62 */
54 this.hostTableEntries_ = []; 63 this.hostTableEntries_ = [];
55 /** 64 /**
56 * @type {Array.<remoting.Host>} 65 * @type {Array.<remoting.Host>}
57 * @private 66 * @private
58 */ 67 */
59 this.hosts_ = []; 68 this.hosts_ = [];
60 /** 69 /**
(...skipping 13 matching lines...) Expand all
74 this.localHostState_ = remoting.HostController.State.NOT_IMPLEMENTED; 83 this.localHostState_ = remoting.HostController.State.NOT_IMPLEMENTED;
75 /** 84 /**
76 * @type {number} 85 * @type {number}
77 * @private 86 * @private
78 */ 87 */
79 this.webappMajorVersion_ = parseInt(chrome.runtime.getManifest().version, 10); 88 this.webappMajorVersion_ = parseInt(chrome.runtime.getManifest().version, 10);
80 89
81 this.errorButton_.addEventListener('click', 90 this.errorButton_.addEventListener('click',
82 this.onErrorClick_.bind(this), 91 this.onErrorClick_.bind(this),
83 false); 92 false);
93 var reloadButton = this.loadingIndicator_.firstElementChild;
94 /** @type {remoting.HostList} */
95 var that = this;
96 /** @param {Event} event */
97 function refresh(event) {
98 event.preventDefault();
99 that.refresh(that.display.bind(that));
100 };
101 reloadButton.addEventListener('click', refresh, false);
84 }; 102 };
85 103
86 /** 104 /**
87 * Load the host-list asynchronously from local storage. 105 * Load the host-list asynchronously from local storage.
88 * 106 *
89 * @param {function():void} onDone Completion callback. 107 * @param {function():void} onDone Completion callback.
90 */ 108 */
91 remoting.HostList.prototype.load = function(onDone) { 109 remoting.HostList.prototype.load = function(onDone) {
92 // Load the cache of the last host-list, if present. 110 // Load the cache of the last host-list, if present.
93 /** @type {remoting.HostList} */ 111 /** @type {remoting.HostList} */
(...skipping 29 matching lines...) Expand all
123 }; 141 };
124 142
125 /** 143 /**
126 * Query the Remoting Directory for the user's list of hosts. 144 * Query the Remoting Directory for the user's list of hosts.
127 * 145 *
128 * @param {function(boolean):void} onDone Callback invoked with true on success 146 * @param {function(boolean):void} onDone Callback invoked with true on success
129 * or false on failure. 147 * or false on failure.
130 * @return {void} Nothing. 148 * @return {void} Nothing.
131 */ 149 */
132 remoting.HostList.prototype.refresh = function(onDone) { 150 remoting.HostList.prototype.refresh = function(onDone) {
151 this.loadingIndicator_.classList.add('loading');
133 /** @param {XMLHttpRequest} xhr The response from the server. */ 152 /** @param {XMLHttpRequest} xhr The response from the server. */
134 var parseHostListResponse = this.parseHostListResponse_.bind(this, onDone); 153 var parseHostListResponse = this.parseHostListResponse_.bind(this, onDone);
135 /** @type {remoting.HostList} */ 154 /** @type {remoting.HostList} */
136 var that = this; 155 var that = this;
137 /** @param {string} token The OAuth2 token. */ 156 /** @param {string} token The OAuth2 token. */
138 var getHosts = function(token) { 157 var getHosts = function(token) {
139 var headers = { 'Authorization': 'OAuth ' + token }; 158 var headers = { 'Authorization': 'OAuth ' + token };
140 remoting.xhr.get( 159 remoting.xhr.get(
141 remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts', 160 remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts',
142 parseHostListResponse, '', headers); 161 parseHostListResponse, '', headers);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } else { 219 } else {
201 this.lastError_ = remoting.Error.UNEXPECTED; 220 this.lastError_ = remoting.Error.UNEXPECTED;
202 } 221 }
203 } 222 }
204 } catch (er) { 223 } catch (er) {
205 var typed_er = /** @type {Object} */ (er); 224 var typed_er = /** @type {Object} */ (er);
206 console.error('Error processing response: ', xhr, typed_er); 225 console.error('Error processing response: ', xhr, typed_er);
207 this.lastError_ = remoting.Error.UNEXPECTED; 226 this.lastError_ = remoting.Error.UNEXPECTED;
208 } 227 }
209 this.save_(); 228 this.save_();
229 this.loadingIndicator_.classList.remove('loading');
210 onDone(this.lastError_ == ''); 230 onDone(this.lastError_ == '');
211 }; 231 };
212 232
213 /** 233 /**
214 * Display the list of hosts or error condition. 234 * Display the list of hosts or error condition.
215 * 235 *
216 * @return {void} Nothing. 236 * @return {void} Nothing.
217 */ 237 */
218 remoting.HostList.prototype.display = function() { 238 remoting.HostList.prototype.display = function() {
219 this.table_.innerText = ''; 239 this.table_.innerText = '';
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 chrome.storage.local.set(items); 487 chrome.storage.local.set(items);
468 }; 488 };
469 489
470 /** 490 /**
471 * Key name under which Me2Me hosts are cached. 491 * Key name under which Me2Me hosts are cached.
472 */ 492 */
473 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; 493 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts';
474 494
475 /** @type {remoting.HostList} */ 495 /** @type {remoting.HostList} */
476 remoting.hostList = null; 496 remoting.hostList = null;
OLDNEW
« no previous file with comments | « remoting/resources/reload.webp ('k') | remoting/webapp/main.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698