]> git.proxmox.com Git - pve-manager.git/blob - www/manager/qemu/Snapshot.js
disable animation of charts on load
[pve-manager.git] / www / manager / qemu / Snapshot.js
1 Ext.define('PVE.window.Snapshot', {
2 extend: 'Ext.window.Window',
3
4 resizable: false,
5
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 }
12
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) {
19 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
20 },
21 success: function(response, options) {
22 var upid = response.result.data;
23 var win = Ext.create('PVE.window.TaskProgress', { upid: upid });
24 win.show();
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) {
39 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
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
58 var summarystore = Ext.create('Ext.data.Store', {
59 model: 'KeyValue',
60 sorters: [
61 {
62 property : 'key',
63 direction: 'ASC'
64 }
65 ]
66 });
67
68 var items = [
69 {
70 xtype: me.snapname ? 'displayfield' : 'textfield',
71 name: 'snapname',
72 value: me.snapname,
73 fieldLabel: gettext('Name'),
74 vtype: 'ConfigId',
75 allowBlank: false
76 }
77 ];
78
79 if (me.snapname) {
80 items.push({
81 xtype: 'displayfield',
82 name: 'snaptime',
83 fieldLabel: gettext('Timestamp')
84 });
85 } else {
86 items.push({
87 xtype: 'pvecheckbox',
88 name: 'vmstate',
89 uncheckedValue: 0,
90 defaultValue: 0,
91 checked: 1,
92 fieldLabel: gettext('Include RAM')
93 });
94 }
95
96 items.push({
97 xtype: 'textareafield',
98 grow: true,
99 name: 'description',
100 fieldLabel: gettext('Description')
101 });
102
103 if (me.snapname) {
104 items.push({
105 title: gettext('Settings'),
106 xtype: 'grid',
107 height: 200,
108 store: summarystore,
109 columns: [
110 {header: gettext('Key'), width: 150, dataIndex: 'key'},
111 {header: gettext('Value'), flex: 1, dataIndex: 'value'}
112 ]
113 });
114 }
115
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) {
131 me.title = gettext('Edit') + ': ' + gettext('Snapshot');
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 {
142 me.title ="VM " + me.vmid + ': ' + gettext('Take Snapshot');
143 submitBtn = Ext.create('Ext.Button', {
144 text: gettext('Take Snapshot'),
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
154 Ext.apply(me, {
155 modal: true,
156 width: 450,
157 border: false,
158 layout: 'fit',
159 buttons: [ submitBtn ],
160 items: [ me.formPanel ]
161 });
162
163 if (me.snapname) {
164 Ext.apply(me, {
165 width: 620,
166 height: 400
167 });
168 }
169
170 me.callParent();
171
172 if (!me.snapname) {
173 return;
174 }
175
176 // else load data
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) {
183 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
184 me.close();
185 },
186 success: function(response, options) {
187 var data = response.result.data;
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 });
195
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);
204 }
205 });
206 }
207 });