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 preferences are visible iff this.isEditable(). All other | |
| 527 // 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') { | |
|
Evan Stade
2016/04/06 21:32:51
nit: no curlies
| |
| 532 item.hidden = !isEditable; | |
| 533 } | |
| 534 } | |
| 535 }, | |
| 536 | |
| 537 /** | |
| 538 * Sets whether user may set preference exceptions. Updates UI. | |
| 539 * | |
| 540 * @param {string} maybeEnable Whether or not user may set preference | |
| 541 * exceptions. | |
| 542 */ | |
| 543 setMaybeEnableEdit: function(maybeEnable) { | |
| 544 var oldIsEditable = this.isEditable(); | |
| 545 this.maybeEnableEdit = maybeEnable; | |
| 546 var newIsEditable = this.isEditable(); | |
| 547 | |
| 548 // If visibility changed, add or remove the Add New Exception row. | |
| 549 if (oldIsEditable != newIsEditable) { | |
| 550 var oldSize = this.dataModel.length; | |
| 551 if (newIsEditable) { | |
| 552 this.dataModel.splice(oldSize, oldSize, null); | |
| 553 } else { | |
| 554 this.dataModel.splice(oldSize - 1, oldSize); | |
| 555 } | |
| 556 } | |
| 557 this.updateRowVisibility(); | |
| 558 }, | |
| 559 | |
| 560 /** | |
| 523 * Sets the exceptions in the js model. | 561 * Sets the exceptions in the js model. |
| 524 * | 562 * |
| 525 * @param {Array<options.Exception>} entries A list of dictionaries of | 563 * @param {Array<options.Exception>} entries A list of dictionaries of |
| 526 * values, each dictionary represents an exception. | 564 * values, each dictionary represents an exception. |
| 527 */ | 565 */ |
| 528 setExceptions: function(entries) { | 566 setExceptions: function(entries) { |
| 529 var deleteCount = this.dataModel.length; | 567 var deleteCount = this.dataModel.length; |
| 530 | 568 |
| 531 if (this.isEditable()) { | 569 if (this.isEditable()) { |
| 532 // We don't want to remove the Add New Exception row. | 570 // We don't want to remove the Add New Exception row. |
| 533 deleteCount = deleteCount - 1; | 571 deleteCount = deleteCount - 1; |
| 534 } | 572 } |
| 535 | 573 |
| 536 var args = [0, deleteCount]; | 574 var args = [0, deleteCount]; |
| 537 args.push.apply(args, entries); | 575 args.push.apply(args, entries); |
| 538 this.dataModel.splice.apply(this.dataModel, args); | 576 this.dataModel.splice.apply(this.dataModel, args); |
| 577 this.updateRowVisibility(); | |
| 539 }, | 578 }, |
| 540 | 579 |
| 541 /** | 580 /** |
| 542 * The browser has finished checking a pattern for validity. Update the list | 581 * The browser has finished checking a pattern for validity. Update the list |
| 543 * item to reflect this. | 582 * item to reflect this. |
| 544 * | 583 * |
| 545 * @param {string} pattern The pattern. | 584 * @param {string} pattern The pattern. |
| 546 * @param {boolean} valid Whether said pattern is valid in the context of a | 585 * @param {boolean} valid Whether said pattern is valid in the context of a |
| 547 * content exception setting. | 586 * content exception setting. |
| 548 */ | 587 */ |
| 549 patternValidityCheckComplete: function(pattern, valid) { | 588 patternValidityCheckComplete: function(pattern, valid) { |
| 550 var listItems = this.items; | 589 var listItems = this.items; |
| 551 for (var i = 0; i < listItems.length; i++) { | 590 for (var i = 0; i < listItems.length; i++) { |
| 552 var listItem = listItems[i]; | 591 var listItem = listItems[i]; |
| 553 // Don't do anything for messages for the item if it is not the intended | 592 // 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 | 593 // recipient, or if the response is stale (i.e. the input value has |
| 555 // changed since we sent the request to analyze it). | 594 // changed since we sent the request to analyze it). |
| 556 if (pattern == listItem.input.value) | 595 if (pattern == listItem.input.value) |
| 557 listItem.setPatternValid(valid); | 596 listItem.setPatternValid(valid); |
| 558 } | 597 } |
| 559 }, | 598 }, |
| 560 | 599 |
| 561 /** | 600 /** |
| 562 * Returns whether the rows are editable in this list. | 601 * Returns whether the rows are editable in this list. |
| 563 */ | 602 */ |
| 564 isEditable: function() { | 603 isEditable: function() { |
| 565 // Exceptions of the following lists are not editable for now. | 604 return this.maybeEnableEdit && isEditableType(this.contentType); |
| 566 return isEditableType(this.contentType); | |
| 567 }, | 605 }, |
| 568 | 606 |
| 569 /** | 607 /** |
| 570 * Removes all exceptions from the js model. | 608 * Removes all exceptions from the js model. |
| 571 */ | 609 */ |
| 572 reset: function() { | 610 reset: function() { |
| 611 this.maybeEnableEdit = true; | |
| 573 if (this.isEditable()) { | 612 if (this.isEditable()) { |
| 574 // The null creates the Add New Exception row. | 613 // The null creates the Add New Exception row. |
| 575 this.dataModel = new ArrayDataModel([null]); | 614 this.dataModel = new ArrayDataModel([null]); |
| 576 } else { | 615 } else { |
| 577 this.dataModel = new ArrayDataModel([]); | 616 this.dataModel = new ArrayDataModel([]); |
| 578 } | 617 } |
| 579 }, | 618 }, |
| 580 | 619 |
| 581 /** @override */ | 620 /** @override */ |
| 582 deleteItemAtIndex: function(index) { | 621 deleteItemAtIndex: function(index) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 } | 735 } |
| 697 }; | 736 }; |
| 698 | 737 |
| 699 return { | 738 return { |
| 700 ExceptionsListItem: ExceptionsListItem, | 739 ExceptionsListItem: ExceptionsListItem, |
| 701 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 740 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
| 702 ExceptionsList: ExceptionsList, | 741 ExceptionsList: ExceptionsList, |
| 703 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 742 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
| 704 }; | 743 }; |
| 705 }); | 744 }); |
| OLD | NEW |