1 (function (_site_domain, _index_page) {
5 /* QUICKLINK EXTENSION */
6 var uh_prob_title = "Unhandled Problems",
7 uh_prob_state_element = null;
8 function query_for_states () {
10 var basepath = _site_domain + _index_page,
11 link = $('#uh_problems'),
12 query = link.attr('href');
14 query = query.split('q=')[1];
17 url : basepath + "/listview/fetch_ajax",
22 "columns": ['description']
24 success : function(data) {
26 if (data && data.totals.service_all[1] > 0) {
28 uh_prob_title = data.totals.service_all[1] + ' unacknowledged services in Critical/Warning state!';
29 link.attr('title', uh_prob_title);
31 if (uh_prob_state_element) {
32 uh_prob_state_element.remove();
34 uh_prob_state_element = $("<span style='margin: 0; position: absolute; color: #000; text-shadow: 0 0 2px #fff; font-weight: bold; font-size: 10px; padding: 1px 1px 0 0; right: 0px; bottom: 0px;' />");
35 if(data.totals.service_all[1] < 100 ) {
36 uh_prob_state_element.text(data.totals.service_all[1]);
38 link.append(uh_prob_state_element);
40 if (data.totals.service_state_critical[1] > 0) {
41 link.find(':first-child').removeClass().addClass('icon-16 x16-shield-critical');
42 } else if (data.totals.service_state_warning[1] > 0) {
43 link.find(':first-child').removeClass().addClass('icon-16 x16-shield-warning');
50 setInterval(query_for_states, 10000);
53 var global_quicklinks = [];
55 var fix_empty_quicklink_border = function() {
56 // there's a magical dot (about 1x1 pixel) hanging in the air,
57 // disturbing probably just me. It's caused by having a quicklinks
58 // container without any quicklinks
59 var quicklinks = $('#dojo-quicklink-external');
60 var tr = quicklinks.parent();
61 if(quicklinks.find('li').length) {
62 tr.css('borderWidth', 1);
64 tr.css('borderWidth', 0);
68 function quicklinks_save_all () {
69 $.ajax(_site_domain + _index_page + '/ajax/save_page_setting', {
71 'type': 'dojo-quicklinks',
73 'setting': JSON.stringify(global_quicklinks)
76 complete: function() {
77 $('#dojo-add-quicklink-href').attr('value','');
78 $('#dojo-add-quicklink-title').attr('value','');
79 $('#dojo-add-quicklink-icon').attr('value','');
80 fix_empty_quicklink_border();
85 $('#dojo-add-quicklink').hover(function () {
86 this.style.opacity = '1.0';
88 this.style.opacity = '0.5';
91 $('#dojo-icon-container').on('click', 'span', function() {
93 $('#dojo-add-quicklink-icon').val(span.data('icon'));
95 // we have to change the background of the td, since the span already
96 // has the icon image as its background
97 var all_tds = $('#dojo-icon-container td');
98 all_tds.removeClass('highlight');
99 span.parents('td').addClass('highlight');
102 $('#dojo-add-quicklink').fancybox({
105 onComplete: function() {
106 $('#dojo-quicklink-remove').html('');
107 for (var i = 0; i < global_quicklinks.length; i += 1) {
108 var l = global_quicklinks[i];
109 var vid = l.title + ':'+ l.href;
110 var quicklink = $('<li><label><input type="checkbox" /><span class="icon-16 x16-'+l.icon+'"></span>' + l.title + '</label> (<a target="_blank" class="external"></a>)</li>');
115 .attr('title', l.title);
118 .attr('href', l.href)
120 $('#dojo-quicklink-remove').append(quicklink);
123 onClose: function() {
124 $('#dojo-add-quicklink-href').attr('value','');
125 $('#dojo-add-quicklink-title').attr('value','');
126 $('#dojo-add-quicklink-icon').attr('value','');
127 fix_empty_quicklink_border();
131 $('#dojo-add-quicklink-menu form').submit(function (ev) {
133 var href = $('#dojo-add-quicklink-href').attr('value'),
134 title = $('#dojo-add-quicklink-title').attr('value'),
135 icon = $('#dojo-add-quicklink-icon').attr('value'),
136 target = $('#dojo-add-quicklink-target').attr('value'),
139 if (href && title && icon) {
140 var i = global_quicklinks.length;
142 if (global_quicklinks[i].href === href) {
143 error += 'This href is already used in a quicklink. <br />';
145 if (global_quicklinks[i].title === title) {
146 error += 'This title is already in use, titles must be unique. <br />';
149 if (error.length === 0) {
150 global_quicklinks.push({'href': href,'title': title,'icon': icon,'target': target});
151 var quicklink = $('<li><a class="image-link"><span class="icon-16 x16-' + icon + '"></span></a></li>');
154 .attr('target', target)
156 .attr('title', title);
157 $('#dojo-quicklink-external').append(quicklink);
164 $('#dojo-quicklink-remove input[type="checkbox"]').each(function () {
165 var i = global_quicklinks.length;
169 vid = global_quicklinks[i].title + ':' + global_quicklinks[i].href;
170 if (this.value === vid) {
171 $('#dojo-quicklink-external li a[title="'+this.title+'"]').parent().remove();
172 global_quicklinks.splice(i, 1);
180 quicklinks_save_all();
187 $.ajax(_site_domain + _index_page + '/ajax/get_setting', {
189 'type': 'dojo-quicklinks',
193 complete: function() {
194 fix_empty_quicklink_border();
196 success: function (obj) {
200 if (obj['dojo-quicklinks']) {
201 links = obj['dojo-quicklinks'];
202 for (var i = 0; i < links.length; i += 1) {
203 var quicklink = $('<li><a class="image-link"><span class="icon-16 x16-'+links[i].icon+'"></span></a></li>');
206 .attr('target', links[i].target)
207 .attr('href', links[i].href)
208 .attr('title', links[i].title);
210 $('#dojo-quicklink-external').append(quicklink);
213 global_quicklinks = links;
217 }(window._site_domain, window._index_page));