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