]>
Commit | Line | Data |
---|---|---|
968270ae TL |
1 | Ext.define('pbs-namespaces', { |
2 | extend: 'Ext.data.Model', | |
3 | fields: [ | |
4 | { | |
5 | name: 'ns', | |
6 | }, | |
7 | { | |
8 | name: 'id', // fake as else the model messes with our value and/or display... | |
9 | type: 'string', | |
10 | calculate: data => data.ns === '' ? '/' : data.ns, | |
11 | }, | |
12 | ], | |
13 | idProperty: 'id', | |
14 | }); | |
15 | ||
16 | Ext.define('PBS.form.NamespaceSelector', { | |
17 | extend: 'Ext.form.field.ComboBox', | |
18 | alias: 'widget.pbsNamespaceSelector', | |
19 | ||
20 | allowBlank: true, | |
21 | autoSelect: true, | |
22 | valueField: 'ns', | |
23 | ||
24 | displayField: 'ns', | |
25 | emptyText: gettext('Root'), | |
26 | ||
27 | editable: true, | |
28 | anyMatch: true, | |
29 | forceSelection: true, | |
4f897c8c | 30 | queryMode: 'local', |
968270ae TL |
31 | |
32 | matchFieldWidth: false, | |
33 | listConfig: { | |
34 | minWidth: 170, | |
35 | maxWidth: 500, | |
36 | // below doesn't work :/ | |
5e1b1701 DC |
37 | minHeight: 30, |
38 | emptyText: `<div class="x-grid-empty">${gettext('No namespaces accessible.')}</div>`, | |
968270ae TL |
39 | }, |
40 | ||
41 | triggers: { | |
42 | clear: { | |
43 | cls: 'pmx-clear-trigger', | |
44 | weight: -1, | |
45 | hidden: true, | |
46 | handler: function() { | |
47 | this.triggers.clear.setVisible(false); | |
48 | this.setValue(''); | |
49 | }, | |
50 | }, | |
51 | }, | |
52 | ||
53 | listeners: { | |
54 | change: function(field, value) { | |
55 | let canClear = value !== ''; | |
56 | field.triggers.clear.setVisible(canClear); | |
57 | }, | |
58 | }, | |
59 | ||
9d809062 TL |
60 | setDatastore: function(datastore) { |
61 | let me = this; | |
62 | if (datastore ?? false) { | |
63 | me.datastore = datastore; | |
64 | me.store.getProxy().setUrl(`/api2/json/admin/datastore/${me.datastore}/namespace`); | |
65 | if (me.isDisabled()) { | |
66 | me.setDisabled(false); | |
67 | } | |
68 | me.store.load(); | |
69 | me.validate(); | |
b70a12e7 DC |
70 | } else { |
71 | me.datastore = undefined; | |
72 | me.setDisabled(true); | |
9d809062 TL |
73 | } |
74 | }, | |
75 | ||
968270ae TL |
76 | initComponent: function() { |
77 | let me = this; | |
78 | if (!me.datastore) { | |
9d809062 | 79 | me.disabled = true; |
968270ae TL |
80 | } |
81 | ||
82 | me.store = Ext.create('Ext.data.Store', { | |
83 | model: 'pbs-namespaces', | |
9d809062 | 84 | autoLoad: !!me.datastore, |
5e1b1701 | 85 | filters: (rec) => rec.data.ns !== '', |
968270ae TL |
86 | proxy: { |
87 | type: 'proxmox', | |
88 | timeout: 30 * 1000, | |
89 | url: `/api2/json/admin/datastore/${me.datastore}/namespace`, | |
90 | }, | |
91 | }); | |
92 | ||
93 | me.callParent(); | |
94 | }, | |
95 | }); |