Merge branch 'maint/7.0'
[ninja.git] / application / views / command / js / command.js
blob493560d49e71018f4d9977a055d5c64a82a71e23
1 $(document).ready(function() {
3 $('#command_form').bind('submit', function() {
4 var form = $(this);
5 if(form.data('already_submitted')) {
6 return false;
8 /*
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);
21 });
23 var inputs = $('#command_form input');
24 $('select[type="select-multiple"]').each(function() {
25 $(this).children('option').attr('selected', true);
26 });
27 var err_str = '';
28 inputs.each(function() {
29 var val = $(this).val();
30 var key_str = /\[.*?\]/.exec(this.name);
31 if (key_str) {
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";
39 });
40 if (err_str.length) {
41 // alert user using translated string from master template
42 alert(sprintf(_form_error_header, "\n", "\n\n") + err_str);
43 return false;
45 form.data('already_submitted', true);
46 return true;
47 });
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();
60 } else {
61 hidden_by_fixed.show();
64 });