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