]> git.proxmox.com Git - pve-manager.git/blame - www/manager/qemu/Snapshot.js
disable animation of charts on load
[pve-manager.git] / www / manager / qemu / Snapshot.js
CommitLineData
5465dda8
DM
1Ext.define('PVE.window.Snapshot', {
2 extend: 'Ext.window.Window',
3
12427b64
DM
4 resizable: false,
5
5465dda8
DM
6 take_snapshot: function(snapname, descr, vmstate) {
7 var me = this;
8 var params = { snapname: snapname, vmstate: vmstate ? 1 : 0 };
9 if (descr) {
10 params.description = descr;
11 }
af03191c 12
5465dda8
DM
13 PVE.Utils.API2Request({
14 params: params,
15 url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot",
16 waitMsgTarget: me,
17 method: 'POST',
18 failure: function(response, opts) {
0070ee37 19 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
5465dda8
DM
20 },
21 success: function(response, options) {
22 var upid = response.result.data;
af03191c
DM
23 var win = Ext.create('PVE.window.TaskProgress', { upid: upid });
24 win.show();
5465dda8
DM
25 me.close();
26 }
27 });
28 },
29
30 update_snapshot: function(snapname, descr) {
31 var me = this;
32 PVE.Utils.API2Request({
33 params: { description: descr },
34 url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot/" +
35 snapname + '/config',
36 waitMsgTarget: me,
37 method: 'PUT',
38 failure: function(response, opts) {
0070ee37 39 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
5465dda8
DM
40 },
41 success: function(response, options) {
42 me.close();
43 }
44 });
45 },
46
47 initComponent : function() {
48 var me = this;
49
50 if (!me.nodename) {
51 throw "no node name specified";
52 }
53
54 if (!me.vmid) {
55 throw "no VM ID specified";
56 }
57
576a5d51
DM
58 var summarystore = Ext.create('Ext.data.Store', {
59 model: 'KeyValue',
60 sorters: [
61 {
62 property : 'key',
63 direction: 'ASC'
64 }
65 ]
66 });
67
5465dda8
DM
68 var items = [
69 {
70 xtype: me.snapname ? 'displayfield' : 'textfield',
71 name: 'snapname',
72 value: me.snapname,
63f9d511 73 fieldLabel: gettext('Name'),
24bf5bd4 74 vtype: 'ConfigId',
5465dda8
DM
75 allowBlank: false
76 }
77 ];
78
79 if (me.snapname) {
80 items.push({
81 xtype: 'displayfield',
82 name: 'snaptime',
63f9d511 83 fieldLabel: gettext('Timestamp')
5465dda8
DM
84 });
85 } else {
86 items.push({
87 xtype: 'pvecheckbox',
88 name: 'vmstate',
89 uncheckedValue: 0,
90 defaultValue: 0,
91 checked: 1,
63f9d511 92 fieldLabel: gettext('Include RAM')
5465dda8
DM
93 });
94 }
95
96 items.push({
97 xtype: 'textareafield',
98 grow: true,
99 name: 'description',
63f9d511 100 fieldLabel: gettext('Description')
5465dda8
DM
101 });
102
689aca16
DM
103 if (me.snapname) {
104 items.push({
105 title: gettext('Settings'),
106 xtype: 'grid',
107 height: 200,
108 store: summarystore,
109 columns: [
59c179fd
DM
110 {header: gettext('Key'), width: 150, dataIndex: 'key'},
111 {header: gettext('Value'), flex: 1, dataIndex: 'value'}
689aca16
DM
112 ]
113 });
114 }
115
5465dda8
DM
116 me.formPanel = Ext.create('Ext.form.Panel', {
117 bodyPadding: 10,
118 border: false,
119 fieldDefaults: {
120 labelWidth: 100,
121 anchor: '100%'
122 },
123 items: items
124 });
125
126 var form = me.formPanel.getForm();
127
128 var submitBtn;
129
130 if (me.snapname) {
63f9d511 131 me.title = gettext('Edit') + ': ' + gettext('Snapshot');
5465dda8
DM
132 submitBtn = Ext.create('Ext.Button', {
133 text: gettext('Update'),
134 handler: function() {
135 if (form.isValid()) {
136 var values = form.getValues();
137 me.update_snapshot(me.snapname, values.description);
138 }
139 }
140 });
141 } else {
14b948f5 142 me.title ="VM " + me.vmid + ': ' + gettext('Take Snapshot');
5465dda8 143 submitBtn = Ext.create('Ext.Button', {
14b948f5 144 text: gettext('Take Snapshot'),
5465dda8
DM
145 handler: function() {
146 if (form.isValid()) {
147 var values = form.getValues();
148 me.take_snapshot(values.snapname, values.description, values.vmstate);
149 }
150 }
151 });
152 }
153
689aca16
DM
154 Ext.apply(me, {
155 modal: true,
156 width: 450,
157 border: false,
158 layout: 'fit',
159 buttons: [ submitBtn ],
995ac416 160 items: [ me.formPanel ]
689aca16
DM
161 });
162
576a5d51
DM
163 if (me.snapname) {
164 Ext.apply(me, {
576a5d51 165 width: 620,
689aca16 166 height: 400
576a5d51
DM
167 });
168 }
169
5465dda8 170 me.callParent();
bfb37bcd
DM
171
172 if (!me.snapname) {
173 return;
174 }
175
176 // else load data
bfb37bcd
DM
177 PVE.Utils.API2Request({
178 url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot/" +
179 me.snapname + '/config',
180 waitMsgTarget: me,
181 method: 'GET',
182 failure: function(response, opts) {
0070ee37 183 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
bfb37bcd
DM
184 me.close();
185 },
186 success: function(response, options) {
187 var data = response.result.data;
576a5d51
DM
188 var kvarray = [];
189 Ext.Object.each(data, function(key, value) {
190 if (key === 'description' || key === 'snaptime') {
191 return;
192 }
193 kvarray.push({ key: key, value: value });
194 });
689aca16 195
576a5d51
DM
196 summarystore.suspendEvents();
197 summarystore.add(kvarray);
198 summarystore.sort();
199 summarystore.resumeEvents();
200 summarystore.fireEvent('datachanged', summarystore);
201
202 form.findField('snaptime').setValue(new Date(data.snaptime));
203 form.findField('description').setValue(data.description);
bfb37bcd
DM
204 }
205 });
5465dda8
DM
206 }
207});