]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/UserBlackWhiteList.js
api: use readable casing for tls-inbound-domains endpoint
[pmg-gui.git] / js / UserBlackWhiteList.js
index 477e1881f66a7b01202247f5191fb030eaa40bfc..134449607c9018be4f805666063c02665e42842d 100644 (file)
@@ -1,8 +1,7 @@
-/*global Proxmox*/
 Ext.define('pmg-address-list', {
     extend: 'Ext.data.Model',
-    fields: [ 'address' ],
-    idProperty: 'address'
+    fields: ['address'],
+    idProperty: 'address',
 });
 
 // base class - do not use directly
@@ -12,146 +11,180 @@ Ext.define('PMG.UserBlackWhiteList', {
     border: false,
     listname: undefined, // 'blacklist' or 'whitelist',
 
-    emptyText: gettext('No data in database.'),
+    selModel: 'checkboxmodel',
+
+    emptyText: gettext('No data in database'),
 
     controller: {
 
         xclass: 'Ext.app.ViewController',
 
        onAddAddress: function() {
-           var me = this.getView();
-           var params = me.getStore().getProxy().getExtraParams() || {};
+           let view = this.getView();
+           let params = view.getStore().getProxy().getExtraParams() || {};
 
-           var url = '/quarantine/' + me.listname;
+           let url = '/quarantine/' + view.listname;
 
-           var items = [{
+           let items = [{
                xtype: 'proxmoxtextfield',
                name: 'address',
-               fieldLabel: gettext("Address")
+               minLength: 3,
+               regex: /^[^,;\s]*$/, // no whitespace no , and no ;
+               fieldLabel: gettext("Address"),
            }];
 
            Ext.Object.each(params, function(key, value) {
                items.push({
                    xtype: 'hidden',
                    name: key,
-                   value: value
+                   value: value,
                });
            });
 
-           var config = {
+           let config = {
                method: 'POST',
                url: url,
-               create: true,
+               onlineHelp: 'pmg_userblackwhitelist',
+               isCreate: true,
                isAdd: true,
-               items: items
+               items: items,
            };
 
-           if (me.listname === 'blacklist') {
+           if (view.listname === 'blacklist') {
                config.subject = gettext("Blacklist");
-           } else if (me.listname == 'whitelist') {
+           } else if (view.listname === 'whitelist') {
                config.subject = gettext("Whitelist");
            } else {
                throw "unknown list - internal error";
            }
 
-           var win = Ext.createWidget('proxmoxWindowEdit', config);
-           win.on('destroy', function() { me.store.load() });
+           let win = Ext.createWidget('proxmoxWindowEdit', config);
+           win.on('destroy', function() { view.store.load(); });
            win.show();
        },
 
        onRemoveAddress: function() {
-           var me = this.getView();
-           var rec = me.selModel.getSelection()[0];
-           if (!rec) return;
+           let view = this.getView();
+           let records = view.selModel.getSelection();
+           if (records.length < 1) {
+               return;
+           }
 
-           var params = me.getStore().getProxy().getExtraParams() || {};
-           var url = '/quarantine/' + me.listname + '/' + rec.getId();
+           let url = '/quarantine/' + view.listname + '/';
+
+           let params = {
+               address: records.map((rec) => rec.getId()).join(','),
+           };
+           Ext.applyIf(params, view.getStore().getProxy().getExtraParams());
 
            Proxmox.Utils.API2Request({
                url: url + '?' + Ext.Object.toQueryString(params),
                method: 'DELETE',
-               waitMsgTarget: me,
+               waitMsgTarget: view,
                callback: function(options, success, response) {
-                   me.store.load();
+                   view.store.load();
                },
-               failure: function (response, opts) {
+               failure: function(response, opts) {
                    Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-               }
+               },
            });
        },
 
        changeEmail: function(combobox, value) {
-           var view = this.getView();
+           let view = this.getView();
            if (value && combobox.isValid()) {
                view.getStore().getProxy().setExtraParams({
-                   pmail: value
+                   pmail: value,
                });
                view.getStore().load();
            }
        },
 
        init: function(view) {
+           let emailcb = this.lookupReference('email');
            if (PMG.view === 'quarantineview') {
-               this.lookupReference('email').setVisible(false);
+               emailcb.setVisible(false);
                view.getStore().load();
+           } else {
+               emailcb.getStore().getProxy().setExtraParams({
+                   list: view.listname === 'blacklist' ? 'BL' : 'WL',
+               });
            }
            Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true);
        },
 
        control: {
-           'combobox':{
+           'combobox': {
                change: {
                    fn: 'changeEmail',
-                   buffer: 500
-               }
-           }
-       }
+                   buffer: 500,
+               },
+           },
+       },
     },
 
     tbar: [
        {
            xtype: 'combobox',
            displayField: 'mail',
-           vtype: 'email',
+           vtype: 'PMGMail',
            allowBlank: false,
            valueField: 'mail',
            store: {
                proxy: {
                    type: 'proxmox',
-                   url: '/api2/json/quarantine/quarusers'
+                   url: '/api2/json/quarantine/quarusers',
                },
                fields: [
                    {
                        name: 'mail',
-                       renderer: Ext.htmlEncode
-                   }
-               ]
+                       renderer: Ext.htmlEncode,
+                   },
+               ],
            },
            queryParam: false,
            queryCaching: false,
            editable: true,
            reference: 'email',
            name: 'email',
-           fieldLabel: 'E-Mail'
+           listConfig: {
+               emptyText:
+               '<div class="x-grid-empty">' +
+               gettext('No data in database') +
+               '</div>',
+           },
+           fieldLabel: 'E-Mail',
        },
        {
            text: gettext('Add'),
-           handler: 'onAddAddress'
+           handler: 'onAddAddress',
        },
        {
            xtype: 'proxmoxButton',
            text: gettext('Remove'),
            disabled: true,
            handler: 'onRemoveAddress',
-           confirmMsg: function(rec) {
-               var me = this;
+           confirmMsg: function() {
+               let view = this.up('gridpanel');
+
+               let selection = view.selModel.getSelection();
+               let text, param;
+               if (selection.length > 1) {
+                   text = gettext('Are you sure you want to remove {0} entries');
+                   param = selection.length.toString();
+               } else if (selection.length > 0) {
+                   let rec = selection[0];
+                   let name = rec.getId();
+                   text = gettext('Are you sure you want to remove entry {0}');
+                   param = "'" + Ext.String.htmlEncode(name) + "'";
+               }
 
-               var name = rec.getId();
-               return Ext.String.format(
-                   gettext('Are you sure you want to remove entry {0}'),
-                   "'" + Ext.String.htmlEncode(name) + "'");
-           }
-       }
+               if (text && param) {
+                   return Ext.String.format(text, param);
+               }
+               return false;
+           },
+       },
     ],
 
     columns: [
@@ -159,9 +192,9 @@ Ext.define('PMG.UserBlackWhiteList', {
             header: gettext('Address'),
             dataIndex: 'address',
            renderer: Ext.String.htmlEncode,
-           flex: 1
-        }
-    ]
+           flex: 1,
+        },
+    ],
 });
 
 Ext.define('PMG.UserBlacklist', {
@@ -177,8 +210,11 @@ Ext.define('PMG.UserBlacklist', {
        autoDestroy: true,
        proxy: {
             type: 'proxmox',
-            url: "/api2/json/quarantine/blacklist"
-       }
+            url: "/api2/json/quarantine/blacklist",
+       },
+       sorters: {
+           property: 'address',
+       },
     },
 
     dockedItems: [
@@ -187,15 +223,14 @@ Ext.define('PMG.UserBlacklist', {
            bodyStyle: {
                padding: '10px',
                'border-left': '0px',
-               'border-right': '0px'
+               'border-right': '0px',
            },
-            html: gettext('With this feature, you can manually mark E-mails from certain domains or addresses as spam.') + '<br><br>' +
-               '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
-               '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
-               '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
-
-        }
-    ]
+            html: gettext('With this feature, you can manually mark E-mails from certain domains or addresses as spam.') + `<br><br>
+               <b>*.com</b> (all mails from <b>.com</b> domains)<br>
+               <b>*@example.com</b> (all mails from domain <b>example.com</b>)<br>
+               <b>john@example.com</b> (all mails from <b>john@example.com</b>)`,
+        },
+    ],
 });
 
 Ext.define('PMG.UserWhitelist', {
@@ -211,8 +246,11 @@ Ext.define('PMG.UserWhitelist', {
        autoDestroy: true,
        proxy: {
             type: 'proxmox',
-            url: "/api2/json/quarantine/whitelist"
-       }
+            url: "/api2/json/quarantine/whitelist",
+       },
+       sorters: {
+           property: 'address',
+       },
     },
 
     dockedItems: [
@@ -221,12 +259,12 @@ Ext.define('PMG.UserWhitelist', {
            bodyStyle: {
                padding: '10px',
                'border-left': '0px',
-               'border-right': '0px'
+               'border-right': '0px',
            },
-            html: gettext('With this feature, you can manually bypass spam checking for certain domains or E-mail addresses.') + '<br><br>' +
-               '<b>*.com</b> (all mails from <b>.com</b> domains)' + '<br>' +
-               '<b>*@example.com</b> (all mails from domain <b>example.com</b>)' + '<br>' +
-               '<b>john@example.com</b> (all mails from <b>john@example.com</b>)'
-        }
-    ]
+            html: gettext('With this feature, you can manually bypass spam checking for certain domains or E-mail addresses.') + `<br><br>
+               <b>*.com</b> (all mails from <b>.com</b> domains)<br>
+               <b>*@example.com</b> (all mails from domain <b>example.com</b>)<br>
+               <b>john@example.com</b> (all mails from <b>john@example.com</b>)`,
+        },
+    ],
 });