1 // Copyright (c) 2012 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.
5 cr.define('options', function() {
6 /** @const */ var Tree = cr.ui.Tree;
7 /** @const */ var TreeItem = cr.ui.TreeItem;
10 * Creates a new tree folder for certificate data.
11 * @param {Object=} data Data used to create a certificate tree folder.
15 function CertificateTreeFolder(data) {
17 var treeFolder = new TreeItem({
21 treeFolder.__proto__ = CertificateTreeFolder.prototype;
24 treeFolder.icon = data.icon;
29 CertificateTreeFolder.prototype = {
30 __proto__: TreeItem.prototype,
42 * Creates a new tree item for certificate data.
43 * @param {Object=} data Data used to create a certificate tree item.
47 function CertificateTreeItem(data) {
49 // TODO(mattm): other columns
50 var treeItem = new TreeItem({
54 treeItem.__proto__ = CertificateTreeItem.prototype;
57 treeItem.icon = data.icon;
60 var badge = document.createElement('span');
61 badge.classList.add('cert-untrusted');
62 badge.textContent = loadTimeData.getString('badgeCertUntrusted');
63 treeItem.labelElement.insertBefore(
64 badge, treeItem.labelElement.firstChild);
68 var policyIndicator = new options.ControlledSettingIndicator();
69 policyIndicator.controlledBy = 'policy';
70 policyIndicator.setAttribute(
71 'textpolicy', loadTimeData.getString('certPolicyInstalled'));
72 policyIndicator.classList.add('cert-policy');
73 treeItem.labelElement.appendChild(policyIndicator);
79 CertificateTreeItem.prototype = {
80 __proto__: TreeItem.prototype,
87 return this.parentItem.pathId + ',' + this.data.id;
92 * Creates a new cookies tree.
93 * @param {Object=} opt_propertyBag Optional properties.
97 var CertificatesTree = cr.ui.define('tree');
99 CertificatesTree.prototype = {
100 __proto__: Tree.prototype,
103 decorate: function() {
104 Tree.prototype.decorate.call(this);
105 this.treeLookup_ = {};
109 addAt: function(child, index) {
110 Tree.prototype.addAt.call(this, child, index);
111 if (child.data && child.data.id)
112 this.treeLookup_[child.data.id] = child;
116 remove: function(child) {
117 Tree.prototype.remove.call(this, child);
118 if (child.data && child.data.id)
119 delete this.treeLookup_[child.data.id];
126 // Remove all fields without recreating the object since other code
128 for (var id in this.treeLookup_)
129 delete this.treeLookup_[id];
130 this.textContent = '';
135 * @param {Array} nodesData Nodes data array.
137 populate: function(nodesData) {
140 for (var i = 0; i < nodesData.length; ++i) {
141 var subnodes = nodesData[i].subnodes;
142 delete nodesData[i].subnodes;
144 var item = new CertificateTreeFolder(nodesData[i]);
147 for (var j = 0; j < subnodes.length; ++j) {
148 var subitem = new CertificateTreeItem(subnodes[j]);
149 item.addAt(subitem, j);
151 // Make tree expanded by default.
152 item.expanded = true;
155 cr.dispatchSimpleEvent(this, 'change');
160 CertificatesTree: CertificatesTree