// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /** * @fileoverview * Dialog for showing the list of clients that are paired with this host. */ 'use strict'; /** @suppress {duplicate} */ var remoting = remoting || {}; /** * Extract the appropriate fields from the input parameter, if present. Use the * isValid() method to determine whether or not a valid paired client instance * was provided. * * @param {Object} pairedClient The paired client, as returned by the native * host instance. * @constructor */ remoting.PairedClient = function(pairedClient) { if (!pairedClient || typeof(pairedClient) != 'object') { return; } this.clientId = /** @type {string} */ (pairedClient['clientId']); this.clientName = /** @type {string} */ (pairedClient['clientName']); this.createdTime = /** @type {number} */ (pairedClient['createdTime']); /** @type {Element} */ this.tableRow = null; /** @type {Element} */ this.deleteButton = null; }; /** * Create the DOM elements representing this client in the paired client * manager dialog. * * @param {remoting.PairedClientManager} parent The paired client manager * dialog containing this row. * @param {Element} tbody The element to which to append the row. */ remoting.PairedClient.prototype.createDom = function(parent, tbody) { this.tableRow = document.createElement('tr'); var td = document.createElement('td'); td.innerText = new Date(this.createdTime).toLocaleDateString(); this.tableRow.appendChild(td); td = document.createElement('td'); td.innerText = this.clientName; this.tableRow.appendChild(td); td = document.createElement('td'); this.deleteButton = document.createElement('a'); this.deleteButton.href = '#'; this.deleteButton.innerText = chrome.i18n.getMessage( /*i18n-content*/'DELETE_PAIRED_CLIENT'); this.deleteButton.id = 'delete-client-' + this.clientId; this.deleteButton.addEventListener( 'click', parent.deletePairedClient.bind(parent, this), false); td.appendChild(this.deleteButton); this.tableRow.appendChild(td); tbody.appendChild(this.tableRow); }; /** * Show or hide the "Delete" button for this row. * * @param {boolean} show True to show the button; false to hide it. */ remoting.PairedClient.prototype.showButton = function(show) { this.deleteButton.hidden = !show; }; /** * @return {boolean} True if the constructor parameter was a well-formed * paired client instance. */ remoting.PairedClient.prototype.isValid = function() { return typeof(this.clientId) == 'string' && typeof(this.clientName) == 'string' && typeof(this.createdTime) == 'number'; }; /** * Converts a raw object to an array of PairedClient instances. Returns null if * the input object is incorrectly formatted. * * @param {*} pairedClients The object to convert. * @return {Array.} The converted result. */ remoting.PairedClient.convertToPairedClientArray = function(pairedClients) { if (!(pairedClients instanceof Array)) { console.error('pairedClients is not an Array:', pairedClients); return null; } var result = []; for (var i = 0; i < pairedClients.length; i++) { var pairedClient = new remoting.PairedClient(pairedClients[i]); if (!pairedClient.isValid()) { console.error('pairedClient[' + i + '] has incorrect format:', /** @type {*} */(pairedClients[i])); return null; } result.push(pairedClient); } return result; } /** * @param {remoting.HostController} hostController * @param {HTMLElement} listContainer HTML
to contain the list of paired * clients. * @param {HTMLElement} message HTML
containing the message notifying * the user that clients are paired and containing the link to open the * dialog. * @param {HTMLElement} deleteAllButton HTML