histogram: Make histograms crash less
[ninja.git] / application / views / reports / js / reports.js
bloba861bd08233d37fe10fadbd65a4585a6eacf2577
1 $(document).ready(function() {
2         // reset options and reload page
3         $('#new_report').click(function() {
4                 var current_report = $('input[name=type]').val();
5                 var base_uri = _site_domain + _index_page + '/' + _current_uri;
6                 var uri_xtra = current_report == 'avail' ? '' : '?type=sla';
7                 self.location.href = base_uri + uri_xtra;
8         });
10         $('#include_trends').click(function() {
11                 if (this.checked) {
12                         $('#include_trends_scaling').attr('disabled', false);
13                 } else {
14                         $('#include_trends_scaling').attr('disabled', true);
15                         $('#include_trends_scaling').attr('checked', false);
16                 }
17         });
19         $("#report_period").bind('change', function() {
20                 show_calendar($(this).attr('value'));
21         });
22         show_calendar($("#report_period").attr('value'));
24         $('.autofill').click(function() {
25                 var the_val = $(this).siblings('input').val();
26                 if (the_val!='') {
27                         if (!confirm(_reports_propagate.replace('this value', the_val+'%'))) {
28                                 return false;
29                         }
30                         set_report_form_values(the_val);
31                 } else {
32                         if (!confirm(_reports_propagate_remove)) {
33                                 return false;
34                         }
35                         set_report_form_values('');
36                 }
37         });
39         $("#new_schedule_btn").click(function() {$('.schedule_error').hide();})
41         $('#filename').blur(function() {
42                 // Make sure the filename is explicit by adding it when focus leaves input
43                 var input = $(this);
44                 var filename = input.val();
45                 if(!filename) {
46                         return;
47                 }
48                 if(!filename.match(/\.(csv|pdf)$/)) {
49                         filename += '.pdf';
50                 }
51                 input.val(filename);
52         });
54         $('#include_trends').live('click', function(ev) {
55                 if (ev.target.checked)
56                         $('.trend_options').show();
57                 else
58                         $('.trend_options').hide();
59         });
61         $('#sla_report_id').on('change', function(ev) {
62                 var sla_id = $(this).attr('value');
63                 if (!sla_id) {
64                         // don't try to fetch sla values when we have no id
65                         return;
66                 }
67                 show_progress('progress', _wait_str);
68                 var url = _site_domain + _index_page + '/sla/per_month_sla_for_report';
69                 var data = {sla_id: sla_id}
71                 $.ajax({
72                         url: url,
73                         data: data,
74                         complete: function() {
75                                 $('#progress').hide();
76                         },
77                         error: function() {
78                                 $.notify(_reports_error + ': Unable to fetch saved sla values...', {'sticky':true});
79                         },
80                         success: function(data) {
81                                 for (var i = 0; i < data.length; i++) {
82                                         var input = $('#month_' + i);
83                                         if (input.is(':disabled') || !data[i]) {
84                                                 input.val('');
85                                         } else {
86                                                 input.val(data[i]);
87                                         }
88                                 }
89                                 $('.sla_values').show();
90                         },
91                         dataType: 'json'
92                 });
93         });
94 });
96 // Propagate sla values
97 function set_report_form_values(the_val)
99         for (i=1;i<=12;i++) {
100                 var field_name = 'month_' + i;
101                 var input = $("#"+field_name);
102                 if (input.attr('disabled')) {
103                         input.attr('value', '');
104                 } else {
105                         input.attr('value', the_val);
106                 }
107         }
111 *       create ajax call to reports/fetch_field_value
112 *       to fetch a specific field value and asssign it to html element.
114 function fetch_field_value(type, id, elem_id)
116         $.ajax({
117                 url: _site_domain + _index_page + '/reports/fetch_field_value?id=' + id + '&type=' + type,
118                 success: function(data) {
119                         $('#' + elem_id).text(data);
120                 }
121         });