]>
Commit | Line | Data |
---|---|---|
ca9a198a WL |
1 | Ext.define('PVE.storage.CIFSScan', { |
2 | extend: 'Ext.form.field.ComboBox', | |
3 | alias: 'widget.pveCIFSScan', | |
4 | ||
5 | queryParam: 'server', | |
6 | ||
7 | valueField: 'share', | |
8 | displayField: 'share', | |
9 | matchFieldWidth: false, | |
10 | listConfig: { | |
11 | loadingText: gettext('Scanning...'), | |
6bea400e | 12 | width: 350, |
ca9a198a | 13 | }, |
6bea400e | 14 | doRawQuery: Ext.emptyFn, |
ca9a198a WL |
15 | |
16 | onTriggerClick: function() { | |
17 | var me = this; | |
18 | ||
19 | if (!me.queryCaching || me.lastQuery !== me.cifsServer) { | |
20 | me.store.removeAll(); | |
21 | } | |
22 | ||
23 | var params = {}; | |
0c77529c TL |
24 | if (me.cifsUsername) { |
25 | params.username = me.cifsUsername; | |
26 | } | |
27 | if (me.cifsPassword) { | |
ca9a198a WL |
28 | params.password = me.cifsPassword; |
29 | } | |
ca9a198a WL |
30 | if (me.cifsDomain) { |
31 | params.domain = me.cifsDomain; | |
32 | } | |
33 | ||
34 | me.store.getProxy().setExtraParams(params); | |
35 | me.allQuery = me.cifsServer; | |
36 | ||
37 | me.callParent(); | |
38 | }, | |
39 | ||
bc13cc36 TL |
40 | resetProxy: function() { |
41 | let me = this; | |
42 | me.lastQuery = null; | |
43 | if (!me.readOnly && !me.disabled) { | |
44 | if (me.isExpanded) { | |
45 | me.collapse(); | |
46 | } | |
47 | } | |
ca9a198a WL |
48 | }, |
49 | ||
bc13cc36 TL |
50 | setServer: function(server) { |
51 | if (this.cifsServer !== server) { | |
52 | this.cifsServer = server; | |
53 | this.resetProxy(); | |
54 | } | |
55 | }, | |
ca9a198a | 56 | setUsername: function(username) { |
bc13cc36 TL |
57 | if (this.cifsUsername !== username) { |
58 | this.cifsUsername = username; | |
59 | this.resetProxy(); | |
60 | } | |
ca9a198a | 61 | }, |
ca9a198a | 62 | setPassword: function(password) { |
bc13cc36 TL |
63 | if (this.cifsPassword !== password) { |
64 | this.cifsPassword = password; | |
65 | this.resetProxy(); | |
66 | } | |
ca9a198a | 67 | }, |
ca9a198a | 68 | setDomain: function(domain) { |
bc13cc36 TL |
69 | if (this.cifsDomain !== domain) { |
70 | this.cifsDomain = domain; | |
71 | this.resetProxy(); | |
72 | } | |
ca9a198a WL |
73 | }, |
74 | ||
6bea400e | 75 | initComponent: function() { |
ca9a198a WL |
76 | var me = this; |
77 | ||
78 | if (!me.nodename) { | |
79 | me.nodename = 'localhost'; | |
80 | } | |
81 | ||
6bea400e | 82 | let store = Ext.create('Ext.data.Store', { |
ca9a198a WL |
83 | fields: ['description', 'share'], |
84 | proxy: { | |
85 | type: 'proxmox', | |
6bea400e TL |
86 | url: '/api2/json/nodes/' + me.nodename + '/scan/cifs', |
87 | }, | |
ca9a198a WL |
88 | }); |
89 | store.sort('share', 'ASC'); | |
90 | ||
91 | Ext.apply(me, { | |
6bea400e | 92 | store: store, |
ca9a198a WL |
93 | }); |
94 | ||
95 | me.callParent(); | |
fcd95fc1 TL |
96 | |
97 | let picker = me.getPicker(); | |
98 | // don't use monStoreErrors directly, it doesn't copes well with comboboxes | |
99 | picker.mon(store, 'beforeload', function(s, operation, eOpts) { | |
100 | picker.unmask(); | |
101 | delete picker.minHeight; | |
102 | }); | |
103 | picker.mon(store.proxy, 'afterload', function(proxy, request, success) { | |
104 | if (success) { | |
105 | Proxmox.Utils.setErrorMask(picker, false); | |
106 | return; | |
107 | } | |
108 | let error = request._operation.getError(); | |
109 | let msg = Proxmox.Utils.getResponseErrorMessage(error); | |
110 | if (msg) { | |
111 | picker.minHeight = 100; | |
112 | } | |
113 | Proxmox.Utils.setErrorMask(picker, msg); | |
114 | }); | |
6bea400e | 115 | }, |
ca9a198a WL |
116 | }); |
117 | ||
118 | Ext.define('PVE.storage.CIFSInputPanel', { | |
f28ec3e4 | 119 | extend: 'PVE.panel.StorageBase', |
ca9a198a | 120 | |
96988dfa DC |
121 | onlineHelp: 'storage_cifs', |
122 | ||
a1592429 TL |
123 | onGetValues: function(values) { |
124 | let me = this; | |
125 | ||
126 | if (values.password?.length === 0) { | |
127 | delete values.password; | |
128 | } | |
129 | if (values.username?.length === 0) { | |
130 | delete values.username; | |
131 | } | |
711658f4 LN |
132 | if (values.subdir?.length === 0) { |
133 | delete values.subdir; | |
134 | } | |
a1592429 TL |
135 | |
136 | return me.callParent([values]); | |
137 | }, | |
138 | ||
6bea400e | 139 | initComponent: function() { |
ca9a198a WL |
140 | var me = this; |
141 | ||
ca9a198a | 142 | me.column1 = [ |
ca9a198a WL |
143 | { |
144 | xtype: me.isCreate ? 'textfield' : 'displayfield', | |
145 | name: 'server', | |
146 | value: '', | |
147 | fieldLabel: gettext('Server'), | |
148 | allowBlank: false, | |
149 | listeners: { | |
150 | change: function(f, value) { | |
151 | if (me.isCreate) { | |
152 | var exportField = me.down('field[name=share]'); | |
153 | exportField.setServer(value); | |
154 | } | |
6bea400e TL |
155 | }, |
156 | }, | |
ca9a198a WL |
157 | }, |
158 | { | |
159 | xtype: me.isCreate ? 'textfield' : 'displayfield', | |
160 | name: 'username', | |
161 | value: '', | |
162 | fieldLabel: gettext('Username'), | |
163 | emptyText: gettext('Guest user'), | |
ca9a198a WL |
164 | listeners: { |
165 | change: function(f, value) { | |
cb1b3427 TL |
166 | if (!me.isCreate) { |
167 | return; | |
168 | } | |
169 | var exportField = me.down('field[name=share]'); | |
170 | exportField.setUsername(value); | |
6bea400e TL |
171 | }, |
172 | }, | |
ca9a198a | 173 | }, |
0c77529c TL |
174 | { |
175 | xtype: me.isCreate ? 'textfield' : 'displayfield', | |
176 | inputType: 'password', | |
177 | name: 'password', | |
178 | value: me.isCreate ? '' : '********', | |
179 | emptyText: me.isCreate ? gettext('None') : '', | |
180 | fieldLabel: gettext('Password'), | |
181 | minLength: 1, | |
182 | listeners: { | |
183 | change: function(f, value) { | |
184 | let exportField = me.down('field[name=share]'); | |
185 | exportField.setPassword(value); | |
186 | }, | |
187 | }, | |
188 | }, | |
ca9a198a WL |
189 | { |
190 | xtype: me.isCreate ? 'pveCIFSScan' : 'displayfield', | |
191 | name: 'share', | |
192 | value: '', | |
193 | fieldLabel: 'Share', | |
6bea400e TL |
194 | allowBlank: false, |
195 | }, | |
ca9a198a WL |
196 | ]; |
197 | ||
198 | me.column2 = [ | |
dad14ab0 TL |
199 | { |
200 | xtype: 'pveContentTypeSelector', | |
201 | name: 'content', | |
202 | value: 'images', | |
203 | multiSelect: true, | |
204 | fieldLabel: gettext('Content'), | |
6bea400e | 205 | allowBlank: false, |
dad14ab0 | 206 | }, |
ca9a198a WL |
207 | { |
208 | xtype: me.isCreate ? 'textfield' : 'displayfield', | |
209 | name: 'domain', | |
210 | value: me.isCreate ? '' : undefined, | |
211 | fieldLabel: gettext('Domain'), | |
212 | allowBlank: true, | |
213 | listeners: { | |
214 | change: function(f, value) { | |
215 | if (me.isCreate) { | |
6bea400e | 216 | let exportField = me.down('field[name=share]'); |
ca9a198a WL |
217 | exportField.setDomain(value); |
218 | } | |
6bea400e TL |
219 | }, |
220 | }, | |
221 | }, | |
711658f4 LN |
222 | { |
223 | xtype: 'pmxDisplayEditField', | |
224 | editable: me.isCreate, | |
225 | name: 'subdir', | |
226 | fieldLabel: gettext('Subdirectory'), | |
227 | allowBlank: true, | |
228 | emptyText: gettext('/some/path'), | |
229 | }, | |
ca9a198a WL |
230 | ]; |
231 | ||
232 | me.callParent(); | |
6bea400e | 233 | }, |
ca9a198a | 234 | }); |