summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/settings/internet_page/internet_config.js
blob: 0b3760d0477dbd772e8f616a81d21be90e9cc5bf (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
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright 2017 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.

/**
 * @fileoverview
 * 'internet-config' is a Settings dialog wrapper for network-config.
 */
Polymer({
  is: 'internet-config',

  behaviors: [I18nBehavior],

  properties: {
    /**
     * Interface for networkingPrivate calls, passed from internet_page.
     * @type {NetworkingPrivate}
     */
    networkingPrivate: Object,

    /** @type {!chrome.networkingPrivate.GlobalPolicy|undefined} */
    globalPolicy: Object,

    /** @private */
    shareAllowEnable_: {
      type: Boolean,
      value: function() {
        return loadTimeData.getBoolean('shareNetworkAllowEnable');
      }
    },

    /** @private */
    shareDefault_: {
      type: Boolean,
      value: function() {
        return loadTimeData.getBoolean('shareNetworkDefault');
      }
    },

    /**
     * The GUID when an existing network is being configured. This will be
     * empty when configuring a new network.
     */
    guid: String,

    /**
     * The type of network to be configured.
     * @type {!chrome.networkingPrivate.NetworkType}
     */
    type: String,

    /**
     * The name of network (for display while the network details are fetched).
     */
    name: String,

    /**
     * Set to true to show the 'connect' button instead of 'save'.
     */
    showConnect: Boolean,

    /** @private */
    enableConnect_: Boolean,

    /** @private */
    enableSave_: Boolean,

    /**
     * The current properties if an existing network is being configured, or
     * a minimal subset for a new network. Note: network-config may modify
     * this (specifically .name).
     * @private {!chrome.networkingPrivate.ManagedProperties}
     */
    managedProperties_: Object,

    /**
     * Set by network-config when a configuration error occurs.
     * @private
     */
    error_: {
      type: String,
      value: '',
    },
  },

  open: function() {
    const dialog = /** @type {!CrDialogElement} */ (this.$.dialog);
    if (!dialog.open) {
      dialog.showModal();
    }

    // Set managedProperties for new configurations and for existing
    // configurations until the current properties are loaded.
    assert(this.type && this.type != CrOnc.Type.ALL);
    this.managedProperties_ = {
      GUID: this.guid,
      Name: {Active: this.name},
      Type: this.type,
    };
    this.$.networkConfig.init();
  },

  close: function() {
    const dialog = /** @type {!CrDialogElement} */ (this.$.dialog);
    if (dialog.open) {
      dialog.close();
    }
  },

  /**
   * @param {!Event} event
   * @private
   */
  onClose_: function(event) {
    this.close();
    event.stopPropagation();
  },

  /**
   * @return {string}
   * @private
   */
  getDialogTitle_: function() {
    // If no properties are available yet, wait until they are set as part of
    // open().
    if (!this.managedProperties_) {
      return '';
    }

    const name = /** @type {string} */ (
        CrOnc.getActiveValue(this.managedProperties_.Name));
    if (name && !this.showConnect) {
      return this.i18n('internetConfigName', HTMLEscape(name));
    }
    const type = this.i18n('OncType' + this.managedProperties_.Type);
    return this.i18n('internetJoinType', type);
  },

  /**
   * @return {string}
   * @private
   */
  getError_: function() {
    if (this.i18nExists(this.error_)) {
      return this.i18n(this.error_);
    }
    return this.i18n('networkErrorUnknown');
  },

  /** @private */
  onCancelTap_: function() {
    this.close();
  },

  /** @private */
  onSaveTap_: function() {
    this.$.networkConfig.save();
  },

  /** @private */
  onConnectTap_: function() {
    this.$.networkConfig.connect();
  },
});