OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 * Javascript for ServiceList and ServiceListItem, served from | 6 * Javascript for ServiceList and ServiceListItem, served from |
7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('service_list', function() { | 10 cr.define('service_list', function() { |
| 11 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
11 /** @const */ var ExpandableList = expandable_list.ExpandableList; | 12 /** @const */ var ExpandableList = expandable_list.ExpandableList; |
12 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem; | 13 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem; |
13 | 14 |
14 /** | 15 /** |
15 * Property names that will be displayed in the ObjectFieldSet which contains | 16 * Property names that will be displayed in the ObjectFieldSet which contains |
16 * the ServiceInfo object. | 17 * the ServiceInfo object. |
17 */ | 18 */ |
18 var PROPERTY_NAMES = { | 19 var PROPERTY_NAMES = { |
19 id: 'ID', | 20 id: 'ID', |
20 'uuid.uuid': 'UUID', | 21 'uuid.uuid': 'UUID', |
(...skipping 22 matching lines...) Expand all Loading... |
43 __proto__: ExpandableListItem.prototype, | 44 __proto__: ExpandableListItem.prototype, |
44 | 45 |
45 /** | 46 /** |
46 * Decorates the element as a service list item. Creates layout and caches | 47 * Decorates the element as a service list item. Creates layout and caches |
47 * references to the created header and fieldset. | 48 * references to the created header and fieldset. |
48 * @override | 49 * @override |
49 */ | 50 */ |
50 decorate: function() { | 51 decorate: function() { |
51 this.classList.add('service-list-item'); | 52 this.classList.add('service-list-item'); |
52 | 53 |
| 54 /** @private {boolean} */ |
| 55 this.characteristicsRequested_ = false; |
| 56 |
53 /** @private {!HTMLElement} */ | 57 /** @private {!HTMLElement} */ |
54 this.infoDiv_ = document.createElement('div'); | 58 this.infoDiv_ = document.createElement('div'); |
55 this.infoDiv_.classList.add('info-container'); | 59 this.infoDiv_.classList.add('info-container'); |
56 | 60 |
57 /** @private {!object_fieldset.ObjectFieldSet} */ | 61 /** @private {!object_fieldset.ObjectFieldSet} */ |
58 this.serviceFieldSet_ = object_fieldset.ObjectFieldSet(); | 62 this.serviceFieldSet_ = object_fieldset.ObjectFieldSet(); |
59 this.serviceFieldSet_.setPropertyDisplayNames(PROPERTY_NAMES); | 63 this.serviceFieldSet_.setPropertyDisplayNames(PROPERTY_NAMES); |
60 this.serviceFieldSet_.setObject({ | 64 this.serviceFieldSet_.setObject({ |
61 id: this.info.id, | 65 id: this.info.id, |
62 'uuid.uuid': this.info.uuid.uuid, | 66 'uuid.uuid': this.info.uuid.uuid, |
(...skipping 12 matching lines...) Expand all Loading... |
75 serviceHeader.appendChild(serviceHeaderValue); | 79 serviceHeader.appendChild(serviceHeaderValue); |
76 this.briefContent_.appendChild(serviceHeader); | 80 this.briefContent_.appendChild(serviceHeader); |
77 | 81 |
78 // Create content for display in expanded content container. | 82 // Create content for display in expanded content container. |
79 var serviceInfoHeader = document.createElement('h4'); | 83 var serviceInfoHeader = document.createElement('h4'); |
80 serviceInfoHeader.textContent = 'Service Info'; | 84 serviceInfoHeader.textContent = 'Service Info'; |
81 | 85 |
82 var serviceDiv = document.createElement('div'); | 86 var serviceDiv = document.createElement('div'); |
83 serviceDiv.classList.add('flex'); | 87 serviceDiv.classList.add('flex'); |
84 serviceDiv.appendChild(this.serviceFieldSet_); | 88 serviceDiv.appendChild(this.serviceFieldSet_); |
85 | |
86 this.infoDiv_.appendChild(serviceInfoHeader); | 89 this.infoDiv_.appendChild(serviceInfoHeader); |
87 this.infoDiv_.appendChild(serviceDiv); | 90 this.infoDiv_.appendChild(serviceDiv); |
| 91 |
| 92 var characteristicsListHeader = document.createElement('h4'); |
| 93 characteristicsListHeader.textContent = 'Characteristics'; |
| 94 this.infoDiv_.appendChild(characteristicsListHeader); |
| 95 |
| 96 this.characteristicList_ = new characteristic_list.CharacteristicList(); |
| 97 this.characteristicList_.setLoading(true); |
| 98 this.infoDiv_.appendChild(this.characteristicList_); |
| 99 |
88 this.expandedContent_.appendChild(this.infoDiv_); | 100 this.expandedContent_.appendChild(this.infoDiv_); |
89 }, | 101 }, |
| 102 |
| 103 /** |
| 104 * Called when the 'characteristicsrequested' event is handled. The incoming |
| 105 * |characteristics| are wrapped in an ArrayDataModel then set as the data |
| 106 * model of the characteristics list and cached in the service info. |
| 107 * @param {!Array<!interfaces.BluetoothDevice.CharacteristicInfo}>} |
| 108 * characteristics |
| 109 */ |
| 110 onCharacteristicsReturned: function(characteristics) { |
| 111 this.characteristicList_.setData(new ArrayDataModel(characteristics)); |
| 112 this.characteristicList_.setLoading(false); |
| 113 |
| 114 this.info.characteristics = this.characteristicList_.dataModel; |
| 115 this.characteristicsRequested_ = false; |
| 116 }, |
| 117 |
| 118 /** @override */ |
| 119 onExpandInternal: function(expanded) { |
| 120 if (!expanded || this.characteristicsRequested_ || |
| 121 !this.characteristicList_.isLoading()) { |
| 122 return; |
| 123 } |
| 124 |
| 125 this.dispatchEvent(new CustomEvent('characteristicsrequested', { |
| 126 bubbles: true, |
| 127 detail: { |
| 128 serviceId: this.info.id, |
| 129 } |
| 130 })); |
| 131 this.characteristicsRequested_ = true; |
| 132 }, |
90 }; | 133 }; |
91 | 134 |
92 /** | 135 /** |
93 * A list that displays ServiceListItems. | 136 * A list that displays ServiceListItems. |
94 * @constructor | 137 * @constructor |
95 */ | 138 */ |
96 var ServiceList = cr.ui.define('list'); | 139 var ServiceList = cr.ui.define('list'); |
97 | 140 |
98 ServiceList.prototype = { | 141 ServiceList.prototype = { |
99 __proto__: ExpandableList.prototype, | 142 __proto__: ExpandableList.prototype, |
100 | 143 |
101 /** @override */ | 144 /** @override */ |
102 decorate: function() { | 145 decorate: function() { |
103 ExpandableList.prototype.decorate.call(this); | 146 ExpandableList.prototype.decorate.call(this); |
104 this.classList.add('service-list'); | 147 this.classList.add('service-list'); |
105 this.setEmptyMessage('No Services Found'); | 148 this.setEmptyMessage('No Services Found'); |
106 }, | 149 }, |
107 | 150 |
108 /** @override */ | 151 /** @override */ |
109 createItem: function(data) { | 152 createItem: function(data) { |
110 return new ServiceListItem(data); | 153 return new ServiceListItem(data); |
111 }, | 154 }, |
112 }; | 155 }; |
113 | 156 |
114 return { | 157 return { |
115 ServiceList: ServiceList, | 158 ServiceList: ServiceList, |
116 ServiceListItem: ServiceListItem, | 159 ServiceListItem: ServiceListItem, |
117 }; | 160 }; |
118 }); | 161 }); |
OLD | NEW |