| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 * | 471 * |
| 472 * @constructor | 472 * @constructor |
| 473 * @extends {options.InlineEditableItemList} | 473 * @extends {options.InlineEditableItemList} |
| 474 */ | 474 */ |
| 475 var ExceptionsList = cr.ui.define('list'); | 475 var ExceptionsList = cr.ui.define('list'); |
| 476 | 476 |
| 477 ExceptionsList.prototype = { | 477 ExceptionsList.prototype = { |
| 478 __proto__: InlineEditableItemList.prototype, | 478 __proto__: InlineEditableItemList.prototype, |
| 479 | 479 |
| 480 /** | 480 /** |
| 481 * True if user may set preference exceptions. | |
| 482 * @private {boolean} | |
| 483 */ | |
| 484 allowEdit_: true, | |
| 485 | |
| 486 /** | |
| 487 * Called when an element is decorated as a list. | 481 * Called when an element is decorated as a list. |
| 488 */ | 482 */ |
| 489 decorate: function() { | 483 decorate: function() { |
| 490 InlineEditableItemList.prototype.decorate.call(this); | 484 InlineEditableItemList.prototype.decorate.call(this); |
| 491 | 485 |
| 492 this.classList.add('settings-list'); | 486 this.classList.add('settings-list'); |
| 493 | 487 |
| 494 for (var parentNode = this.parentNode; parentNode; | 488 for (var parentNode = this.parentNode; parentNode; |
| 495 parentNode = parentNode.parentNode) { | 489 parentNode = parentNode.parentNode) { |
| 496 if (parentNode.hasAttribute('contentType')) { | 490 if (parentNode.hasAttribute('contentType')) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 519 entry); | 513 entry); |
| 520 } else { | 514 } else { |
| 521 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 515 var addRowItem = new ExceptionsAddRowListItem(this.contentType, |
| 522 this.mode); | 516 this.mode); |
| 523 addRowItem.deletable = false; | 517 addRowItem.deletable = false; |
| 524 return addRowItem; | 518 return addRowItem; |
| 525 } | 519 } |
| 526 }, | 520 }, |
| 527 | 521 |
| 528 /** | 522 /** |
| 529 * Updates visibility of each row, depending on content. | |
| 530 */ | |
| 531 updateRowVisibility: function() { | |
| 532 // Rows with user exceptions are visible iff this.isEditable(). | |
| 533 // All other rows are visible. | |
| 534 var isEditable = this.isEditable(); | |
| 535 for (var index = 0; index < this.dataModel.length; ++index) { | |
| 536 var item = this.getListItemByIndex(index); | |
| 537 if (item.dataItem.source == 'preference') | |
| 538 item.hidden = !isEditable; | |
| 539 } | |
| 540 }, | |
| 541 | |
| 542 /** | |
| 543 * Sets whether user is allowed to set preference exceptions. Updates UI. | |
| 544 * | |
| 545 * @param {boolean} allowEdit New value for this.allowEdit_. | |
| 546 */ | |
| 547 setAllowEdit: function(allowEdit) { | |
| 548 var oldIsEditable = this.isEditable(); | |
| 549 this.allowEdit_ = allowEdit; | |
| 550 var newIsEditable = this.isEditable(); | |
| 551 | |
| 552 // If visibility changed, add or remove the Add New Exception row. | |
| 553 if (oldIsEditable != newIsEditable) { | |
| 554 if (newIsEditable) | |
| 555 this.dataModel.push(null); | |
| 556 else | |
| 557 this.dataModel.pop(); | |
| 558 this.updateRowVisibility(); | |
| 559 } | |
| 560 }, | |
| 561 | |
| 562 /** | |
| 563 * Sets the exceptions in the js model. | 523 * Sets the exceptions in the js model. |
| 564 * | 524 * |
| 565 * @param {Array<options.Exception>} entries A list of dictionaries of | 525 * @param {Array<options.Exception>} entries A list of dictionaries of |
| 566 * values, each dictionary represents an exception. | 526 * values, each dictionary represents an exception. |
| 567 */ | 527 */ |
| 568 setExceptions: function(entries) { | 528 setExceptions: function(entries) { |
| 569 var deleteCount = this.dataModel.length; | 529 var deleteCount = this.dataModel.length; |
| 570 | 530 |
| 571 if (this.isEditable()) { | 531 if (this.isEditable()) { |
| 572 // We don't want to remove the Add New Exception row. | 532 // We don't want to remove the Add New Exception row. |
| 573 deleteCount = deleteCount - 1; | 533 deleteCount = deleteCount - 1; |
| 574 } | 534 } |
| 575 | 535 |
| 576 var args = [0, deleteCount]; | 536 var args = [0, deleteCount]; |
| 577 args.push.apply(args, entries); | 537 args.push.apply(args, entries); |
| 578 this.dataModel.splice.apply(this.dataModel, args); | 538 this.dataModel.splice.apply(this.dataModel, args); |
| 579 this.updateRowVisibility(); | |
| 580 }, | 539 }, |
| 581 | 540 |
| 582 /** | 541 /** |
| 583 * The browser has finished checking a pattern for validity. Update the list | 542 * The browser has finished checking a pattern for validity. Update the list |
| 584 * item to reflect this. | 543 * item to reflect this. |
| 585 * | 544 * |
| 586 * @param {string} pattern The pattern. | 545 * @param {string} pattern The pattern. |
| 587 * @param {boolean} valid Whether said pattern is valid in the context of a | 546 * @param {boolean} valid Whether said pattern is valid in the context of a |
| 588 * content exception setting. | 547 * content exception setting. |
| 589 */ | 548 */ |
| 590 patternValidityCheckComplete: function(pattern, valid) { | 549 patternValidityCheckComplete: function(pattern, valid) { |
| 591 var listItems = this.items; | 550 var listItems = this.items; |
| 592 for (var i = 0; i < listItems.length; i++) { | 551 for (var i = 0; i < listItems.length; i++) { |
| 593 var listItem = listItems[i]; | 552 var listItem = listItems[i]; |
| 594 // Don't do anything for messages for the item if it is not the intended | 553 // Don't do anything for messages for the item if it is not the intended |
| 595 // recipient, or if the response is stale (i.e. the input value has | 554 // recipient, or if the response is stale (i.e. the input value has |
| 596 // changed since we sent the request to analyze it). | 555 // changed since we sent the request to analyze it). |
| 597 if (pattern == listItem.input.value) | 556 if (pattern == listItem.input.value) |
| 598 listItem.setPatternValid(valid); | 557 listItem.setPatternValid(valid); |
| 599 } | 558 } |
| 600 }, | 559 }, |
| 601 | 560 |
| 602 /** | 561 /** |
| 603 * Returns whether the rows are editable in this list. | 562 * Returns whether the rows are editable in this list. |
| 604 */ | 563 */ |
| 605 isEditable: function() { | 564 isEditable: function() { |
| 606 return this.allowEdit_ && isEditableType(this.contentType); | 565 // Exceptions of the following lists are not editable for now. |
| 566 return isEditableType(this.contentType); |
| 607 }, | 567 }, |
| 608 | 568 |
| 609 /** | 569 /** |
| 610 * Removes all exceptions from the js model. | 570 * Removes all exceptions from the js model. |
| 611 */ | 571 */ |
| 612 reset: function() { | 572 reset: function() { |
| 613 this.allowEdit_ = true; | |
| 614 if (this.isEditable()) { | 573 if (this.isEditable()) { |
| 615 // The null creates the Add New Exception row. | 574 // The null creates the Add New Exception row. |
| 616 this.dataModel = new ArrayDataModel([null]); | 575 this.dataModel = new ArrayDataModel([null]); |
| 617 } else { | 576 } else { |
| 618 this.dataModel = new ArrayDataModel([]); | 577 this.dataModel = new ArrayDataModel([]); |
| 619 } | 578 } |
| 620 }, | 579 }, |
| 621 | 580 |
| 622 /** @override */ | 581 /** @override */ |
| 623 deleteItemAtIndex: function(index) { | 582 deleteItemAtIndex: function(index) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 } | 696 } |
| 738 }; | 697 }; |
| 739 | 698 |
| 740 return { | 699 return { |
| 741 ExceptionsListItem: ExceptionsListItem, | 700 ExceptionsListItem: ExceptionsListItem, |
| 742 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 701 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
| 743 ExceptionsList: ExceptionsList, | 702 ExceptionsList: ExceptionsList, |
| 744 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 703 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
| 745 }; | 704 }; |
| 746 }); | 705 }); |
| OLD | NEW |