Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: ui/webui/resources/cr_elements/network/cr_network_list_item.js

Issue 2627023006: WebUI: Remove i18n from cr_elements/network (Closed)
Patch Set: Allow <if> in settings_ui.html Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** 5 /**
6 * @fileoverview Polymer element for displaying information about a network 6 * @fileoverview Polymer element for displaying information about a network
7 * in a list or summary based on ONC state properties. 7 * in a list or summary based on ONC state properties.
8 */ 8 */
9 9
10 Polymer({ 10 Polymer({
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * elements (e.g. the show subpage button) can become keyboard focusable 50 * elements (e.g. the show subpage button) can become keyboard focusable
51 * when this element has keyboard focus. 51 * when this element has keyboard focus.
52 */ 52 */
53 tabindex: { 53 tabindex: {
54 type: Number, 54 type: Number,
55 value: -1, 55 value: -1,
56 reflectToAttribute: true, 56 reflectToAttribute: true,
57 }, 57 },
58 }, 58 },
59 59
60 behaviors: [I18nBehavior, CrPolicyNetworkBehavior], 60 behaviors: [CrPolicyNetworkBehavior],
61 61
62 /** @private */ 62 /** @private */
63 itemChanged_: function() { 63 itemChanged_: function() {
64 if (this.item && !this.item.hasOwnProperty('customItemName')) { 64 if (this.item && !this.item.hasOwnProperty('customItemName')) {
65 this.networkState = 65 this.networkState =
66 /** @type {!CrOnc.NetworkStateProperties} */ (this.item); 66 /** @type {!CrOnc.NetworkStateProperties} */ (this.item);
67 } else if (this.networkState) { 67 } else if (this.networkState) {
68 this.networkState = undefined; 68 this.networkState = undefined;
69 } 69 }
70 }, 70 },
71 71
72 /** @private */ 72 /** @private */
73 networkStateChanged_: function() { 73 networkStateChanged_: function() {
74 if (this.networkState && 74 if (this.networkState &&
75 this.networkState.ConnectionState == CrOnc.ConnectionState.CONNECTED) { 75 this.networkState.ConnectionState == CrOnc.ConnectionState.CONNECTED) {
76 this.fire('network-connected', this.networkState); 76 this.fire('network-connected', this.networkState);
77 } 77 }
78 }, 78 },
79 79
80 /** 80 /**
81 * This gets called for network items and custom items. 81 * This gets called for network items and custom items.
82 * @private 82 * @private
83 */ 83 */
84 getItemName_: function() { 84 getItemName_: function() {
85 if (this.item.hasOwnProperty('customItemName')) { 85 if (this.item.hasOwnProperty('customItemName')) {
86 let item = /** @type {!CrNetworkList.CustomItemState} */ (this.item); 86 let item = /** @type {!CrNetworkList.CustomItemState} */ (this.item);
87 let name = item.customItemName || ''; 87 let name = item.customItemName || '';
88 if (this.i18nExists(item.customItemName)) 88 if (CrOncStrings.hasOwnProperty(item.customItemName))
89 name = this.i18n(item.customItemName); 89 name = CrOncStrings[item.customItemName];
90 return name; 90 return name;
91 } 91 }
92 let network = /** @type {!CrOnc.NetworkStateProperties} */ (this.item); 92 let network = /** @type {!CrOnc.NetworkStateProperties} */ (this.item);
93 if (this.isListItem) 93 if (this.isListItem)
94 return CrOnc.getNetworkName(network, this); 94 return CrOnc.getNetworkName(network);
95 return this.i18n('OncType' + network.Type); 95 return CrOncStrings['OncType' + network.Type];
96 }, 96 },
97 97
98 /** @private */ 98 /** @private */
99 isStateTextVisible_: function() { 99 isStateTextVisible_: function() {
100 return !!this.networkState && (!this.isListItem || this.isConnected_()); 100 return !!this.networkState && (!this.isListItem || this.isConnected_());
101 }, 101 },
102 102
103 /** @private */ 103 /** @private */
104 isStateTextConnected_: function() { 104 isStateTextConnected_: function() {
105 return this.isListItem && this.isConnected_(); 105 return this.isListItem && this.isConnected_();
106 }, 106 },
107 107
108 /** 108 /**
109 * This only gets called for network items once networkState is set. 109 * This only gets called for network items once networkState is set.
110 * @private 110 * @private
111 */ 111 */
112 getNetworkStateText_: function() { 112 getNetworkStateText_: function() {
113 if (!this.isStateTextVisible_()) 113 if (!this.isStateTextVisible_())
114 return ''; 114 return '';
115 let network = this.networkState; 115 let network = this.networkState;
116 if (this.isListItem) { 116 if (this.isListItem) {
117 if (this.isConnected_()) 117 if (this.isConnected_())
118 return this.i18n('networkListItemConnected'); 118 return CrOncStrings.networkListItemConnected;
119 return ''; 119 return '';
120 } 120 }
121 if (network.Name && network.ConnectionState) { 121 if (network.Name && network.ConnectionState) {
122 return this.getConnectionStateText_( 122 return this.getConnectionStateText_(
123 network.ConnectionState, CrOnc.getNetworkName(network, this)); 123 network.ConnectionState, CrOnc.getNetworkName(network));
124 } 124 }
125 return this.i18n('networkDisabled'); 125 return CrOncStrings.networkDisabled;
126 }, 126 },
127 127
128 /** 128 /**
129 * Returns the appropriate connection state text. 129 * Returns the appropriate connection state text.
130 * @param {string} state The connection state. 130 * @param {CrOnc.ConnectionState} state The connection state.
131 * @param {string} name The name of the network. 131 * @param {string} name The name of the network.
132 * @return {string} 132 * @return {string}
133 * @private 133 * @private
134 */ 134 */
135 getConnectionStateText_: function(state, name) { 135 getConnectionStateText_: function(state, name) {
136 if (state == CrOnc.ConnectionState.CONNECTED) 136 switch (state) {
137 return name; 137 case CrOnc.ConnectionState.CONNECTED:
138 if (state == CrOnc.ConnectionState.CONNECTING) 138 return name;
139 return this.i18n('networkListItemConnecting', name); 139 case CrOnc.ConnectionState.CONNECTING:
140 if (state == CrOnc.ConnectionState.NOT_CONNECTED) 140 return CrOncStrings.networkListItemConnecting.replace('$1', name);
141 return this.i18n('networkListItemNotConnected'); 141 case CrOnc.ConnectionState.NOT_CONNECTED:
142 // TODO(stevenjb): Audit state translations and remove test. 142 return CrOncStrings.networkListItemNotConnected;
143 if (this.i18nExists(state)) 143 }
144 return this.i18n(state); 144 assertNotReached();
145 return state; 145 return state;
146 }, 146 },
147 147
148 /** 148 /**
149 * @param {!CrOnc.NetworkStateProperties} networkState 149 * @param {!CrOnc.NetworkStateProperties} networkState
150 * @param {boolean} showButtons 150 * @param {boolean} showButtons
151 * @return {boolean} 151 * @return {boolean}
152 * @private 152 * @private
153 */ 153 */
154 isSubpageButtonVisible_: function(networkState, showButtons) { 154 isSubpageButtonVisible_: function(networkState, showButtons) {
(...skipping 13 matching lines...) Expand all
168 * Fires a 'show-details' event with |this.networkState| as the details. 168 * Fires a 'show-details' event with |this.networkState| as the details.
169 * @param {Event} event 169 * @param {Event} event
170 * @private 170 * @private
171 */ 171 */
172 fireShowDetails_: function(event) { 172 fireShowDetails_: function(event) {
173 assert(this.networkState); 173 assert(this.networkState);
174 this.fire('show-detail', this.networkState); 174 this.fire('show-detail', this.networkState);
175 event.stopPropagation(); 175 event.stopPropagation();
176 }, 176 },
177 }); 177 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698