luci2: move most RPC proxy function declarations into the views using them to reduce...
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / system.system.js
1 L.ui.view.extend({
2 execute: function() {
3 var m = new L.cbi.Map('system', {
4 caption: L.tr('System'),
5 description: L.tr('Here you can configure the basic aspects of your device like its hostname or the timezone.'),
6 collabsible: true
7 });
8
9 var s = m.section(L.cbi.TypedSection, 'system', {
10 caption: L.tr('System Properties'),
11 teasers: [ 'hostname', 'zonename', 'languages', 'themes' ],
12 readonly: !this.options.acls.system
13 });
14
15 s.tab({
16 id: 'general',
17 caption: L.tr('General Settings')
18 });
19
20 var t = s.taboption('general', L.cbi.DummyValue, '__time', {
21 caption: L.tr('Local Time')
22 });
23
24 t.load = function(sid)
25 {
26 var id = this.id(sid);
27
28 return L.system.getSystemInfo().then(function(info) {
29 var date = new Date();
30 var time = info.localtime;
31
32 window.setInterval(function() {
33 date.setTime(++time * 1000);
34
35 $('#' + id).text('%04d/%02d/%02d %02d:%02d:%02d'.format(
36 date.getUTCFullYear(),
37 date.getUTCMonth() + 1,
38 date.getUTCDate(),
39 date.getUTCHours(),
40 date.getUTCMinutes(),
41 date.getUTCSeconds()
42 ));
43 }, 1000);
44 });
45 };
46
47
48 s.taboption('general', L.cbi.InputValue, 'hostname', {
49 caption: L.tr('Hostname'),
50 datatype: 'hostname'
51 });
52
53
54 var z = s.taboption('general', L.cbi.ListValue, 'zonename', {
55 caption: L.tr('Timezone')
56 });
57
58 z.load = function(sid) {
59 return $.getJSON(L.globals.resource + '/zoneinfo.json').then(function(zones) {
60 var znames = [ ];
61
62 for (var i = 0; i < zones.length; i++)
63 for (var j = 5; j < zones[i].length; j++)
64 znames.push(zones[i][j]);
65
66 znames.sort();
67
68 for (var i = 0; i < znames.length; i++)
69 z.value(znames[i]);
70
71 z.zones = zones;
72 });
73 };
74
75 z.save = function(sid)
76 {
77 var uci = this.ucipath(sid);
78 var val = this.formvalue(sid);
79
80 if (!this.callSuper('save', sid))
81 return false;
82
83 for (var i = 0; i < z.zones.length; i++)
84 for (var j = 5; j < z.zones[i].length; j++)
85 if (z.zones[i][j] == val)
86 {
87 m.set(uci.config, uci.section, 'timezone', z.zones[i][0]);
88 return true;
89 }
90
91 m.set(uci.config, uci.section, 'timezone', 'GMT0');
92 return true;
93 };
94
95
96 s.tab({
97 id: 'logging',
98 caption: L.tr('Logging')
99 });
100
101 s.taboption('logging', L.cbi.InputValue, 'log_size', {
102 caption: L.tr('System log buffer size'),
103 description: L.tr('kiB'),
104 placeholder: 16,
105 optional: true,
106 datatype: 'range(0, 32)'
107 });
108
109 s.taboption('logging', L.cbi.InputValue, 'log_ip', {
110 caption: L.tr('External system log server'),
111 placeholder: '0.0.0.0',
112 optional: true,
113 datatype: 'ip4addr'
114 });
115
116 s.taboption('logging', L.cbi.InputValue, 'log_port', {
117 caption: L.tr('External system log server port'),
118 placeholder: 514,
119 optional: true,
120 datatype: 'port'
121 });
122
123 s.taboption('logging', L.cbi.ListValue, 'conloglevel', {
124 caption: L.tr('Log output level')
125 }).value(8, L.tr('Debug'))
126 .value(7, L.tr('Info'))
127 .value(6, L.tr('Notice'))
128 .value(5, L.tr('Warning'))
129 .value(4, L.tr('Error'))
130 .value(3, L.tr('Critical'))
131 .value(2, L.tr('Alert'))
132 .value(1, L.tr('Emergency'));
133
134 s.taboption('logging', L.cbi.ListValue, 'cronloglevel', {
135 caption: L.tr('Cron Log level')
136 }).value(5, L.tr('Debug'))
137 .value(8, L.tr('Normal'))
138 .value(9, L.tr('Warning'));
139
140 s.tab({
141 id: 'language',
142 caption: L.tr('Language and Style')
143 });
144
145
146 var l = s.taboption('language', L.cbi.ListValue, 'languages', {
147 caption: L.tr('Language'),
148 uci_package: 'luci',
149 uci_section: 'main',
150 uci_option: 'lang'
151 }).value('auto', L.tr('Automatic'));
152
153 l.load = function(sid)
154 {
155 var langs = m.get('luci', 'languages');
156 for (var key in langs)
157 if (key.charAt(0) != '.')
158 l.value(key, langs[key]);
159 };
160
161
162 var t = s.taboption('language', L.cbi.ListValue, 'themes', {
163 caption: L.tr('Design'),
164 uci_package: 'luci',
165 uci_section: 'main',
166 uci_option: 'mediaurlbase'
167 });
168
169 t.load = function(sid)
170 {
171 var themes = m.get('luci', 'themes');
172 for (var key in themes)
173 if (key.charAt(0) != '.')
174 t.value(themes[key], key);
175 };
176
177
178 var s2 = m.section(L.cbi.NamedSection, 'ntp', {
179 caption: L.tr('Time Synchronization'),
180 readonly: !this.options.acls.system
181 });
182
183 var e = s2.option(L.cbi.CheckboxValue, '.enable', {
184 caption: L.tr('Enable NTP client'),
185 optional: true
186 });
187
188 e.load = function(sid) {
189 return L.system.initEnabled('sysntpd').then(function(enabled) {
190 e.options.initial = enabled;
191 });
192 };
193
194 e.save = function(sid) {
195 if (this.formvalue(sid))
196 return L.system.initEnable('sysntpd');
197 else
198 return L.system.initDisable('sysntpd');
199 };
200
201 s2.option(L.cbi.CheckboxValue, 'enable_server', {
202 caption: L.tr('Enable NTP server')
203 }).depends('.enable');
204
205 s2.option(L.cbi.DynamicList, 'server', {
206 caption: L.tr('NTP server candidates'),
207 datatype: 'host'
208 }).depends('.enable');
209
210 return m.insertInto('#map');
211 }
212 });