]>
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 | ||
71 | if(successfull) { | |
72 | records.forEach(function(record) { | |
73 | if(record.data.cidr && record.data.cidr6) { | |
74 | var tempcopy = record.copy(null); | |
75 | tempcopy.data.cidr = tempcopy.data.cidr6; | |
76 | delete tempcopy.data.cidr6; | |
77 | tempcopy.data.comment = tempcopy.data.comments6; | |
78 | delete tempcopy.data.comments6; | |
79 | store.add(tempcopy); | |
80 | } | |
81 | ||
82 | if(!record.data.cidr && record.data.cidr6) { | |
83 | record.data.cidr = record.data.cidr6; | |
84 | delete record.data.cidr6; | |
85 | record.data.comments = record.data.comments6; | |
86 | delete record.data.comments6; | |
87 | store.add(record); | |
88 | } | |
89 | }); | |
90 | } | |
91 | } | |
92 | } | |
93 | }, | |
94 | listConfig: { | |
95 | width: 600, | |
96 | columns: [ | |
ce8c5365 TL |
97 | { |
98 | ||
99 | header: gettext('CIDR'), | |
100 | dataIndex: 'cidr', | |
101 | hideable: false, | |
102 | flex: 1 | |
103 | }, | |
607c37ef TM |
104 | { |
105 | header: gettext('Interface'), | |
ce8c5365 | 106 | width: 90, |
607c37ef TM |
107 | dataIndex: 'iface' |
108 | }, | |
109 | { | |
110 | header: gettext('Active'), | |
ce8c5365 TL |
111 | renderer: Proxmox.Utils.format_boolean, |
112 | width: 60, | |
607c37ef TM |
113 | dataIndex: 'active' |
114 | }, | |
607c37ef TM |
115 | { |
116 | header: gettext('Type'), | |
ce8c5365 TL |
117 | width: 80, |
118 | hidden: true, | |
607c37ef TM |
119 | dataIndex: 'type' |
120 | }, | |
121 | { | |
122 | header: gettext('Comment'), | |
ce8c5365 | 123 | flex: 2, |
607c37ef TM |
124 | dataIndex: 'comments' |
125 | } | |
126 | ] | |
127 | } | |
128 | }); |