summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/media_router/elements/issue_banner/issue_banner.js
blob: 7466340118ba2f844b64c66a9bf091f13b01b7ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This Polymer element is used to show information about issues related
// to casting.
Polymer({
  is: 'issue-banner',

  properties: {
    /**
     * The issue to show.
     * @type {?media_router.Issue}
     */
    issue: {
      type: Object,
      value: null,
      observer: 'updateActionButtonText_',
    },

    /**
     * Maps an issue action type to the resource identifier of the text shown
     * in the action button.
     * This is a property of issue-banner because it is used in tests.
     * @type {!Array<string>}
     */
    issueActionTypeToButtonTextResource_: {
      type: Array,
      value: function() {
        return ['dismissButton', 'learnMoreButton'];
      },
    },

    /**
     * The text shown in the default action button.
     * @private {string}
     */
    defaultActionButtonText_: {
      type: String,
      value: '',
    },

    /**
     * The text shown in the secondary action button.
     * @private {string}
     */
    secondaryActionButtonText_: {
      type: String,
      value: '',
    },
  },

  /**
   * @param {?media_router.Issue} issue
   * @return {boolean} Whether or not to hide the blocking issue UI.
   * @private
   */
  computeIsBlockingIssueHidden_: function(issue) {
    return !issue || !issue.isBlocking;
  },

  /**
   * Returns true to hide the non-blocking issue UI, false to show it.
   *
   * @param {?media_router.Issue} issue
   * @private
   */
  computeIsNonBlockingIssueHidden_: function(issue) {
    return !issue || issue.isBlocking;
  },

  /**
   * @param {?media_router.Issue} issue The current issue.
   * @return {string} The class for the overall issue-banner.
   * @private
   */
  computeIssueClass_: function(issue) {
    if (!issue)
      return '';

    return issue.isBlocking ? 'blocking' : 'non-blocking';
  },

  /**
   * @param {?media_router.Issue} issue
   * @return {boolean} Whether or not to hide the non-blocking issue UI.
   * @private
   */
  computeOptionalActionHidden_: function(issue) {
    return !issue || !issue.secondaryActionType;
  },

  /**
   * Fires an issue-action-click event.
   *
   * @param {number} actionType The type of issue action.
   * @private
   */
  fireIssueActionClick_: function(actionType) {
    this.fire('issue-action-click', {
      id: this.issue.id,
      actionType: actionType,
      helpPageId: this.issue.helpPageId
    });
  },

  /**
   * Called when a default issue action is clicked.
   *
   * @param {!Event} event The event object.
   * @private
   */
  onClickDefaultAction_: function(event) {
    this.fireIssueActionClick_(this.issue.defaultActionType);
  },

  /**
   * Called when an optional issue action is clicked.
   *
   * @param {!Event} event The event object.
   * @private
   */
  onClickOptAction_: function(event) {
    this.fireIssueActionClick_(this.issue.secondaryActionType);
  },

  /**
   * Called when |issue| is updated. This updates the default and secondary
   * action button text.
   *
   * @private
   */
  updateActionButtonText_: function() {
    var defaultText = '';
    var secondaryText = '';
    if (this.issue) {
      defaultText = loadTimeData.getString(
          this.issueActionTypeToButtonTextResource_[
          this.issue.defaultActionType]);

      if (this.issue.secondaryActionType) {
        secondaryText = loadTimeData.getString(
            this.issueActionTypeToButtonTextResource_[
            this.issue.secondaryActionType]);
      }
    }

    this.defaultActionButtonText_ = defaultText;
    this.secondaryActionButtonText_ = secondaryText;
  },
});