Chromium Code Reviews| Index: chrome/browser/resources/bluetooth_internals/object_fieldset.js |
| diff --git a/chrome/browser/resources/bluetooth_internals/object_fieldset.js b/chrome/browser/resources/bluetooth_internals/object_fieldset.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2bc17de6aa58cd60b3dcb16121b175b97000050c |
| --- /dev/null |
| +++ b/chrome/browser/resources/bluetooth_internals/object_fieldset.js |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * 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.
|
| + * chrome://bluetooth-internals/. |
| + */ |
| + |
| +cr.define('object_fieldset', function() { |
| + |
| + /** |
| + * A fieldset that lists the properties of a given object. |
| + * @constructor |
| + * @extends {HTMLFieldSetElement} |
| + */ |
| + var ObjectFieldSet = cr.ui.define('fieldset'); |
| + |
| + ObjectFieldSet.prototype = { |
| + __proto__: HTMLFieldSetElement.prototype, |
| + |
| + /** |
| + * 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.
|
| + */ |
| + decorate: function() { |
| + this.classList.add('object-fieldset'); |
| + }, |
| + |
| + /** |
| + * Sets the object data to be displayed in the fieldset. |
| + * @param {!Object} value |
| + */ |
| + setObject: function(value) { |
| + this.value = value; |
| + this.redraw(); |
| + }, |
| + |
| + /** |
| + * Sets the object used to map property names to display names. If a display |
| + * name is not provided, the default property name will be used. |
| + * @param {!Object<string, string>} nameMap |
| + */ |
| + setPropertyDisplayNames: function(nameMap) { |
| + this.nameMap_ = nameMap; |
| + }, |
| + |
| + /** |
| + * Deletes and recreates the table structure with current object data. |
| + */ |
| + redraw: function() { |
| + this.innerHTML = ''; |
| + |
| + for (var propName in this.value) { |
| + if (!this.value.hasOwnProperty(propName)) continue; |
| + |
| + var name = this.nameMap_[propName] || propName; |
| + var value = this.value[propName]; |
| + var newField = document.createElement('div'); |
| + newField.classList.add('status'); |
| + |
| + var nameDiv = document.createElement('div'); |
| + nameDiv.textContent = name + ':'; |
| + newField.appendChild(nameDiv); |
| + |
| + var valueDiv = document.createElement('div'); |
| + valueDiv.dataset.field = propName; |
| + |
| + if (typeof(value) === 'boolean') { |
| + valueDiv.classList.add('toggle-status'); |
| + valueDiv.classList.toggle('checked', value); |
| + } else { |
| + valueDiv.textContent = String(value); |
| + } |
| + |
| + newField.appendChild(valueDiv); |
| + this.appendChild(newField); |
| + } |
| + }, |
| + }; |
| + |
| + return { |
| + ObjectFieldSet: ObjectFieldSet, |
| + }; |
| +}); |