- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / examples / api / deviceInfo / basic / popup.js
1 // Copyright 2013 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 function dumpDevices(devices) {
6     $('#deviceinfos').empty();
7     $('#deviceinfos').append(outputDevicesToList(devices));
8 }
9
10 function outputDevicesToList(devices) {
11     var table = $('<table border="1">');
12     table.append($("<tr>" +
13                    "<th>" + "Name" + "</th>" +
14                    "<th>" + "OS" + "</th>" +
15                    "<th>" + "Id" + "</th>" +
16                    "<th>" + "Type" + "</th>" +
17                    "<th>" + "Chrome Version" + "</th>" +
18                    "</tr>"));
19     for (i = 0; i < devices.length; i++) {
20         table.append($("<tr>" +
21                        "<td>" + devices[i].name + "</td>" +
22                        "<td>" + devices[i].os + "</td>" +
23                        "<td>" + devices[i].id + "</td>" +
24                        "<td>" + devices[i].type + "</td>" +
25                        "<td>" + devices[i].chromeVersion + "</td>" +
26                        "</tr>"));
27     }
28     return table;
29 }
30
31 // Add an event listener to listen for changes to device info. The
32 // callback would redisplay the list of devices.
33 chrome.signedInDevices.onDeviceInfoChange.addListener(dumpDevices);
34
35 function populateDevices() {
36   // Get the list of devices and display it.
37   chrome.signedInDevices.get(false, dumpDevices);
38 }
39
40 document.addEventListener('DOMContentLoaded', function () {
41     populateDevices();
42 });