luci-mod-system: crontab.js: use common fs.js class
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
df8078d542
commit
641c82cb21
1 changed files with 4 additions and 21 deletions
|
@ -1,36 +1,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
'require rpc';
|
'require fs';
|
||||||
|
|
||||||
return L.view.extend({
|
return L.view.extend({
|
||||||
callFileRead: rpc.declare({
|
|
||||||
object: 'file',
|
|
||||||
method: 'read',
|
|
||||||
params: [ 'path' ],
|
|
||||||
expect: { data: '' }
|
|
||||||
}),
|
|
||||||
|
|
||||||
callFileWrite: rpc.declare({
|
|
||||||
object: 'file',
|
|
||||||
method: 'write',
|
|
||||||
params: [ 'path', 'data' ]
|
|
||||||
}),
|
|
||||||
|
|
||||||
load: function() {
|
load: function() {
|
||||||
return this.callFileRead('/etc/crontabs/root');
|
return L.resolveDefault(fs.read('/etc/crontabs/root'), '');
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSave: function(ev) {
|
handleSave: function(ev) {
|
||||||
var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
|
var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
|
||||||
|
|
||||||
return this.callFileWrite('/etc/crontabs/root', value).then(function(rc) {
|
return fs.write('/etc/crontabs/root', value).then(function(rc) {
|
||||||
if (rc != 0)
|
|
||||||
throw rpc.getStatusText(rc);
|
|
||||||
|
|
||||||
document.querySelector('textarea').value = value;
|
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');
|
||||||
|
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e)));
|
L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue