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 // TODO(estade): these should be plain text when the items are not |
| 40 // actively being edited. |
| 41 var input = cr.doc.createElement('input'); |
| 42 input.type = 'text'; |
| 43 input.value = this.exceptionsPattern; |
| 44 this.appendChild(input); |
| 45 input.className = 'exceptionInput'; |
| 46 |
| 47 var select = cr.doc.createElement('select'); |
| 48 var option_allow = cr.doc.createElement('option'); |
| 49 option_allow.textContent = templateData.allowException; |
| 50 var option_block = cr.doc.createElement('option'); |
| 51 option_block.textContent = templateData.blockException; |
| 52 select.appendChild(option_allow); |
| 53 select.appendChild(option_block); |
| 54 this.appendChild(select); |
| 55 select.className = 'exceptionSelect'; |
| 56 |
| 57 this.input = input; |
| 58 this.select = select; |
| 59 this.option_allow = option_allow; |
| 60 this.option_block = option_block; |
| 61 } |
| 62 }; |
| 63 |
| 64 /** |
| 65 * Creates a new exceptions list. |
| 66 * @constructor |
| 67 * @extends {cr.ui.List} |
| 68 */ |
| 69 var ExceptionsList = cr.ui.define('list'); |
| 70 |
| 71 ExceptionsList.prototype = { |
| 72 __proto__: List.prototype, |
| 73 |
| 74 /** |
| 75 * Called when an element is decorated as a list. |
| 76 */ |
| 77 decorate: function() { |
| 78 List.prototype.decorate.call(this); |
| 79 |
| 80 this.dataModel = new ArrayDataModel([]); |
| 81 }, |
| 82 |
| 83 /** |
| 84 * Creates an item to go in the list. |
| 85 * @param {Object} entry The element from the data model for this row. |
| 86 */ |
| 87 createItem: function(entry) { |
| 88 return new ExceptionsListItem(entry); |
| 89 }, |
| 90 |
| 91 /** |
| 92 * Adds an exception to the js model. |
| 93 * @param {Array} entry A pair of the form [filter, setting]. |
| 94 */ |
| 95 addException: function(entry) { |
| 96 this.dataModel.push(entry); |
| 97 }, |
| 98 |
| 99 /** |
| 100 * Removes all exceptions from the js model. |
| 101 */ |
| 102 clear: function() { |
| 103 this.dataModel = new ArrayDataModel([]); |
| 104 }, |
| 105 |
| 106 /** |
| 107 * Removes all selected rows from browser's model. |
| 108 */ |
| 109 removeSelectedRows: function() { |
| 110 var selection = this.selectionModel; |
| 111 var removePatterns = []; |
| 112 var selectedItems = this.selectedItems; |
| 113 for (var i = 0; i < selectedItems.length; ++i) { |
| 114 removePatterns.push(selectedItems[i][0]); |
| 115 } |
| 116 |
| 117 chrome.send('removeImageExceptions', removePatterns); |
| 118 } |
| 119 }; |
| 120 |
| 121 var ExceptionsArea = cr.ui.define('div'); |
| 122 |
| 123 ExceptionsArea.prototype = { |
| 124 __proto__: HTMLDivElement.prototype, |
| 125 |
| 126 decorate: function() { |
| 127 ExceptionsList.decorate($('imagesExceptionsList')); |
| 128 |
| 129 var addRow = cr.doc.createElement('button'); |
| 130 addRow.textContent = templateData.addExceptionRow; |
| 131 this.appendChild(addRow); |
| 132 |
| 133 // TODO(estade): disable "Remove" when no row is highlighted. |
| 134 var removeRow = cr.doc.createElement('button'); |
| 135 removeRow.textContent = templateData.removeExceptionRow; |
| 136 this.appendChild(removeRow); |
| 137 |
| 138 removeRow.onclick = function(event) { |
| 139 imagesExceptionsList.removeSelectedRows(); |
| 140 }; |
| 141 |
| 142 addRow.onclick = function(event) { |
| 143 // TODO(estade): implement this. |
| 144 }; |
| 145 } |
| 146 }; |
| 147 |
| 148 return { |
| 149 ExceptionsListItem: ExceptionsListItem, |
| 150 ExceptionsList: ExceptionsList, |
| 151 ExceptionsArea: ExceptionsArea |
| 152 }; |
| 153 }); |
OLD | NEW |