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
|
// Copyright (c) 2012 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.
cr.exportPath('options');
/**
* @typedef {{GUID: string, Name: string, Source: string, Type: string}}
*/
options.PreferredNetwork;
cr.define('options', function() {
var Page = cr.ui.pageManager.Page;
var PageManager = cr.ui.pageManager.PageManager;
var ArrayDataModel = cr.ui.ArrayDataModel;
var DeletableItem = options.DeletableItem;
var DeletableItemList = options.DeletableItemList;
/////////////////////////////////////////////////////////////////////////////
// NetworkPreferences class:
/**
* Encapsulated handling of ChromeOS network preferences page.
* @constructor
* @extends {cr.ui.pageManager.Page}
*/
function PreferredNetworks(model) {
Page.call(this, 'preferredNetworksPage', '', 'preferredNetworksPage');
}
cr.addSingletonGetter(PreferredNetworks);
PreferredNetworks.prototype = {
__proto__: Page.prototype,
/** @override */
initializePage: function() {
Page.prototype.initializePage.call(this);
PreferredNetworkList.decorate($('remembered-network-list'));
$('preferred-networks-confirm').onclick =
PageManager.closeOverlay.bind(PageManager);
},
update: function(rememberedNetworks) {
var list = $('remembered-network-list');
list.clear();
for (var i = 0; i < rememberedNetworks.length; i++) {
list.append(rememberedNetworks[i]);
}
list.redraw();
}
};
/**
* Creates a list entry for a remembered network.
* @param {options.PreferredNetwork} data Description of the network.
* @constructor
* @extends {options.DeletableItem}
*/
function PreferredNetworkListItem(data) {
var el = cr.doc.createElement('div');
el.__proto__ = PreferredNetworkListItem.prototype;
el.data = {};
for (var key in data)
el.data[key] = data[key];
el.decorate();
return el;
}
PreferredNetworkListItem.prototype = {
__proto__: DeletableItem.prototype,
/**
* Description of the network.
* @type {?options.PreferredNetwork}
*/
data: null,
/** @override */
decorate: function() {
DeletableItem.prototype.decorate.call(this);
var label = this.ownerDocument.createElement('div');
label.textContent = this.data.Name;
if (this.data.Source == 'DevicePolicy' ||
this.data.Source == 'UserPolicy') {
this.deletable = false;
}
this.contentElement.appendChild(label);
}
};
/**
* Class for displaying a list of preferred networks.
* @constructor
* @extends {options.DeletableItemList}
*/
var PreferredNetworkList = cr.ui.define('list');
PreferredNetworkList.prototype = {
__proto__: DeletableItemList.prototype,
/** @override */
decorate: function() {
DeletableItemList.prototype.decorate.call(this);
this.addEventListener('blur', this.onBlur_);
this.clear();
},
/**
* When the list loses focus, unselect all items in the list.
* @private
*/
onBlur_: function() {
this.selectionModel.unselectAll();
},
/**
* @override
* @param {options.PreferredNetwork} entry
*/
createItem: function(entry) {
return new PreferredNetworkListItem(entry);
},
/** @override */
deleteItemAtIndex: function(index) {
var item = this.dataModel.item(index);
if (item)
chrome.networkingPrivate.forgetNetwork(item.GUID);
this.dataModel.splice(index, 1);
// Invalidate the list since it has a stale cache after a splice
// involving a deletion.
this.invalidate();
this.redraw();
},
/**
* Purges all networks from the list.
*/
clear: function() {
this.dataModel = new ArrayDataModel([]);
this.redraw();
},
/**
* Adds a remembered network to the list.
* @param {options.PreferredNetwork} data Description of the network.
*/
append: function(data) {
this.dataModel.push(data);
}
};
// Export
return {
PreferredNetworks: PreferredNetworks
};
});
|