Commit 8bf7e77c authored by Dietmar Maurer's avatar Dietmar Maurer

mprove snapshot GUI

parent 38524f51
......@@ -100,6 +100,7 @@ JSSRC= \
qemu/StartupEdit.js \
qemu/ScsiHwEdit.js \
qemu/Options.js \
qemu/Snapshot.js \
qemu/SnapshotTree.js \
qemu/Config.js \
qemu/CreateWizard.js \
......
Ext.define('PVE.window.Snapshot', {
extend: 'Ext.window.Window',
resizable: false,
take_snapshot: function(snapname, descr, vmstate) {
var me = this;
var params = { snapname: snapname, vmstate: vmstate ? 1 : 0 };
if (descr) {
params.description = descr;
}
PVE.Utils.API2Request({
params: params,
url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot",
waitMsgTarget: me,
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();
}
});
},
update_snapshot: function(snapname, descr) {
var me = this;
PVE.Utils.API2Request({
params: { description: descr },
url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot/" +
snapname + '/config',
waitMsgTarget: me,
method: 'PUT',
failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus);
},
success: function(response, options) {
me.close();
}
});
},
initComponent : function() {
var me = this;
if (!me.nodename) {
throw "no node name specified";
}
if (!me.vmid) {
throw "no VM ID specified";
}
var items = [
{
xtype: me.snapname ? 'displayfield' : 'textfield',
name: 'snapname',
value: me.snapname,
fieldLabel: 'Snapshot Name',
allowBlank: false
}
];
if (me.snapname) {
items.push({
xtype: 'displayfield',
name: 'snaptime',
value: new Date(me.snaptime),
fieldLabel: 'Timestamp'
});
} else {
items.push({
xtype: 'pvecheckbox',
name: 'vmstate',
uncheckedValue: 0,
defaultValue: 0,
checked: 1,
fieldLabel: 'Include State'
});
}
items.push({
xtype: 'textareafield',
grow: true,
name: 'description',
value: me.description,
fieldLabel: 'Description'
});
me.formPanel = Ext.create('Ext.form.Panel', {
bodyPadding: 10,
border: false,
fieldDefaults: {
labelWidth: 100,
anchor: '100%'
},
items: items
});
var form = me.formPanel.getForm();
var submitBtn;
if (me.snapname) {
me.title = "Edit Snapshot '" + me.snapname + " of VM " + me.vmid;
submitBtn = Ext.create('Ext.Button', {
text: gettext('Update'),
handler: function() {
if (form.isValid()) {
var values = form.getValues();
me.update_snapshot(me.snapname, values.description);
}
}
});
} else {
me.title = "Take Snapshot of VM " + me.vmid;
submitBtn = Ext.create('Ext.Button', {
text: 'Take Snapshot',
handler: function() {
if (form.isValid()) {
var values = form.getValues();
me.take_snapshot(values.snapname, values.description, values.vmstate);
}
}
});
}
Ext.apply(me, {
width: 450,
modal: true,
layout: 'auto',
border: false,
items: [ me.formPanel ],
buttons: [ submitBtn ]
});
me.callParent();
}
});
......@@ -58,14 +58,39 @@ Ext.define('PVE.qemu.SnapshotTree', {
var sm = Ext.create('Ext.selection.RowModel', {});
me.rollbackBtn = new PVE.button.Button({
var valid_snapshot = function(record) {
return record && record.data && record.data.name &&
record.data.name !== '__current';
};
var run_editor = function() {
var rec = sm.getSelection()[0];
if (valid_snapshot(rec)) {
var win = Ext.create('PVE.window.Snapshot', {
snapname: rec.data.name,
snaptime: rec.data.snaptime,
description: rec.data.description,
nodename: me.nodename,
vmid: me.vmid
});
win.show();
me.mon(win, 'close', me.reload, me);
}
};
var editBtn = new PVE.button.Button({
text: gettext('Edit'),
disabled: true,
selModel: sm,
enableFn: valid_snapshot,
handler: run_editor
});
var rollbackBtn = new PVE.button.Button({
text: gettext('Rollback'),
disabled: true,
selModel: sm,
enableFn: function(record) {
return record && record.data && record.data.name &&
record.data.name !== '__current';
},
enableFn: valid_snapshot,
handler: function(btn, event) {
var rec = sm.getSelection()[0];
if (!rec) {
......@@ -87,15 +112,12 @@ Ext.define('PVE.qemu.SnapshotTree', {
}
});
me.deleteBtn = new PVE.button.Button({
text: gettext('Delete'),
var removeBtn = new PVE.button.Button({
text: gettext('Remove'),
disabled: true,
selModel: sm,
confirmMsg: gettext('Are you sure you want to remove this entry'),
enableFn: function(record) {
return record && record.data && record.data.name &&
record.data.name !== '__current';
},
enableFn: valid_snapshot,
handler: function(btn, event) {
var rec = sm.getSelection()[0];
if (!rec) {
......@@ -117,12 +139,23 @@ Ext.define('PVE.qemu.SnapshotTree', {
}
});
var snapshotBtn = Ext.create('Ext.Button', {
text: gettext('Take Snapshot'),
handler: function() {
var win = Ext.create('PVE.window.Snapshot', {
nodename: me.nodename,
vmid: me.vmid
});
win.show();
}
});
Ext.apply(me, {
layout: 'fit',
rootVisible: false,
animate: false,
selModel: sm,
tbar: [ me.rollbackBtn, me.deleteBtn ],
tbar: [ snapshotBtn, rollbackBtn, removeBtn, editBtn ],
fields: [
'name', 'description',
{ name: 'snaptime', type: 'date', dateFormat: 'timestamp' }
......@@ -160,12 +193,15 @@ Ext.define('PVE.qemu.SnapshotTree', {
}
}
}
]
],
columnLines: true, // will work in 4.1?
listeners: {
show: me.reload,
itemdblclick: run_editor
}
});
me.callParent();
me.on('show', me.reload);
}
});
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