luci2: early wireless configuration
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / system.upgrade.js
index be8885b..4c0799c 100644 (file)
@@ -1,22 +1,78 @@
 L.ui.view.extend({
        title: L.tr('Flash operations'),
 
-       handle_flash_upload: function() {
+       testUpgrade: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'upgrade_test',
+               expect: { '': { } }
+       }),
+
+       startUpgrade: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'upgrade_start',
+               params: [ 'keep' ]
+       }),
+
+       cleanUpgrade: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'upgrade_clean'
+       }),
+
+       restoreBackup: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'backup_restore'
+       }),
+
+       cleanBackup: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'backup_clean'
+       }),
+
+       getBackupConfig: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'backup_config_get',
+               expect: { config: '' }
+       }),
+
+       setBackupConfig: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'backup_config_set',
+               params: [ 'data' ]
+       }),
+
+       listBackup: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'backup_list',
+               expect: { files: [ ] }
+       }),
+
+       testReset: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'reset_test',
+               expect: { supported: false }
+       }),
+
+       startReset: L.rpc.declare({
+               object: 'luci2.system',
+               method: 'reset_start'
+       }),
+
+       handleFlashUpload: function() {
                var self = this;
                L.ui.upload(
                        L.tr('Firmware upload'),
                        L.tr('Select the sysupgrade image to flash and click "%s" to proceed.').format(L.tr('Ok')), {
                                filename: '/tmp/firmware.bin',
                                success: function(info) {
-                                       self.handle_flash_verify(info);
+                                       self.handleFlashVerify(info);
                                }
                        }
                );
        },
 
-       handle_flash_verify: function(info) {
+       handleFlashVerify: function(info) {
                var self = this;
-               L.system.testUpgrade().then(function(res) {
+               self.testUpgrade().then(function(res) {
                        if (res.code == 0)
                        {
                                L.ui.dialog(
@@ -38,7 +94,7 @@ L.ui.view.extend({
                                        ], {
                                                style: 'confirm',
                                                confirm: function() {
-                                                       //L.system.startUpgrade().then(function() {
+                                                       //self.startUpgrade().then(function() {
                                                        //      L.ui.reconnect();
                                                        //});
 
@@ -59,7 +115,7 @@ L.ui.view.extend({
                                        ], {
                                                style: 'close',
                                                close: function() {
-                                                       L.system.cleanUpgrade().then(function() {
+                                                       self.cleanUpgrade().then(function() {
                                                                L.ui.dialog(false);
                                                        });
                                                }
@@ -69,20 +125,20 @@ L.ui.view.extend({
                });
        },
 
-       handle_backup_upload: function() {
+       handleBackupUpload: function() {
                var self = this;
                L.ui.upload(
                        L.tr('Backup restore'),
                        L.tr('Select the backup archive to restore and click "%s" to proceed.').format(L.tr('Ok')), {
                                filename: '/tmp/backup.tar.gz',
                                success: function(info) {
-                                       self.handle_backup_verify(info);
+                                       self.handleBackupVerify(info);
                                }
                        }
                );
        },
 
-       handle_backup_verify: function(info) {
+       handleBackupVerify: function(info) {
                var self = this;
                L.ui.dialog(
                        L.tr('Backup restore'), [
@@ -97,15 +153,15 @@ L.ui.view.extend({
                        ], {
                                style: 'confirm',
                                confirm: function() {
-                                       self.handle_backup_restore();
+                                       self.handleBackupRestore();
                                }
                        }
                );
        },
 
-       handle_backup_restore: function() {
+       handleBackupRestore: function() {
                var self = this;
-               L.system.restoreBackup().then(function(res) {
+               self.restoreBackup().then(function(res) {
                        if (res.code == 0)
                        {
                                L.ui.dialog(
@@ -119,7 +175,7 @@ L.ui.view.extend({
                                        ], {
                                                style: 'close',
                                                close: function() {
-                                                       L.system.cleanBackup().then(function() {
+                                                       self.cleanBackup().then(function() {
                                                                L.ui.dialog(false);
                                                        });
                                                }
@@ -138,7 +194,7 @@ L.ui.view.extend({
                                        ], {
                                                style: 'close',
                                                close: function() {
-                                                       L.system.cleanBackup().then(function() {
+                                                       self.cleanBackup().then(function() {
                                                                L.ui.dialog(false);
                                                        });
                                                }
@@ -148,18 +204,19 @@ L.ui.view.extend({
                });
        },
 
-       handle_backup_download: function() {
+       handleBackupDownload: function() {
                var form = $('#btn_backup').parent();
 
                form.find('[name=sessionid]').val(L.globals.sid);
                form.submit();
        },
 
-       handle_reset: function() {
+       handleReset: function() {
+               var self = this;
                L.ui.dialog(L.tr('Really reset all changes?'), L.tr('This will reset the system to its initial configuration, all changes made since the initial flash will be lost!'), {
                        style: 'confirm',
                        confirm: function() {
-                               //L.system.startReset().then(function() {
+                               //self.startReset().then(function() {
                                //      L.ui.reconnect();
                                //});
 
@@ -171,7 +228,7 @@ L.ui.view.extend({
        execute: function() {
                var self = this;
 
-               L.system.testReset().then(function(reset_avail) {
+               self.testReset().then(function(reset_avail) {
                        if (!reset_avail) {
                                $('#btn_reset').prop('disabled', true);
                        }
@@ -180,19 +237,19 @@ L.ui.view.extend({
                                $('#btn_restore, #btn_save, textarea').prop('disabled', true);
                        }
                        else {
-                               $('#btn_backup').click(function() { self.handle_backup_download(); });
-                               $('#btn_restore').click(function() { self.handle_backup_upload(); });
+                               $('#btn_backup').click(function() { self.handleBackupDownload(); });
+                               $('#btn_restore').click(function() { self.handleBackupUpload(); });
                        }
 
                        if (!self.options.acls.upgrade) {
                                $('#btn_flash, #btn_reset').prop('disabled', true);
                        }
                        else {
-                               $('#btn_flash').click(function() { self.handle_flash_upload(); });
-                               $('#btn_reset').click(function() { self.handle_reset(); });
+                               $('#btn_flash').click(function() { self.handleFlashUpload(); });
+                               $('#btn_reset').click(function() { self.handleReset(); });
                        }
 
-                       return L.system.getBackupConfig();
+                       return self.getBackupConfig();
                }).then(function(config) {
                        $('textarea')
                                .attr('rows', (config.match(/\n/g) || [ ]).length + 1)
@@ -202,7 +259,7 @@ L.ui.view.extend({
                                .click(function() {
                                        var data = ($('textarea').val() || '').replace(/\r/g, '').replace(/\n?$/, '\n');
                                        L.ui.loading(true);
-                                       L.system.setBackupConfig(data).then(function() {
+                                       self.setBackupConfig(data).then(function() {
                                                $('textarea')
                                                        .attr('rows', (data.match(/\n/g) || [ ]).length + 1)
                                                        .val(data);
@@ -214,7 +271,7 @@ L.ui.view.extend({
                        $('#btn_list')
                                .click(function() {
                                        L.ui.loading(true);
-                                       L.system.listBackup().then(function(list) {
+                                       self.listBackup().then(function(list) {
                                                L.ui.loading(false);
                                                L.ui.dialog(
                                                        L.tr('Backup file list'),
@@ -228,8 +285,6 @@ L.ui.view.extend({
                                                );
                                        });
                                });
-               }).then(function() {
-                       $('#tabs').show().tabs();
                });
        }
 });