// this singleton contains miscellaneous utilities
+ // use in panels with object spread (...) operator, for example:
+ // ...PMG.Utils.onlineHelpTool('sysadmin_certificate_management'),
+ onlineHelpTool: function(blockid) {
+ let info = Proxmox.Utils.get_help_info(blockid);
+ if (info === undefined) {
+ info = Proxmox.Utils.get_help_info('pmg_documentation_index');
+ if (info === undefined) {
+ throw "get_help_info failed"; // should not happen
+ }
+ }
+
+ let docsURI = window.location.origin + info.link;
+ let title = info.title || gettext('Help');
+ if (info.subtitle) {
+ title += ' - ' + info.subtitle;
+ }
+ return {
+ tools: [
+ {
+ type: 'help',
+ tooltip: title,
+ handler: () => window.open(docsURI),
+ },
+ ],
+ };
+ },
+
senderText: gettext('Sender'),
receiverText: gettext('Receiver'),
scoreText: gettext('Score'),
},
format_otype: function(otype) {
- var editor = PMG.Utils.object_editors[otype];
- var iconCls = 'fa fa-question-circle';
+ let editor = PMG.Utils.object_editors[otype];
+ let iconCls = 'fa fa-question-circle';
if (editor) {
- var icon = '<span class="fa-fw ' + (editor.iconCls || iconCls) + '"></span> ';
- return icon + editor.subject;
+ return `<span class="fa-fw ${editor.iconCls || iconCls}"></span> ${editor.subject}`;
}
-
- return '<span class="fa-fw ' + iconCls + '"></span> unknown';
+ return `<span class="fa-fw ${iconCls}"></span> unknown`;
},
format_ldap_protocol: function(p) {
},
convert_field_to_per_min: function(value, record) {
- return value/(record.data.timespan/60);
+ return value / (record.data.timespan / 60);
},
object_editors: {
{
xtype: 'textfield',
name: 'regex',
- labelWidth: 150,
reference: 'regex',
- fieldLabel: gettext("Regular Expression"),
+ fieldLabel: gettext("Regex"),
},
{
- labelWidth: 150,
- fieldLabel: gettext('Test String'),
xtype: 'pmgRegexTester',
+ fieldLabel: gettext('Test String'),
wholeMatch: true,
regexFieldReference: 'regex',
},
{
xtype: 'textfield',
name: 'regex',
- labelWidth: 150,
- fieldLabel: gettext("Regular Expression"),
+ fieldLabel: gettext("Regex"),
},
],
},
{
xtype: 'textfield',
name: 'field',
- labelWidth: 150,
allowBlank: false,
fieldLabel: gettext('Field'),
},
{
xtype: 'textfield',
- reference: 'value',
name: 'value',
- labelWidth: 150,
+ reference: 'value',
allowBlank: false,
fieldLabel: gettext('Value'),
},
{
- labelWidth: 150,
- fieldLabel: gettext('Test String'),
xtype: 'pmgRegexTester',
+ fieldLabel: gettext('Test String'),
regexFieldReference: 'value',
},
],
{
xtype: 'combobox',
displayField: 'text',
- labelWidth: 150,
valueField: 'mimetype',
name: 'contenttype',
editable: true,
{
xtype: 'displayfield',
fieldLabel: gettext('Value'),
- labelWidth: 150,
allowBlank: false,
reset: Ext.emptyFn,
},
name: 'filename',
reference: 'filename',
fieldLabel: gettext('Filename'),
- labelWidth: 150,
allowBlank: false,
},
{
- labelWidth: 150,
+ xtype: 'pmgRegexTester',
fieldLabel: gettext('Test String'),
wholeMatch: true,
- xtype: 'pmgRegexTester',
regexFieldReference: 'filename',
},
],
{
xtype: 'combobox',
displayField: 'text',
- labelWidth: 150,
valueField: 'mimetype',
name: 'contenttype',
editable: true,
{
xtype: 'displayfield',
fieldLabel: gettext('Value'),
- labelWidth: 150,
allowBlank: false,
reset: Ext.emptyFn,
},
name: 'filename',
reference: 'filename',
fieldLabel: gettext('Filename'),
- labelWidth: 150,
allowBlank: false,
},
{
- labelWidth: 150,
+ xtype: 'pmgRegexTester',
fieldLabel: gettext('Test String'),
wholeMatch: true,
- xtype: 'pmgRegexTester',
regexFieldReference: 'filename',
},
],
xtype: 'proxmoxcheckbox',
checked: true,
name: 'original',
- fieldLabel: gettext("send orig. Mail"),
+ boxLabel: gettext("Send Original Mail"),
},
],
subdir: 'removeattachments',
subject: gettext('Remove Attachments'),
width: 500,
- fieldDefaults: {
- labelWidth: 150,
- },
items: [
{
xtype: 'textfield',
xtype: 'proxmoxcheckbox',
checked: true,
name: 'all',
- fieldLabel: gettext("Remove all attachments"),
+ boxLabel: gettext("Remove all Attachments"),
},
{
xtype: 'proxmoxcheckbox',
checked: false,
name: 'quarantine',
- fieldLabel: gettext("Copy orignal mail to Attachment Quarantine"),
+ boxLabel: gettext("Copy original mail to Attachment Quarantine"),
},
],
},
slideBackAnimation: 'easeOut',
iconCls: 'fa fa-check',
shadow: true,
+ align: 'br',
});
if (Ext.isFunction(callback)) {
return `<i class='fa ${iconCls}'></i> ${text}`;
},
- sender_renderer: function(value, metaData, rec) {
- var subject = Ext.htmlEncode(value);
- var from = Ext.htmlEncode(rec.data.from);
- var sender = Ext.htmlEncode(rec.data.sender);
- if (sender) {
- from = Ext.String.format(gettext("{0} on behalf of {1}"),
- sender, from);
+ render_envelope: function(value, { data }, render_receiver) {
+ let subject = Ext.htmlEncode(value);
+ let from = Ext.htmlEncode(data.from);
+ if (data.sender) {
+ let sender = Ext.htmlEncode(data.sender);
+ from = Ext.String.format(gettext("{0} on behalf of {1}"), sender, from);
+ }
+ if (render_receiver) {
+ let receiver = Ext.htmlEncode(data.receiver);
+ return `<small>${from}<br>To: ${receiver}</small><br>${subject}`;
}
- return '<small>' + from + '</small><br>' + subject;
+ return `<small>${from}</small><br>${subject}`;
},
+ render_sender: (value, _meta, rec) => PMG.Utils.render_envelope(value, rec, false),
+ render_sender_receiver: (value, _meta, rec) => PMG.Utils.render_envelope(value, rec, true),
+
constructor: function() {
var me = this;
});
},
});
+
+Ext.define('PMG.Async', {
+ singleton: true,
+
+ // Returns a Promise which executes a quarantine action when awaited.
+ // Shows a Toast message box once completed, if batchNumber and batchTotal
+ // are set, they will be included into the title of that toast.
+ doQAction: function(action, ids, batchNumber, batchTotal) {
+ if (!Ext.isArray(ids)) {
+ ids = [ids];
+ }
+ return Proxmox.Async.api2({
+ url: '/quarantine/content/',
+ params: {
+ action: action,
+ id: ids.join(';'),
+ },
+ method: 'POST',
+ }).then(
+ response => {
+ let count = ids.length;
+ let fmt = count > 1
+ ? gettext("Action '{0}' for '{1}' items successful")
+ : gettext("Action '{0}' successful")
+ ;
+ let message = Ext.String.format(fmt, action, count);
+ let titleFmt = batchNumber !== undefined && batchTotal > 1
+ ? gettext("{0} ({1}/{2}) successful")
+ : gettext("{0} successful")
+ ;
+ let title = Ext.String.format(
+ titleFmt,
+ Ext.String.capitalize(action),
+ batchNumber,
+ batchTotal,
+ );
+
+ Ext.toast({
+ html: message,
+ title: title,
+ minWidth: 200,
+ hideDuration: 250,
+ slideBackDuration: 250,
+ slideBackAnimation: 'easeOut',
+ iconCls: 'fa fa-check',
+ shadow: true,
+ align: 'br',
+ });
+ },
+ response => Proxmox.Utils.alertResponseFailure(response),
+ );
+ },
+});
+
+// custom Vtypes
+Ext.apply(Ext.form.field.VTypes, {
+ // matches the pmg-email-address in pmg-api
+ PMGMail: function(v) {
+ return (/[^\s\\@]+@[^\s/\\@]+/).test(v);
+ },
+ PMGMailText: gettext('Example') + ": user@example.com",
+});