Back

0% Statements 0/45
0% Branches 0/1
0% Functions 0/1
0% Lines 0/45

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
document.addEventListener( 'DOMContentLoaded', function () {
	const sendUserNotificationCheckbox = document.getElementById( 'send_user_notification' );
	const userExternalContractorCheckbox = document.getElementById( 'user_external_contractor' );
	const inviteUserWpcomCheckbox = document.getElementById( 'invite_user_wpcom' );
	const customEmailMessageBlock = document.getElementById( 'custom_email_message_block' );

	if ( inviteUserWpcomCheckbox && sendUserNotificationCheckbox && customEmailMessageBlock ) {
		// Toggle Send User Notification checkbox enabled/disabled based on Invite User checkbox
		// Enable External Contractor checkbox if Invite User checkbox is checked
		// Show/hide the external email message field.
		inviteUserWpcomCheckbox.addEventListener( 'change', function () {
			sendUserNotificationCheckbox.disabled = inviteUserWpcomCheckbox.checked;
			if ( inviteUserWpcomCheckbox.checked ) {
				sendUserNotificationCheckbox.checked = false;
				if ( userExternalContractorCheckbox ) {
					userExternalContractorCheckbox.disabled = false;
				}
				customEmailMessageBlock.style.display = 'table';
			} else {
				if ( userExternalContractorCheckbox ) {
					userExternalContractorCheckbox.disabled = true;
					userExternalContractorCheckbox.checked = false;
				}
				customEmailMessageBlock.style.display = 'none';
			}
		} );

		// On load, disable Send User Notification checkbox
		// and show the custom email message if Invite User checkbox is checked
		if ( inviteUserWpcomCheckbox.checked ) {
			sendUserNotificationCheckbox.disabled = true;
			sendUserNotificationCheckbox.checked = false;
			customEmailMessageBlock.style.display = 'table';
		}

		// On load, disable External Contractor checkbox
		// and hide the custom email message if Invite User checkbox is unchecked
		if ( ! inviteUserWpcomCheckbox.checked ) {
			if ( userExternalContractorCheckbox ) {
				userExternalContractorCheckbox.disabled = true;
			}
			customEmailMessageBlock.style.display = 'none';
		}
	}
} );