Chromium Code Reviews| 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.contentSettings', function() { | 5 cr.define('options.contentSettings', function() { |
| 6 /** @const */ var ControlledSettingIndicator = | 6 /** @const */ var ControlledSettingIndicator = |
| 7 options.ControlledSettingIndicator; | 7 options.ControlledSettingIndicator; |
| 8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; | 8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; |
| 9 /** @const */ var InlineEditableItem = options.InlineEditableItem; | 9 /** @const */ var InlineEditableItem = options.InlineEditableItem; |
| 10 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 10 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 entry); | 513 entry); |
| 514 } else { | 514 } else { |
| 515 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 515 var addRowItem = new ExceptionsAddRowListItem(this.contentType, |
| 516 this.mode); | 516 this.mode); |
| 517 addRowItem.deletable = false; | 517 addRowItem.deletable = false; |
| 518 return addRowItem; | 518 return addRowItem; |
| 519 } | 519 } |
| 520 }, | 520 }, |
| 521 | 521 |
| 522 /** | 522 /** |
| 523 * Updates visibility of each row, depending on content. | |
| 524 */ | |
| 525 updateRowVisibility: function() { | |
| 526 // Rows with user exceptions are visible iff this.isEditable(). | |
| 527 // All other rows are visible. | |
| 528 var isEditable = this.isEditable(); | |
| 529 for (var index = 0; index < this.dataModel.length; ++index) { | |
| 530 var item = this.getListItemByIndex(index); | |
| 531 if (item.dataItem.source == 'preference') | |
| 532 item.hidden = !isEditable; | |
| 533 } | |
| 534 }, | |
| 535 | |
| 536 /** | |
| 537 * Sets whether user is allowed to set preference exceptions. Updates UI. | |
| 538 * | |
| 539 * @param {string} allowEdit Whether or not user may set preference | |
|
Dan Beam
2016/05/03 04:20:26
should this be a boolean?
huangs
2016/05/03 18:34:19
Done.
| |
| 540 * exceptions. | |
| 541 */ | |
| 542 setAllowEdit: function(allowEdit) { | |
| 543 var oldIsEditable = this.isEditable(); | |
| 544 this.allowEdit = allowEdit; | |
|
Dan Beam
2016/05/03 04:20:26
can this be private?
huangs
2016/05/03 18:34:19
Done.
| |
| 545 var newIsEditable = this.isEditable(); | |
| 546 | |
| 547 // If visibility changed, add or remove the Add New Exception row. | |
| 548 if (oldIsEditable != newIsEditable) { | |
| 549 if (newIsEditable) | |
| 550 this.dataModel.push(null); | |
| 551 else | |
| 552 this.dataModel.pop(); | |
| 553 this.updateRowVisibility(); | |
| 554 } | |
| 555 }, | |
| 556 | |
| 557 /** | |
| 523 * Sets the exceptions in the js model. | 558 * Sets the exceptions in the js model. |
| 524 * | 559 * |
| 525 * @param {Array<options.Exception>} entries A list of dictionaries of | 560 * @param {Array<options.Exception>} entries A list of dictionaries of |
| 526 * values, each dictionary represents an exception. | 561 * values, each dictionary represents an exception. |
| 527 */ | 562 */ |
| 528 setExceptions: function(entries) { | 563 setExceptions: function(entries) { |
| 529 var deleteCount = this.dataModel.length; | 564 var deleteCount = this.dataModel.length; |
| 530 | 565 |
| 531 if (this.isEditable()) { | 566 if (this.isEditable()) { |
| 532 // We don't want to remove the Add New Exception row. | 567 // We don't want to remove the Add New Exception row. |
| 533 deleteCount = deleteCount - 1; | 568 deleteCount = deleteCount - 1; |
| 534 } | 569 } |
| 535 | 570 |
| 536 var args = [0, deleteCount]; | 571 var args = [0, deleteCount]; |
| 537 args.push.apply(args, entries); | 572 args.push.apply(args, entries); |
| 538 this.dataModel.splice.apply(this.dataModel, args); | 573 this.dataModel.splice.apply(this.dataModel, args); |
| 574 this.updateRowVisibility(); | |
| 539 }, | 575 }, |
| 540 | 576 |
| 541 /** | 577 /** |
| 542 * The browser has finished checking a pattern for validity. Update the list | 578 * The browser has finished checking a pattern for validity. Update the list |
| 543 * item to reflect this. | 579 * item to reflect this. |
| 544 * | 580 * |
| 545 * @param {string} pattern The pattern. | 581 * @param {string} pattern The pattern. |
| 546 * @param {boolean} valid Whether said pattern is valid in the context of a | 582 * @param {boolean} valid Whether said pattern is valid in the context of a |
| 547 * content exception setting. | 583 * content exception setting. |
| 548 */ | 584 */ |
| 549 patternValidityCheckComplete: function(pattern, valid) { | 585 patternValidityCheckComplete: function(pattern, valid) { |
| 550 var listItems = this.items; | 586 var listItems = this.items; |
| 551 for (var i = 0; i < listItems.length; i++) { | 587 for (var i = 0; i < listItems.length; i++) { |
| 552 var listItem = listItems[i]; | 588 var listItem = listItems[i]; |
| 553 // Don't do anything for messages for the item if it is not the intended | 589 // Don't do anything for messages for the item if it is not the intended |
| 554 // recipient, or if the response is stale (i.e. the input value has | 590 // recipient, or if the response is stale (i.e. the input value has |
| 555 // changed since we sent the request to analyze it). | 591 // changed since we sent the request to analyze it). |
| 556 if (pattern == listItem.input.value) | 592 if (pattern == listItem.input.value) |
| 557 listItem.setPatternValid(valid); | 593 listItem.setPatternValid(valid); |
| 558 } | 594 } |
| 559 }, | 595 }, |
| 560 | 596 |
| 561 /** | 597 /** |
| 562 * Returns whether the rows are editable in this list. | 598 * Returns whether the rows are editable in this list. |
| 563 */ | 599 */ |
| 564 isEditable: function() { | 600 isEditable: function() { |
| 565 // Exceptions of the following lists are not editable for now. | 601 return this.allowEdit && isEditableType(this.contentType); |
| 566 return isEditableType(this.contentType); | |
| 567 }, | 602 }, |
| 568 | 603 |
| 569 /** | 604 /** |
| 570 * Removes all exceptions from the js model. | 605 * Removes all exceptions from the js model. |
| 571 */ | 606 */ |
| 572 reset: function() { | 607 reset: function() { |
| 608 this.allowEdit = true; | |
| 573 if (this.isEditable()) { | 609 if (this.isEditable()) { |
| 574 // The null creates the Add New Exception row. | 610 // The null creates the Add New Exception row. |
| 575 this.dataModel = new ArrayDataModel([null]); | 611 this.dataModel = new ArrayDataModel([null]); |
| 576 } else { | 612 } else { |
| 577 this.dataModel = new ArrayDataModel([]); | 613 this.dataModel = new ArrayDataModel([]); |
| 578 } | 614 } |
| 579 }, | 615 }, |
| 580 | 616 |
| 581 /** @override */ | 617 /** @override */ |
| 582 deleteItemAtIndex: function(index) { | 618 deleteItemAtIndex: function(index) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 } | 732 } |
| 697 }; | 733 }; |
| 698 | 734 |
| 699 return { | 735 return { |
| 700 ExceptionsListItem: ExceptionsListItem, | 736 ExceptionsListItem: ExceptionsListItem, |
| 701 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 737 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
| 702 ExceptionsList: ExceptionsList, | 738 ExceptionsList: ExceptionsList, |
| 703 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 739 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
| 704 }; | 740 }; |
| 705 }); | 741 }); |
| OLD | NEW |