]>
Commit | Line | Data |
---|---|---|
208ba0c6 DM |
1 | Ext.define('PVE.storage.IScsiScan', { |
2 | extend: 'Ext.form.field.ComboBox', | |
3 | alias: 'widget.pveIScsiScan', | |
4 | ||
5 | queryParam: 'portal', | |
6 | ||
7 | doRawQuery: function() { | |
8 | }, | |
9 | ||
10 | onTriggerClick: function() { | |
11 | var me = this; | |
12 | ||
13 | if (!me.queryCaching || me.lastQuery !== me.portal) { | |
14 | me.store.removeAll(); | |
15 | } | |
16 | ||
17 | me.allQuery = me.portal; | |
18 | ||
19 | me.callParent(); | |
20 | }, | |
21 | ||
22 | setPortal: function(portal) { | |
23 | var me = this; | |
24 | ||
25 | me.portal = portal; | |
26 | }, | |
27 | ||
28 | initComponent : function() { | |
29 | var me = this; | |
30 | ||
31 | if (!me.nodename) { | |
32 | me.nodename = 'localhost'; | |
33 | } | |
34 | ||
35 | var store = Ext.create('Ext.data.Store', { | |
36 | fields: [ 'target', 'portal' ], | |
37 | proxy: { | |
38 | type: 'pve', | |
39 | url: '/api2/json/nodes/' + me.nodename + '/scan/iscsi' | |
40 | } | |
41 | }); | |
42 | ||
43 | Ext.apply(me, { | |
44 | store: store, | |
45 | valueField: 'target', | |
46 | displayField: 'target', | |
47 | matchFieldWidth: false, | |
48 | listConfig: { | |
49 | loadingText: gettext('Scanning...'), | |
50 | listeners: { | |
51 | // hack: call setHeight to show scroll bars correctly | |
52 | refresh: function(list) { | |
53 | var lh = PVE.Utils.gridLineHeigh(); | |
54 | var count = store.getCount(); | |
55 | list.setHeight(lh * ((count > 10) ? 10 : count)); | |
56 | } | |
57 | }, | |
58 | width: 350 | |
59 | } | |
60 | }); | |
61 | ||
62 | me.callParent(); | |
63 | } | |
64 | }); | |
65 | ||
66 | Ext.define('PVE.storage.IScsiInputPanel', { | |
67 | extend: 'PVE.panel.InputPanel', | |
68 | ||
69 | onGetValues: function(values) { | |
70 | var me = this; | |
71 | ||
72 | if (me.create) { | |
73 | values.type = 'iscsi'; | |
74 | } else { | |
75 | delete values.storage; | |
76 | } | |
77 | ||
78 | values.content = values.luns ? 'images' : 'none'; | |
79 | delete values.luns; | |
80 | ||
81 | values.disable = values.enable ? 0 : 1; | |
82 | delete values.enable; | |
83 | ||
84 | return values; | |
85 | }, | |
86 | ||
87 | initComponent : function() { | |
88 | var me = this; | |
89 | ||
90 | ||
91 | me.column1 = [ | |
92 | { | |
93 | xtype: me.create ? 'textfield' : 'displayfield', | |
94 | name: 'storage', | |
95 | height: 22, // hack: set same height as text fields | |
96 | value: me.storageId || '', | |
97 | fieldLabel: 'ID', | |
98 | vtype: 'StorageId', | |
99 | allowBlank: false | |
100 | }, | |
101 | { | |
102 | xtype: me.create ? 'textfield' : 'displayfield', | |
103 | height: 22, // hack: set same height as text fields | |
104 | name: 'portal', | |
105 | value: '', | |
106 | fieldLabel: 'Portal', | |
107 | allowBlank: false, | |
108 | listeners: { | |
109 | change: function(f, value) { | |
110 | if (me.create) { | |
111 | var exportField = me.down('field[name=target]'); | |
112 | exportField.setPortal(value); | |
113 | exportField.setValue(''); | |
114 | } | |
115 | } | |
116 | } | |
117 | }, | |
118 | { | |
119 | readOnly: !me.create, | |
120 | xtype: me.create ? 'pveIScsiScan' : 'displayfield', | |
121 | name: 'target', | |
122 | value: '', | |
123 | fieldLabel: 'Target', | |
124 | allowBlank: false | |
125 | } | |
126 | ]; | |
127 | ||
128 | me.column2 = [ | |
129 | { | |
130 | xtype: 'PVE.form.NodeSelector', | |
131 | name: 'nodes', | |
132 | fieldLabel: gettext('Nodes'), | |
133 | emptyText: gettext('All') + ' (' + | |
134 | gettext('No restrictions') +')', | |
135 | multiSelect: true, | |
136 | autoSelect: false | |
137 | }, | |
138 | { | |
139 | xtype: 'pvecheckbox', | |
140 | name: 'enable', | |
141 | checked: true, | |
142 | uncheckedValue: 0, | |
143 | fieldLabel: gettext('Enable') | |
144 | }, | |
145 | { | |
146 | xtype: 'checkbox', | |
147 | name: 'luns', | |
148 | checked: true, | |
149 | fieldLabel: gettext('Use LUNs directly') | |
150 | } | |
151 | ]; | |
152 | ||
153 | me.callParent(); | |
154 | } | |
155 | }); | |
156 | ||
157 | Ext.define('PVE.storage.IScsiEdit', { | |
158 | extend: 'PVE.window.Edit', | |
159 | ||
160 | initComponent : function() { | |
161 | var me = this; | |
162 | ||
163 | me.create = !me.storageId; | |
164 | ||
165 | if (me.create) { | |
166 | me.url = '/api2/extjs/storage'; | |
167 | me.method = 'POST'; | |
168 | } else { | |
169 | me.url = '/api2/extjs/storage/' + me.storageId; | |
170 | me.method = 'PUT'; | |
171 | } | |
172 | ||
173 | var ipanel = Ext.create('PVE.storage.IScsiInputPanel', { | |
174 | create: me.create, | |
175 | storageId: me.storageId | |
176 | }); | |
177 | ||
178 | Ext.apply(me, { | |
179 | subject: PVE.Utils.format_storage_type('iscsi'), | |
180 | isAdd: true, | |
181 | items: [ ipanel ] | |
182 | }); | |
183 | ||
184 | me.callParent(); | |
185 | ||
186 | if (!me.create) { | |
187 | me.load({ | |
188 | success: function(response, options) { | |
189 | var values = response.result.data; | |
190 | var ctypes = values.content || ''; | |
191 | ||
192 | if (values.storage === 'local') { | |
193 | values.content = ctypes.split(','); | |
194 | } | |
195 | if (values.nodes) { | |
196 | values.nodes = values.nodes.split(','); | |
197 | } | |
198 | values.enable = values.disable ? 0 : 1; | |
199 | values.luns = (values.content === 'images') ? true : false; | |
200 | ||
201 | ipanel.setValues(values); | |
202 | } | |
203 | }); | |
204 | } | |
205 | } | |
206 | }); |