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.
9 * subnodes: Array<{id: string, name: string, readonly: boolean,
10 * untrusted: boolean, extractable: boolean,
16 cr
.define('options', function() {
17 /** @const */ var Tree
= cr
.ui
.Tree
;
18 /** @const */ var TreeItem
= cr
.ui
.TreeItem
;
21 * Creates a new tree folder for certificate data.
22 * @param {Object=} data Data used to create a certificate tree folder.
26 function CertificateTreeFolder(data
) {
28 var treeFolder
= new TreeItem({
32 treeFolder
.__proto__
= CertificateTreeFolder
.prototype;
35 treeFolder
.icon
= data
.icon
;
40 CertificateTreeFolder
.prototype = {
41 __proto__
: TreeItem
.prototype,
53 * Creates a new tree item for certificate data.
54 * @param {Object=} data Data used to create a certificate tree item.
58 function CertificateTreeItem(data
) {
60 // TODO(mattm): other columns
61 var treeItem
= new TreeItem({
65 treeItem
.__proto__
= CertificateTreeItem
.prototype;
68 treeItem
.icon
= data
.icon
;
71 var badge
= document
.createElement('span');
72 badge
.classList
.add('cert-untrusted');
73 badge
.textContent
= loadTimeData
.getString('badgeCertUntrusted');
74 treeItem
.labelElement
.insertBefore(
75 badge
, treeItem
.labelElement
.firstChild
);
79 var policyIndicator
= new options
.ControlledSettingIndicator();
80 policyIndicator
.controlledBy
= 'policy';
81 policyIndicator
.setAttribute(
82 'textpolicy', loadTimeData
.getString('certPolicyInstalled'));
83 policyIndicator
.classList
.add('cert-policy');
84 treeItem
.labelElement
.appendChild(policyIndicator
);
90 CertificateTreeItem
.prototype = {
91 __proto__
: TreeItem
.prototype,
98 return this.parentItem
.pathId
+ ',' + this.data
.id
;
103 * Creates a new cookies tree.
104 * @param {Object=} opt_propertyBag Optional properties.
108 var CertificatesTree
= cr
.ui
.define('tree');
110 CertificatesTree
.prototype = {
111 __proto__
: Tree
.prototype,
114 decorate: function() {
115 Tree
.prototype.decorate
.call(this);
116 this.treeLookup_
= {};
120 addAt: function(child
, index
) {
121 Tree
.prototype.addAt
.call(this, child
, index
);
122 if (child
.data
&& child
.data
.id
)
123 this.treeLookup_
[child
.data
.id
] = child
;
127 remove: function(child
) {
128 Tree
.prototype.remove
.call(this, child
);
129 if (child
.data
&& child
.data
.id
)
130 delete this.treeLookup_
[child
.data
.id
];
137 // Remove all fields without recreating the object since other code
139 for (var id
in this.treeLookup_
)
140 delete this.treeLookup_
[id
];
141 this.textContent
= '';
146 * @param {Array<CertificateData>} nodesData Nodes data array.
148 populate: function(nodesData
) {
151 for (var i
= 0; i
< nodesData
.length
; ++i
) {
152 var subnodes
= nodesData
[i
].subnodes
;
153 delete nodesData
[i
].subnodes
;
155 var item
= new CertificateTreeFolder(nodesData
[i
]);
158 for (var j
= 0; j
< subnodes
.length
; ++j
) {
159 var subitem
= new CertificateTreeItem(subnodes
[j
]);
160 item
.addAt(subitem
, j
);
162 // Make tree expanded by default.
163 item
.expanded
= true;
166 cr
.dispatchSimpleEvent(this, 'change');
171 CertificatesTree
: CertificatesTree