luci-mod-system: fix zram compression placeholder
[project/luci.git] / modules / luci-mod-system / htdocs / luci-static / resources / view / system / system.js
1 'use strict';
2 'require ui';
3 'require uci';
4 'require rpc';
5 'require form';
6
7 var callInitList, callInitAction, callTimezone,
8 callGetLocaltime, callSetLocaltime, CBILocalTime;
9
10 callInitList = rpc.declare({
11 object: 'luci',
12 method: 'getInitList',
13 params: [ 'name' ],
14 expect: { '': {} },
15 filter: function(res) {
16 for (var k in res)
17 return +res[k].enabled;
18 return null;
19 }
20 });
21
22 callInitAction = rpc.declare({
23 object: 'luci',
24 method: 'setInitAction',
25 params: [ 'name', 'action' ],
26 expect: { result: false }
27 });
28
29 callGetLocaltime = rpc.declare({
30 object: 'luci',
31 method: 'getLocaltime',
32 expect: { result: 0 }
33 });
34
35 callSetLocaltime = rpc.declare({
36 object: 'luci',
37 method: 'setLocaltime',
38 params: [ 'localtime' ],
39 expect: { result: 0 }
40 });
41
42 callTimezone = rpc.declare({
43 object: 'luci',
44 method: 'getTimezones',
45 expect: { '': {} }
46 });
47
48 CBILocalTime = form.DummyValue.extend({
49 renderWidget: function(section_id, option_id, cfgvalue) {
50 return E([], [
51 E('span', {}, [
52 E('input', {
53 'id': 'localtime',
54 'type': 'text',
55 'readonly': true,
56 'value': new Date(cfgvalue * 1000).toLocaleString()
57 })
58 ]),
59 ' ',
60 E('button', {
61 'class': 'cbi-button cbi-button-apply',
62 'click': ui.createHandlerFn(this, function() {
63 return callSetLocaltime(Math.floor(Date.now() / 1000));
64 })
65 }, _('Sync with browser')),
66 ' ',
67 this.ntpd_support ? E('button', {
68 'class': 'cbi-button cbi-button-apply',
69 'click': ui.createHandlerFn(this, function() {
70 return callInitAction('sysntpd', 'restart');
71 })
72 }, _('Sync with NTP-Server')) : ''
73 ]);
74 },
75 });
76
77 return L.view.extend({
78 load: function() {
79 return Promise.all([
80 callInitList('sysntpd'),
81 callTimezone(),
82 callGetLocaltime(),
83 uci.load('luci'),
84 uci.load('system')
85 ]);
86 },
87
88 render: function(rpc_replies) {
89 var ntpd_enabled = rpc_replies[0],
90 timezones = rpc_replies[1],
91 localtime = rpc_replies[2],
92 m, s, o;
93
94 m = new form.Map('system',
95 _('System'),
96 _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
97
98 m.chain('luci');
99
100 s = m.section(form.TypedSection, 'system', _('System Properties'));
101 s.anonymous = true;
102 s.addremove = false;
103
104 s.tab('general', _('General Settings'));
105 s.tab('logging', _('Logging'));
106 s.tab('timesync', _('Time Synchronization'));
107 s.tab('language', _('Language and Style'));
108
109 /*
110 * System Properties
111 */
112
113 o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
114 o.cfgvalue = function() { return localtime };
115 o.ntpd_support = ntpd_enabled;
116
117 o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
118 o.datatype = 'hostname';
119
120 o = s.taboption('general', form.ListValue, 'zonename', _('Timezone'));
121 o.value('UTC');
122
123 var zones = Object.keys(timezones || {}).sort();
124 for (var i = 0; i < zones.length; i++)
125 o.value(zones[i]);
126
127 o.write = function(section_id, formvalue) {
128 var tz = timezones[formvalue] ? timezones[formvalue].tzstring : null;
129 uci.set('system', section_id, 'zonename', formvalue);
130 uci.set('system', section_id, 'timezone', tz);
131 };
132
133 /*
134 * Logging
135 */
136
137 o = s.taboption('logging', form.Value, 'log_size', _('System log buffer size'), "kiB")
138 o.optional = true
139 o.placeholder = 16
140 o.datatype = 'uinteger'
141
142 o = s.taboption('logging', form.Value, 'log_ip', _('External system log server'))
143 o.optional = true
144 o.placeholder = '0.0.0.0'
145 o.datatype = 'host'
146
147 o = s.taboption('logging', form.Value, 'log_port', _('External system log server port'))
148 o.optional = true
149 o.placeholder = 514
150 o.datatype = 'port'
151
152 o = s.taboption('logging', form.ListValue, 'log_proto', _('External system log server protocol'))
153 o.value('udp', 'UDP')
154 o.value('tcp', 'TCP')
155
156 o = s.taboption('logging', form.Value, 'log_file', _('Write system log to file'))
157 o.optional = true
158 o.placeholder = '/tmp/system.log'
159
160 o = s.taboption('logging', form.ListValue, 'conloglevel', _('Log output level'))
161 o.value(8, _('Debug'))
162 o.value(7, _('Info'))
163 o.value(6, _('Notice'))
164 o.value(5, _('Warning'))
165 o.value(4, _('Error'))
166 o.value(3, _('Critical'))
167 o.value(2, _('Alert'))
168 o.value(1, _('Emergency'))
169
170 o = s.taboption('logging', form.ListValue, 'cronloglevel', _('Cron Log Level'))
171 o.default = 8
172 o.value(5, _('Debug'))
173 o.value(8, _('Normal'))
174 o.value(9, _('Warning'))
175
176 /*
177 * Zram Properties
178 */
179
180 if (L.hasSystemFeature('zram')) {
181 s.tab('zram', _('ZRam Settings'));
182
183 o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
184 o.optional = true;
185 o.placeholder = 16;
186 o.datatype = 'uinteger';
187
188 o = s.taboption('zram', form.ListValue, 'zram_comp_algo', _('ZRam Compression Algorithm'));
189 o.optional = true;
190 o.default = 'lzo';
191 o.value('lzo', 'lzo');
192 o.value('lz4', 'lz4');
193 o.value('deflate', 'deflate');
194
195 o = s.taboption('zram', form.Value, 'zram_comp_streams', _('ZRam Compression Streams'), _('Number of parallel threads used for compression'));
196 o.optional = true;
197 o.placeholder = 1;
198 o.datatype = 'uinteger';
199 }
200
201 /*
202 * Language & Style
203 */
204
205 o = s.taboption('language', form.ListValue, '_lang', _('Language'))
206 o.uciconfig = 'luci';
207 o.ucisection = 'main';
208 o.ucioption = 'lang';
209 o.value('auto');
210
211 var k = Object.keys(uci.get('luci', 'languages') || {}).sort();
212 for (var i = 0; i < k.length; i++)
213 if (k[i].charAt(0) != '.')
214 o.value(k[i], uci.get('luci', 'languages', k[i]));
215
216 o = s.taboption('language', form.ListValue, '_mediaurlbase', _('Design'))
217 o.uciconfig = 'luci';
218 o.ucisection = 'main';
219 o.ucioption = 'mediaurlbase';
220
221 var k = Object.keys(uci.get('luci', 'themes') || {}).sort();
222 for (var i = 0; i < k.length; i++)
223 if (k[i].charAt(0) != '.')
224 o.value(uci.get('luci', 'themes', k[i]), k[i]);
225
226 /*
227 * NTP
228 */
229
230 if (L.hasSystemFeature('sysntpd')) {
231 var default_servers = [
232 '0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
233 '2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
234 ];
235
236 o = s.taboption('timesync', form.Flag, 'enabled', _('Enable NTP client'));
237 o.rmempty = false;
238 o.ucisection = 'ntp';
239 o.default = o.disabled;
240 o.write = function(section_id, value) {
241 ntpd_enabled = +value;
242
243 if (ntpd_enabled && !uci.get('system', 'ntp')) {
244 uci.add('system', 'timeserver', 'ntp');
245 uci.set('system', 'ntp', 'server', default_servers);
246 }
247
248 if (!ntpd_enabled)
249 uci.set('system', 'ntp', 'enabled', 0);
250 else
251 uci.unset('system', 'ntp', 'enabled');
252
253 return callInitAction('sysntpd', 'enable');
254 };
255 o.load = function(section_id) {
256 return (ntpd_enabled == 1 &&
257 uci.get('system', 'ntp') != null &&
258 uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
259 };
260
261 o = s.taboption('timesync', form.Flag, 'enable_server', _('Provide NTP server'));
262 o.ucisection = 'ntp';
263 o.depends('enabled', '1');
264
265 o = s.taboption('timesync', form.Flag, 'use_dhcp', _('Use DHCP advertised servers'));
266 o.ucisection = 'ntp';
267 o.default = o.enabled;
268 o.depends('enabled', '1');
269
270 o = s.taboption('timesync', form.DynamicList, 'server', _('NTP server candidates'));
271 o.datatype = 'host(0)';
272 o.ucisection = 'ntp';
273 o.depends('enabled', '1');
274 o.load = function(section_id) {
275 return uci.get('system', 'ntp', 'server');
276 };
277 }
278
279 return m.render().then(function(mapEl) {
280 L.Poll.add(function() {
281 return callGetLocaltime().then(function(t) {
282 mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();
283 });
284 });
285
286 return mapEl;
287 });
288 }
289 });