summaryrefslogtreecommitdiff
path: root/chromium/ui/webui/resources/cr_components/chromeos/cellular_setup/button_bar.js
blob: 653bcf509f42e75d033ab5030db00e5b8717fea0 (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
// Copyright 2019 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.

/** Element containing navigation buttons for the Cellular Setup flow. */
Polymer({
  is: 'button-bar',

  behaviors: [
    I18nBehavior,
  ],

  properties: {
    /**
     * Sets the states of all buttons
     * @type {!cellularSetup.ButtonBarState}
     */
    buttonState: {
      type: Object,
      value: {},
    },

    /**
     * @type {!cellularSetup.Button}
     */
    Button: {
      type: Object,
      value: cellularSetup.Button,
    },

    forwardButtonLabel: {
      type: String,
      value: '',
    },
  },

  /**
   * @param {!cellularSetup.Button} buttonName
   * @return {boolean}
   * @private
   */
  isButtonHidden_(buttonName) {
    const state = this.getButtonBarState_(buttonName);
    return state === cellularSetup.ButtonState.HIDDEN;
  },

  /**
   * @param {!cellularSetup.Button} buttonName
   * @return {boolean}
   * @private
   */
  isButtonDisabled_(buttonName) {
    const state = this.getButtonBarState_(buttonName);
    return state === cellularSetup.ButtonState.DISABLED;
  },

  focusDefaultButton() {
    const buttons = this.shadowRoot.querySelectorAll('cr-button');
    // Focus the first non-disabled, non-hidden button from the end.
    for (let i = buttons.length - 1; i >= 0; i--) {
      const button = buttons.item(i);
      if (!button.disabled && !button.hidden) {
        cr.ui.focusWithoutInk(button);
        return;
      }
    }
  },

  /** @private */
  onBackwardButtonClicked_() {
    this.fire('backward-nav-requested');
  },

  /** @private */
  onCancelButtonClicked_() {
    this.fire('cancel-requested');
  },

  /** @private */
  onForwardButtonClicked_() {
    this.fire('forward-nav-requested');
  },

  /**
   * @param {!cellularSetup.Button} button
   * @returns {!cellularSetup.ButtonState|undefined}
   * @private
   */
  getButtonBarState_(button) {
    assert(this.buttonState);
    switch (button) {
      case cellularSetup.Button.BACKWARD:
        return this.buttonState.backward;
      case cellularSetup.Button.CANCEL:
        return this.buttonState.cancel;
      case cellularSetup.Button.FORWARD:
        return this.buttonState.forward;
      default:
        assertNotReached();
        return cellularSetup.ButtonState.ENABLED;
    }
  },
});