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