]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/grid/PoolMembers.js
use KVCombobox from widget toolkit
[pve-manager.git] / www / manager6 / grid / PoolMembers.js
CommitLineData
80c8dbf7
DM
1Ext.define('PVE.pool.AddVM', {
2 extend: 'PVE.window.Edit',
8dc0c049
DC
3 width: 600,
4 height: 400,
5 isAdd: true,
d5e771ce 6 isCreate: true,
80c8dbf7 7 initComponent : function() {
d5e771ce 8
80c8dbf7
DM
9 var me = this;
10
11 if (!me.pool) {
12 throw "no pool specified";
13 }
14
80c8dbf7
DM
15 me.url = "/pools/" + me.pool;
16 me.method = 'PUT';
3d9bc0a2 17
8dc0c049
DC
18 var vmsField = Ext.create('Ext.form.field.Text', {
19 name: 'vms',
20 hidden: true,
21 allowBlank: false
22 });
23
24 var vmStore = Ext.create('Ext.data.Store', {
25 model: 'PVEResources',
d5e771ce
EK
26 sorters: [
27 {
28 property: 'vmid',
29 order: 'ASC'
30 }
31 ],
8dc0c049
DC
32 filters: [
33 function(item) {
34 return ((item.data.type === 'lxc' || item.data.type === 'qemu') && item.data.pool === '');
80c8dbf7
DM
35 }
36 ]
37 });
38
8dc0c049
DC
39 var vmGrid = Ext.create('widget.grid',{
40 store: vmStore,
41 border: true,
42 height: 300,
43 scrollable: true,
44 selModel: {
45 selType: 'checkboxmodel',
46 mode: 'SIMPLE',
47 listeners: {
48 selectionchange: function(model, selected, opts) {
49 var selectedVms = [];
50 selected.forEach(function(vm) {
51 selectedVms.push(vm.data.vmid);
52 });
53 vmsField.setValue(selectedVms);
54 }
22f2f9d6 55 }
8dc0c049
DC
56 },
57 columns: [
58 {
59 header: 'ID',
60 dataIndex: 'vmid',
61 width: 60
62 },
63 {
64 header: gettext('Node'),
65 dataIndex: 'node'
66 },
67 {
68 header: gettext('Status'),
69 dataIndex: 'uptime',
70 renderer: function(value) {
71 if (value) {
e7ade592 72 return Proxmox.Utils.runningText;
8dc0c049 73 } else {
e7ade592 74 return Proxmox.Utils.stoppedText;
8dc0c049
DC
75 }
76 }
77 },
78 {
79 header: gettext('Name'),
80 dataIndex: 'name',
81 flex: 1
82 },
83 {
84 header: gettext('Type'),
85 dataIndex: 'type'
86 }
22f2f9d6 87 ]
8dc0c049
DC
88 });
89 Ext.apply(me, {
90 subject: gettext('Virtual Machine'),
91 items: [ vmsField, vmGrid ]
92 });
93
80c8dbf7 94 me.callParent();
8dc0c049 95 vmStore.load();
80c8dbf7
DM
96 }
97});
98
99Ext.define('PVE.pool.AddStorage', {
100 extend: 'PVE.window.Edit',
101
102 initComponent : function() {
d5e771ce 103
80c8dbf7
DM
104 var me = this;
105
106 if (!me.pool) {
107 throw "no pool specified";
108 }
109
d5e771ce 110 me.isCreate = true;
80c8dbf7
DM
111 me.isAdd = true;
112 me.url = "/pools/" + me.pool;
113 me.method = 'PUT';
3d9bc0a2 114
80c8dbf7
DM
115 Ext.apply(me, {
116 subject: gettext('Storage'),
117 width: 350,
118 items: [
119 {
f118971d 120 xtype: 'pveStorageSelector',
80c8dbf7
DM
121 name: 'storage',
122 nodename: 'localhost',
123 autoSelect: false,
124 value: '',
125 fieldLabel: gettext("Storage")
126 }
127 ]
128 });
129
130 me.callParent();
131 }
132});
133
134Ext.define('PVE.grid.PoolMembers', {
135 extend: 'Ext.grid.GridPanel',
136 alias: ['widget.pvePoolMembers'],
137
138 // fixme: dynamic status update ?
139
07a3397f
DC
140 stateful: true,
141 stateId: 'grid-pool-members',
142
80c8dbf7
DM
143 initComponent : function() {
144 var me = this;
145
146 if (!me.pool) {
147 throw "no pool specified";
148 }
149
150 var store = Ext.create('Ext.data.Store', {
151 model: 'PVEResources',
152 sorters: [
153 {
154 property : 'type',
155 direction: 'ASC'
156 }
157 ],
3d9bc0a2 158 proxy: {
80c8dbf7
DM
159 type: 'pve',
160 root: 'data.members',
161 url: "/api2/json/pools/" + me.pool
162 }
163 });
164
3a8c89c2 165 var coldef = PVE.data.ResourceStore.defaultColumns();
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,
177 confirmMsg: function (rec) {
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 },
199 failure: function (response, opts) {
200 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
201 }
202 });
203 }
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();
221 }
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();
230 }
231 }
232 ]
233 })
234 },
235 remove_btn
236 ],
237 viewConfig: {
238 stripeRows: true
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 },
1928545b 247 activate: reload
80c8dbf7
DM
248 }
249 });
250
251 me.callParent();
252 }
a00a9ffd 253});