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