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