]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/node/ACME.js
ui: eslint: fix trailing comma and comma related whitespaces errors
[pve-manager.git] / www / manager6 / node / ACME.js
index ba1906b4715a62960596d2bb95265bdf2c8d57d6..cfe9cc12907d4a5c39c3ed37dabd09fa51dad50f 100644 (file)
@@ -1,21 +1,32 @@
 Ext.define('PVE.node.ACMEAccountCreate', {
     extend: 'Proxmox.window.Edit',
+    mixins: ['Proxmox.Mixin.CBind'],
 
-    width: 400,
+    width: 450,
     title: gettext('Register Account'),
     isCreate: true,
     method: 'POST',
     submitText: gettext('Register'),
     url: '/cluster/acme/account',
     showTaskViewer: true,
+    defaultExists: false,
 
     items: [
        {
            xtype: 'proxmoxtextfield',
-           fieldLabel: gettext('Name'),
+           fieldLabel: gettext('Account Name'),
            name: 'name',
-           emptyText: 'default',
-           allowBlank: true,
+           cbind: {
+               emptyText: (get) => get('defaultExists') ? '' : 'default',
+               allowBlank: (get) => !get('defaultExists'),
+           },
+       },
+       {
+           xtype: 'textfield',
+           name: 'contact',
+           vtype: 'email',
+           allowBlank: false,
+           fieldLabel: gettext('E-Mail'),
        },
        {
            xtype: 'proxmoxComboGrid',
@@ -30,26 +41,26 @@ Ext.define('PVE.node.ACMEAccountCreate', {
                idProperty: ['name'],
                proxy: {
                    type: 'proxmox',
-                   url: '/api2/json/cluster/acme/directories'
+                   url: '/api2/json/cluster/acme/directories',
                },
                sorters: {
                    property: 'name',
-                   order: 'ASC'
-               }
+                   order: 'ASC',
+               },
            },
            listConfig: {
                columns: [
                    {
                        header: gettext('Name'),
                        dataIndex: 'name',
-                       flex: 1
+                       flex: 1,
                    },
                    {
                        header: gettext('URL'),
                        dataIndex: 'url',
-                       flex: 1
-                   }
-               ]
+                       flex: 1,
+                   },
+               ],
            },
            listeners: {
                change: function(combogrid, value) {
@@ -65,56 +76,50 @@ Ext.define('PVE.node.ACMEAccountCreate', {
                    disp.setValue(gettext('Loading'));
                    field.setValue(undefined);
                    checkbox.setValue(undefined);
+                   checkbox.setHidden(true);
 
                    Proxmox.Utils.API2Request({
                        url: '/cluster/acme/tos',
                        method: 'GET',
                        params: {
-                           directory: value
+                           directory: value,
                        },
                        success: function(response, opt) {
-                           me.up('window').down('#tos_url').setValue(response.result.data);
-                           me.up('window').down('#tos_url_display').setValue(response.result.data);
+                           field.setValue(response.result.data);
+                           disp.setValue(response.result.data);
+                           checkbox.setHidden(false);
                        },
                        failure: function(response, opt) {
                            Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-                       }
+                       },
                    });
-               }
-           }
+               },
+           },
        },
        {
            xtype: 'displayfield',
            itemId: 'tos_url_display',
-           fieldLabel: gettext('Terms of Service'),
            renderer: PVE.Utils.render_optional_url,
-           name: 'tos_url_display'
+           name: 'tos_url_display',
        },
        {
            xtype: 'hidden',
            itemId: 'tos_url',
-           name: 'tos_url'
+           name: 'tos_url',
        },
        {
            xtype: 'proxmoxcheckbox',
            itemId: 'tos_checkbox',
-           fieldLabel: gettext('Accept TOS'),
+           boxLabel: gettext('Accept TOS'),
            submitValue: false,
            validateValue: function(value) {
                if (value && this.checked) {
                    return true;
                }
                return false;
-           }
+           },
        },
-       {
-           xtype: 'textfield',
-           name: 'contact',
-           vtype: 'email',
-           allowBlank: false,
-           fieldLabel: gettext('E-Mail')
-       }
-    ]
+    ],
 
 });
 
@@ -123,7 +128,7 @@ Ext.define('PVE.node.ACMEAccountView', {
 
     width: 600,
     fieldDefaults: {
-       labelWidth: 140
+       labelWidth: 140,
     },
 
     title: gettext('Account'),
@@ -132,30 +137,30 @@ Ext.define('PVE.node.ACMEAccountView', {
        {
            xtype: 'displayfield',
            fieldLabel: gettext('E-Mail'),
-           name: 'email'
+           name: 'email',
        },
        {
            xtype: 'displayfield',
            fieldLabel: gettext('Created'),
-           name: 'createdAt'
+           name: 'createdAt',
        },
        {
            xtype: 'displayfield',
            fieldLabel: gettext('Status'),
-           name: 'status'
+           name: 'status',
        },
        {
            xtype: 'displayfield',
            fieldLabel: gettext('Directory'),
            renderer: PVE.Utils.render_optional_url,
-           name: 'directory'
+           name: 'directory',
        },
        {
            xtype: 'displayfield',
            fieldLabel: gettext('Terms of Services'),
            renderer: PVE.Utils.render_optional_url,
-           name: 'tos'
-       }
+           name: 'tos',
+       },
     ],
 
     initComponent: function() {
@@ -179,9 +184,9 @@ Ext.define('PVE.node.ACMEAccountView', {
                data.createdAt = data.account.createdAt;
                data.status = data.account.status;
                me.setValues(data);
-           }
+           },
        });
-    }
+    },
 });
 
 Ext.define('PVE.node.ACMEDomainEdit', {
@@ -350,12 +355,15 @@ Ext.define('PVE.node.ACME', {
 
     viewModel: {
        data: {
-           account: undefined,
+           domaincount: 0,
+           account: undefined, // the account we display
+           configaccount: undefined, // the account set in the config
            accountEditable: false,
            accountsAvailable: false,
        },
 
        formulas: {
+           canOrder: (get) => !!get('account') && get('domaincount') > 0,
            editBtnIcon: (get) => 'fa black fa-' + (get('accountEditable') ? 'check' : 'pencil'),
            accountTextHidden: (get) => get('accountEditable') || !get('accountsAvailable'),
            accountValueHidden: (get) => !get('accountEditable') || !get('accountsAvailable'),
@@ -373,6 +381,7 @@ Ext.define('PVE.node.ACME', {
        onAccountsLoad: function(store, records, success) {
            let me = this;
            let vm = me.getViewModel();
+           let configaccount = vm.get('configaccount');
            vm.set('accountsAvailable', records.length > 0);
            if (me.autoChangeAccount && records.length > 0) {
                me.changeAccount(records[0].data.name, () => {
@@ -380,6 +389,12 @@ Ext.define('PVE.node.ACME', {
                    me.reload();
                });
                me.autoChangeAccount = false;
+           } else if (configaccount) {
+               if (store.findExact('name', configaccount) !== -1) {
+                   vm.set('account', configaccount);
+               } else {
+                   vm.set('account', null);
+               }
            }
        },
 
@@ -558,7 +573,7 @@ Ext.define('PVE.node.ACME', {
            reference: 'order',
            text: gettext('Order Certificates Now'),
            bind: {
-               disabled: '{!accountsAvailable}',
+               disabled: '{!canOrder}',
            },
            handler: 'order',
        },
@@ -573,6 +588,7 @@ Ext.define('PVE.node.ACME', {
        {
            xtype: 'displayfield',
            reference: 'accounttext',
+           renderer: (val) => val || Proxmox.Utils.NoneText,
            bind: {
                value: '{account}',
                hidden: '{accountTextHidden}',
@@ -655,16 +671,8 @@ Ext.define('PVE.node.ACME', {
 
        // account changed, and we do not edit currently, load again to verify
        if (oldaccount !== account && !vm.get('accountEditable')) {
-           Proxmox.Utils.API2Request({
-               url: `/cluster/acme/account/${account}`,
-               waitMsgTarget: me,
-               success: function(response, opt) {
-                   vm.set('account', account);
-               },
-               failure: function(response, opt) {
-                   vm.set('account', Proxmox.Utils.NoneText);
-               },
-           });
+           vm.set('configaccount', account);
+           me.lookup('accountselector').store.load();
        }
 
        for (let i = 0; i < PVE.Utils.acmedomain_count; i++) {
@@ -677,6 +685,7 @@ Ext.define('PVE.node.ACME', {
            data.push(record);
        }
 
+       vm.set('domaincount', data.length);
        me.store.loadData(data, false);
     },
 
@@ -727,5 +736,6 @@ Ext.define('PVE.node.ACME', {
        me.callParent();
        me.mon(me.rstore, 'load', 'updateStore', me);
        Proxmox.Utils.monStoreErrors(me, me.rstore);
+       me.on('destroy', me.rstore.stopUpdate, me.rstore);
     },
 });