OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var Tree = cr.ui.Tree; | 6 /** @const */ var Tree = cr.ui.Tree; |
7 /** @const */ var TreeItem = cr.ui.TreeItem; | 7 /** @const */ var TreeItem = cr.ui.TreeItem; |
8 | 8 |
9 /** | 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 /** |
10 * Creates a new tree item for certificate data. | 42 * Creates a new tree item for certificate data. |
11 * @param {Object=} data Data used to create a certificate tree item. | 43 * @param {Object=} data Data used to create a certificate tree item. |
12 * @constructor | 44 * @constructor |
13 * @extends {TreeItem} | 45 * @extends {TreeItem} |
14 */ | 46 */ |
15 function CertificateTreeItem(data) { | 47 function CertificateTreeItem(data) { |
| 48 data.isCert = true; |
16 // TODO(mattm): other columns | 49 // TODO(mattm): other columns |
17 var treeItem = new TreeItem({ | 50 var treeItem = new TreeItem({ |
18 label: data.name, | 51 label: data.name, |
19 data: data | 52 data: data |
20 }); | 53 }); |
21 treeItem.__proto__ = CertificateTreeItem.prototype; | 54 treeItem.__proto__ = CertificateTreeItem.prototype; |
22 | 55 |
23 if (data.icon) { | 56 if (data.icon) |
24 treeItem.icon = data.icon; | 57 treeItem.icon = data.icon; |
25 } | |
26 | 58 |
27 if (data.untrusted) { | 59 if (data.untrusted) { |
28 var badge = document.createElement('span'); | 60 var badge = document.createElement('span'); |
29 badge.classList.add('cert-untrusted'); | 61 badge.classList.add('cert-untrusted'); |
30 badge.textContent = loadTimeData.getString('badgeCertUntrusted'); | 62 badge.textContent = loadTimeData.getString('badgeCertUntrusted'); |
31 treeItem.labelElement.insertBefore( | 63 treeItem.labelElement.insertBefore( |
32 badge, treeItem.labelElement.firstChild); | 64 badge, treeItem.labelElement.firstChild); |
33 } | 65 } |
34 | 66 |
35 return treeItem; | 67 return treeItem; |
36 } | 68 } |
37 | 69 |
38 CertificateTreeItem.prototype = { | 70 CertificateTreeItem.prototype = { |
39 __proto__: TreeItem.prototype, | 71 __proto__: TreeItem.prototype, |
40 | 72 |
41 /** | 73 /** |
42 * The tree path id/. | 74 * The tree path id/. |
43 * @type {string} | 75 * @type {string} |
44 */ | 76 */ |
45 get pathId() { | 77 get pathId() { |
46 var parent = this.parentItem; | 78 return this.parentItem.pathId + ',' + this.data.id; |
47 if (parent && parent instanceof CertificateTreeItem) { | |
48 return parent.pathId + ',' + this.data.id; | |
49 } else { | |
50 return this.data.id; | |
51 } | |
52 } | 79 } |
53 }; | 80 }; |
54 | 81 |
55 /** | 82 /** |
56 * Creates a new cookies tree. | 83 * Creates a new cookies tree. |
57 * @param {Object=} opt_propertyBag Optional properties. | 84 * @param {Object=} opt_propertyBag Optional properties. |
58 * @constructor | 85 * @constructor |
59 * @extends {Tree} | 86 * @extends {Tree} |
60 */ | 87 */ |
61 var CertificatesTree = cr.ui.define('tree'); | 88 var CertificatesTree = cr.ui.define('tree'); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 * Populate the tree. | 125 * Populate the tree. |
99 * @param {Array} nodesData Nodes data array. | 126 * @param {Array} nodesData Nodes data array. |
100 */ | 127 */ |
101 populate: function(nodesData) { | 128 populate: function(nodesData) { |
102 this.clear(); | 129 this.clear(); |
103 | 130 |
104 for (var i = 0; i < nodesData.length; ++i) { | 131 for (var i = 0; i < nodesData.length; ++i) { |
105 var subnodes = nodesData[i]['subnodes']; | 132 var subnodes = nodesData[i]['subnodes']; |
106 delete nodesData[i]['subnodes']; | 133 delete nodesData[i]['subnodes']; |
107 | 134 |
108 var item = new CertificateTreeItem(nodesData[i]); | 135 var item = new CertificateTreeFolder(nodesData[i]); |
109 this.addAt(item, i); | 136 this.addAt(item, i); |
110 | 137 |
111 for (var j = 0; j < subnodes.length; ++j) { | 138 for (var j = 0; j < subnodes.length; ++j) { |
112 var subitem = new CertificateTreeItem(subnodes[j]); | 139 var subitem = new CertificateTreeItem(subnodes[j]); |
113 item.addAt(subitem, j); | 140 item.addAt(subitem, j); |
114 } | 141 } |
115 // Make tree expanded by default. | 142 // Make tree expanded by default. |
116 item.expanded = true; | 143 item.expanded = true; |
117 } | 144 } |
118 | 145 |
119 cr.dispatchSimpleEvent(this, 'change'); | 146 cr.dispatchSimpleEvent(this, 'change'); |
120 }, | 147 }, |
121 }; | 148 }; |
122 | 149 |
123 return { | 150 return { |
124 CertificatesTree: CertificatesTree | 151 CertificatesTree: CertificatesTree |
125 }; | 152 }; |
126 }); | 153 }); |
127 | 154 |
OLD | NEW |