treewide: import utility classes explicitly
[project/luci.git] / modules / luci-mod-system / htdocs / luci-static / resources / view / system / crontab.js
1 'use strict';
2 'require view';
3 'require fs';
4 'require ui';
5
6 return view.extend({
7 load: function() {
8 return L.resolveDefault(fs.read('/etc/crontabs/root'), '');
9 },
10
11 handleSave: function(ev) {
12 var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
13
14 return fs.write('/etc/crontabs/root', value).then(function(rc) {
15 document.querySelector('textarea').value = value;
16 ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
17 }).catch(function(e) {
18 ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
19 });
20 },
21
22 render: function(crontab) {
23 return E([
24 E('h2', _('Scheduled Tasks')),
25 E('p', { 'class': 'cbi-section-descr' },
26 _('This is the system crontab in which scheduled tasks can be defined.') +
27 _('<br/>Note: you need to manually restart the cron service if the crontab file was empty before editing.')),
28 E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 10 }, [ crontab != null ? crontab : '' ]))
29 ]);
30 },
31
32 handleSaveApply: null,
33 handleReset: null
34 });