Chromium Code Reviews| Index: chrome/browser/resources/options/content_settings_exceptions_area.js |
| diff --git a/chrome/browser/resources/options/content_settings_exceptions_area.js b/chrome/browser/resources/options/content_settings_exceptions_area.js |
| index 3ad7ac62a552f0e1079168e4d2c97cf12e4e61c1..4a27ecdfbcf0b018b1bca8f57a061bf6002412d4 100644 |
| --- a/chrome/browser/resources/options/content_settings_exceptions_area.js |
| +++ b/chrome/browser/resources/options/content_settings_exceptions_area.js |
| @@ -520,6 +520,43 @@ cr.define('options.contentSettings', function() { |
| }, |
| /** |
| + * Updates visibility of each row, depending on content. |
| + */ |
| + updateRowVisibility: function() { |
| + // Rows with user exceptions are visible iff this.isEditable(). |
| + // All other rows are visible. |
| + var isEditable = this.isEditable(); |
| + for (var index = 0; index < this.dataModel.length; ++index) { |
| + var item = this.getListItemByIndex(index); |
| + if (item.dataItem.source == 'preference') |
| + item.hidden = !isEditable; |
| + } |
| + }, |
| + |
| + /** |
| + * Sets whether user is allowed to set preference exceptions. Updates UI. |
| + * |
| + * @param {string} allowEdit Whether or not user may set preference |
| + * exceptions. |
| + */ |
| + setAllowEdit: function(allowEdit) { |
| + var oldIsEditable = this.isEditable(); |
| + this.allowEdit = allowEdit; |
| + var newIsEditable = this.isEditable(); |
| + |
| + // If visibility changed, add or remove the Add New Exception row. |
| + if (oldIsEditable != newIsEditable) { |
| + var oldSize = this.dataModel.length; |
| + if (newIsEditable) { |
| + this.dataModel.push(null); |
| + } else { |
| + this.dataModel.splice(oldSize - 1, 1); // pop. |
|
Evan Stade
2016/04/26 16:05:16
I would be in favor of adding pop to ArrayDataMode
huangs
2016/04/26 17:37:03
ArrayDataModel stores raw list of data in |this.ar
Evan Stade
2016/04/26 22:58:09
Don't you think pop() would be useful in other pla
huangs
2016/04/26 23:18:20
My preference is to keep the CL small. It seems a
Dan Beam
2016/04/27 02:29:39
i don't really know much about ArrayDataModel, but
huangs
2016/04/27 14:28:01
Added pop(). It returns the last item as well, for
|
| + } |
| + } |
| + this.updateRowVisibility(); |
| + }, |
| + |
| + /** |
| * Sets the exceptions in the js model. |
| * |
| * @param {Array<options.Exception>} entries A list of dictionaries of |
| @@ -536,6 +573,7 @@ cr.define('options.contentSettings', function() { |
| var args = [0, deleteCount]; |
| args.push.apply(args, entries); |
| this.dataModel.splice.apply(this.dataModel, args); |
| + this.updateRowVisibility(); |
| }, |
| /** |
| @@ -562,14 +600,14 @@ cr.define('options.contentSettings', function() { |
| * Returns whether the rows are editable in this list. |
| */ |
| isEditable: function() { |
| - // Exceptions of the following lists are not editable for now. |
| - return isEditableType(this.contentType); |
| + return this.allowEdit && isEditableType(this.contentType); |
| }, |
| /** |
| * Removes all exceptions from the js model. |
| */ |
| reset: function() { |
| + this.allowEdit = true; |
| if (this.isEditable()) { |
| // The null creates the Add New Exception row. |
| this.dataModel = new ArrayDataModel([null]); |