Skip to content
Snippets Groups Projects
Commit 4f68d592 authored by Jigish Chauhan's avatar Jigish Chauhan Committed by Yas Naoi
Browse files

Issue #3118211 by jigish.addweb, yas: Remove JavaScript to hide and show the...

Issue #3118211 by jigish.addweb, yas: Remove JavaScript to hide and show the form elements in AWS Cloud
parent 3553e5ce
No related branches found
No related tags found
No related merge requests found
...@@ -33,14 +33,6 @@ aws_cloud_security_groups: ...@@ -33,14 +33,6 @@ aws_cloud_security_groups:
- core/jquery - core/jquery
- core/jquery.once - core/jquery.once
aws_cloud_elastic_ips:
version: 8.x-1.x
js:
js/aws_cloud_elastic_ip.js: {}
dependencies:
- core/jquery
- core/jquery.once
aws_cloud_auto_refresh: aws_cloud_auto_refresh:
version: 8.x-1.x version: 8.x-1.x
js: js:
......
(function ($, Drupal) {
'use strict';
Drupal.ElasticIp = {
showHide: function (type) {
if (type === 'instance') {
// hide the network container
$('#network-interface-ip-container').hide();
$('#instance-ip-container').show();
}
else {
$('#network-interface-ip-container').show();
$('#instance-ip-container').hide();
}
}
};
Drupal.behaviors.elasticIpFormSwitcher = {
attach: function (context, settings) {
// Show/hide the different containers.
$('#edit-resource-type', context).change(function () {
let selected = $(this).children('option:selected').val();
Drupal.ElasticIp.showHide(selected);
});
// Initialize and reinitialize when Ajax form refreshes.
let selected = $('#edit-resource-type').children('option:selected').val();
Drupal.ElasticIp.showHide(selected);
}
};
})(jQuery, Drupal);
...@@ -13,46 +13,6 @@ ...@@ -13,46 +13,6 @@
}; };
Drupal.SecurityGroup.showHide = { Drupal.SecurityGroup.showHide = {
showIp4: function (field, key) {
// Hide cidr_ipv6 and group.
$('.form-item-' + field + '-' + key + '-cidr-ip-v6').hide();
// Hide group attributes.
$('.form-item-' + field + '-' + key + '-group-id').hide();
$('.form-item-' + field + '-' + key + '-group-name').hide();
$('.form-item-' + field + '-' + key + '-peering-status').hide();
$('.form-item-' + field + '-' + key + '-user-id').hide();
$('.form-item-' + field + '-' + key + '-vpc-id').hide();
$('.form-item-' + field + '-' + key + '-peering-connection-id').hide();
$('.form-item-' + field + '-' + key + '-cidr-ip').show();
},
showIp6: function (field, key) {
// Hide CIDR IP field.
$('.form-item-' + field + '-' + key + '-cidr-ip').hide();
// Hide group attributes.
$('.form-item-' + field + '-' + key + '-group-id').hide();
$('.form-item-' + field + '-' + key + '-group-name').hide();
$('.form-item-' + field + '-' + key + '-peering-status').hide();
$('.form-item-' + field + '-' + key + '-user-id').hide();
$('.form-item-' + field + '-' + key + '-vpc-id').hide();
$('.form-item-' + field + '-' + key + '-peering-connection-id').hide();
// Show ip6.
$('.form-item-' + field + '-' + key + '-cidr-ip-v6').show();
},
showGroup: function (field, key) {
// Hide CIDR and cidr_ipv6
$('.form-item-' + field + '-' + key + '-cidr-ip').hide();
$('.form-item-' + field + '-' + key + '-cidr-ip-v6').hide();
// Show group attributes.
$('.form-item-' + field + '-' + key + '-group-id').show();
$('.form-item-' + field + '-' + key + '-group-name').show();
$('.form-item-' + field + '-' + key + '-peering-status').show();
$('.form-item-' + field + '-' + key + '-user-id').show();
$('.form-item-' + field + '-' + key + '-vpc-id').show();
$('.form-item-' + field + '-' + key + '-peering-connection-id').show();
},
hideRow: function (field, row_count, table_id) { hideRow: function (field, row_count, table_id) {
let from_port = $('.' + table_id + ' tr.row-' + row_count + ' .form-item-' + field + '-' + row_count + '-from-port input').val(); let from_port = $('.' + table_id + ' tr.row-' + row_count + ' .form-item-' + field + '-' + row_count + '-from-port input').val();
let to_port = $('.' + table_id + ' tr.row-' + row_count + ' .form-item-' + field + '-' + row_count + '-to-port input').val(); let to_port = $('.' + table_id + ' tr.row-' + row_count + ' .form-item-' + field + '-' + row_count + '-to-port input').val();
...@@ -69,42 +29,10 @@ ...@@ -69,42 +29,10 @@
} }
} }
}, },
showFields: function (type, field, key) {
if (type === 'ip4') {
Drupal.SecurityGroup.showHide.showIp4(field, key);
}
else if (type === 'ip6') {
Drupal.SecurityGroup.showHide.showIp6(field, key);
}
else {
Drupal.SecurityGroup.showHide.showGroup(field, key);
}
}
}; };
Drupal.behaviors.securityPermissions = { Drupal.behaviors.securityPermissions = {
attach: function (context, settings) { attach: function (context, settings) {
// Initialize inbound permissions.
$.each($('.field--name-ip-permission .ip-permission-select', context), function (k, el) {
// Initialize default behavior.
Drupal.SecurityGroup.showHide.showFields($(this).val(), 'ip-permission', k);
$(el).change(function () {
Drupal.SecurityGroup.showHide.showFields($(this).val(), 'ip-permission', k);
});
});
// Initialize outbound permissions.
$.each($('.field--name-outbound-permission .ip-permission-select', context), function (k, el) {
// Initialize default behavior.
Drupal.SecurityGroup.showHide.showFields($(this).val(), 'outbound-permission', k);
$(el).change(function () {
Drupal.SecurityGroup.showHide.showFields($(this).val(), 'outbound-permission', k);
});
});
$.each($('.field--name-ip-permission .ip-protocol-select', context), function (k, el) { $.each($('.field--name-ip-permission .ip-protocol-select', context), function (k, el) {
$(el).change(function () { $(el).change(function () {
// Populate from-to ports for "all traffic" option. // Populate from-to ports for "all traffic" option.
......
...@@ -48,7 +48,6 @@ class ElasticIpAssociateForm extends AwsDeleteForm { ...@@ -48,7 +48,6 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
unset($form['actions']['submit']); unset($form['actions']['submit']);
} }
else { else {
$form['#attached']['library'][] = 'aws_cloud/aws_cloud_elastic_ips';
$form['resource_type'] = [ $form['resource_type'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t('Resource type'), '#title' => $this->t('Resource type'),
...@@ -80,6 +79,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm { ...@@ -80,6 +79,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
'message' => $this->t('Retrieving...'), 'message' => $this->t('Retrieving...'),
], ],
], ],
'#states' => [
'visible' => [
'select[name="resource_type"]' => ['value' => 'instance'],
],
],
]; ];
$form['instance_ip_container']['instance_private_ip'] = [ $form['instance_ip_container']['instance_private_ip'] = [
...@@ -89,6 +93,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm { ...@@ -89,6 +93,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
'#options' => [ '#options' => [
'-1' => $this->t('Select a private IP.'), '-1' => $this->t('Select a private IP.'),
], ],
'#states' => [
'visible' => [
'select[name="resource_type"]' => ['value' => 'instance'],
],
],
]; ];
$form['network_interface_ip_container'] = [ $form['network_interface_ip_container'] = [
...@@ -111,6 +120,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm { ...@@ -111,6 +120,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
'message' => $this->t('Retrieving...'), 'message' => $this->t('Retrieving...'),
], ],
], ],
'#states' => [
'visible' => [
'select[name="resource_type"]' => ['value' => 'network_interface'],
],
],
]; ];
$form['network_interface_ip_container']['network_private_ip'] = [ $form['network_interface_ip_container']['network_private_ip'] = [
'#type' => 'select', '#type' => 'select',
...@@ -119,6 +133,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm { ...@@ -119,6 +133,11 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
'#options' => [ '#options' => [
'-1' => $this->t('Select a private IP.'), '-1' => $this->t('Select a private IP.'),
], ],
'#states' => [
'visible' => [
'select[name="resource_type"]' => ['value' => 'network_interface'],
],
],
]; ];
// Ajax support: Look at the instance value, and rebuild the private_ip // Ajax support: Look at the instance value, and rebuild the private_ip
......
...@@ -37,6 +37,7 @@ class IpPermissionItem extends WidgetBase { ...@@ -37,6 +37,7 @@ class IpPermissionItem extends WidgetBase {
'ip4' => 'IP', 'ip4' => 'IP',
'group' => 'Group', 'group' => 'Group',
]; ];
$field_name = $this->fieldDefinition->getName();
// Add IPv6 protocols if the group is a vpc. // Add IPv6 protocols if the group is a vpc.
if (!empty($security_group->getVpcId())) { if (!empty($security_group->getVpcId())) {
...@@ -104,6 +105,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -104,6 +105,11 @@ class IpPermissionItem extends WidgetBase {
'#default_value' => $items[$delta]->cidr_ip ?? NULL, '#default_value' => $items[$delta]->cidr_ip ?? NULL,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#placeholder' => '0.0.0.0/0', '#placeholder' => '0.0.0.0/0',
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'ip4'],
],
],
]; ];
$element['cidr_ip_v6'] = [ $element['cidr_ip_v6'] = [
...@@ -112,6 +118,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -112,6 +118,11 @@ class IpPermissionItem extends WidgetBase {
'#size' => 50, '#size' => 50,
'#default_value' => $items[$delta]->cidr_ip_v6 ?? NULL, '#default_value' => $items[$delta]->cidr_ip_v6 ?? NULL,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'ip6'],
],
],
]; ];
if (!empty($security_group->getVpcId())) { if (!empty($security_group->getVpcId())) {
$element['prefix_list_id'] = [ $element['prefix_list_id'] = [
...@@ -128,6 +139,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -128,6 +139,11 @@ class IpPermissionItem extends WidgetBase {
'#default_value' => $items[$delta]->group_id ?? NULL, '#default_value' => $items[$delta]->group_id ?? NULL,
'#size' => 20, '#size' => 20,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'group'],
],
],
]; ];
if (isset($items[$delta]->group_name)) { if (isset($items[$delta]->group_name)) {
$element['group_name'] = [ $element['group_name'] = [
...@@ -137,6 +153,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -137,6 +153,11 @@ class IpPermissionItem extends WidgetBase {
'#size' => 20, '#size' => 20,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#disabled' => TRUE, '#disabled' => TRUE,
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'group'],
],
],
]; ];
} }
$element['peering_status'] = [ $element['peering_status'] = [
...@@ -145,6 +166,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -145,6 +166,11 @@ class IpPermissionItem extends WidgetBase {
'#default_value' => $items[$delta]->peering_status ?? NULL, '#default_value' => $items[$delta]->peering_status ?? NULL,
'#size' => 20, '#size' => 20,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'group'],
],
],
]; ];
$element['user_id'] = [ $element['user_id'] = [
'#type' => 'textfield', '#type' => 'textfield',
...@@ -152,6 +178,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -152,6 +178,11 @@ class IpPermissionItem extends WidgetBase {
'#default_value' => $items[$delta]->user_id ?? NULL, '#default_value' => $items[$delta]->user_id ?? NULL,
'#size' => 20, '#size' => 20,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'group'],
],
],
]; ];
$element['vpc_id'] = [ $element['vpc_id'] = [
'#type' => 'textfield', '#type' => 'textfield',
...@@ -159,6 +190,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -159,6 +190,11 @@ class IpPermissionItem extends WidgetBase {
'#default_value' => $items[$delta]->vpc_id ?? NULL, '#default_value' => $items[$delta]->vpc_id ?? NULL,
'#size' => 20, '#size' => 20,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'group'],
],
],
]; ];
$element['peering_connection_id'] = [ $element['peering_connection_id'] = [
'#type' => 'textfield', '#type' => 'textfield',
...@@ -166,6 +202,11 @@ class IpPermissionItem extends WidgetBase { ...@@ -166,6 +202,11 @@ class IpPermissionItem extends WidgetBase {
'#default_value' => $items[$delta]->peering_connection_id ?? NULL, '#default_value' => $items[$delta]->peering_connection_id ?? NULL,
'#size' => 20, '#size' => 20,
'#maxlength' => $this->getFieldSetting('max_length'), '#maxlength' => $this->getFieldSetting('max_length'),
'#states' => [
'visible' => [
'select[name="' . $field_name . '[' . $delta . ']' . '[source]"]' => ['value' => 'group'],
],
],
]; ];
return $element; return $element;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment