From 7f261b55d5c35871d693ce903a19e6caf82f12b0 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 7 Nov 2017 07:42:22 +0100 Subject: [PATCH] js/BackupRestore.js - implement backup/restore panel --- js/BackupRestore.js | 112 ++++++++++++++++++++++++++++++++++++++ js/Makefile | 1 + js/SystemConfiguration.js | 53 ++---------------- 3 files changed, 117 insertions(+), 49 deletions(-) create mode 100644 js/BackupRestore.js diff --git a/js/BackupRestore.js b/js/BackupRestore.js new file mode 100644 index 0000000..955ed50 --- /dev/null +++ b/js/BackupRestore.js @@ -0,0 +1,112 @@ +/*global Proxmox*/ +Ext.define('pmg-backup-list', { + extend: 'Ext.data.Model', + fields: [ + 'filename', + { type: 'integer', name: 'size' } + ], + proxy: { + type: 'proxmox', + url: "/api2/json/nodes/" + Proxmox.NodeName + "/backup" + }, + idProperty: 'filename' +}); + +Ext.define('PMG.BackupRestore', { + extend: 'Ext.grid.GridPanel', + xtype: 'pmgBackupRestore', + + title: gettext('Backup') + '/' + gettext('Restore'), + + controller: { + xclass: 'Ext.app.ViewController', + + createBackup: function() { + var me = this.getView(); + Proxmox.Utils.API2Request({ + url: "/nodes/" + Proxmox.NodeName + "/backup", + method: 'POST', + waitMsgTarget: me, + failure: function (response, opts) { + Ext.Msg.alert(gettext('Error'), response.htmlStatus); + }, + success: function(response, opts) { + var upid = response.result.data; + + var win = Ext.create('Proxmox.window.TaskViewer', { + upid: upid + }); + win.show(); + me.mon(win, 'close', function() { me.store.load(); }); + } + }); + }, + + onAfterRemove: function(btn, res) { + var me = this.getView(); + me.store.load(); + }, + + onFactoryDefaults: function() { + var me = this.getView(); + + Ext.Msg.confirm( + gettext('Confirm'), + gettext('Reset rule database to factory defaults?'), + function(button) { + if (button !== 'yes') { + return; + } + var url = '/config/ruledb'; + Proxmox.Utils.API2Request({ + url: '/config/ruledb', + method: 'POST', + waitMsgTarget: me, + failure: function (response, opts) { + Ext.Msg.alert(gettext('Error'), response.htmlStatus); + } + }); + } + ); + } + }, + + tbar: [ + { + text: gettext('Backup'), + handler: 'createBackup' + }, + { + xtype: 'proxmoxStdRemoveButton', + baseurl: '/nodes/' + Proxmox.NodeName + '/backup', + reference: 'removeBtn', + callback: 'onAfterRemove', + waitMsgTarget: true + }, + { + text: gettext('Factory Defaults'), + handler: 'onFactoryDefaults' + } + ], + + store: { + autoLoad: true, + model: 'pmg-backup-list' + }, + + columns: [ + { + header: gettext('Filename'), + width: 300, + sortable: true, + renderer: Ext.htmlEncode, + dataIndex: 'filename' + }, + { + header: gettext('Size'), + width: 100, + sortable: true, + dataIndex: 'size' + } + ] +}); diff --git a/js/Makefile b/js/Makefile index a97e3c3..dd35f74 100644 --- a/js/Makefile +++ b/js/Makefile @@ -35,6 +35,7 @@ JSSRC= \ RuleConfiguration.js \ SystemOptions.js \ Subscription.js \ + BackupRestore.js \ SystemConfiguration.js \ MailProxyRelaying.js \ MailProxyPorts.js \ diff --git a/js/SystemConfiguration.js b/js/SystemConfiguration.js index 2c816fe..8e51127 100644 --- a/js/SystemConfiguration.js +++ b/js/SystemConfiguration.js @@ -1,44 +1,4 @@ /*global Proxmox*/ -Ext.define('PMG.RestoreSystemConfiguration', { - extend: 'Ext.Panel', - xtype: 'pmgRestoreSystemConfiguration', - - title: gettext('Restore'), - - controller: { - xclass: 'Ext.app.ViewController', - - onFactoryDefaults: function() { - var me = this.getView(); - - Ext.Msg.confirm( - gettext('Confirm'), - gettext('Reset rule database to factory defaults?'), - function(button) { - if (button !== 'yes') { - return; - } - var url = '/config/ruledb'; - Proxmox.Utils.API2Request({ - url: '/config/ruledb', - method: 'POST', - waitMsgTarget: me, - failure: function (response, opts) { - Ext.Msg.alert(gettext('Error'), response.htmlStatus); - } - }); - } - ); - } - }, - - tbar: [ - { - text: gettext('Factory Defaults'), - handler: 'onFactoryDefaults' - } - ] -}); Ext.define('PMG.SystemConfiguration', { extend: 'Ext.tab.Panel', @@ -84,19 +44,14 @@ Ext.define('PMG.SystemConfiguration', { } ] }, - { - itemId: 'backup', - title: gettext('Backup'), - html: "Backup" - }, - { - itemId: 'restore', - xtype: 'pmgRestoreSystemConfiguration' - }, { itemId: 'options', title: gettext('Options'), xtype: 'pmgSystemOptions' + }, + { + itemId: 'backup', + xtype: 'pmgBackupRestore' } ] });