]> git.datanom.net - omvzfs.git/blob - gui/js/omv/module/admin/storage/zfs/Overview.js
22f74dbf3f97235e374268accdf870bec91870bb
[omvzfs.git] / gui / js / omv / module / admin / storage / zfs / Overview.js
1 // require("js/omv/tree/Panel.js")
2 // require("js/omv/module/admin/storage/zfs/TreePanel.js")
3 // require("js/omv/workspace/window/Grid.js")
4 // require("js/omv/form/field/CheckboxGrid.js")
5
6 Ext.define("OMV.module.admin.storage.zfs.AddPool", {
7 extend: "OMV.workspace.window.Form",
8 requires: [
9 "OMV.data.Store",
10 "OMV.data.Model",
11 "OMV.data.proxy.Rpc",
12 "OMV.form.field.CheckboxGrid"
13 ],
14
15 rpcService: "ZFS",
16 rpcSetMethod: "addPool",
17 title: _("Create ZFS pool"),
18 autoLoadData: false,
19 hideResetButton: true,
20 width: 550,
21 height: 350,
22
23 getFormItems: function() {
24 var me = this;
25 return [{
26 xtype: "textfield",
27 name: "name",
28 fieldLabel: _("Name")
29 },{
30 xtype: "combo",
31 name: "pooltype",
32 fieldLabel: _("Pool type"),
33 queryMode: "local",
34 store: Ext.create("Ext.data.ArrayStore", {
35 fields: [ "value", "text" ],
36 data: [
37 [ "basic", _("Basic") ],
38 [ "mirror", _("Mirror") ],
39 [ "raidz1", _("RAID-Z1") ],
40 [ "raidz2", _("RAID-Z2") ],
41 [ "raidz3", _("RAID-Z3") ]
42 ]
43 }),
44 displayField: "text",
45 valueField: "value",
46 allowBlank: false,
47 editable: false,
48 triggerAction: "all",
49 value: "raidz1",
50 listeners: {
51 scope: me,
52 change: function(combo, value) {
53 var devicesField = this.findField("devices");
54 switch(value) {
55 case "basic":
56 devicesField.minSelections = 1;
57 break;
58 case "mirror":
59 devicesField.minSelections = 2;
60 break;
61 case "raidz1":
62 devicesField.minSelections = 3;
63 break;
64 case "raidz2":
65 devicesField.minSelections = 4;
66 case "raidz3":
67 devicesField.minSelections = 5;
68 break;
69 default:
70 devicesField.minSelections = 2;
71 break;
72 }
73 devicesField.validate();
74 }
75 }
76 },{
77 xtype: "checkboxgridfield",
78 name: "devices",
79 fieldLabel: _("Devices"),
80 valueField: "devicefile",
81 minSelections: 3, // Min. number of devices for RAIDZ-1
82 useStringValue: true,
83 height: 130,
84 store: Ext.create("OMV.data.Store", {
85 autoLoad: true,
86 model: OMV.data.Model.createImplicit({
87 idProperty: "devicefile",
88 fields: [
89 { name: "devicefile", type: "string" },
90 { name: "size", type: "string" },
91 { name: "vendor", type: "string" },
92 { name: "serialnumber", type: "string" }
93 ]
94 }),
95 proxy: {
96 type: "rpc",
97 appendSortParams: false,
98 rpcData: {
99 service: "RaidMgmt",
100 method: "getCandidates"
101 }
102 },
103 sorters: [{
104 direction: "ASC",
105 property: "devicefile"
106 }]
107 }),
108 gridConfig: {
109 stateful: true,
110 stateId: "1866b5d0-327e-11e4-8c21-0800200c9a66",
111 columns: [{
112 text: _("Device"),
113 sortable: true,
114 dataIndex: "devicefile",
115 stateId: "devicefile",
116 flex: 1
117 },{
118 xtype: "binaryunitcolumn",
119 text: _("Capacity"),
120 sortable: true,
121 dataIndex: "size",
122 stateId: "size",
123 width: 50,
124 flex: 1
125 },{
126 text: _("Vendor"),
127 sortable: true,
128 dataIndex: "vendor",
129 stateId: "vendor",
130 flex: 1
131 },{
132 text: _("Serial Number"),
133 sortable: true,
134 dataIndex: "serialnumber",
135 stateId: "serialnumber",
136 flex: 1
137 }]
138 }
139 },{
140 xtype: "checkbox",
141 name: "force",
142 fieldLabel: _("Force creation"),
143 checked: false,
144 boxLabel: _("Forces the creation of the pool even if errors are reported. Use with extreme caution!")
145 }];
146 },
147
148 doSubmit: function() {
149 var me = this;
150 OMV.MessageBox.show({
151 title: _("Confirmation"),
152 msg: _("Do you really want to create the ZFS pool?"),
153 buttons: Ext.Msg.YESNO,
154 fn: function(answer) {
155 if(answer === "no")
156 return;
157 me.superclass.doSubmit.call(me);
158 },
159 scope: me,
160 icon: Ext.Msg.QUESTION
161 });
162 }
163 });
164
165 Ext.define("OMV.module.admin.storage.zfs.AddObject", {
166 extend: "OMV.workspace.window.Form",
167 uses: [
168 "OMV.data.Store",
169 "OMV.data.Model",
170 "OMV.data.proxy.Rpc",
171 "OMV.data.reader.RpcArray"
172 ],
173
174 rpcService: "ZFS",
175 rpcSetMethod: "addObject",
176 width: 420,
177
178 getFormItems: function() {
179 var me = this;
180 return [{
181 xtype: "combo",
182 name: "type",
183 fieldLabel: _("Object Type"),
184 queryMode: "local",
185 store: [
186 [ "filesystem", "Filesystem" ],
187 [ "snapshot", "Snapshot" ],
188 [ "volume", "Volume" ]
189 ],
190 allowBlank: true,
191 editable: false,
192 triggerAction: "all",
193 value: "filesystem",
194 listeners: {
195 scope: me,
196 change: function(combo, value) {
197 var sizeField = this.findField("size");
198 switch(value) {
199 case "volume":
200 sizeField.show();
201 sizeField.allowBlank = false;
202 break;
203 default:
204 sizeField.hide();
205 sizeField.allowBlank = true;
206 break;
207 }
208 sizeField.validate();
209 }
210 }
211 },{
212 xtype: "textfield",
213 name: "path",
214 fieldLabel: _("Prefix"),
215 allowBlank: false,
216 readOnly: true
217 },{
218 xtype: "textfield",
219 name: "name",
220 fieldLabel: _("Name"),
221 allowBlank: false,
222 plugins: [{
223 ptype: "fieldinfo",
224 text: _("Name of the new object. Prefix will prepend the name. Please omit leading /")
225 }]
226 },{
227 xtype: "textfield",
228 name: "size",
229 hidden: true,
230 fieldLabel: _("Size"),
231 allowBlank: true,
232 plugins: [{
233 ptype: "fieldinfo",
234 text: _("Size of the volume e.g. 5mb,100gb,1tb etc")
235 }]
236 }];
237 }
238 });
239
240
241
242 Ext.define("OMV.module.admin.storage.zfs.EditProperties", {
243 extend: "OMV.workspace.window.Grid",
244 requires: [
245 "OMV.data.Store",
246 "OMV.data.Model",
247 "OMV.data.proxy.Rpc"
248 ],
249
250 rpcService: "ZFS",
251 rpcSetMethod: "setProperties",
252
253 title: _("Edit properties"),
254 width: 500,
255 height: 305,
256
257 getGridConfig: function() {
258 var me = this;
259
260 var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
261 clicksToEdit: 1,
262 pluginId: 'rowEditing',
263 listeners: {
264 validateedit: function(editor, e, eOpts) {
265 e.record.set("modified", "true");
266 },
267 beforeedit: function(editor, e, eOpts) {
268 if (e.record.get("property") === "mountpoint") {
269 e.grid.getPlugin('rowEditing').editor.form.findField("value").disable();
270 e.grid.getPlugin('rowEditing').editor.form.findField("property").disable();
271 } else if (e.record.get("newproperty") === "false") {
272 e.grid.getPlugin('rowEditing').editor.form.findField("value").enable();
273 e.grid.getPlugin('rowEditing').editor.form.findField("property").disable();
274 } else {
275 e.grid.getPlugin('rowEditing').editor.form.findField("value").enable();
276 e.grid.getPlugin('rowEditing').editor.form.findField("property").enable();
277 }
278 }
279
280 }
281 });
282
283 var store = Ext.create("OMV.data.Store", {
284 autoLoad: true,
285 model: OMV.data.Model.createImplicit({
286 fields: [
287 { name: "property", type: "string" },
288 { name: "value", type: "string" },
289 { name: "source", type: "string" },
290 { name: "modified", type: "string" },
291 { name: "newproperty", type: "string", defaultValue: "false" }
292 ]
293 }),
294 proxy: {
295 type: "rpc",
296 rpcData: {
297 service: "ZFS",
298 method: "getProperties",
299 params: {
300 name: me.name,
301 type: me.type
302 }
303 }
304 }
305 });
306
307 return {
308 border: false,
309 stateful: true,
310 stateId: "8c3dc800-bdbb-11e3-b1b6-0800200c9a66",
311 selType: 'rowmodel',
312 plugins: [rowEditing],
313 store: store,
314 tbar: [{
315 text: "Add property",
316 icon: "images/add.png",
317 iconCls: Ext.baseCSSPrefix + "btn-icon-16x16",
318 handler: function(view) {
319 Ext.define('Property', {
320 extend: 'Ext.data.Model',
321 fields: [
322 "property",
323 "value",
324 "source",
325 "modified",
326 "newproperty"
327 ]
328 });
329 var newProperty = Ext.create("Property", {
330 property: "",
331 value: "",
332 source: "local",
333 modified: "true",
334 newproperty: "true"
335 });
336 rowEditing.cancelEdit();
337 store.insert(0, newProperty);
338 rowEditing.startEdit();
339 }
340 }],
341 columns: [{
342 text: _("Property"),
343 sortable: true,
344 dataIndex: "property",
345 stateId: "property",
346 editor: {
347 xtype: "textfield",
348 allowBlank: false,
349 }
350 },{
351 text: _("Value"),
352 sortable: true,
353 dataIndex: "value",
354 stateId: "value",
355 flex: 1,
356 readOnly: true,
357 editor: {
358 xtype: "textfield",
359 allowBlank: false,
360 }
361 },{
362 text: _("Source"),
363 sortable: true,
364 dataIndex: "source",
365 stateId: "source",
366 },{
367 xtype: 'actioncolumn',
368 header: 'Inherit',
369 icon: "images/checkmark.png",
370 tooltip: "Inherit",
371 handler: function(view, rowIndex, colIndex, item, e, record, row) {
372 OMV.RpcObserver.request({
373 msg : _("Updating property..."),
374 rpcData : {
375 service: "ZFS",
376 method: "inherit",
377 params: {
378 name: me.name,
379 type: me.type,
380 property: record.get("property")
381 }
382 },
383 finish : function() {
384 view.getStore().reload();
385 }
386 });
387 },
388 isDisabled: function(view, rowIdx, colIdx, item, record) {
389 var src = record.get("source");
390 if(src === "local") {
391 return false;
392 } else {
393 return true;
394 }
395 }
396 },{
397 text: _("New"),
398 dataIndex: "newproperty",
399 stateId: "newproperty",
400 sortable: false,
401 hidden: true
402 },{
403 text: _("Modified"),
404 sortable: false,
405 dataIndex: "modified",
406 stateId: "modified",
407 hidden: true
408 }],
409 };
410 },
411
412 getRpcSetParams: function() {
413 var me = this;
414 var properties = [];
415 var values = me.getValues();
416 Ext.Array.each(values, function(value) {
417 if(value.modified === "false")
418 return;
419 properties.push({
420 "property": value.property,
421 "value": value.value,
422 });
423 });
424 return {
425 name: me.name,
426 type: me.type,
427 properties: properties
428 };
429 }
430
431 });
432
433
434 Ext.define("OMV.module.admin.storage.zfs.CreateShare", {
435 extend: "OMV.workspace.window.Form",
436 uses: [
437 "OMV.data.Store",
438 "OMV.data.Model",
439 "OMV.data.proxy.Rpc",
440 "OMV.data.reader.RpcArray"
441 ],
442
443 rpcService: "ZFS",
444 rpcSetMethod: "createShare",
445 width: 500,
446
447 getFormItems: function() {
448 var me = this;
449 return [{
450 xtype: "textfield",
451 name: "sharename",
452 fieldLabel: _("Name"),
453 allowBlank: false,
454 },{
455 xtype: "textfield",
456 name: "mountpoint",
457 fieldLabel: _("Path"),
458 allowBlank: false,
459 readOnly: true
460 },{
461 xtype: "combo",
462 name: "mode",
463 fieldLabel: _("Permissions"),
464 queryMode: "local",
465 store: Ext.create("Ext.data.ArrayStore", {
466 fields: [ "value", "text" ],
467 data: [
468 [ "700", _("Administrator: read/write, Users: no access, Others: no access") ],
469 [ "750", _("Administrator: read/write, Users: read-only, Others: no access") ],
470 [ "770", _("Administrator: read/write, Users: read/write, Others: no access") ],
471 [ "755", _("Administrator: read/write, Users: read-only, Others: read-only") ],
472 [ "775", _("Administrator: read/write, Users: read/write, Others: read-only") ],
473 [ "777", _("Everyone: read/write") ]
474 ]
475 }),
476 displayField: "text",
477 valueField: "value",
478 allowBlank: false,
479 editable: false,
480 showItemTooltip: true,
481 triggerAction: "all",
482 value: "775",
483 plugins: [{
484 ptype: "fieldinfo",
485 text: _("The file mode of the shared folder path.")
486 }]
487 },{
488 xtype: "textarea",
489 name: "comment",
490 fieldLabel: _("Comment"),
491 allowBlank: true
492 },{
493 xtype: "textarea",
494 name: "name",
495 hidden: true
496 },{
497 xtype: "textarea",
498 name: "type",
499 hidden: true
500 }];
501 }
502 });
503
504
505
506 Ext.define("OMV.module.admin.storage.zfs.Overview", {
507 extend: "OMV.module.admin.storage.zfs.TreePanel",
508
509 rpcService: "ZFS",
510 rpcGetMethod: "getObjectTree",
511 requires: [
512 "OMV.data.Store",
513 "OMV.data.Model",
514 "OMV.data.proxy.Rpc"
515 ],
516
517 rootVisible: false,
518 stateful: true,
519 stateId: "cec54550-bc2a-11e3-a5e2-0800200c9a66",
520
521 columns: [{
522 text: _("Name"),
523 xtype: 'treecolumn',
524 dataIndex: 'name',
525 sortable: true,
526 flex: 2,
527 stateId: 'name'
528 },{
529 text: _("Type"),
530 dataIndex: 'type',
531 sortable: true,
532 flex: 1,
533 stateId: 'type'
534 },{
535 text: _("Share"),
536 xtype: 'actioncolumn',
537 tooltip: 'Create shared folder',
538 align: 'center',
539 icon: 'images/checkmark.png',
540 handler: function(view, rowIndex, colIndex, item, e, record, row) {
541 var me = this;
542 Ext.create("OMV.module.admin.storage.zfs.CreateShare", {
543 title: _("Create shared folder"),
544 rpcGetMethod: "getSharedParams",
545 rpcGetParams: {
546 name: record.get('path'),
547 type: record.get('type')
548 }
549 }).show();
550 },
551 isDisabled: function(view, rowIdx, colIdx, item, record) {
552 var src = record.get("type");
553 if((src === "Filesystem") && (record.get("shared") === "false")) {
554 return false;
555 } else {
556 return true;
557 }
558 }
559
560
561 },{
562 text: _("Details"),
563 xtype: 'actioncolumn',
564 tooltip: 'Details',
565 align: 'center',
566 icon: 'images/search.png'
567 },{
568 text: _("Shared"),
569 dataIndex: 'shared',
570 sortable: false,
571 stateId: 'shared',
572 hidden: true
573 }],
574
575 initComponent: function() {
576 var me = this;
577 this.width = 600;
578 Ext.apply(me, {
579 store: Ext.create("Ext.data.TreeStore", {
580 autoLoad: true,
581 model: OMV.data.Model.createImplicit({
582 fields: [
583 { name: "name", type: "string" },
584 { name: "type", type: "string" },
585 { name: "id", type: "string" },
586 { name: "path", type: "string" },
587 { name: "origin", type: "string", defaultValue: "none" },
588 { name: "shared", type: "string", defaultValue: "false" }
589 ]
590 }),
591 proxy: {
592 type: "rpc",
593 rpcData: {
594 service: "ZFS",
595 method: "getObjectTree",
596 }
597 },
598 folderSort: true
599 })
600 });
601 me.callParent(arguments);
602 },
603
604 onAddButton: function() {
605 var me = this;
606 Ext.create("OMV.module.admin.storage.zfs.AddPool", {
607 listeners: {
608 scope: me,
609 submit: function() {
610 this.doReload();
611 }
612 }
613 }).show();
614 },
615
616 onAddObjButton: function() {
617 var me = this;
618 var sm = me.getSelectionModel();
619 var records = sm.getSelection();
620 var record = records[0];
621 Ext.create("OMV.module.admin.storage.zfs.AddObject", {
622 title: _("Add Object"),
623 rpcGetMethod: "passParam",
624 rpcGetParams: {
625 key: "path",
626 value: record.get('path')
627 },
628 listeners: {
629 scope: me,
630 submit: function() {
631 this.doReload();
632 }
633 }
634 }).show();
635 },
636
637 onEditButton: function() {
638 var me = this;
639 var sm = me.getSelectionModel();
640 var records = sm.getSelection();
641 var record = records[0];
642 Ext.create("OMV.module.admin.storage.zfs.EditProperties", {
643 name: record.get("path"),
644 type: record.get("type")
645 }).show();
646 },
647
648 doDeletion: function(record) {
649 var me = this;
650 OMV.Rpc.request({
651 scope: me,
652 callback: me.onDeletion,
653 rpcData: {
654 service: "ZFS",
655 method: "deleteObject",
656 params: {
657 name: record.get('path'),
658 type: record.get('type')
659 }
660 }
661 });
662 }
663
664 });
665
666 OMV.WorkspaceManager.registerPanel({
667 id: "overview",
668 path: "/storage/zfs",
669 text: _("Overview"),
670 position: 10,
671 className: "OMV.module.admin.storage.zfs.Overview"
672 });
673
674
675
This page took 0.211392 seconds and 4 git commands to generate.