Commit 8747655a authored by Dietmar Maurer's avatar Dietmar Maurer

implement restore GUI

parent 161b8020
......@@ -52,6 +52,7 @@ JSSRC= \
window/Wizard.js \
window/NotesEdit.js \
window/Backup.js \
window/Restore.js \
panel/NotesView.js \
grid/SelectFeature.js \
grid/ObjectGrid.js \
......
......@@ -223,7 +223,32 @@ Ext.define('PVE.storage.ContentView', {
features: [ groupingFeature ],
tbar: [
{
text: 'Restore'
xtype: 'pveButton',
text: 'Restore',
selModel: sm,
disabled: true,
enableFn: function(rec) {
return rec && rec.data.content === 'backup';
},
handler: function(b, e, rec) {
var vmtype;
if (rec.data.volid.match(/vzdump-qemu-/)) {
vmtype = 'qemu';
} else if (rec.data.volid.match(/vzdump-openvz-/)) {
vmtype = 'openvz';
} else {
return;
}
var win = Ext.create('PVE.window.Restore', {
nodename: nodename,
volid: rec.data.volid,
volidText: PVE.Utils.render_storage_content(rec.data.volid, {}, rec),
vmtype: vmtype
});
win.show();
win.on('destroy', reload);
}
},
{
xtype: 'pveButton',
......
Ext.define('PVE.window.Restore', {
extend: 'Ext.window.Window', // fixme: PVE.window.Edit?
resizable: false,
initComponent : function() {
var 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', {
nodename: me.nodename,
name: 'storage',
value: '',
fieldLabel: 'Storage',
storageContent: (me.vmtype === 'openvz') ? 'rootdir' : 'images',
allowBlank: true
});
me.formPanel = Ext.create('Ext.form.Panel', {
bodyPadding: 10,
border: false,
fieldDefaults: {
labelWidth: 60,
anchor: '100%'
},
items: [
{
xtype: 'displayfield',
value: me.volidText || me.volid,
fieldLabel: 'Source'
},
storagesel,
{
xtype: 'pveVMIDSelector',
name: 'vmid',
value: PVE.data.ResourceStore.findNextVMID(),
validateExists: false
}
]
});
var form = me.formPanel.getForm();
form.on('validitychange', function(f, valid) {
submitBtn.setDisabled(!valid);
});
var submitBtn = Ext.create('Ext.Button', {
text: 'Restore',
handler: function(){
var storage = storagesel.getValue();
var values = form.getValues();
var params = {
storage: storage,
vmid: values.vmid
};
if (me.vmtype === 'openvz') {
url = '/nodes/' + me.nodename + '/openvz';
params.ostemplate = me.volid;
} else if (me.vmtype === 'qemu') {
url = '/nodes/' + me.nodename + '/qemu';
params.archive = me.volid;
} else {
throw 'unknown VM type';
}
PVE.Utils.API2Request({
url: url,
params: params,
method: 'POST',
failure: function (response, opts) {
Ext.Msg.alert('Error',response.htmlStatus);
},
success: function(response, options) {
var upid = response.result.data;
var win = Ext.create('PVE.window.TaskViewer', {
upid: upid
});
win.show();
me.close();
}
});
}
});
var title = (me.vmtype === 'openvz') ? "Restore CT" : "Restore VM";
Ext.apply(me, {
title: title,
width: 450,
modal: true,
layout: 'auto',
border: false,
items: [ me.formPanel ],
buttons: [ submitBtn ],
});
me.callParent();
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment