1 $(document
).ready(function() {
3 $('#command_form').bind('submit', function() {
5 if(form
.data('already_submitted')) {
9 * Since all command input fields are required, we check
10 * them all and prompt user in case they are empty.
13 var cmd_typ
= $('input[name=cmd_typ]').val();
14 if (cmd_typ
!= 'DEL_ALL_SVC_COMMENTS' && cmd_typ
!= 'DEL_ALL_HOST_COMMENTS') {
15 // don't select all options in multi-select if we are trying to delete
16 // service/host comments since we want to let the user choose objects
17 $('select').each(function() {
18 if ($(this).attr('multiple')) {
19 $(this).children('option').attr('selected', true);
23 var inputs
= $('#command_form input');
24 $('select[type="select-multiple"]').each(function() {
25 $(this).children('option').attr('selected', true);
28 inputs
.each(function() {
29 var val
= $(this).val();
30 var key_str
= /\[.*?\]/.exec(this.name
);
32 key_str
= key_str
[0].replace('[', '').replace(']', '');
33 if ((key_str
== 'duration' && $("input[name='cmd_param\\[fixed\\]']").attr('checked') && $.trim(val
) == '') ||
34 ( key_str
!= '_perfdata' && (typeof val
== 'string' && $.trim(val
) == '') || (typeof val
== 'object' && !val
.length
) )) {
35 // Only require 'duration' when 'fixed' is checked
36 err_str
+= ' - ' + sprintf(_command_empty_field
, key_str
)+"\n";
41 // alert user using translated string from master template
42 alert(sprintf(_form_error_header
, "\n", "\n\n") + err_str
);
45 form
.data('already_submitted', true);
49 var hidden_by_fixed
= $('#field_duration, #field_trigger_id').parents('tr');
50 var fixed
= $('#field_fixed');
52 if (fixed
.is(':checked')) {
53 hidden_by_fixed
.hide();
57 fixed
.click(function() {
58 if (fixed
.is(':checked')) {
59 hidden_by_fixed
.hide();
61 hidden_by_fixed
.show();