]>
Commit | Line | Data |
---|---|---|
f5de8682 DM |
1 | Ext.define('pmg-action-list', { |
2 | extend: 'Ext.data.Model', | |
3 | fields: [ | |
4 | 'id', 'name', 'info', 'descr', | |
5 | { name: 'otype', type: 'integer' }, | |
6 | ], | |
7 | idProperty: 'id' | |
8 | }); | |
9 | ||
39700611 | 10 | Ext.define('PMG.ActionList', { |
f5de8682 | 11 | extend: 'Ext.grid.GridPanel', |
39700611 | 12 | alias: ['widget.pmgActionList'], |
f5de8682 DM |
13 | |
14 | title: PMG.Utils.oclass_text['action'], | |
f2ca0a1a | 15 | border: false, |
f5de8682 DM |
16 | |
17 | baseurl: '/config/ruledb/action', | |
18 | ||
19 | otype_list: [4005], | |
20 | ||
39700611 DM |
21 | enableButtons: true, |
22 | ||
f5de8682 DM |
23 | initComponent : function() { |
24 | var me = this; | |
25 | ||
26 | me.store = new Ext.data.Store({ | |
27 | model: 'pmg-action-list', | |
28 | proxy: { | |
29 | type: 'proxmox', | |
30 | url: "/api2/json" + me.baseurl + '/objects', | |
31 | }, | |
32 | sorters: { | |
33 | property: 'name', | |
34 | order: 'DESC' | |
35 | } | |
36 | }); | |
37 | ||
38 | me.selModel = Ext.create('Ext.selection.RowModel', {}); | |
39 | ||
40 | var reload = function() { | |
41 | me.store.load(); | |
42 | }; | |
43 | ||
44 | var run_editor = function() { | |
45 | var rec = me.selModel.getSelection()[0]; | |
46 | if (!rec) { | |
47 | return; | |
48 | } | |
49 | ||
50 | var editor = PMG.Utils.object_editors[rec.data.otype]; | |
51 | if (!editor) { | |
52 | return; | |
53 | } | |
54 | ||
55 | var config = Ext.apply({ method: 'PUT' }, editor); | |
39700611 | 56 | |
f5de8682 DM |
57 | config.url = me.baseurl + '/' + editor.subdir + '/' + rec.data.id; |
58 | ||
59 | var win = Ext.createWidget('proxmoxWindowEdit', config); | |
60 | ||
61 | win.load(); | |
62 | win.on('destroy', reload); | |
63 | win.show(); | |
64 | }; | |
65 | ||
66 | var remove_btn = Ext.createWidget('proxmoxButton', { | |
67 | text: gettext('Remove'), | |
68 | disabled: true, | |
69 | selModel: me.selModel, | |
70 | confirmMsg: function (rec) { | |
71 | return Ext.String.format( | |
72 | gettext('Are you sure you want to remove entry {0}'), | |
73 | "'" + rec.data.descr + "'"); | |
74 | }, | |
75 | handler: function(btn, event, rec) { | |
76 | Proxmox.Utils.API2Request({ | |
77 | url: me.baseurl + '/objects/' + rec.data.id, | |
78 | method: 'DELETE', | |
79 | waitMsgTarget: me, | |
80 | callback: reload, | |
81 | failure: function (response, opts) { | |
82 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
83 | } | |
84 | }); | |
85 | } | |
86 | }); | |
87 | ||
88 | var menu_items = []; | |
89 | ||
90 | Ext.Array.each(me.otype_list, function(otype) { | |
91 | ||
92 | var editor = PMG.Utils.object_editors[otype]; | |
93 | ||
94 | var config = Ext.apply({ method: 'POST' }, editor); | |
95 | ||
96 | config.create = true, | |
97 | menu_items.push({ | |
98 | text: config.subject, | |
99 | handler: function() { | |
100 | if (me.baseurl == undefined) { | |
101 | return; | |
102 | } | |
103 | config.url = me.baseurl + '/' + editor.subdir; | |
104 | var win = Ext.createWidget('proxmoxWindowEdit', config); | |
105 | win.on('destroy', reload); | |
106 | win.show(); | |
107 | } | |
108 | }); | |
109 | }); | |
110 | ||
111 | var tbar = [ | |
112 | { | |
113 | text: gettext('Add'), | |
114 | menu: new Ext.menu.Menu({ | |
115 | items: menu_items | |
116 | }) | |
117 | }, | |
118 | { | |
119 | xtype: 'proxmoxButton', | |
120 | text: gettext('Edit'), | |
121 | disabled: true, | |
122 | selModel: me.selModel, | |
123 | handler: run_editor | |
124 | }, | |
125 | remove_btn | |
126 | ]; | |
127 | ||
128 | Proxmox.Utils.monStoreErrors(me, me.store); | |
129 | ||
39700611 DM |
130 | if (me.enableButtons) { |
131 | me.tbar = tbar; | |
132 | } | |
133 | ||
f5de8682 | 134 | Ext.apply(me, { |
f5de8682 DM |
135 | columns: [ |
136 | { | |
137 | header: gettext('Name'), | |
138 | sortable: true, | |
139 | width: 200, | |
140 | dataIndex: 'name', | |
141 | renderer: Ext.String.htmlEncode | |
142 | }, | |
143 | { | |
144 | header: gettext('Description'), | |
145 | sortable: true, | |
146 | width: 300, | |
147 | dataIndex: 'descr', | |
148 | renderer: Ext.String.htmlEncode | |
149 | }, | |
150 | { | |
151 | header: gettext('Comment'), | |
152 | sortable: false, | |
153 | flex: 1, | |
154 | dataIndex: 'info', | |
155 | renderer: Ext.String.htmlEncode | |
156 | }, | |
157 | ], | |
158 | listeners: { | |
39700611 DM |
159 | itemdblclick: function() { |
160 | if (me.enableButtons) { | |
161 | run_editor(); | |
162 | } | |
163 | }, | |
f5de8682 DM |
164 | activate: reload |
165 | } | |
166 | }); | |
167 | ||
168 | me.callParent(); | |
169 | ||
170 | reload(); // initial load | |
171 | } | |
172 | }); |