]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/storage/RBDEdit.js
35568b9854e8d04d6520f804c886c80d0475af3d
[pve-manager.git] / www / manager6 / storage / RBDEdit.js
1 Ext.define('PVE.storage.Ceph.Model', {
2 extend: 'Ext.app.ViewModel',
3 alias: 'viewmodel.cephstorage',
4
5 data: {
6 pveceph: true,
7 pvecephPossible: true,
8 namespacePresent: false,
9 },
10 });
11
12 Ext.define('PVE.storage.Ceph.Controller', {
13 extend: 'PVE.controller.StorageEdit',
14 alias: 'controller.cephstorage',
15
16 control: {
17 '#': {
18 afterrender: 'queryMonitors',
19 },
20 'textfield[name=username]': {
21 disable: 'resetField',
22 },
23 'displayfield[name=monhost]': {
24 enable: 'queryMonitors',
25 },
26 'textfield[name=monhost]': {
27 disable: 'resetField',
28 enable: 'resetField',
29 },
30 'textfield[name=namespace]': {
31 change: 'updateNamespaceHint',
32 },
33 },
34 resetField: function(field) {
35 field.reset();
36 },
37 updateNamespaceHint: function(field, newVal, oldVal) {
38 this.getViewModel().set('namespacePresent', newVal);
39 },
40 queryMonitors: function(field, newVal, oldVal) {
41 // we get called with two signatures, the above one for a field
42 // change event and the afterrender from the view, this check only
43 // can be true for the field change one and omit the API request if
44 // pveceph got unchecked - as it's not needed there.
45 if (field && !newVal && oldVal) {
46 return;
47 }
48 var view = this.getView();
49 var vm = this.getViewModel();
50 if (!(view.isCreate || vm.get('pveceph'))) {
51 return; // only query on create or if editing a pveceph store
52 }
53
54 var monhostField = this.lookupReference('monhost');
55
56 Proxmox.Utils.API2Request({
57 url: '/api2/json/nodes/localhost/ceph/mon',
58 method: 'GET',
59 scope: this,
60 callback: function(options, success, response) {
61 var data = response.result.data;
62 if (response.status === 200) {
63 if (data.length > 0) {
64 var monhost = Ext.Array.pluck(data, 'name').sort().join(',');
65 monhostField.setValue(monhost);
66 monhostField.resetOriginalValue();
67 if (view.isCreate) {
68 vm.set('pvecephPossible', true);
69 }
70 } else {
71 vm.set('pveceph', false);
72 }
73 } else {
74 vm.set('pveceph', false);
75 vm.set('pvecephPossible', false);
76 }
77 },
78 });
79 },
80 });
81
82 Ext.define('PVE.storage.RBDInputPanel', {
83 extend: 'PVE.panel.StorageBase',
84 controller: 'cephstorage',
85
86 onlineHelp: 'ceph_rados_block_devices',
87
88 viewModel: {
89 type: 'cephstorage',
90 },
91
92 setValues: function(values) {
93 if (values.monhost) {
94 this.viewModel.set('pveceph', false);
95 this.lookupReference('pvecephRef').setValue(false);
96 this.lookupReference('pvecephRef').resetOriginalValue();
97 }
98 if (values.namespace) {
99 this.getViewModel().set('namespacePresent', true);
100 }
101 this.callParent([values]);
102 },
103
104 initComponent: function() {
105 var me = this;
106
107 if (!me.nodename) {
108 me.nodename = 'localhost';
109 }
110 me.type = 'rbd';
111
112 me.column1 = [];
113
114 if (me.isCreate) {
115 me.column1.push({
116 xtype: 'pveCephPoolSelector',
117 nodename: me.nodename,
118 name: 'pool',
119 bind: {
120 disabled: '{!pveceph}',
121 submitValue: '{pveceph}',
122 hidden: '{!pveceph}',
123 },
124 fieldLabel: gettext('Pool'),
125 allowBlank: false,
126 }, {
127 xtype: 'textfield',
128 name: 'pool',
129 value: 'rbd',
130 bind: {
131 disabled: '{pveceph}',
132 submitValue: '{!pveceph}',
133 hidden: '{pveceph}',
134 },
135 fieldLabel: gettext('Pool'),
136 allowBlank: false,
137 });
138 } else {
139 me.column1.push({
140 xtype: 'displayfield',
141 nodename: me.nodename,
142 name: 'pool',
143 fieldLabel: gettext('Pool'),
144 allowBlank: false,
145 });
146 }
147
148 me.column1.push(
149 {
150 xtype: 'textfield',
151 name: 'monhost',
152 vtype: 'HostList',
153 bind: {
154 disabled: '{pveceph}',
155 submitValue: '{!pveceph}',
156 hidden: '{pveceph}',
157 },
158 value: '',
159 fieldLabel: 'Monitor(s)',
160 allowBlank: false,
161 },
162 {
163 xtype: 'displayfield',
164 reference: 'monhost',
165 bind: {
166 disabled: '{!pveceph}',
167 hidden: '{!pveceph}',
168 },
169 value: '',
170 fieldLabel: 'Monitor(s)',
171 },
172 {
173 xtype: me.isCreate ? 'textfield' : 'displayfield',
174 name: 'username',
175 bind: {
176 disabled: '{pveceph}',
177 submitValue: '{!pveceph}',
178 },
179 value: 'admin',
180 fieldLabel: gettext('User name'),
181 allowBlank: true,
182 },
183 );
184
185 me.column2 = [
186 {
187 xtype: 'pveContentTypeSelector',
188 cts: ['images', 'rootdir'],
189 fieldLabel: gettext('Content'),
190 name: 'content',
191 value: ['images'],
192 multiSelect: true,
193 allowBlank: false,
194 },
195 {
196 xtype: 'proxmoxcheckbox',
197 name: 'krbd',
198 uncheckedValue: 0,
199 fieldLabel: 'KRBD',
200 },
201 ];
202
203 me.columnB = [
204 {
205 xtype: 'proxmoxcheckbox',
206 name: 'pveceph',
207 reference: 'pvecephRef',
208 bind: {
209 disabled: '{!pvecephPossible}',
210 value: '{pveceph}',
211 },
212 checked: true,
213 uncheckedValue: 0,
214 submitValue: false,
215 hidden: !me.isCreate,
216 boxLabel: gettext('Use Proxmox VE managed hyper-converged ceph pool'),
217 },
218 ];
219
220 me.advancedColumn1 = [
221 {
222 xtype: 'pmxDisplayEditField',
223 editable: me.isCreate,
224 name: 'namespace',
225 value: '',
226 fieldLabel: gettext('Namespace'),
227 allowBlank: true,
228 },
229 ];
230 me.advancedColumn2 = [
231 {
232 xtype: 'displayfield',
233 name: 'namespace-hint',
234 userCls: 'pmx-hint',
235 value: gettext('RBD namespaces must be created manually!'),
236 bind: {
237 hidden: '{!namespacePresent}',
238 },
239 },
240 ];
241
242 me.callParent();
243 },
244 });