]>
Commit | Line | Data |
---|---|---|
0d1ac958 | 1 | /*jslint confusion: true*/ |
c0dee88e | 2 | Ext.define('PVE.storage.RBDInputPanel', { |
f28ec3e4 | 3 | extend: 'PVE.panel.StorageBase', |
c0dee88e | 4 | |
0d1ac958 TL |
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 | ||
c0dee88e DM |
84 | initComponent : function() { |
85 | var me = this; | |
86 | ||
3c23c025 DC |
87 | if (!me.nodename) { |
88 | me.nodename = 'localhost'; | |
89 | } | |
f28ec3e4 | 90 | me.type = 'rbd'; |
c0dee88e | 91 | |
0d1ac958 TL |
92 | var getBinds = function (activeIfPVECeph, hide) { |
93 | var bind = { | |
94 | disabled: activeIfPVECeph ? '{!pveceph}' : '{pveceph}' | |
95 | }; | |
c0dee88e | 96 | |
0d1ac958 TL |
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}' | |
3c23c025 | 140 | }, |
0d1ac958 TL |
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 | ]; | |
3c23c025 | 153 | |
c0dee88e | 154 | me.column2 = [ |
c0dee88e DM |
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 | { | |
896c0d50 | 165 | xtype: 'proxmoxcheckbox', |
c0dee88e DM |
166 | name: 'krbd', |
167 | uncheckedValue: 0, | |
ed9896e2 | 168 | fieldLabel: 'KRBD' |
c0dee88e DM |
169 | } |
170 | ]; | |
0d1ac958 TL |
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 | }]; | |
c0dee88e | 186 | |
c0dee88e DM |
187 | me.callParent(); |
188 | } | |
189 | }); |