]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/grid/PoolMembers.js
ui: backup: replication: replace non-clickable checkbox with icons
[pve-manager.git] / www / manager6 / grid / PoolMembers.js
CommitLineData
80c8dbf7 1Ext.define('PVE.pool.AddVM', {
9fccc702 2 extend: 'Proxmox.window.Edit',
8dc0c049
DC
3 width: 600,
4 height: 400,
5 isAdd: true,
d5e771ce 6 isCreate: true,
8058410f 7 initComponent: function() {
80c8dbf7
DM
8 var me = this;
9
10 if (!me.pool) {
11 throw "no pool specified";
12 }
13
80c8dbf7
DM
14 me.url = "/pools/" + me.pool;
15 me.method = 'PUT';
3d9bc0a2 16
8dc0c049
DC
17 var vmsField = Ext.create('Ext.form.field.Text', {
18 name: 'vms',
19 hidden: true,
f6710aac 20 allowBlank: false,
8dc0c049
DC
21 });
22
23 var vmStore = Ext.create('Ext.data.Store', {
24 model: 'PVEResources',
d5e771ce
EK
25 sorters: [
26 {
27 property: 'vmid',
392e3cf1 28 direction: 'ASC',
f6710aac 29 },
d5e771ce 30 ],
8dc0c049
DC
31 filters: [
32 function(item) {
53e3ea84 33 return (item.data.type === 'lxc' || item.data.type === 'qemu') && item.data.pool === '';
f6710aac
TL
34 },
35 ],
80c8dbf7
DM
36 });
37
f6710aac 38 var vmGrid = Ext.create('widget.grid', {
8dc0c049
DC
39 store: vmStore,
40 border: true,
41 height: 300,
42 scrollable: true,
43 selModel: {
44 selType: 'checkboxmodel',
45 mode: 'SIMPLE',
46 listeners: {
47 selectionchange: function(model, selected, opts) {
48 var selectedVms = [];
49 selected.forEach(function(vm) {
50 selectedVms.push(vm.data.vmid);
51 });
52 vmsField.setValue(selectedVms);
f6710aac
TL
53 },
54 },
8dc0c049
DC
55 },
56 columns: [
57 {
58 header: 'ID',
59 dataIndex: 'vmid',
f6710aac 60 width: 60,
8dc0c049
DC
61 },
62 {
63 header: gettext('Node'),
f6710aac 64 dataIndex: 'node',
8dc0c049
DC
65 },
66 {
67 header: gettext('Status'),
68 dataIndex: 'uptime',
69 renderer: function(value) {
70 if (value) {
e7ade592 71 return Proxmox.Utils.runningText;
8dc0c049 72 } else {
e7ade592 73 return Proxmox.Utils.stoppedText;
8dc0c049 74 }
f6710aac 75 },
8dc0c049
DC
76 },
77 {
78 header: gettext('Name'),
79 dataIndex: 'name',
f6710aac 80 flex: 1,
8dc0c049
DC
81 },
82 {
83 header: gettext('Type'),
f6710aac
TL
84 dataIndex: 'type',
85 },
86 ],
8dc0c049
DC
87 });
88 Ext.apply(me, {
89 subject: gettext('Virtual Machine'),
8058410f 90 items: [vmsField, vmGrid],
8dc0c049
DC
91 });
92
80c8dbf7 93 me.callParent();
8dc0c049 94 vmStore.load();
f6710aac 95 },
80c8dbf7
DM
96});
97
98Ext.define('PVE.pool.AddStorage', {
9fccc702 99 extend: 'Proxmox.window.Edit',
80c8dbf7 100
8058410f 101 initComponent: function() {
80c8dbf7
DM
102 var me = this;
103
104 if (!me.pool) {
105 throw "no pool specified";
106 }
107
d5e771ce 108 me.isCreate = true;
80c8dbf7
DM
109 me.isAdd = true;
110 me.url = "/pools/" + me.pool;
111 me.method = 'PUT';
3d9bc0a2 112
80c8dbf7
DM
113 Ext.apply(me, {
114 subject: gettext('Storage'),
115 width: 350,
116 items: [
117 {
f118971d 118 xtype: 'pveStorageSelector',
80c8dbf7
DM
119 name: 'storage',
120 nodename: 'localhost',
121 autoSelect: false,
8058410f 122 value: '',
f6710aac
TL
123 fieldLabel: gettext("Storage"),
124 },
125 ],
80c8dbf7
DM
126 });
127
128 me.callParent();
f6710aac 129 },
80c8dbf7
DM
130});
131
132Ext.define('PVE.grid.PoolMembers', {
133 extend: 'Ext.grid.GridPanel',
134 alias: ['widget.pvePoolMembers'],
135
136 // fixme: dynamic status update ?
137
07a3397f
DC
138 stateful: true,
139 stateId: 'grid-pool-members',
140
8058410f 141 initComponent: function() {
80c8dbf7
DM
142 var me = this;
143
144 if (!me.pool) {
145 throw "no pool specified";
146 }
147
148 var store = Ext.create('Ext.data.Store', {
149 model: 'PVEResources',
150 sorters: [
151 {
8058410f 152 property: 'type',
f6710aac
TL
153 direction: 'ASC',
154 },
80c8dbf7 155 ],
3d9bc0a2 156 proxy: {
56a353b9 157 type: 'proxmox',
80c8dbf7 158 root: 'data.members',
f6710aac
TL
159 url: "/api2/json/pools/" + me.pool,
160 },
80c8dbf7
DM
161 });
162
4d9e2176
DC
163 var coldef = PVE.data.ResourceStore.defaultColumns().filter((c) =>
164 c.dataIndex !== 'tags' && c.dataIndex !== 'lock',
165 );
80c8dbf7
DM
166
167 var reload = function() {
168 store.load();
169 };
170
171 var sm = Ext.create('Ext.selection.RowModel', {});
172
5720fafa 173 var remove_btn = new Proxmox.button.Button({
80c8dbf7
DM
174 text: gettext('Remove'),
175 disabled: true,
176 selModel: sm,
8058410f 177 confirmMsg: function(rec) {
80c8dbf7
DM
178 return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
179 "'" + rec.data.id + "'");
180 },
181 handler: function(btn, event, rec) {
182 var params = { 'delete': 1 };
183 if (rec.data.type === 'storage') {
184 params.storage = rec.data.storage;
a00a9ffd 185 } else if (rec.data.type === 'qemu' || rec.data.type === 'lxc' || rec.data.type === 'openvz') {
80c8dbf7
DM
186 params.vms = rec.data.vmid;
187 } else {
188 throw "unknown resource type";
189 }
190
e7ade592 191 Proxmox.Utils.API2Request({
80c8dbf7
DM
192 url: '/pools/' + me.pool,
193 method: 'PUT',
194 params: params,
195 waitMsgTarget: me,
196 callback: function() {
197 reload();
198 },
8058410f 199 failure: function(response, opts) {
80c8dbf7 200 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
f6710aac 201 },
80c8dbf7 202 });
f6710aac 203 },
80c8dbf7
DM
204 });
205
206 Ext.apply(me, {
207 store: store,
208 selModel: sm,
209 tbar: [
210 {
211 text: gettext('Add'),
212 menu: new Ext.menu.Menu({
213 items: [
214 {
215 text: gettext('Virtual Machine'),
216 iconCls: 'pve-itype-icon-qemu',
217 handler: function() {
218 var win = Ext.create('PVE.pool.AddVM', { pool: me.pool });
219 win.on('destroy', reload);
220 win.show();
f6710aac 221 },
80c8dbf7
DM
222 },
223 {
224 text: gettext('Storage'),
225 iconCls: 'pve-itype-icon-storage',
226 handler: function() {
227 var win = Ext.create('PVE.pool.AddStorage', { pool: me.pool });
228 win.on('destroy', reload);
229 win.show();
f6710aac
TL
230 },
231 },
232 ],
233 }),
80c8dbf7 234 },
f6710aac 235 remove_btn,
80c8dbf7
DM
236 ],
237 viewConfig: {
f6710aac 238 stripeRows: true,
80c8dbf7
DM
239 },
240 columns: coldef,
241 listeners: {
685b7aa4 242 itemcontextmenu: PVE.Utils.createCmdMenu,
26eac3a6
DC
243 itemdblclick: function(v, record) {
244 var ws = me.up('pveStdWorkspace');
245 ws.selectById(record.data.id);
246 },
f6710aac
TL
247 activate: reload,
248 },
80c8dbf7
DM
249 });
250
251 me.callParent();
f6710aac 252 },
a00a9ffd 253});