]>
Commit | Line | Data |
---|---|---|
14d9ecc4 | 1 | Ext.define('PVE.form.ComboBoxSetStoreNode', { |
d420b29a | 2 | extend: 'Proxmox.form.ComboGrid', |
14d9ecc4 SH |
3 | config: { |
4 | apiBaseUrl: '/api2/json/nodes/', | |
5 | apiSuffix: '', | |
6 | }, | |
7 | ||
d420b29a DC |
8 | showNodeSelector: false, |
9 | ||
14d9ecc4 SH |
10 | setNodeName: function(value) { |
11 | let me = this; | |
12 | value ||= Proxmox.NodeName; | |
13 | ||
14 | me.getStore().getProxy().setUrl(`${me.apiBaseUrl}${value}${me.apiSuffix}`); | |
d420b29a DC |
15 | me.clearValue(); |
16 | }, | |
17 | ||
18 | nodeChange: function(_field, value) { | |
19 | let me = this; | |
20 | // disable autoSelect if there is already a selection or we have the picker open | |
21 | if (me.getValue() || me.isExpanded) { | |
22 | let autoSelect = me.autoSelect; | |
23 | me.autoSelect = false; | |
24 | me.store.on('afterload', function() { | |
25 | me.autoSelect = autoSelect; | |
26 | }, { single: true }); | |
27 | } | |
28 | me.setNodeName(value); | |
29 | me.fireEvent('nodechanged', value); | |
14d9ecc4 SH |
30 | }, |
31 | ||
7528c257 | 32 | tbarMouseDown: function() { |
ab4ea492 | 33 | this.topBarMousePress = true; |
7528c257 DC |
34 | }, |
35 | ||
36 | tbarMouseUp: function() { | |
37 | let me = this; | |
ab4ea492 | 38 | delete this.topBarMousePress; |
7528c257 DC |
39 | if (me.focusLeft) { |
40 | me.focus(); | |
41 | delete me.focusLeft; | |
42 | } | |
43 | }, | |
44 | ||
45 | // conditionally prevent the focusLeave handler to continue, preventing collapsing of the picker | |
46 | onFocusLeave: function() { | |
47 | let me = this; | |
48 | me.focusLeft = true; | |
ab4ea492 | 49 | if (!me.topBarMousePress) { |
7528c257 DC |
50 | me.callParent(arguments); |
51 | } | |
52 | ||
53 | return undefined; | |
54 | }, | |
55 | ||
d420b29a DC |
56 | initComponent: function() { |
57 | let me = this; | |
58 | ||
59 | if (me.showNodeSelector && PVE.data.ResourceStore.getNodes().length > 1) { | |
60 | me.errorHeight = 140; | |
61 | Ext.apply(me.listConfig ?? {}, { | |
62 | tbar: { | |
63 | xtype: 'toolbar', | |
7b668b16 | 64 | minHeight: 40, |
7528c257 DC |
65 | listeners: { |
66 | mousedown: me.tbarMouseDown, | |
67 | mouseup: me.tbarMouseUp, | |
68 | element: 'el', | |
69 | scope: me, | |
70 | }, | |
d420b29a DC |
71 | items: [ |
72 | { | |
73 | xtype: "pveStorageScanNodeSelector", | |
74 | autoSelect: false, | |
75 | fieldLabel: gettext('Node to scan'), | |
76 | listeners: { | |
77 | change: (field, value) => me.nodeChange(field, value), | |
78 | }, | |
79 | }, | |
80 | ], | |
81 | }, | |
82 | emptyText: me.listConfig?.emptyText ?? gettext('Nothing found'), | |
83 | }); | |
84 | } | |
85 | ||
86 | me.callParent(); | |
87 | }, | |
14d9ecc4 | 88 | }); |