]>
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) { | |
6 | var me = this; | |
7 | ||
8 | if (!view.nodename) { | |
9 | throw "missing custom view config: nodename"; | |
10 | } | |
11 | view.getStore().getProxy().setUrl('/api2/json/nodes/'+ view.nodename + '/network'); | |
12 | } | |
13 | }); | |
14 | ||
15 | Ext.define('Proxmox.data.NetworkSelector', { | |
16 | extend: 'Ext.data.Model', | |
17 | fields: [ | |
18 | {name: 'active'}, | |
19 | {name: 'cidr'}, | |
20 | {name: 'cidr6'}, | |
1dd79958 TL |
21 | {name: 'address'}, |
22 | {name: 'address6'}, | |
607c37ef TM |
23 | {name: 'comments'}, |
24 | {name: 'iface'}, | |
25 | {name: 'slaves'}, | |
26 | {name: 'type'} | |
27 | ] | |
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; | |
39 | var networkSelectorStore = this.getStore(); | |
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: { | |
58 | type: 'proxmox' | |
59 | }, | |
60 | sorters: [ | |
61 | { | |
62 | property : 'iface', | |
63 | direction: 'ASC' | |
64 | } | |
65 | ], | |
66 | filters: [ | |
67 | function(item) { | |
68 | return item.data.cidr; | |
69 | } | |
70 | ], | |
71 | listeners: { | |
72 | load: function(store, records, successfull) { | |
73 | ||
e6bf8a81 | 74 | if (successfull) { |
607c37ef | 75 | records.forEach(function(record) { |
e6bf8a81 TL |
76 | if (record.data.cidr6) { |
77 | let dest = (record.data.cidr) ? record.copy(null) : record; | |
78 | dest.data.cidr = record.data.cidr6; | |
1dd79958 | 79 | dest.data.address = record.data.address6; |
607c37ef | 80 | delete record.data.cidr6; |
e6bf8a81 | 81 | dest.data.comments = record.data.comments6; |
607c37ef | 82 | delete record.data.comments6; |
e6bf8a81 | 83 | store.add(dest); |
607c37ef TM |
84 | } |
85 | }); | |
86 | } | |
87 | } | |
88 | } | |
89 | }, | |
90 | listConfig: { | |
91 | width: 600, | |
92 | columns: [ | |
ce8c5365 TL |
93 | { |
94 | ||
95 | header: gettext('CIDR'), | |
96 | dataIndex: 'cidr', | |
97 | hideable: false, | |
98 | flex: 1 | |
99 | }, | |
1dd79958 TL |
100 | { |
101 | ||
102 | header: gettext('IP'), | |
103 | dataIndex: 'address', | |
104 | hidden: true, | |
105 | }, | |
607c37ef TM |
106 | { |
107 | header: gettext('Interface'), | |
ce8c5365 | 108 | width: 90, |
607c37ef TM |
109 | dataIndex: 'iface' |
110 | }, | |
111 | { | |
112 | header: gettext('Active'), | |
ce8c5365 TL |
113 | renderer: Proxmox.Utils.format_boolean, |
114 | width: 60, | |
607c37ef TM |
115 | dataIndex: 'active' |
116 | }, | |
607c37ef TM |
117 | { |
118 | header: gettext('Type'), | |
ce8c5365 TL |
119 | width: 80, |
120 | hidden: true, | |
607c37ef TM |
121 | dataIndex: 'type' |
122 | }, | |
123 | { | |
124 | header: gettext('Comment'), | |
ce8c5365 | 125 | flex: 2, |
607c37ef TM |
126 | dataIndex: 'comments' |
127 | } | |
128 | ] | |
129 | } | |
130 | }); |