luci-mod-system: crontab.js: use common fs.js class
authorJo-Philipp Wich <jo@mein.io>
Wed, 2 Oct 2019 17:45:36 +0000 (19:45 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 7 Oct 2019 09:53:39 +0000 (11:53 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/crontab.js

index 512f601eb69338fe9e0d5e140dc4b08c3152afdb..bb0dd41f99446c371f4e4363f3f6cc7b94c6302a 100644 (file)
@@ -1,36 +1,19 @@
 'use strict';
-'require rpc';
+'require fs';
 
 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() {
-               return this.callFileRead('/etc/crontabs/root');
+               return L.resolveDefault(fs.read('/etc/crontabs/root'), '');
        },
 
        handleSave: function(ev) {
                var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
 
-               return this.callFileWrite('/etc/crontabs/root', value).then(function(rc) {
-                       if (rc != 0)
-                               throw rpc.getStatusText(rc);
-
+               return fs.write('/etc/crontabs/root', value).then(function(rc) {
                        document.querySelector('textarea').value = value;
                        L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
-
                }).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)));
                });
        },