| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 cr.define('options', function() { | |
| 6 const Tree = cr.ui.Tree; | |
| 7 const TreeItem = cr.ui.TreeItem; | |
| 8 | |
| 9 /** | |
| 10 * Creates a new tree item for certificate data. | |
| 11 * @param {Object=} data Data used to create a certificate tree item. | |
| 12 * @constructor | |
| 13 * @extends {TreeItem} | |
| 14 */ | |
| 15 function CertificateTreeItem(data) { | |
| 16 // TODO(mattm): other columns | |
| 17 var treeItem = new TreeItem({ | |
| 18 label: data.name, | |
| 19 data: data | |
| 20 }); | |
| 21 treeItem.__proto__ = CertificateTreeItem.prototype; | |
| 22 | |
| 23 if (data.icon) { | |
| 24 treeItem.icon = data.icon; | |
| 25 } | |
| 26 | |
| 27 if (data.untrusted) { | |
| 28 var badge = document.createElement('span'); | |
| 29 badge.setAttribute('class', 'certUntrusted'); | |
| 30 badge.textContent = localStrings.getString("badgeCertUntrusted"); | |
| 31 treeItem.labelElement.insertBefore( | |
| 32 badge, treeItem.labelElement.firstChild); | |
| 33 } | |
| 34 | |
| 35 return treeItem; | |
| 36 } | |
| 37 | |
| 38 CertificateTreeItem.prototype = { | |
| 39 __proto__: TreeItem.prototype, | |
| 40 | |
| 41 /** | |
| 42 * The tree path id/. | |
| 43 * @type {string} | |
| 44 */ | |
| 45 get pathId() { | |
| 46 var parent = this.parentItem; | |
| 47 if (parent && parent instanceof CertificateTreeItem) { | |
| 48 return parent.pathId + ',' + this.data.id; | |
| 49 } else { | |
| 50 return this.data.id; | |
| 51 } | |
| 52 } | |
| 53 }; | |
| 54 | |
| 55 /** | |
| 56 * Creates a new cookies tree. | |
| 57 * @param {Object=} opt_propertyBag Optional properties. | |
| 58 * @constructor | |
| 59 * @extends {Tree} | |
| 60 */ | |
| 61 var CertificatesTree = cr.ui.define('tree'); | |
| 62 | |
| 63 CertificatesTree.prototype = { | |
| 64 __proto__: Tree.prototype, | |
| 65 | |
| 66 /** @inheritDoc */ | |
| 67 decorate: function() { | |
| 68 Tree.prototype.decorate.call(this); | |
| 69 this.treeLookup_ = {}; | |
| 70 }, | |
| 71 | |
| 72 /** @inheritDoc */ | |
| 73 addAt: function(child, index) { | |
| 74 Tree.prototype.addAt.call(this, child, index); | |
| 75 if (child.data && child.data.id) | |
| 76 this.treeLookup_[child.data.id] = child; | |
| 77 }, | |
| 78 | |
| 79 /** @inheritDoc */ | |
| 80 remove: function(child) { | |
| 81 Tree.prototype.remove.call(this, child); | |
| 82 if (child.data && child.data.id) | |
| 83 delete this.treeLookup_[child.data.id]; | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * Clears the tree. | |
| 88 */ | |
| 89 clear: function() { | |
| 90 // Remove all fields without recreating the object since other code | |
| 91 // references it. | |
| 92 for (var id in this.treeLookup_){ | |
| 93 delete this.treeLookup_[id]; | |
| 94 } | |
| 95 this.textContent = ''; | |
| 96 }, | |
| 97 | |
| 98 /** | |
| 99 * Populate the tree. | |
| 100 * @param {Array} nodesData Nodes data array. | |
| 101 */ | |
| 102 populate: function(nodesData) { | |
| 103 this.clear(); | |
| 104 | |
| 105 for (var i = 0; i < nodesData.length; ++i) { | |
| 106 var subnodes = nodesData[i]['subnodes']; | |
| 107 delete nodesData[i]['subnodes']; | |
| 108 | |
| 109 var item = new CertificateTreeItem(nodesData[i]); | |
| 110 this.addAt(item, i); | |
| 111 | |
| 112 for (var j = 0; j < subnodes.length; ++j) { | |
| 113 var subitem = new CertificateTreeItem(subnodes[j]); | |
| 114 item.addAt(subitem, j); | |
| 115 } | |
| 116 // Make tree expanded by default. | |
| 117 item.expanded = true; | |
| 118 } | |
| 119 | |
| 120 cr.dispatchSimpleEvent(this, 'change'); | |
| 121 }, | |
| 122 }; | |
| 123 | |
| 124 return { | |
| 125 CertificatesTree: CertificatesTree | |
| 126 }; | |
| 127 }); | |
| 128 | |
| OLD | NEW |