OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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.contentSettings', function() { | |
6 const List = cr.ui.List; | |
7 const ListItem = cr.ui.ListItem; | |
8 const ArrayDataModel = cr.ui.ArrayDataModel; | |
9 | |
10 /** | |
11 * Creates a new exceptions list item. | |
12 * @param {Array} exception A pair of the form [filter, setting]. | |
13 * @constructor | |
14 * @extends {cr.ui.ListItem} | |
15 */ | |
16 function ExceptionsListItem(exception) { | |
17 var el = cr.doc.createElement('li'); | |
18 el.exceptionsPattern = exception[0]; | |
19 el.__proto__ = ExceptionsListItem.prototype; | |
20 el.decorate(); | |
21 | |
22 if (exception[1] == 'allow') | |
23 el.option_allow.selected = 'selected'; | |
24 else if (exception[1] == 'block') | |
25 el.option_block.selected = 'selected'; | |
26 | |
27 return el; | |
28 } | |
29 | |
30 ExceptionsListItem.prototype = { | |
31 __proto__: ListItem.prototype, | |
32 | |
33 /** | |
34 * Called when an element is decorated as a list item. | |
35 */ | |
36 decorate: function() { | |
37 ListItem.prototype.decorate.call(this); | |
38 | |
39 var input = cr.doc.createElement('input'); | |
40 input.type = 'text'; | |
41 input.value = this.exceptionsPattern; | |
42 this.appendChild(input); | |
43 | |
44 var select = cr.doc.createElement('select'); | |
45 var option_allow = cr.doc.createElement('option'); | |
46 option_allow.textContent = templateData.allowException; | |
47 var option_block = cr.doc.createElement('option'); | |
48 option_block.textContent = templateData.blockException; | |
49 | |
50 select.appendChild(option_allow); | |
51 select.appendChild(option_block); | |
52 this.appendChild(select); | |
53 | |
54 this.input = input; | |
55 this.select = select; | |
56 this.option_allow = option_allow; | |
57 this.option_block = option_block | |
58 } | |
59 }; | |
60 | |
61 /** | |
62 * Creates a new exceptions list. | |
63 * @constructor | |
64 * @extends {cr.ui.List} | |
65 */ | |
66 var ExceptionsList = cr.ui.define('list'); | |
67 | |
68 ExceptionsList.prototype = { | |
69 __proto__: List.prototype, | |
70 | |
71 /** | |
72 * Called when an element is decorated as a list. | |
73 */ | |
74 decorate: function() { | |
75 List.prototype.decorate.call(this); | |
76 | |
77 this.dataModel = new ArrayDataModel([]); | |
78 }, | |
79 | |
80 /** | |
81 * Creates an item to go in the list. | |
82 * @param {Object} entry The element from the data model for this row. | |
83 */ | |
84 createItem: function(entry) { | |
85 return new ExceptionsListItem(entry); | |
86 }, | |
87 | |
88 /** | |
89 * Adds an exception to the model. | |
90 * @param {Array} entry A pair of the form [filter, setting]. | |
91 */ | |
92 addException: function(entry) { | |
93 this.dataModel.push(entry); | |
94 } | |
95 }; | |
96 | |
97 return { | |
98 ExceptionsListItem: ExceptionsListItem, | |
99 ExceptionsList: ExceptionsList | |
100 }; | |
101 }); | |
OLD | NEW |