luci-mod-system: system.js: simplify btn actions, use feature flags
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
7dd6fde57e
commit
982b08f45d
1 changed files with 26 additions and 34 deletions
|
@ -47,33 +47,27 @@ callTimezone = rpc.declare({
|
||||||
CBILocalTime = form.DummyValue.extend({
|
CBILocalTime = form.DummyValue.extend({
|
||||||
renderWidget: function(section_id, option_id, cfgvalue) {
|
renderWidget: function(section_id, option_id, cfgvalue) {
|
||||||
return E([], [
|
return E([], [
|
||||||
E('span', { 'id': 'localtime' },
|
E('span', {}, [
|
||||||
new Date(cfgvalue * 1000).toLocaleString()),
|
E('input', {
|
||||||
|
'id': 'localtime',
|
||||||
|
'type': 'text',
|
||||||
|
'readonly': true,
|
||||||
|
'value': new Date(cfgvalue * 1000).toLocaleString()
|
||||||
|
})
|
||||||
|
]),
|
||||||
' ',
|
' ',
|
||||||
E('button', {
|
E('button', {
|
||||||
'class': 'cbi-button cbi-button-apply',
|
'class': 'cbi-button cbi-button-apply',
|
||||||
'click': function() {
|
'click': L.ui.createHandlerFn(this, function() {
|
||||||
this.blur();
|
return callSetLocaltime(Math.floor(Date.now() / 1000));
|
||||||
this.classList.add('spinning');
|
})
|
||||||
this.disabled = true;
|
|
||||||
callSetLocaltime(Math.floor(Date.now() / 1000)).then(L.bind(function() {
|
|
||||||
this.classList.remove('spinning');
|
|
||||||
this.disabled = false;
|
|
||||||
}, this));
|
|
||||||
}
|
|
||||||
}, _('Sync with browser')),
|
}, _('Sync with browser')),
|
||||||
' ',
|
' ',
|
||||||
this.ntpd_support ? E('button', {
|
this.ntpd_support ? E('button', {
|
||||||
'class': 'cbi-button cbi-button-apply',
|
'class': 'cbi-button cbi-button-apply',
|
||||||
'click': function() {
|
'click': L.ui.createHandlerFn(this, function() {
|
||||||
this.blur();
|
return callInitAction('sysntpd', 'restart');
|
||||||
this.classList.add('spinning');
|
})
|
||||||
this.disabled = true;
|
|
||||||
callInitAction('sysntpd', 'restart').then(L.bind(function() {
|
|
||||||
this.classList.remove('spinning');
|
|
||||||
this.disabled = false;
|
|
||||||
}, this));
|
|
||||||
}
|
|
||||||
}, _('Sync with NTP-Server')) : ''
|
}, _('Sync with NTP-Server')) : ''
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
@ -83,7 +77,6 @@ return L.view.extend({
|
||||||
load: function() {
|
load: function() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
callInitList('sysntpd'),
|
callInitList('sysntpd'),
|
||||||
callInitList('zram'),
|
|
||||||
callTimezone(),
|
callTimezone(),
|
||||||
callGetLocaltime(),
|
callGetLocaltime(),
|
||||||
uci.load('luci'),
|
uci.load('luci'),
|
||||||
|
@ -92,11 +85,10 @@ return L.view.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(rpc_replies) {
|
render: function(rpc_replies) {
|
||||||
var ntpd_support = rpc_replies[0],
|
var ntpd_enabled = rpc_replies[0],
|
||||||
zram_support = rpc_replies[1],
|
timezones = rpc_replies[1],
|
||||||
timezones = rpc_replies[2],
|
localtime = rpc_replies[2],
|
||||||
localtime = rpc_replies[3],
|
m, s, o;
|
||||||
ntp_setup, ntp_enabled, m, s, o;
|
|
||||||
|
|
||||||
m = new form.Map('system',
|
m = new form.Map('system',
|
||||||
_('System'),
|
_('System'),
|
||||||
|
@ -119,7 +111,7 @@ return L.view.extend({
|
||||||
|
|
||||||
o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
|
o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
|
||||||
o.cfgvalue = function() { return localtime };
|
o.cfgvalue = function() { return localtime };
|
||||||
o.ntpd_support = ntpd_support;
|
o.ntpd_support = ntpd_enabled;
|
||||||
|
|
||||||
o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
|
o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
|
||||||
o.datatype = 'hostname';
|
o.datatype = 'hostname';
|
||||||
|
@ -184,7 +176,7 @@ return L.view.extend({
|
||||||
* Zram Properties
|
* Zram Properties
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (zram_support != null) {
|
if (L.hasSystemFeature('zram')) {
|
||||||
s.tab('zram', _('ZRam Settings'));
|
s.tab('zram', _('ZRam Settings'));
|
||||||
|
|
||||||
o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
|
o = s.taboption('zram', form.Value, 'zram_size_mb', _('ZRam Size'), _('Size of the ZRam device in megabytes'));
|
||||||
|
@ -234,7 +226,7 @@ return L.view.extend({
|
||||||
* NTP
|
* NTP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (ntpd_support != null) {
|
if (L.hasSystemFeature('sysntpd')) {
|
||||||
var default_servers = [
|
var default_servers = [
|
||||||
'0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
|
'0.openwrt.pool.ntp.org', '1.openwrt.pool.ntp.org',
|
||||||
'2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
|
'2.openwrt.pool.ntp.org', '3.openwrt.pool.ntp.org'
|
||||||
|
@ -245,14 +237,14 @@ return L.view.extend({
|
||||||
o.ucisection = 'ntp';
|
o.ucisection = 'ntp';
|
||||||
o.default = o.disabled;
|
o.default = o.disabled;
|
||||||
o.write = function(section_id, value) {
|
o.write = function(section_id, value) {
|
||||||
ntpd_support = +value;
|
ntpd_enabled = +value;
|
||||||
|
|
||||||
if (ntpd_support && !uci.get('system', 'ntp')) {
|
if (ntpd_enabled && !uci.get('system', 'ntp')) {
|
||||||
uci.add('system', 'timeserver', 'ntp');
|
uci.add('system', 'timeserver', 'ntp');
|
||||||
uci.set('system', 'ntp', 'server', default_servers);
|
uci.set('system', 'ntp', 'server', default_servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ntpd_support)
|
if (!ntpd_enabled)
|
||||||
uci.set('system', 'ntp', 'enabled', 0);
|
uci.set('system', 'ntp', 'enabled', 0);
|
||||||
else
|
else
|
||||||
uci.unset('system', 'ntp', 'enabled');
|
uci.unset('system', 'ntp', 'enabled');
|
||||||
|
@ -260,7 +252,7 @@ return L.view.extend({
|
||||||
return callInitAction('sysntpd', 'enable');
|
return callInitAction('sysntpd', 'enable');
|
||||||
};
|
};
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return (ntpd_support == 1 &&
|
return (ntpd_enabled == 1 &&
|
||||||
uci.get('system', 'ntp') != null &&
|
uci.get('system', 'ntp') != null &&
|
||||||
uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
|
uci.get('system', 'ntp', 'enabled') != 0) ? '1' : '0';
|
||||||
};
|
};
|
||||||
|
@ -284,7 +276,7 @@ return L.view.extend({
|
||||||
return m.render().then(function(mapEl) {
|
return m.render().then(function(mapEl) {
|
||||||
L.Poll.add(function() {
|
L.Poll.add(function() {
|
||||||
return callGetLocaltime().then(function(t) {
|
return callGetLocaltime().then(function(t) {
|
||||||
mapEl.querySelector('#localtime').innerHTML = new Date(t * 1000).toLocaleString();
|
mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue