luci-mod-system: add heading to startup page, improve error reporting

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-09-12 18:55:50 +02:00
parent 0e5be0d68a
commit 53516cc302

View file

@ -37,15 +37,12 @@ return L.view.extend({
handleAction: function(name, action, ev) { handleAction: function(name, action, ev) {
return this.callInitAction(name, action).then(function(success) { return this.callInitAction(name, action).then(function(success) {
if (success != true) { if (success != true)
L.ui.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action').format(name, action))); throw _('Command failed');
return Promise.reject(false);
}
return true; return true;
}).catch(function() { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Connection failure while executing "/etc/init.d/%s %s" action').format(name, action))); L.ui.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name, action, e)));
return Promise.reject(false);
}); });
}, },
@ -59,12 +56,16 @@ return L.view.extend({
}, },
handleSave: function(ev) { handleSave: function(ev) {
var value = document.querySelector('textarea').value || ''; var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
return this.callFileWrite('/etc/rc.local', value.replace(/\r\n/g, '\n')).then(function() { return this.callFileWrite('/etc/rc.local', value).then(function(rc) {
if (rc != 0)
throw rpc.getStatusText(rc);
document.querySelector('textarea').value = value;
L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info'); L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
}, function() { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Unable to save contents.'))); L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e)));
}); });
}, },
@ -115,24 +116,27 @@ return L.view.extend({
cbi_update_table(table, rows); cbi_update_table(table, rows);
var view = E('div', {}, E('div', {}, [ var view = E('div', {}, [
E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [ E('h2', _('Startup')),
E('p', {}, _('You can enable or disable installed init scripts here. Changes will applied after a device reboot.<br /><strong>Warning: If you disable essential init scripts like "network", your device might become inaccessible!</strong>')), E('div', {}, [
table E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [
]), E('p', {}, _('You can enable or disable installed init scripts here. Changes will applied after a device reboot.<br /><strong>Warning: If you disable essential init scripts like "network", your device might become inaccessible!</strong>')),
E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [ table
E('p', {}, _('This is the content of /etc/rc.local. Insert your own commands here (in front of \'exit 0\') to execute them at the end of the boot process.')), ]),
E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20 }, rcLocal != null ? rcLocal : '')), E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [
E('div', { 'class': 'right' }, [ E('p', {}, _('This is the content of /etc/rc.local. Insert your own commands here (in front of \'exit 0\') to execute them at the end of the boot process.')),
E('button', { E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20 }, rcLocal != null ? rcLocal : '')),
'class': 'btn cbi-button-positive important', E('div', { 'class': 'right' }, [
'click': L.ui.createHandlerFn(this, 'handleSave') E('button', {
}, _('Save')) 'class': 'btn cbi-button-positive important',
'click': L.ui.createHandlerFn(this, 'handleSave')
}, _('Save'))
])
]) ])
]) ])
])); ]);
L.ui.tabs.initTabGroup(view.firstElementChild.childNodes); L.ui.tabs.initTabGroup(view.lastElementChild.childNodes);
return view; return view;
} }