]>
git.proxmox.com Git - pmg-gui.git/blob - js/ObjectGroup.js
8c72dd229bd252b6a8a3e57e19263172283b785f
1 Ext
.define('PMG.ObjectGroup', {
2 extend
: 'Ext.grid.GridPanel',
3 alias
: 'widget.pmgObjectGroup',
10 showDirection
: false, // only important for SMTP Whitelist
13 objectClass
: undefined,
15 emptyText
: gettext('Please select an object.'),
17 setBaseUrl: function(baseurl
) {
22 if (me
.baseurl
=== undefined) {
23 me
.store
.proxy
.setUrl(undefined);
25 me
.setButtonState(me
.store
, [], false);
27 let url
= '/api2/json' + me
.baseurl
+ '/objects';
28 me
.store
.proxy
.setUrl(url
);
33 setObjectInfo: function(ogdata
) {
36 let mode
= ogdata
?.invert
? 'not' : '';
37 mode
+= ogdata
?.and
? 'all' : 'any';
41 if (me
.ogdata
=== undefined) {
42 me
.down('#oginfo').update(me
.emptyText
);
43 me
.down('#modeBox').setHidden(true);
44 me
.down('#whatWarning').setHidden(true);
46 let html
= '<b style="font-weight: bold;">' + Ext
.String
.htmlEncode(me
.ogdata
.name
) + '</b>';
48 html
+= Ext
.String
.htmlEncode(Ext
.String
.trim(me
.ogdata
.info
));
50 me
.down('#oginfo').update(html
);
51 me
.down('#ogdata').setHidden(false);
52 let modeSelector
= me
.down('#modeSelector');
53 modeSelector
.suspendEvents();
54 me
.down('#modeSelector').setValue(mode
);
55 modeSelector
.resumeEvents();
56 me
.down('#modeBox').setHidden(false);
57 me
.down('#whatWarning').setHidden(me
.objectClass
!== 'what' || mode
=== 'any');
61 setButtonState: function(store
, records
, success
) {
63 if (!success
|| !me
.baseurl
) {
64 me
.down('#addMenuButton').setDisabled(true);
67 me
.down('#addMenuButton').setDisabled(false);
70 initComponent: function() {
73 me
.store
= new Ext
.data
.Store({
74 model
: 'pmg-object-list',
80 property
: 'receivertest',
90 header
: gettext('Type'),
92 renderer
: PMG
.Utils
.format_otype
,
96 if (me
.showDirection
) {
98 header
: gettext('Direction'),
99 dataIndex
: 'receivertest',
100 renderer: function(value
) {
101 return value
? PMG
.Utils
.receiverText
: PMG
.Utils
.senderText
;
107 header
: gettext('Value'),
109 renderer
: Ext
.String
.htmlEncode
,
113 let reload = function() {
117 me
.selModel
= Ext
.create('Ext.selection.RowModel', {});
119 let remove_btn
= Ext
.createWidget('proxmoxStdRemoveButton', {
120 selModel
: me
.selModel
,
121 getUrl: function(rec
) {
122 return me
.baseurl
+ '/objects/' + rec
.data
.id
;
125 getRecordName: function(rec
) {
126 return PMG
.Utils
.format_otype(rec
.data
.otype
) +
127 ': ' + rec
.data
.descr
;
132 let full_subject = function(subject
, receivertest
) {
133 if (me
.showDirection
) {
134 let direction
= receivertest
135 ? PMG
.Utils
.receiverText
: PMG
.Utils
.senderText
;
137 return subject
+ ' (' + direction
+ ')';
143 let run_editor = function() {
144 let rec
= me
.selModel
.getSelection()[0];
149 let editor
= PMG
.Utils
.object_editors
[rec
.data
.otype
];
150 if (!editor
|| editor
.uneditable
) {
154 let config
= Ext
.apply({ method
: 'PUT' }, editor
);
155 config
.subject
= full_subject(editor
.subject
, rec
.data
.receivertest
);
156 config
.url
= me
.baseurl
+ '/' + editor
.subdir
+ '/' + rec
.data
.id
;
158 let win
= Ext
.createWidget(config
);
161 win
.on('destroy', reload
);
167 Ext
.Array
.each(me
.otype_list
, function(otype
) {
168 let editor
= PMG
.Utils
.object_editors
[otype
];
170 let config
= Ext
.apply({ method
: 'POST' }, editor
);
171 config
.subject
= full_subject(editor
.subject
, editor
.receivertest
);
174 text
: config
.subject
,
175 iconCls
: config
.iconCls
|| 'fa fa-question-circle',
176 handler: function() {
177 if (me
.baseurl
=== undefined) {
180 config
.url
= me
.baseurl
+ '/' + editor
.subdir
;
181 let win
= Ext
.create(config
);
182 win
.on('destroy', reload
);
190 me
.dockedItems
.push({
195 text
: gettext('Add'),
197 itemId
: 'addMenuButton',
203 xtype
: 'proxmoxButton',
204 text
: gettext('Edit'),
206 selModel
: me
.selModel
,
207 enableFn: function(rec
) {
208 let editor
= PMG
.Utils
.object_editors
[rec
.data
.otype
];
209 return editor
&& !editor
.uneditable
;
216 xtype
: 'pmgFilterField',
220 renderer
: (otype
) => PMG
.Utils
.object_editors
[otype
].subject
,
228 me
.dockedItems
.push({
232 hidden
: !!me
.hideGroupInfo
,
248 html
: `<b style="font-weight: bold;">${gettext("Match if")}</b>`,
251 xtype
: 'pmgMatchModeSelector',
252 itemId
: 'modeSelector',
255 change: function(_field
, value
) {
256 let invert
= value
.startsWith('not') ? 1 : 0;
257 let and
= value
.endsWith('all') ? 1 : 0;
259 Proxmox
.Utils
.API2Request({
260 url
: `${me.baseurl}/config`,
267 me
.fireEvent('modeUpdate', me
, !!and
, !!invert
);
268 me
.down('#whatWarning')
269 .setHidden(me
.objectClass
!== 'what' || value
=== 'any');
281 style
: { 'white-space': 'pre' },
287 if (me
.ogdata
=== undefined) { return; }
288 me
.fireEvent('dblclickOGInfo', me
, e
, t
, me
.ogdata
);
298 me
.dockedItems
.push({
302 itemId
: 'whatWarning',
305 xtype
: 'displayfield',
307 value
: gettext("Caution: 'What Objects' match each mail part separately, so be careful with any option besides 'Any matches'."),
312 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
315 run_editor
: run_editor
,
317 itemdblclick
: run_editor
,
324 me
.mon(me
.store
, 'load', me
.setButtonState
, me
);
327 me
.setBaseUrl(me
.baseurl
); // configure store, load()