]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/window/Snapshot.js
gui: refactor snapshot window
[pve-manager.git] / www / manager6 / window / Snapshot.js
CommitLineData
4e0e6b77
DC
1Ext.define('PVE.window.Snapshot', {
2 extend: 'Proxmox.window.Edit',
3
4 onGetValues: function(values) {
5 let me = this;
6
7 if (me.type === 'lxc') {
8 delete values.vmstate;
9 }
10
11 return values;
12 },
13
14 initComponent : function() {
15 var me = this;
16
17 if (!me.nodename) {
18 throw "no node name specified";
19 }
20
21 if (!me.vmid) {
22 throw "no VM ID specified";
23 }
24
25 if (!me.type) {
26 throw "no VM ID specified";
27 }
28
29 me.items = [
30 {
31 xtype: me.snapname ? 'displayfield' : 'textfield',
32 name: 'snapname',
33 value: me.snapname,
34 fieldLabel: gettext('Name'),
35 vtype: 'ConfigId',
36 allowBlank: false
37 },
38 {
39 xtype: 'displayfield',
40 hidden: !me.snapname,
41 disabled: !me.snapname,
42 name: 'snaptime',
43 renderer: PVE.Utils.render_timestamp_human_readable,
44 fieldLabel: gettext('Timestamp')
45 },
46 {
47 xtype: 'proxmoxcheckbox',
48 hidden: me.type !== 'qemu' || me.snapname,
49 disabled: me.type !== 'qemu' || me.snapname,
50 name: 'vmstate',
51 uncheckedValue: 0,
52 defaultValue: 0,
53 checked: 1,
54 fieldLabel: gettext('Include RAM')
55 },
56 {
57 xtype: 'textareafield',
58 grow: true,
59 editable: !me.viewonly,
60 name: 'description',
61 fieldLabel: gettext('Description')
62 },
63 {
64 title: gettext('Settings'),
65 hidden: !me.snapname,
66 xtype: 'grid',
67 itemId: 'summary',
68 border: true,
69 height: 200,
70 store: {
71 model: 'KeyValue',
72 sorters: [
73 {
74 property : 'key',
75 direction: 'ASC'
76 }
77 ]
78 },
79 columns: [
80 {header: gettext('Key'), width: 150, dataIndex: 'key'},
81 {header: gettext('Value'), flex: 1, dataIndex: 'value'}
82 ]
83 }
84 ];
85
86 me.url = `/nodes/${me.nodename}/${me.type}/${me.vmid}/snapshot`;
87
88 let subject;
89 if (me.snapname) {
90 subject = gettext('Snapshot') + ` ${me.snapname}`;
91 me.url += `/${me.snapname}/config`;
92 } else {
93 subject = (me.type === 'qemu' ? 'VM' : 'CT') + me.vmid + ' ' + gettext('Snapshot');
94 me.method = 'POST';
95 me.showProgress = true;
96 }
97
98 Ext.apply(me, {
99 subject: subject,
100 width: me.snapname ? 620 : 450,
101 height: me.snapname ? 420 : undefined,
102 });
103
104 me.callParent();
105
106 if (!me.snapname) {
107 return;
108 }
109
110 me.load({
111 success: function(response) {
112 let kvarray = [];
113 Ext.Object.each(response.result.data, function(key, value) {
114 if (key === 'description' || key === 'snaptime') {
115 return;
116 }
117 kvarray.push({ key: key, value: value });
118 });
119
120 let summarystore = me.down('#summary').getStore();
121 summarystore.suspendEvents();
122 summarystore.add(kvarray);
123 summarystore.sort();
124 summarystore.resumeEvents();
125 summarystore.fireEvent('refresh', summarystore);
126
127 me.setValues(response.result.data);
128 }
129 });
130 }
131});