1<script type="text/x-jquery-tmpl" id="exec_params_row">
2	<tr class="form_row">
3		<td>
4			<input type="text" id="exec_params_#{rowNum}_exec_param" name="exec_params[#{rowNum}][exec_param]" maxlength="255" style="width: <?= ZBX_TEXTAREA_STANDARD_WIDTH ?>px;">
5		</td>
6		<td>
7			<button type="button" id="exec_params_#{rowNum}_remove" name="exec_params[#{rowNum}][remove]" class="<?= ZBX_STYLE_BTN_LINK ?> element-table-remove"><?= _('Remove') ?></button>
8		</td>
9	</tr>
10</script>
11<script type="text/javascript">
12	jQuery(document).ready(function($) {
13		// type of media
14		$('#type').change(function() {
15			switch ($(this).val()) {
16				case '<?= MEDIA_TYPE_EMAIL ?>':
17					$('#smtp_server, #smtp_port, #smtp_helo, #smtp_email, #smtp_security, #smtp_authentication').closest('li').show();
18					$('#exec_path, #gsm_modem, #jabber_username, #eztext_username, #eztext_limit, #exec_params_table')
19						.closest('li')
20						.hide();
21					$('#eztext_link').hide();
22
23					// radio button actions
24					toggleSecurityOptions();
25					toggleAuthenticationOptions();
26					break;
27
28				case '<?= MEDIA_TYPE_EXEC ?>':
29					$('#exec_path, #exec_params_table').closest('li').show();
30					$('#smtp_server, #smtp_port, #smtp_helo, #smtp_email, #gsm_modem, #jabber_username, #eztext_username, #eztext_limit, #passwd, #smtp_verify_peer, #smtp_verify_host, #smtp_username, #smtp_security, #smtp_authentication')
31						.closest('li')
32						.hide();
33					$('#eztext_link').hide();
34					break;
35
36				case '<?= MEDIA_TYPE_SMS ?>':
37					$('#gsm_modem').closest('li').show();
38					$('#smtp_server, #smtp_port, #smtp_helo, #smtp_email, #exec_path, #jabber_username, #eztext_username, #eztext_limit, #passwd, #smtp_verify_peer, #smtp_verify_host, #smtp_username, #smtp_security, #smtp_authentication, #exec_params_table')
39						.closest('li')
40						.hide();
41					$('#eztext_link').hide();
42					break;
43
44				case '<?= MEDIA_TYPE_JABBER ?>':
45					$('#jabber_username, #passwd').closest('li').show();
46					$('#smtp_server, #smtp_port, #smtp_helo, #smtp_email, #exec_path, #gsm_modem, #eztext_username, #eztext_limit, #smtp_verify_peer, #smtp_verify_host, #smtp_username, #smtp_security, #smtp_authentication, #exec_params_table')
47						.closest('li')
48						.hide();
49					$('#eztext_link').hide();
50					break;
51
52				case '<?= MEDIA_TYPE_EZ_TEXTING ?>':
53					$('#eztext_username, #eztext_limit, #passwd').closest('li').show();
54					$('#eztext_link').show();
55					$('#smtp_server, #smtp_port, #smtp_helo, #smtp_email, #exec_path, #gsm_modem, #jabber_username, #smtp_verify_peer, #smtp_verify_host, #smtp_username, #smtp_security, #smtp_authentication, #exec_params_table')
56						.closest('li')
57						.hide();
58					break;
59			}
60		});
61
62		// clone button
63		$('#clone').click(function() {
64			$('#mediatypeid, #delete, #clone').remove();
65			$('#update').text(<?= CJs::encodeJson(_('Add')) ?>);
66			$('#update').val('mediatype.create').attr({id: 'add'});
67			$('#description').focus();
68		});
69
70		// Trim spaces on sumbit. Spaces for script parameters should not be trimmed.
71		$('#media_type_form').submit(function() {
72			$(this).trimValues([
73				'#description', '#smtp_server', '#smtp_port', '#smtp_helo', '#smtp_email', '#exec_path', '#gsm_modem',
74				'#jabber_username', '#eztext_username', '#smtp_username'
75			]);
76		});
77
78		// Refresh field visibility on document load.
79		$('#type').trigger('change');
80
81		$('input[name=smtp_security]').change(function() {
82			toggleSecurityOptions();
83		});
84
85		$('input[name=smtp_authentication]').change(function() {
86			toggleAuthenticationOptions();
87		});
88
89		/**
90		 * Show or hide "SSL verify peer" and "SSL verify host" fields.
91		 */
92		function toggleSecurityOptions() {
93			if ($('input[name=smtp_security]:checked').val() == <?= SMTP_CONNECTION_SECURITY_NONE ?>) {
94				$('#smtp_verify_peer, #smtp_verify_host').prop('checked', false).closest('li').hide();
95			}
96			else {
97				$('#smtp_verify_peer, #smtp_verify_host').closest('li').show();
98			}
99		}
100
101		/**
102		 * Show or hide "Username" and "Password" fields.
103		 */
104		function toggleAuthenticationOptions() {
105			if ($('input[name=smtp_authentication]:checked').val() == <?= SMTP_AUTHENTICATION_NORMAL ?>) {
106				$('#smtp_username, #passwd').closest('li').show();
107			}
108			else {
109				$('#smtp_username, #passwd').val('').closest('li').hide();
110			}
111		}
112
113		$('#chPass_btn').on('click', function() {
114			$(this).hide();
115			$('#passwd')
116				.show()
117				.removeAttr('disabled')
118				.focus();
119		});
120
121		// When adding and removing dynamic rows, store counter in hidden field.
122		$('#exec_params_table').dynamicRows({
123			template: '#exec_params_row',
124			dataCallback: function() {
125				$('#exec_params_count').val(parseInt($('#exec_params_count').val()) + 1);
126			}
127		});
128
129		$('#exec_params_table').on('click', 'button.element-table-remove', function() {
130			$('#exec_params_count').val($('#exec_params_table .form_row input[type="text"]').length);
131		});
132	});
133</script>
134