1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 cr
.exportPath('options');
8 * @typedef {{GUID: string, Name: string, Source: string, Type: string}}
10 options
.PreferredNetwork
;
12 cr
.define('options', function() {
14 var Page
= cr
.ui
.pageManager
.Page
;
15 var PageManager
= cr
.ui
.pageManager
.PageManager
;
16 var ArrayDataModel
= cr
.ui
.ArrayDataModel
;
17 var DeletableItem
= options
.DeletableItem
;
18 var DeletableItemList
= options
.DeletableItemList
;
20 /////////////////////////////////////////////////////////////////////////////
21 // NetworkPreferences class:
24 * Encapsulated handling of ChromeOS network preferences page.
26 * @extends {cr.ui.pageManager.Page}
28 function PreferredNetworks(model
) {
29 Page
.call(this, 'preferredNetworksPage', '', 'preferredNetworksPage');
32 cr
.addSingletonGetter(PreferredNetworks
);
34 PreferredNetworks
.prototype = {
35 __proto__
: Page
.prototype,
38 initializePage: function() {
39 Page
.prototype.initializePage
.call(this);
40 PreferredNetworkList
.decorate($('remembered-network-list'));
41 $('preferred-networks-confirm').onclick
=
42 PageManager
.closeOverlay
.bind(PageManager
);
45 update: function(rememberedNetworks
) {
46 var list
= $('remembered-network-list');
48 for (var i
= 0; i
< rememberedNetworks
.length
; i
++) {
49 list
.append(rememberedNetworks
[i
]);
57 * Creates a list entry for a remembered network.
58 * @param {options.PreferredNetwork} data Description of the network.
60 * @extends {options.DeletableItem}
62 function PreferredNetworkListItem(data
) {
63 var el
= cr
.doc
.createElement('div');
64 el
.__proto__
= PreferredNetworkListItem
.prototype;
67 el
.data
[key
] = data
[key
];
72 PreferredNetworkListItem
.prototype = {
73 __proto__
: DeletableItem
.prototype,
76 * Description of the network.
77 * @type {?options.PreferredNetwork}
82 decorate: function() {
83 DeletableItem
.prototype.decorate
.call(this);
84 var label
= this.ownerDocument
.createElement('div');
85 label
.textContent
= this.data
.Name
;
86 if (this.data
.Source
== 'DevicePolicy' ||
87 this.data
.Source
== 'UserPolicy') {
88 this.deletable
= false;
90 this.contentElement
.appendChild(label
);
95 * Class for displaying a list of preferred networks.
97 * @extends {options.DeletableItemList}
99 var PreferredNetworkList
= cr
.ui
.define('list');
101 PreferredNetworkList
.prototype = {
102 __proto__
: DeletableItemList
.prototype,
105 decorate: function() {
106 DeletableItemList
.prototype.decorate
.call(this);
107 this.addEventListener('blur', this.onBlur_
);
112 * When the list loses focus, unselect all items in the list.
115 onBlur_: function() {
116 this.selectionModel
.unselectAll();
121 * @param {options.PreferredNetwork} entry
123 createItem: function(entry
) {
124 return new PreferredNetworkListItem(entry
);
128 deleteItemAtIndex: function(index
) {
129 var item
= this.dataModel
.item(index
);
131 chrome
.networkingPrivate
.forgetNetwork(item
.GUID
);
132 this.dataModel
.splice(index
, 1);
133 // Invalidate the list since it has a stale cache after a splice
134 // involving a deletion.
140 * Purges all networks from the list.
143 this.dataModel
= new ArrayDataModel([]);
148 * Adds a remembered network to the list.
149 * @param {options.PreferredNetwork} data Description of the network.
151 append: function(data
) {
152 this.dataModel
.push(data
);
158 PreferredNetworks
: PreferredNetworks