extend: 'Ext.window.Window', // fixme: Proxmox.window.Edit?
resizable: false,
+ width: 500,
+ modal: true,
+ layout: 'auto',
+ border: false,
controller: {
xclass: 'Ext.app.ViewController',
start.setDisabled(newVal);
},
},
+ 'form': {
+ validitychange: function(f, valid) {
+ this.lookupReference('doRestoreBtn').setDisabled(!valid);
+ },
+ },
+ },
+
+ doRestore: function() {
+ let me = this;
+ let view = me.getView();
+
+ let values = view.down('form').getForm().getValues();
+
+ let params = {
+ vmid: view.vmid || values.vmid,
+ force: view.vmid ? 1 : 0,
+ };
+ if (values.unique) {
+ params.unique = 1;
+ }
+ if (values.start && !values['live-restore']) {
+ params.start = 1;
+ }
+ if (values['live-restore']) {
+ params['live-restore'] = 1;
+ }
+ if (values.storage) {
+ params.storage = values.storage;
+ }
+ if (values.bwlimit !== undefined) {
+ params.bwlimit = values.bwlimit;
+ }
+
+ let confirmMsg;
+ if (view.vmtype === 'lxc') {
+ params.ostemplate = view.volid;
+ params.restore = 1;
+ if (values.unprivileged !== 'keep') {
+ params.unprivileged = values.unprivileged;
+ }
+ confirmMsg = Proxmox.Utils.format_task_description('vzrestore', params.vmid);
+ } else if (view.vmtype === 'qemu') {
+ params.archive = view.volid;
+ confirmMsg = Proxmox.Utils.format_task_description('qmrestore', params.vmid);
+ } else {
+ throw 'unknown VM type';
+ }
+
+ let executeRestore = () => {
+ Proxmox.Utils.API2Request({
+ url: `/nodes/${view.nodename}/${view.vmtype}`,
+ params: params,
+ method: 'POST',
+ waitMsgTarget: view,
+ failure: response => Ext.Msg.alert(gettext('Error'), response.htmlStatus),
+ success: function(response, options) {
+ Ext.create('Proxmox.window.TaskViewer', {
+ autoShow: true,
+ upid: response.result.data,
+ });
+ view.close();
+ },
+ });
+ };
+
+ if (view.vmid) {
+ confirmMsg += '. ' + gettext('This will permanently erase current VM data.');
+ Ext.Msg.confirm(gettext('Confirm'), confirmMsg, function(btn) {
+ if (btn === 'yes') {
+ executeRestore();
+ }
+ });
+ } else {
+ executeRestore();
+ }
},
},
initComponent: function() {
- var me = this;
+ let me = this;
if (!me.nodename) {
throw "no node name specified";
}
-
if (!me.volid) {
throw "no volume ID specified";
}
-
if (!me.vmtype) {
throw "no vmtype specified";
}
- var storagesel = Ext.create('PVE.form.StorageSelector', {
+ let storagesel = Ext.create('PVE.form.StorageSelector', {
nodename: me.nodename,
name: 'storage',
value: '',
autoSelect: me.vmtype === 'lxc',
});
- var IDfield;
+ let IDfield;
if (me.vmid) {
IDfield = Ext.create('Ext.form.field.Display', {
name: 'vmid',
});
}
- var items = [
+ let items = [
{
xtype: 'displayfield',
value: me.volidText || me.volid,
hidden: !me.isPBS,
// align checkbox with 'start' if 'unique' is hidden
labelWidth: me.vmid ? 105 : 100,
- });
- items.push({
+ },
+ {
xtype: 'displayfield',
reference: 'liveWarning',
// TODO: Remove once more tested/stable?
});
}
- me.formPanel = Ext.create('Ext.form.Panel', {
- bodyPadding: 10,
- border: false,
- fieldDefaults: {
- labelWidth: 100,
- anchor: '100%',
- },
- items: items,
- });
-
- var form = me.formPanel.getForm();
-
- var doRestore = function(url, params) {
- Proxmox.Utils.API2Request({
- url: url,
- params: params,
- method: 'POST',
- waitMsgTarget: me,
- failure: function(response, opts) {
- Ext.Msg.alert(gettext('Error'), response.htmlStatus);
- },
- success: function(response, options) {
- var upid = response.result.data;
-
- var win = Ext.create('Proxmox.window.TaskViewer', {
- upid: upid,
- });
- win.show();
- me.close();
- },
- });
- };
-
- var submitBtn = Ext.create('Ext.Button', {
- text: gettext('Restore'),
- handler: function() {
- var values = form.getValues();
-
- var params = {
- vmid: me.vmid || values.vmid,
- force: me.vmid ? 1 : 0,
- };
- if (values.unique) { params.unique = 1; }
- if (values.start && !values['live-restore']) { params.start = 1; }
- if (values['live-restore']) { params['live-restore'] = 1; }
- if (values.storage) { params.storage = values.storage; }
-
- if (values.bwlimit !== undefined) {
- params.bwlimit = values.bwlimit;
- }
-
- var url;
- var msg;
- if (me.vmtype === 'lxc') {
- url = '/nodes/' + me.nodename + '/lxc';
- params.ostemplate = me.volid;
- params.restore = 1;
- if (values.unprivileged !== 'keep') {
- params.unprivileged = values.unprivileged;
- }
- msg = Proxmox.Utils.format_task_description('vzrestore', params.vmid);
- } else if (me.vmtype === 'qemu') {
- url = '/nodes/' + me.nodename + '/qemu';
- params.archive = me.volid;
- msg = Proxmox.Utils.format_task_description('qmrestore', params.vmid);
- } else {
- throw 'unknown VM type';
- }
-
- if (me.vmid) {
- msg += '. ' + gettext('This will permanently erase current VM data.');
- Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
- if (btn !== 'yes') {
- return;
- }
- doRestore(url, params);
- });
- } else {
- doRestore(url, params);
- }
- },
- });
-
- form.on('validitychange', function(f, valid) {
- submitBtn.setDisabled(!valid);
- });
-
- var title = gettext('Restore') + ": " + (
- me.vmtype === 'lxc' ? 'CT' : 'VM');
-
+ let title = gettext('Restore') + ": " + (me.vmtype === 'lxc' ? 'CT' : 'VM');
if (me.vmid) {
title += " " + me.vmid;
}
Ext.apply(me, {
title: title,
- width: 500,
- modal: true,
- layout: 'auto',
- border: false,
- items: [me.formPanel],
- buttons: [submitBtn],
+ items: [
+ {
+ xtype: 'form',
+ bodyPadding: 10,
+ border: false,
+ fieldDefaults: {
+ labelWidth: 100,
+ anchor: '100%',
+ },
+ items: items,
+ },
+ ],
+ buttons: [
+ {
+ text: gettext('Restore'),
+ reference: 'doRestoreBtn',
+ handler: 'doRestore',
+ },
+ ],
});
me.callParent();