]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/Utils.js
quarantines: fix the default behavior of the theme toggle button
[pmg-gui.git] / js / Utils.js
index 328a146b3483c9770ac6bfd5cd9641fad4c2c703..7fa154eab560ca075be83ca859de9614132eac3b 100644 (file)
@@ -129,14 +129,12 @@ Ext.define('PMG.Utils', {
     },
 
     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) {
@@ -148,7 +146,7 @@ Ext.define('PMG.Utils', {
     },
 
     convert_field_to_per_min: function(value, record) {
-       return value/(record.data.timespan/60);
+       return value / (record.data.timespan / 60);
     },
 
     object_editors: {
@@ -163,14 +161,12 @@ Ext.define('PMG.Utils', {
                {
                    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',
                },
@@ -202,8 +198,7 @@ Ext.define('PMG.Utils', {
                {
                    xtype: 'textfield',
                    name: 'regex',
-                   labelWidth: 150,
-                   fieldLabel: gettext("Regular Expression"),
+                   fieldLabel: gettext("Regex"),
                },
            ],
        },
@@ -361,22 +356,19 @@ Ext.define('PMG.Utils', {
                {
                    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',
                },
            ],
@@ -392,7 +384,6 @@ Ext.define('PMG.Utils', {
                {
                    xtype: 'combobox',
                    displayField: 'text',
-                   labelWidth: 150,
                    valueField: 'mimetype',
                    name: 'contenttype',
                    editable: true,
@@ -417,7 +408,6 @@ Ext.define('PMG.Utils', {
                {
                    xtype: 'displayfield',
                    fieldLabel: gettext('Value'),
-                   labelWidth: 150,
                    allowBlank: false,
                    reset: Ext.emptyFn,
                },
@@ -436,14 +426,12 @@ Ext.define('PMG.Utils', {
                    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',
                },
            ],
@@ -459,7 +447,6 @@ Ext.define('PMG.Utils', {
                {
                    xtype: 'combobox',
                    displayField: 'text',
-                   labelWidth: 150,
                    valueField: 'mimetype',
                    name: 'contenttype',
                    editable: true,
@@ -484,7 +471,6 @@ Ext.define('PMG.Utils', {
                {
                    xtype: 'displayfield',
                    fieldLabel: gettext('Value'),
-                   labelWidth: 150,
                    allowBlank: false,
                    reset: Ext.emptyFn,
                },
@@ -503,14 +489,12 @@ Ext.define('PMG.Utils', {
                    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',
                },
            ],
@@ -633,7 +617,7 @@ Ext.define('PMG.Utils', {
                    xtype: 'proxmoxcheckbox',
                    checked: true,
                    name: 'original',
-                   fieldLabel: gettext("send orig. Mail"),
+                   boxLabel: gettext("Send Original Mail"),
                },
            ],
 
@@ -644,9 +628,6 @@ Ext.define('PMG.Utils', {
            subdir: 'removeattachments',
            subject: gettext('Remove Attachments'),
            width: 500,
-           fieldDefaults: {
-               labelWidth: 150,
-           },
            items: [
                {
                    xtype: 'textfield',
@@ -670,13 +651,13 @@ Ext.define('PMG.Utils', {
                    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"),
                },
            ],
        },
@@ -832,17 +813,23 @@ Ext.define('PMG.Utils', {
        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;
 
@@ -911,3 +898,12 @@ Ext.define('PMG.Async', {
        );
     },
 });
+
+// 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",
+});