1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr.define('print_preview', function() {
9 * Base class for print option section components.
11 * @extends {print_preview.Component}
13 function SettingsSection() {
14 print_preview.Component.call(this);
17 * Cached "hasCollapsibleContent" status for COLLAPSIBLE_CONTENT_CHANGED
21 this.hasCollapsibleContentCached_ = null;
24 * Whether content of this section should be collapsed or not.
27 this.collapseContent_ = true;
31 * Event types dispatched by this class.
34 SettingsSection.EventType = {
35 COLLAPSIBLE_CONTENT_CHANGED:
36 'print_preview.SettingsSection.COLLAPSIBLE_CONTENT_CHANGED'
39 SettingsSection.prototype = {
40 __proto__: print_preview.Component.prototype,
42 /** @return {boolean} Whether this section should be displayed or not. */
43 isAvailable: function() {
44 throw Error('Abstract method not overridden');
48 * @return {boolean} Whether this section has a content which can be
51 hasCollapsibleContent: function() {
52 throw Error('Abstract method not overridden');
55 /** @param {boolean} isEnabled Whether this component is enabled. */
56 set isEnabled(isEnabled) {
57 throw Error('Abstract method not overridden');
61 * @return {boolean} Whether the content of this section should be
64 get collapseContent() {
65 return this.collapseContent_;
69 * @param {boolean} collapseContent Whether the content of this section
70 * should be collapsed, even if this section is available.
71 * @param {boolean} noAnimation Whether section visibility transition
72 * should not be animated.
74 setCollapseContent: function(collapseContent, noAnimation) {
75 this.collapseContent_ = collapseContent && this.hasCollapsibleContent();
76 this.updateUiStateInternal(noAnimation);
80 enterDocument: function() {
81 print_preview.Component.prototype.enterDocument.call(this);
82 this.isAvailable_ = this.isAvailable();
83 if (!this.isAvailable())
84 fadeOutOption(this.getElement(), true);
88 * Updates the component appearance according to the current state.
89 * @param {boolean=} opt_noAnimation Whether section visibility transition
90 * should not be animated.
93 updateUiStateInternal: function(opt_noAnimation) {
94 var hasCollapsibleContent = this.hasCollapsibleContent();
95 var changed = this.hasCollapsibleContentCached_ != hasCollapsibleContent;
96 this.hasCollapsibleContentCached_ = hasCollapsibleContent;
98 if (this.isSectionVisibleInternal())
99 fadeInOption(this.getElement(), opt_noAnimation);
101 fadeOutOption(this.getElement(), opt_noAnimation);
104 cr.dispatchSimpleEvent(
105 this, SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED);
110 * @return {boolean} Whether this section should be displayed or not.
113 isSectionVisibleInternal: function() {
114 return this.isAvailable() && !this.collapseContent_;
120 SettingsSection: SettingsSection