Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / network_configuration / js / network_config.js
blob815886a3f87c49b4498e9f189bcd2f3f259ed9f0
1 // Copyright (c) 2013 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.define('network.config', function() {
6 var NetworkConfig = cr.ui.define('div');
8 NetworkConfig.prototype = {
9 __proto__: HTMLDivElement.prototype,
10 decorate: function() {
11 var params = parseQueryParams(window.location);
12 this.networkId_ = params.network;
13 this.activeArea_ = null;
14 this.userArea_ = null;
15 this.managedArea_ = null;
16 this.stateArea_ = null;
17 this.updateDom_();
18 this.fetchProperties_();
21 fetchProperties_: function() {
22 chrome.networkingPrivate.getProperties(
23 this.networkId_,
24 this.updateActiveSettings_.bind(this));
25 chrome.networkingPrivate.getManagedProperties(
26 this.networkId_,
27 this.updateManagedSettings_.bind(this));
28 chrome.networkingPrivate.getState(
29 this.networkId_,
30 this.updateState_.bind(this));
33 stringifyJSON_: function(properties) {
34 return JSON.stringify(properties, undefined, 2);
37 updateActiveSettings_: function(properties) {
38 this.activeArea_.value = this.stringifyJSON_(properties);
41 updateManagedSettings_: function(properties) {
42 var error = chrome.runtime.lastError;
43 if (error) {
44 this.managedArea_.value = error.message;
45 this.userArea_.value = 'undefined';
46 } else {
47 this.managedArea_.value = this.stringifyJSON_(properties);
48 this.userArea_.value = this.stringifyJSON_(
49 this.extractUserSettings_(properties));
53 updateState_: function(properties) {
54 this.stateArea_.value = this.stringifyJSON_(properties);
57 extractUserSettings_: function(properties) {
58 if ('UserSetting' in properties)
59 return properties['UserSetting'];
61 if ('SharedSetting' in properties)
62 return properties['SharedSetting'];
64 var result = {};
65 for (var fieldName in properties) {
66 var entry = properties[fieldName];
67 if (typeof entry === 'object') {
68 var nestedResult = this.extractUserSettings_(entry);
69 if (nestedResult)
70 result[fieldName] = nestedResult;
73 if (Object.keys(result).length)
74 return result;
75 else
76 return undefined;
79 updateDom_: function() {
80 var div = document.createElement('div');
82 this.activeArea_ = function() {
83 var label = document.createElement('h4');
84 label.textContent = 'Active Settings (getProperties)';
85 div.appendChild(label);
86 var area = document.createElement('textarea');
87 div.appendChild(area);
88 return area;
89 }();
91 this.userArea_ = function() {
92 var label = document.createElement('h4');
93 label.textContent = 'User Settings';
94 div.appendChild(label);
95 var area = document.createElement('textarea');
96 div.appendChild(area);
97 return area;
98 }();
100 this.managedArea_ = function() {
101 var label = document.createElement('h4');
102 label.textContent = 'Managed Settings (getManagedProperties)';
103 div.appendChild(label);
104 var area = document.createElement('textarea');
105 div.appendChild(area);
106 return area;
107 }();
109 this.stateArea_ = function() {
110 var label = document.createElement('h4');
111 label.textContent = 'State (getState)';
112 div.appendChild(label);
113 var area = document.createElement('textarea');
114 div.appendChild(area);
115 return area;
116 }();
118 this.appendChild(div);
121 get userSettings() {
122 return JSON.parse(this.userArea_.value);
125 get networkId() {
126 return this.networkId_;
130 return {
131 NetworkConfig: NetworkConfig