Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/resources/bluetooth_internals/object_fieldset.js

Issue 2567983007: bluetooth: Add adapter page to internals page. (Closed)
Patch Set: Merge upstream Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 Mojo interface helpers, served from
scheib 2017/01/07 00:31:40 This isn't a descriptive comment for the code modu
mbrunson 2017/01/07 01:05:22 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 an element as a UI element class. Adds the header row.
scheib 2017/01/07 00:31:40 no header row these days.
mbrunson 2017/01/07 01:05:22 Done.
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 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698