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