autoBackupForm = (req) => {
  const isRoot = db.getTenantSchema() === db.connectObj.default_schema;

  return new Form({
    action: "/admin/set-auto-backup",
    onChange: `saveAndContinue(this);$('#btnBackupNow').prop('disabled', $('#inputauto_backup_frequency').val()==='Never');`,
    noSubmitButton: true,
    additionalButtons: [
      {
        label: req.__("Backup now"),
        id: "btnBackupNow",
        class: "btn btn-outline-secondary",
        onclick:
          "ajax_post('/admin/auto-backup-now');press_store_button(this);",
      },
    ],
    fields: [
      {
        type: "String",
        label: req.__("Frequency"),
        name: "auto_backup_frequency",
        required: true,
        attributes: { options: ["Never", "Daily", "Weekly"] },
      },
      {
        type: "String",
        label: req.__("Destination"),
        name: "auto_backup_destination",
        required: true,
        showIf: { auto_backup_frequency: ["Daily", "Weekly"] },
        attributes: {
          auto_backup_frequency: ["Daily", "Weekly"],
          options: ["Saltcorn files", "Local directory", "SFTP server", "S3"],
        },
      },
      {
        type: "String",
        label: req.__("Server host"),
        name: "auto_backup_server",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "SFTP server",
        },
      },
      {
        type: "String",
        label: req.__("Username"),
        name: "auto_backup_username",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "SFTP server",
        },
      },
      {
        type: "String",
        label: req.__("Password"),
        fieldview: "password",
        name: "auto_backup_password",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "SFTP server",
        },
      },
      {
        type: "Integer",
        label: req.__("Port"),
        name: "auto_backup_port",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "SFTP server",
        },
      },
      {
        type: "String",
        label: req.__("Directory"),
        name: "auto_backup_directory",
        sublabel: req.__("Directory for backup files"),
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          //auto_backup_destination: "Local directory",
        },
      },
      {
        type: "String",
        label: req.__("Retain local directory"),
        name: "auto_backup_retain_local_directory",
        sublabel: req.__(
          "Retain a local backup copy in this directory (optional)"
        ),
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "SFTP server",
          //auto_backup_destination: "Local directory",
        },
      },
      ...(isRoot
        ? [
            {
              type: "Bool",
              label: req.__("All tenants"),
              sublabel: req.__("Also backup all tenants"),
              name: "auto_backup_tenants",
              showIf: {
                auto_backup_frequency: ["Daily", "Weekly"],
              },
            },
          ]
        : []),
      {
        type: "String",
        label: req.__("S3 Endpoint"),
        name: "backup_s3_endpoint",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "S3",
        },
      },
      {
        type: "String",
        label: req.__("S3 Bucket Name"),
        name: "backup_s3_bucket",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "S3",
        },
      },
      {
        type: "String",
        label: req.__("S3 Access Key"),
        name: "backup_s3_access_key",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "S3",
        },
      },
      {
        type: "String",
        label: req.__("S3 Secret Key"),
        fieldview: "password",
        name: "backup_s3_access_secret",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "S3",
        },
      },
      {
        type: "String",
        label: req.__("S3 Region"),
        name: "backup_s3_region",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: "S3",
        },
      },
      {
        type: "Integer",
        label: req.__("Expiration in days"),
        sublabel: req.__(
          "Delete old backup files in this directory after the set number of days"
        ),
        name: "auto_backup_expire_days",
        showIf: {
          auto_backup_frequency: ["Daily", "Weekly"],
          auto_backup_destination: ["Local directory", "S3"],
        },
      },
    ],
  });
}
Auto backup Form
@param {object} req
@returns {Form} form