]>
Commit | Line | Data |
---|---|---|
1 | Ext.define('Proxmox.panel.AuthView', { | |
2 | extend: 'Ext.grid.GridPanel', | |
3 | ||
4 | alias: 'widget.pmxAuthView', | |
5 | ||
6 | stateful: true, | |
7 | stateId: 'grid-authrealms', | |
8 | ||
9 | viewConfig: { | |
10 | trackOver: false, | |
11 | }, | |
12 | ||
13 | columns: [ | |
14 | { | |
15 | header: gettext('Realm'), | |
16 | width: 100, | |
17 | sortable: true, | |
18 | dataIndex: 'realm', | |
19 | }, | |
20 | { | |
21 | header: gettext('Type'), | |
22 | width: 100, | |
23 | sortable: true, | |
24 | dataIndex: 'type', | |
25 | }, | |
26 | { | |
27 | header: gettext('Comment'), | |
28 | sortable: false, | |
29 | dataIndex: 'comment', | |
30 | renderer: Ext.String.htmlEncode, | |
31 | flex: 1, | |
32 | }, | |
33 | ], | |
34 | ||
35 | store: { | |
36 | model: 'pmx-domains', | |
37 | sorters: { | |
38 | property: 'realm', | |
39 | order: 'DESC', | |
40 | }, | |
41 | }, | |
42 | ||
43 | openEditWindow: function(authType, realm) { | |
44 | let me = this; | |
45 | Ext.create('Proxmox.window.AuthEditBase', { | |
46 | authType, | |
47 | realm, | |
48 | listeners: { | |
49 | destroy: () => me.reload(), | |
50 | }, | |
51 | }).show(); | |
52 | }, | |
53 | ||
54 | reload: function() { | |
55 | let me = this; | |
56 | me.getStore().load(); | |
57 | }, | |
58 | ||
59 | run_editor: function() { | |
60 | let me = this; | |
61 | let rec = me.getSelection()[0]; | |
62 | if (!rec) { | |
63 | return; | |
64 | } | |
65 | ||
66 | if (!Proxmox.Utils.authSchema[rec.data.type].edit) { | |
67 | return; | |
68 | } | |
69 | ||
70 | me.openEditWindow(rec.data.type, rec.data.realm); | |
71 | }, | |
72 | ||
73 | initComponent: function() { | |
74 | var me = this; | |
75 | ||
76 | let menuitems = []; | |
77 | for (const [authType, config] of Object.entries(Proxmox.Utils.authSchema).sort()) { | |
78 | if (!config.add) { continue; } | |
79 | menuitems.push({ | |
80 | text: config.name, | |
81 | iconCls: 'fa fa-fw ' + (config.iconCls || 'fa-address-book-o'), | |
82 | handler: () => me.openEditWindow(authType), | |
83 | }); | |
84 | } | |
85 | ||
86 | let tbar = [ | |
87 | { | |
88 | text: gettext('Add'), | |
89 | menu: { | |
90 | items: menuitems, | |
91 | }, | |
92 | }, | |
93 | { | |
94 | xtype: 'proxmoxButton', | |
95 | text: gettext('Edit'), | |
96 | disabled: true, | |
97 | enableFn: (rec) => Proxmox.Utils.authSchema[rec.data.type].edit, | |
98 | handler: () => me.run_editor(), | |
99 | }, | |
100 | { | |
101 | xtype: 'proxmoxStdRemoveButton', | |
102 | baseurl: '/access/domains/', | |
103 | enableFn: (rec) => Proxmox.Utils.authSchema[rec.data.type].add, | |
104 | callback: () => me.reload(), | |
105 | }, | |
106 | ]; | |
107 | ||
108 | if (me.extraButtons) { | |
109 | tbar.push('-'); | |
110 | for (const button of me.extraButtons) { | |
111 | tbar.push(button); | |
112 | } | |
113 | } | |
114 | ||
115 | Ext.apply(me, { | |
116 | tbar, | |
117 | listeners: { | |
118 | activate: () => me.reload(), | |
119 | itemdblclick: () => me.run_editor(), | |
120 | }, | |
121 | }); | |
122 | ||
123 | me.callParent(); | |
124 | }, | |
125 | }); |