]>
Commit | Line | Data |
---|---|---|
607c37ef TM |
1 | Ext.define('Proxmox.form.NetworkSelectorController', { |
2 | extend: 'Ext.app.ViewController', | |
3 | alias: 'controller.proxmoxNetworkSelectorController', | |
4 | ||
5 | init: function(view) { | |
05a977a2 | 6 | let me = this; |
607c37ef TM |
7 | |
8 | if (!view.nodename) { | |
9 | throw "missing custom view config: nodename"; | |
10 | } | |
11 | view.getStore().getProxy().setUrl('/api2/json/nodes/'+ view.nodename + '/network'); | |
01031528 | 12 | }, |
607c37ef TM |
13 | }); |
14 | ||
15 | Ext.define('Proxmox.data.NetworkSelector', { | |
16 | extend: 'Ext.data.Model', | |
17 | fields: [ | |
01031528 TL |
18 | { name: 'active' }, |
19 | { name: 'cidr' }, | |
20 | { name: 'cidr6' }, | |
21 | { name: 'address' }, | |
22 | { name: 'address6' }, | |
23 | { name: 'comments' }, | |
24 | { name: 'iface' }, | |
25 | { name: 'slaves' }, | |
26 | { name: 'type' }, | |
27 | ], | |
607c37ef TM |
28 | }); |
29 | ||
30 | Ext.define('Proxmox.form.NetworkSelector', { | |
31 | extend: 'Proxmox.form.ComboGrid', | |
32 | alias: 'widget.proxmoxNetworkSelector', | |
33 | ||
607c37ef | 34 | controller: 'proxmoxNetworkSelectorController', |
1dd79958 TL |
35 | |
36 | nodename: 'localhost', | |
607c37ef TM |
37 | setNodename: function(nodename) { |
38 | this.nodename = nodename; | |
05a977a2 | 39 | let networkSelectorStore = this.getStore(); |
607c37ef TM |
40 | networkSelectorStore.removeAll(); |
41 | // because of manual local copy of data for ip4/6 | |
42 | this.getPicker().refresh(); | |
43 | if (networkSelectorStore && typeof networkSelectorStore.getProxy === 'function') { | |
44 | networkSelectorStore.getProxy().setUrl('/api2/json/nodes/'+ nodename + '/network'); | |
45 | networkSelectorStore.load(); | |
46 | } | |
47 | }, | |
48 | // set default value to empty array, else it inits it with | |
49 | // null and after the store load it is an empty array, | |
50 | // triggering dirtychange | |
51 | value: [], | |
52 | valueField: 'cidr', | |
53 | displayField: 'cidr', | |
54 | store: { | |
55 | autoLoad: true, | |
56 | model: 'Proxmox.data.NetworkSelector', | |
57 | proxy: { | |
01031528 | 58 | type: 'proxmox', |
607c37ef TM |
59 | }, |
60 | sorters: [ | |
61 | { | |
01031528 TL |
62 | property: 'iface', |
63 | direction: 'ASC', | |
64 | }, | |
607c37ef TM |
65 | ], |
66 | filters: [ | |
67 | function(item) { | |
68 | return item.data.cidr; | |
01031528 | 69 | }, |
607c37ef TM |
70 | ], |
71 | listeners: { | |
72 | load: function(store, records, successfull) { | |
e6bf8a81 | 73 | if (successfull) { |
607c37ef | 74 | records.forEach(function(record) { |
e6bf8a81 | 75 | if (record.data.cidr6) { |
01031528 | 76 | let dest = record.data.cidr ? record.copy(null) : record; |
e6bf8a81 | 77 | dest.data.cidr = record.data.cidr6; |
1dd79958 | 78 | dest.data.address = record.data.address6; |
607c37ef | 79 | delete record.data.cidr6; |
e6bf8a81 | 80 | dest.data.comments = record.data.comments6; |
607c37ef | 81 | delete record.data.comments6; |
e6bf8a81 | 82 | store.add(dest); |
607c37ef TM |
83 | } |
84 | }); | |
85 | } | |
01031528 TL |
86 | }, |
87 | }, | |
607c37ef TM |
88 | }, |
89 | listConfig: { | |
90 | width: 600, | |
91 | columns: [ | |
ce8c5365 TL |
92 | { |
93 | ||
94 | header: gettext('CIDR'), | |
95 | dataIndex: 'cidr', | |
96 | hideable: false, | |
01031528 | 97 | flex: 1, |
ce8c5365 | 98 | }, |
1dd79958 TL |
99 | { |
100 | ||
101 | header: gettext('IP'), | |
102 | dataIndex: 'address', | |
103 | hidden: true, | |
104 | }, | |
607c37ef TM |
105 | { |
106 | header: gettext('Interface'), | |
ce8c5365 | 107 | width: 90, |
01031528 | 108 | dataIndex: 'iface', |
607c37ef TM |
109 | }, |
110 | { | |
111 | header: gettext('Active'), | |
ce8c5365 TL |
112 | renderer: Proxmox.Utils.format_boolean, |
113 | width: 60, | |
01031528 | 114 | dataIndex: 'active', |
607c37ef | 115 | }, |
607c37ef TM |
116 | { |
117 | header: gettext('Type'), | |
ce8c5365 TL |
118 | width: 80, |
119 | hidden: true, | |
01031528 | 120 | dataIndex: 'type', |
607c37ef TM |
121 | }, |
122 | { | |
123 | header: gettext('Comment'), | |
ce8c5365 | 124 | flex: 2, |
01031528 TL |
125 | dataIndex: 'comments', |
126 | }, | |
127 | ], | |
128 | }, | |
607c37ef | 129 | }); |