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