luci-mod-system: flash.js: improve storage size detection heuristics
[oweals/luci.git] / modules / luci-mod-system / htdocs / luci-static / resources / view / system / crontab.js
1 'use strict';
2 'require rpc';
3
4 return L.view.extend({
5         callFileRead: rpc.declare({
6                 object: 'file',
7                 method: 'read',
8                 params: [ 'path' ],
9                 expect: { data: '' }
10         }),
11
12         callFileWrite: rpc.declare({
13                 object: 'file',
14                 method: 'write',
15                 params: [ 'path', 'data' ]
16         }),
17
18         load: function() {
19                 return this.callFileRead('/etc/crontabs/root');
20         },
21
22         handleSave: function(ev) {
23                 var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
24
25                 return this.callFileWrite('/etc/crontabs/root', value).then(function(rc) {
26                         if (rc != 0)
27                                 throw rpc.getStatusText(rc);
28
29                         document.querySelector('textarea').value = value;
30                         L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
31
32                 }).catch(function(e) {
33                         L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e)));
34                 });
35         },
36
37         render: function(crontab) {
38                 return E([
39                         E('h2', _('Scheduled Tasks')),
40                         E('p', {},
41                                 _('This is the system crontab in which scheduled tasks can be defined.') +
42                                 _('<br/>Note: you need to manually restart the cron service if the crontab file was empty before editing.')),
43                         E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 10 }, [ crontab != null ? crontab : '' ]))
44                 ]);
45         },
46
47         handleSaveApply: null,
48         handleReset: null
49 });