OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 * Javascript for ServiceList and ServiceListItem, served from |
| 7 * chrome://bluetooth-internals/. |
| 8 */ |
| 9 |
| 10 cr.define('service_list', function() { |
| 11 /** @const */ var ExpandableList = expandable_list.ExpandableList; |
| 12 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem; |
| 13 |
| 14 /** |
| 15 * Property names that will be displayed in the ObjectFieldSet which contains |
| 16 * the ServiceInfo object. |
| 17 */ |
| 18 var PROPERTY_NAMES = { |
| 19 id: 'ID', |
| 20 'uuid.uuid': 'UUID', |
| 21 is_primary: 'Type', |
| 22 }; |
| 23 |
| 24 /** |
| 25 * A list item that displays the data in a ServiceInfo object. The brief |
| 26 * section contains the UUID of the given |serviceInfo|. The expanded section |
| 27 * contains an ObjectFieldSet that displays all of the properties in the |
| 28 * given |serviceInfo|. |
| 29 * @param {!interfaces.BluetoothDevice.ServiceInfo} serviceInfo |
| 30 * @constructor |
| 31 */ |
| 32 function ServiceListItem(serviceInfo) { |
| 33 var listItem = new ExpandableListItem(); |
| 34 listItem.__proto__ = ServiceListItem.prototype; |
| 35 |
| 36 listItem.info = serviceInfo; |
| 37 listItem.decorate(); |
| 38 |
| 39 return listItem; |
| 40 } |
| 41 |
| 42 ServiceListItem.prototype = { |
| 43 __proto__: ExpandableListItem.prototype, |
| 44 |
| 45 /** |
| 46 * Decorates the element as a service list item. Creates layout and caches |
| 47 * references to the created header and fieldset. |
| 48 * @override |
| 49 */ |
| 50 decorate: function() { |
| 51 this.classList.add('service-list-item'); |
| 52 |
| 53 /** @private {!HTMLElement} */ |
| 54 this.infoDiv_ = document.createElement('div'); |
| 55 this.infoDiv_.classList.add('info-container'); |
| 56 |
| 57 /** @private {!object_fieldset.ObjectFieldSet} */ |
| 58 this.serviceFieldSet_ = object_fieldset.ObjectFieldSet(); |
| 59 this.serviceFieldSet_.setPropertyDisplayNames(PROPERTY_NAMES); |
| 60 this.serviceFieldSet_.setObject({ |
| 61 id: this.info.id, |
| 62 'uuid.uuid': this.info.uuid.uuid, |
| 63 is_primary: this.info.is_primary ? 'Primary' : 'Secondary', |
| 64 }); |
| 65 |
| 66 // Create content for display in brief content container. |
| 67 var serviceHeaderText = document.createElement('div'); |
| 68 serviceHeaderText.textContent = 'Service:'; |
| 69 |
| 70 var serviceHeaderValue = document.createElement('div'); |
| 71 serviceHeaderValue.textContent = this.info.uuid.uuid; |
| 72 |
| 73 var serviceHeader = document.createElement('div'); |
| 74 serviceHeader.appendChild(serviceHeaderText); |
| 75 serviceHeader.appendChild(serviceHeaderValue); |
| 76 this.briefContent_.appendChild(serviceHeader); |
| 77 |
| 78 // Create content for display in expanded content container. |
| 79 var serviceInfoHeader = document.createElement('h4'); |
| 80 serviceInfoHeader.textContent = 'Service Info'; |
| 81 |
| 82 var serviceDiv = document.createElement('div'); |
| 83 serviceDiv.classList.add('flex'); |
| 84 serviceDiv.appendChild(this.serviceFieldSet_); |
| 85 |
| 86 this.infoDiv_.appendChild(serviceInfoHeader); |
| 87 this.infoDiv_.appendChild(serviceDiv); |
| 88 this.expandedContent_.appendChild(this.infoDiv_); |
| 89 }, |
| 90 }; |
| 91 |
| 92 /** |
| 93 * A list that displays ServiceListItems. |
| 94 * @constructor |
| 95 */ |
| 96 var ServiceList = cr.ui.define('list'); |
| 97 |
| 98 ServiceList.prototype = { |
| 99 __proto__: ExpandableList.prototype, |
| 100 |
| 101 /** @override */ |
| 102 decorate: function() { |
| 103 ExpandableList.prototype.decorate.call(this); |
| 104 this.classList.add('service-list'); |
| 105 this.setEmptyMessage('No Services Found'); |
| 106 }, |
| 107 |
| 108 /** @override */ |
| 109 createItem: function(data) { |
| 110 return new ServiceListItem(data); |
| 111 }, |
| 112 }; |
| 113 |
| 114 return { |
| 115 ServiceList: ServiceList, |
| 116 ServiceListItem: ServiceListItem, |
| 117 }; |
| 118 }); |
OLD | NEW |