]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/storage/RBDEdit.js
ui: storage: combine RBD external and hyperconverged add dialog
[pve-manager.git] / www / manager6 / storage / RBDEdit.js
1 /*jslint confusion: true*/
2 Ext.define('PVE.storage.RBDInputPanel', {
3 extend: 'PVE.panel.StorageBase',
4
5 viewModel: {
6 parent: null,
7 data: {
8 pveceph: true,
9 pvecephPossible: true
10 }
11 },
12
13 controller: {
14 xclass: 'Ext.app.ViewController',
15 control: {
16 '#': {
17 afterrender: 'queryMonitors'
18 },
19 'textfield[name=username]': {
20 disable: 'resetField'
21 },
22 'displayfield[name=monhost]': {
23 enable: 'queryMonitors'
24 },
25 'textfield[name=monhost]': {
26 disable: 'resetField',
27 enable: 'resetField'
28 }
29 },
30 resetField: function(field) {
31 field.reset();
32 },
33 queryMonitors: function(field, newVal, oldVal) {
34 // we get called with two signatures, the above one for a field
35 // change event and the afterrender from the view, this check only
36 // can be true for the field change one and omit the API request if
37 // pveceph got unchecked - as it's not needed there.
38 if (field && !newVal && oldVal) {
39 return;
40 }
41 var view = this.getView();
42 var vm = this.getViewModel();
43 if (!(view.isCreate || vm.get('pveceph'))) {
44 return; // only query on create or if editing a pveceph store
45 }
46
47 var monhostField = this.lookupReference('monhost');
48
49 Proxmox.Utils.API2Request({
50 url: '/api2/json/nodes/localhost/ceph/mon',
51 method: 'GET',
52 scope: this,
53 callback: function(options, success, response) {
54 var data = response.result.data;
55 if (response.status === 200) {
56 if (data.length > 0) {
57 var monhost = Ext.Array.pluck(data, 'name').sort().join(',');
58 monhostField.setValue(monhost);
59 monhostField.resetOriginalValue();
60 if (view.isCreate) {
61 vm.set('pvecephPossible', true);
62 }
63 } else {
64 vm.set('pveceph', false);
65 }
66 } else {
67 vm.set('pveceph', false);
68 vm.set('pvecephPossible', false);
69 }
70 }
71 });
72 }
73 },
74
75 setValues: function(values) {
76 if (values.monhost) {
77 this.viewModel.set('pveceph', false);
78 this.lookupReference('pvecephRef').setValue(false);
79 this.lookupReference('pvecephRef').resetOriginalValue();
80 }
81 this.callParent([values]);
82 },
83
84 initComponent : function() {
85 var me = this;
86
87 if (!me.nodename) {
88 me.nodename = 'localhost';
89 }
90 me.type = 'rbd';
91
92 var getBinds = function (activeIfPVECeph, hide) {
93 var bind = {
94 disabled: activeIfPVECeph ? '{!pveceph}' : '{pveceph}'
95 };
96
97 // displayfield has no submitValue and bind mixin cannot handle that
98 if (me.isCreate) {
99 bind.submitValue = activeIfPVECeph ? '{pveceph}' : '{!pveceph}';
100 }
101 if (hide) {
102 bind.hidden = activeIfPVECeph ? '{!pveceph}' : '{pveceph}';
103 }
104
105 return bind;
106 };
107
108 me.column1 = [
109 {
110 xtype: me.isCreate ? 'pveCephPoolSelector' : 'displayfield',
111 nodename: me.nodename,
112 name: 'pool',
113 bind: getBinds(true, true),
114 fieldLabel: gettext('Pool'),
115 allowBlank: false
116 },
117 {
118 xtype: me.isCreate ? 'textfield' : 'displayfield',
119 name: 'pool',
120 value: 'rbd',
121 bind: getBinds(false, true),
122 fieldLabel: gettext('Pool'),
123 allowBlank: false
124 },
125 {
126 xtype: 'textfield',
127 name: 'monhost',
128 vtype: 'HostList',
129 bind: getBinds(false, true),
130 value: '',
131 fieldLabel: 'Monitor(s)',
132 allowBlank: false
133 },
134 {
135 xtype: 'displayfield',
136 reference: 'monhost',
137 bind: {
138 disabled: '{!pveceph}',
139 hidden: '{!pveceph}'
140 },
141 value: '',
142 fieldLabel: 'Monitor(s)'
143 },
144 {
145 xtype: me.isCreate ? 'textfield' : 'displayfield',
146 name: 'username',
147 bind: me.isCreate ? getBinds(false) : {},
148 value: 'admin',
149 fieldLabel: gettext('User name'),
150 allowBlank: true
151 }
152 ];
153
154 me.column2 = [
155 {
156 xtype: 'pveContentTypeSelector',
157 cts: ['images', 'rootdir'],
158 fieldLabel: gettext('Content'),
159 name: 'content',
160 value: ['images'],
161 multiSelect: true,
162 allowBlank: false
163 },
164 {
165 xtype: 'proxmoxcheckbox',
166 name: 'krbd',
167 uncheckedValue: 0,
168 fieldLabel: 'KRBD'
169 }
170 ];
171
172 me.columnB = [{
173 xtype: 'proxmoxcheckbox',
174 name: 'pveceph',
175 reference: 'pvecephRef',
176 bind : {
177 disabled: '{!pvecephPossible}',
178 value: '{pveceph}'
179 },
180 checked: true,
181 uncheckedValue: 0,
182 submitValue: false,
183 hidden: !me.isCreate,
184 boxLabel: gettext('Use Proxmox VE managed hyper-converged ceph pool')
185 }];
186
187 me.callParent();
188 }
189 });