1 function icon12(name, title, link)
3 var img = $('<span />');
4 img.addClass('icon-12');
5 img.addClass('x12-' + name);
6 if (title) img.attr('title', title);
8 img = link.clone().append(img);
9 img.css('border', '0');
13 function icon16(name, title, link, base)
15 if( !base ) base = 'x16';
16 var img = $('<span />');
17 img.addClass('icon-16');
18 img.addClass(base + '-' + name);
19 if (title) img.attr('title', title);
21 img = link.append(img);
22 img.css('border', '0');
26 function icon(url, link)
28 var img = $('<img />');
29 img.attr('src', _logo_path + url); // FIXME
30 img.css('height', '16px');
31 img.css('width', '16px');
33 img = link.append(img);
34 img.css('border', '0');
38 function link(rel_url, args)
42 for ( var key in args) {
43 get_data += delim + key + "=" + encodeURIComponent(args[key]);
48 el.attr('href', _site_domain + _index_page + "/" + rel_url + get_data);
51 function link_fnc(fnc)
53 return $('<a />').click(fnc);
55 function link_query(query)
57 var link = $('<a />');
58 link.attr('href', _site_domain + _index_page + '/listview?q='
59 + encodeURIComponent(query));
60 link.attr('data-query', query);
61 link.addClass('query_link');
64 function extinfo_link(args)
66 return link('extinfo/details', args);
68 function format_timestamp(timestamp)
70 // remember: server's offset is local - UTC, client's offset is UTC - local,
71 // so the sign should be the same.
72 var dateobj = new Date((timestamp + _server_utc_offset) * 1000);
73 dateobj = new Date(dateobj.getTime() + (dateobj.getTimezoneOffset() * 60000));
74 var ret = dateobj.format(_date_format);
78 function format_interval(interval)
80 if (interval < 0) return _('N/A');
82 if (interval % 60 !== 0) str = (interval % 60) + "s " + str;
83 interval = Math.floor(interval / 60);
84 if (interval % 60 !== 0) str = (interval % 60) + "m " + str;
85 interval = Math.floor(interval / 60);
86 if (interval % 24 !== 0) str = (interval % 24) + "h " + str;
87 interval = Math.floor(interval / 24);
88 if (interval !== 0) str = (interval) + "d " + str;
92 function comment_icon( host, service ) {
93 var obj_name = service ? host+';'+service : host;
94 var query = '[comments] host.name="' + host + '"' + (service?' and service.description="'+service+'"':'');
96 link_data.host = host;
98 link_data.service = service;
100 return extinfo_link(link_data)
101 .append(icon16('add-comment', _('Comments')))
102 .css('border', '0px')
103 .qtip($.extend(true, {}, qtip_default, {
105 text: function(ev, api) {
107 url: _site_domain + _index_page + "/ajax/fetch_comments/",
108 data: {host: obj_name}
110 .done(function(html) {
111 api.set('content.text', html);
113 .fail(function(xhr, status, error) {
114 api.set('content.text', status + ': ' + error);
117 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';
123 function pnp_popup(elem, args)
126 for ( var key in args) {
127 get_data.push(key + "=" + encodeURIComponent(args[key].replace(/[ :\/\\]/g, "_")));
130 $(elem).qtip($.extend(true, {}, qtip_default, {
132 text: function(ev, api) {
134 url: _site_domain + _index_page + "/ajax/pnp_image/",
135 data: {param: get_data.join("&")},
138 .done(function(html) {
139 api.set('content.text', html);
141 .fail(function(xhr, status, error) {
142 api.set('content.text', status + ': ' + error);
145 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';
151 jQuery.fn.update_text = function(text) {
152 if( _escape_html_tags ) {
153 return this.text(text);
155 return this.html(text);
159 jQuery.fn.querylink = function(text) {
160 if( _escape_html_tags ) {
161 return this.text(text);
163 return this.html(text);
167 jQuery.fn.replaceContent = function(new_data) {
169 this.append(new_data);
178 function render_summary_state(ul, state, stats, substates)
180 if (stats.stats[state] === 0) return;
182 var li = $('<li />').append(
183 link_query(stats.queries[state]).append(icon16('shield-' + state))
186 .text(stats.stats[state] + " " + state)));
191 for ( var tag in substates) {
192 var key = state + tag;
193 var type = substates[tag];
195 if (stats.stats[key]) {
197 li.append(link_query(stats.queries[key]).text(
198 stats.stats[key] + ' ' + type));
209 function render_service_status_summary(stats)
211 var ul = $('<ul class="listview-summary" />');
213 render_summary_state(ul, 'ok', stats, {});
214 render_summary_state(ul, 'warning', stats, {
215 '_and_ack': _('acknowledged'),
216 '_and_disabled_active': _('disabled active'),
217 '_and_scheduled': _('scheduled'),
218 '_and_unhandled': _('unhandled'),
219 '_on_down_host': _('on down host')
221 render_summary_state(ul, 'critical', stats, {
222 '_and_ack': _('acknowledged'),
223 '_and_disabled_active': _('disabled active'),
224 '_and_scheduled': _('scheduled'),
225 '_and_unhandled': _('unhandled'),
226 '_on_down_host': _('on down host')
228 render_summary_state(ul, 'unknown', stats, {
229 '_and_ack': _('acknowledged'),
230 '_and_disabled_active': _('disabled active'),
231 '_and_scheduled': _('scheduled'),
232 '_and_unhandled': _('unhandled'),
233 '_on_down_host': _('on down host')
235 render_summary_state(ul, 'pending', stats, {});
240 function render_host_status_summary(stats)
242 var ul = $('<ul class="listview-summary" />');
244 render_summary_state(ul, 'up', stats, {});
245 render_summary_state(ul, 'down', stats, {});
246 render_summary_state(ul, 'unreachable', stats, {});
247 render_summary_state(ul, 'pending', stats, {});
252 var listview_multi_select_header = $('<input type="checkbox" id="select_all" class="listview_multiselect_checkbox_all" />');
254 var listview_multi_select_cell_renderer = function(args)
257 '<input type="checkbox" name="object_select[]" class="listview_multiselect_checkbox" />')
258 .attr('value', args.obj.key);
259 if ( lsfilter_multiselect.box_selected(args.obj.key) ) {
260 checkbox.prop('checked', true);
261 if (args.row.hasClass('odd'))
262 args.row.addClass('selected_odd');
264 args.row.addClass('selected_even');
266 return $('<td style="width: 1em; padding: 0 3px" />').append(checkbox);