OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('network.config', function() { | 5 cr.define('network.config', function() { |
6 var NetworkConfig = cr.ui.define('div'); | 6 var NetworkConfig = cr.ui.define('div'); |
7 | 7 |
8 NetworkConfig.prototype = { | 8 NetworkConfig.prototype = { |
9 __proto__: HTMLDivElement.prototype, | 9 __proto__: HTMLDivElement.prototype, |
10 decorate: function() { | 10 decorate: function() { |
11 var params = parseQueryParams(window.location); | 11 var params = parseQueryParams(window.location); |
12 this.networkId_ = params.network; | 12 this.networkId_ = params.network; |
13 this.settingsArea_ = null; | 13 this.activeArea_ = null; |
14 this.userArea_ = null; | |
15 this.managedArea_ = null; | |
16 this.updateDom_(); | |
14 this.fetchProperties_(); | 17 this.fetchProperties_(); |
15 }, | 18 }, |
16 | 19 |
17 fetchProperties_: function() { | 20 fetchProperties_: function() { |
18 chrome.networkingPrivate.getProperties(this.networkId_, | 21 chrome.networkingPrivate.getProperties( |
19 this.updateDom.bind(this)); | 22 this.networkId_, |
23 this.updateActiveSettings_.bind(this)); | |
24 chrome.networkingPrivate.getManagedProperties( | |
25 this.networkId_, | |
26 this.updateManagedSettings_.bind(this)); | |
20 }, | 27 }, |
21 | 28 |
22 updateDom: function(properties) { | 29 stringifyJSON_: function(properties) { |
30 return JSON.stringify(properties, undefined, 2); | |
31 }, | |
32 | |
33 updateActiveSettings_: function(properties) { | |
34 this.activeArea_.value = this.stringifyJSON_(properties); | |
35 }, | |
36 | |
37 updateManagedSettings_: function(properties) { | |
38 var error = chrome.runtime.lastError; | |
39 if (error) { | |
40 this.managedArea_.value = error.message; | |
41 this.userArea_.value = 'undefined'; | |
42 } else { | |
43 this.managedArea_.value = this.stringifyJSON_(properties); | |
44 this.userArea_.value = this.stringifyJSON_( | |
45 this.extractUserSettings_(properties)); | |
46 } | |
47 }, | |
48 | |
49 extractUserSettings_: function(properties) { | |
50 if ('UserSetting' in properties) { | |
51 return properties['UserSetting']; | |
52 } | |
53 if ('SharedSetting' in properties) { | |
54 return properties['SharedSetting']; | |
55 } | |
56 | |
57 var result = {}; | |
58 for (var fieldName in properties) { | |
59 var entry = properties[fieldName]; | |
60 if (typeof entry === 'object') { | |
61 var nestedResult = this.extractUserSettings_(entry); | |
62 if (nestedResult) { | |
63 result[fieldName] = nestedResult; | |
64 } | |
65 } | |
66 } | |
67 if (Object.keys(result).length) | |
pastarmovj
2013/04/11 14:46:29
This is inconsistent. Either use curlies around si
pneubeck (no reviews)
2013/04/15 12:16:24
Done.
| |
68 return result; | |
69 else | |
70 return undefined; | |
71 }, | |
72 | |
73 updateDom_: function() { | |
23 var div = document.createElement('div'); | 74 var div = document.createElement('div'); |
24 var label = document.createElement('h4'); | 75 |
25 label.textContent = 'User Settings'; | 76 this.activeArea_ = function() { |
26 div.appendChild(label); | 77 var label = document.createElement('h4'); |
27 var area = document.createElement('textarea'); | 78 label.textContent = 'Active Settings (getProperties)'; |
28 var str = JSON.stringify(properties, undefined, 2); | 79 div.appendChild(label); |
29 area.value = str; | 80 var area = document.createElement('textarea'); |
30 div.appendChild(area); | 81 div.appendChild(area); |
82 return area; | |
83 }(); | |
84 | |
85 this.userArea_ = function() { | |
86 var label = document.createElement('h4'); | |
87 label.textContent = 'User Settings'; | |
88 div.appendChild(label); | |
89 var area = document.createElement('textarea'); | |
90 div.appendChild(area); | |
91 return area; | |
92 }(); | |
93 | |
94 this.managedArea_ = function() { | |
95 var label = document.createElement('h4'); | |
96 label.textContent = 'Managed Settings (getManagedProperties)'; | |
97 div.appendChild(label); | |
98 var area = document.createElement('textarea'); | |
99 div.appendChild(area); | |
100 return area; | |
101 }(); | |
31 | 102 |
32 this.appendChild(div); | 103 this.appendChild(div); |
33 this.settingsArea_ = area; | |
34 }, | 104 }, |
35 | 105 |
36 applyUserSettings: function() { | 106 get userSettings() { |
37 chrome.networkingPrivate.setProperties( | 107 return JSON.parse(this.userArea_.value); |
38 this.networkId_, | |
39 JSON.parse(this.settingsArea_.value)); | |
40 }, | 108 }, |
41 | 109 |
42 get networkId() { | 110 get networkId() { |
43 return this.networkId_; | 111 return this.networkId_; |
44 } | 112 } |
45 }; | 113 }; |
46 | 114 |
47 return { | 115 return { |
48 NetworkConfig: NetworkConfig | 116 NetworkConfig: NetworkConfig |
49 }; | 117 }; |
50 }); | 118 }); |
OLD | NEW |