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 ObjectFieldSet, served from | |
scheib
2017/01/07 01:46:20
Describe at a high level a bit more what this is u
mbrunson
2017/01/07 02:34:28
Done.
| |
7 * chrome://bluetooth-internals/. | |
8 */ | |
9 | |
10 cr.define('object_fieldset', function() { | |
11 | |
12 /** | |
13 * A fieldset that lists the properties of a given object. | |
14 * @constructor | |
15 * @extends {HTMLFieldSetElement} | |
16 */ | |
17 var ObjectFieldSet = cr.ui.define('fieldset'); | |
18 | |
19 ObjectFieldSet.prototype = { | |
20 __proto__: HTMLFieldSetElement.prototype, | |
21 | |
22 /** | |
23 * Decorates the element as an ObjectFieldset. | |
24 */ | |
25 decorate: function() { | |
26 this.classList.add('object-fieldset'); | |
27 }, | |
28 | |
29 /** | |
30 * Sets the object data to be displayed in the fieldset. | |
31 * @param {!Object} value | |
32 */ | |
33 setObject: function(value) { | |
34 this.value = value; | |
35 this.redraw(); | |
36 }, | |
37 | |
38 /** | |
39 * Sets the object used to map property names to display names. If a display | |
40 * name is not provided, the default property name will be used. | |
41 * @param {!Object<string, string>} nameMap | |
42 */ | |
43 setPropertyDisplayNames: function(nameMap) { | |
44 this.nameMap_ = nameMap; | |
45 }, | |
46 | |
47 /** | |
48 * Deletes and recreates the table structure with current object data. | |
49 */ | |
50 redraw: function() { | |
51 this.innerHTML = ''; | |
52 | |
53 for (var propName in this.value) { | |
54 if (!this.value.hasOwnProperty(propName)) continue; | |
55 | |
56 var name = this.nameMap_[propName] || propName; | |
57 var value = this.value[propName]; | |
58 var newField = document.createElement('div'); | |
59 newField.classList.add('status'); | |
60 | |
61 var nameDiv = document.createElement('div'); | |
62 nameDiv.textContent = name + ':'; | |
63 newField.appendChild(nameDiv); | |
64 | |
65 var valueDiv = document.createElement('div'); | |
66 valueDiv.dataset.field = propName; | |
67 | |
68 if (typeof(value) === 'boolean') { | |
69 valueDiv.classList.add('toggle-status'); | |
70 valueDiv.classList.toggle('checked', value); | |
71 } else { | |
72 valueDiv.textContent = String(value); | |
73 } | |
74 | |
75 newField.appendChild(valueDiv); | |
76 this.appendChild(newField); | |
77 } | |
78 }, | |
79 }; | |
80 | |
81 return { | |
82 ObjectFieldSet: ObjectFieldSet, | |
83 }; | |
84 }); | |
OLD | NEW |