histogram: Make histograms crash less
[ninja.git] / application / views / extinfo / js / extinfo.js
blob1dc5e43cfcb6435e368b1dc86a35a9ec26b8f9af
1 $(document).ready(function() {
2         var old_refresh = 0;
4         $('.filterboxfield').focus(function() {
5                 if (!$('#ninja_refresh_control').attr('checked')) {
6                         // save previous refresh rate
7                         // to be able to restore it later
8                         old_refresh = current_interval;
9                         $('#ninja_refresh_lable').css('font-weight', 'bold');
10                         ninja_refresh(0);
11                         $("#ninja_refresh_control").attr('checked', true);
12                 }
13         });
15         $('.filterboxfield').blur(function() {
16                 if ($(this).val() != '') {
17                         // don't do anything if we have a current filter value
18                         return;
19                 }
20                 if ($('#ninja_refresh_control').attr('checked')) {
21                         // restore previous refresh rate
22                         ninja_refresh(old_refresh);
23                         $("#ninja_refresh_control").attr('checked', false);
24                         $('#ninja_refresh_lable').css('font-weight', '');
25                 }
26         });
29         /**
30                 ========================
31                 comment filters
32                 ========================
33         */
34         // host comments
35         if ($.tablesorter)
36                 $('#hostcomments_table').tablesorter({headers:{0:{sorter:false}}});
38         $('#clearhostsearch').click(function() {
39                 $('#hostfilterbox').val('').trigger('keyup').trigger('blur');
40                 return false;
41         });
43         $('#hostfilterbox').keyup(function(){
44                 filter_table(this, 'hostcomments_table');})
45                 .focus(function(){
46                         if(this.value==_filter_label) {
47                                 this.value='';
48                         }
49         })
50         .blur(function() {
51                 if (this.value == '') {
52                         this.value = _filter_label;
53                 }
54         });
56         $('.filterboxfield')
57                 .parents('form')
58                         .submit(function(ev) {
59                                 ev.preventDefault();
60                         });
62         // service comments
63         if ($.tablesorter)
64                 $('#servicecomments_table').tablesorter({headers:{0:{sorter:false}}});
66         $('#clearservicesearch').click(function() {
67                 $('#servicefilterbox').val('').trigger('keyup').trigger('blur');
68                 return false;
69         });
71         $('#servicefilterbox').keyup(function(){
72                 filter_table(this, 'servicecomments_table');})
73                 .focus(function(){
74                         if(this.value==_filter_label) {
75                                 this.value='';
76                         }
77         })
78         .blur(function() {
79                 if (this.value == '') {
80                         this.value = _filter_label;
81                 }
82         });
84         $('.pnp_graph').map(function() {
85                 var el = $(this);
86                 pnp_popup(el, el.data());
87         });
90         /**
91                 ========================
92                 scheduled downtime filters
93                 ========================
94         */
95         // host scheduled downtime
96         if ($.tablesorter)
97                 $('#scheduled_host_downtime').tablesorter({headers:{0:{sorter:false}}});
99         $('#clearhostsearch_sched').click(function() {
100                 $('#hostfilterbox_sched').val('').trigger('keyup').trigger('blur');
101                 return false;
102         });
104         $('#hostfilterbox_sched').keyup(function(){
105                 filter_table(this, 'scheduled_host_downtime');})
106                 .focus(function(){
107                         if(this.value==_filter_label) {
108                                 this.value='';
109                         }
110         })
111         .blur(function() {
112                 if (this.value == '') {
113                         this.value = _filter_label;
114                 }
115         });
118         // service scheduled downtime
119         if ($.tablesorter)
120                 $('#scheduled_service_downtime').tablesorter({headers:{0:{sorter:false}}});
122         $('#clearservicesearch_sched').click(function() {
123                 $('#servicefilterbox_sched').val('').trigger('keyup').trigger('blur');
124                 return false;
125         });
127         $('#servicefilterbox_sched').keyup(function(){
128                 filter_table(this, 'scheduled_service_downtime');})
129                 .focus(function(){
130                         if(this.value==_filter_label) {
131                                 this.value='';
132                         }
133         })
134         .blur(function() {
135                 if (this.value == '') {
136                         this.value = _filter_label;
137                 }
138         });
140         $('.extinfo_contactgroup').each(function() {
141                 $(this).bind('click', function() {
142                         var the_id = $(this).attr('id');
143                         the_id = the_id.replace('extinfo_contactgroup_', '');
144                         $('#extinfo_contacts_' + the_id).toggle();
145                         return false;
146                 });
147         });
149         setTimeout('hide_del_msg()', 3000);
151         $('#del_host_downtime_form').bind('submit', function() {
152                 //return false;
153         });
155         var validate_host_submit = function() {
156                 $('.deletecommentbox_host').each(function() {
157                         if (!$(this).is(':visible'))
158                                 $(this).attr('checked', false);
159                 });
160                 if (!$('.deletecommentbox_host').filter(':checked').length) {
161                         $('.host_feedback').text('   Nothing selected...');
162                         setTimeout(function() {$('.host_feedback').hide();}, 5000);
163                         return false;
164                 } else {
165                         $('.host_feedback').text('');
166                 }
167         }
169         $('#del_submithost_svc').click(function() {
170                 if (validate_host_submit() == false)
171                         return false;
173                 var hostform = $(this).parents('form');
174                 // borderline evil:
175                 // this moves the checkboxes from the service form to the host form before submitting.
176                 var cb = trigger_cb_on_nth_call(function() {hostform.submit();}, $('.deletecommentbox_host').length);
177                 hostform.append('<input type="hidden" name="del_submithost_svc" value="1" />');
178                 $('.deletecommentbox_host').each(function() {
179                         if ($(this).attr('checked')) {
180                                 var hostname = $(this).closest('tr').find('td:nth-child(2)').text();
181                                 $('#scheduled_service_downtime').find('tr td:nth-child(2)').each(function() {
182                                         if ($(this).text() == hostname) {
183                                                 hostform.append($(this).closest('tr').find('td:nth-child(1) input[type="checkbox"]').css('display', 'none').attr('checked', true));
184                                         }
185                                 });
186                         }
187                         cb();
188                 });
189                 return false;
190         });
192         // check that user selected any checkboxes before submitting
193         $('#del_submithost').click(validate_host_submit);
195         $('#del_submitservice').click(function() {
196                 $('.deletecommentbox_service').each(function() {
197                         if (!$(this).is(':visible'))
198                                 $(this).attr('checked', false);
199                 });
200                 if (!$('.deletecommentbox_service').filter(':checked').length) {
201                         $('.service_feedback').text('   Nothing selected...');
202                         setTimeout(function() {$('.service_feedback').hide();}, 5000);
203                         return false;
204                 } else {
205                         $('.service_feedback').text('');
206                 }
207         });
208         $('.custom_command a').fancybox({
209                         'overlayOpacity': 0.7,
210                         'overlayColor' : '#000000',
211                         'hideOnContentClick': false,
212                         'hideOnOverlayClick': false,
213                         'titleShow': false,
214                         'showCloseButton': false,
215                         'enableEscapeButton': false,
216                         'autoDimensions': true,
217                         'width': 250,
218                         'height': 10
219         })
220         .css('border-bottom', '1px dotted #777');
221         $('.custom_command a').click(function() {
222                 // Don't refresh page while script is running.
223                 clearInterval(_interval);
224                 var cmd = $(this).attr('title');
225                 cmd = cmd.replace(/;/g, "/");
226                 $('#fancybox-content').text('Executing command, please wait for acknowledgement.');
227                 // Load executing function with custom var name as parameter
228                 $('#fancybox-content').load(_site_domain+'index.php/command/exec_custom_command/'+encodeURI(cmd), function() {
229                         $('#fancybox-close').show();
230                         // It's ok to refresh again so let's start doing so.
231                         ninja_refresh(0);
232                 });
233         });
236 function hide_del_msg() {
237         $('#comment_del_msg').hide('slow');
240 function filter_table (phrase, _id){
241         var words = phrase.value.toLowerCase().split(" ");
242         var table = document.getElementById(_id);
243         var ele;
245         for (var r = 1; r < table.rows.length; r++){
246                 ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
247                 var displayStyle = 'none';
248                 if (table.rows[r].className.indexOf('submit') == -1) {
249                         for (var i = 0; i < words.length; i++) {
250                                 if (ele.toLowerCase().indexOf(words[i])>=0)
251                                         displayStyle = '';
252                                 else {
253                                         displayStyle = 'none';
254                                         break;
255                                 }
256                         }
257                 }
258                 table.rows[r].style.display = displayStyle;
259         }