1 function helpicon(controller, key)
3 var link = $('<a class="helptext_target" style="border: 0" href="#"/>');
4 link.append(icon12('help'));
5 bind_helptext(link, controller, key);
9 function icon12(name, title, link)
11 var img = $('<span />');
12 img.addClass('icon-12');
13 img.addClass('x12-' + name);
14 if (title) img.attr('title', title);
16 img = link.clone().append(img);
17 img.css('border', '0');
21 function icon16(name, title, link, base)
23 if( !base ) base = 'x16';
24 var img = $('<span />');
25 img.addClass('icon-16');
26 img.addClass(base + '-' + name);
27 if (title) img.attr('title', title);
29 img = link.append(img);
30 img.css('border', '0');
34 function icon(url, link)
36 var img = $('<img />');
37 img.attr('src', _logo_path + url); // FIXME
38 img.css('height', '16px');
39 img.css('width', '16px');
41 img = link.append(img);
42 img.css('border', '0');
46 function link(rel_url, args)
50 for ( var key in args) {
51 get_data += delim + key + "=" + encodeURIComponent(args[key]);
56 el.attr('href', _site_domain + _index_page + "/" + rel_url + get_data);
59 function link_fnc(fnc)
61 return $('<a />').click(fnc);
63 function link_query(query)
65 var link = $('<a />');
66 link.attr('href', _site_domain + _index_page + '/listview?q='
67 + encodeURIComponent(query));
68 link.attr('data-query', query);
69 link.addClass('query_link');
72 function extinfo_link(args)
74 return link('extinfo/details', args);
76 function format_timestamp(timestamp)
78 // remember: server's offset is local - UTC, client's offset is UTC - local,
79 // so the sign should be the same.
80 var timestamp_int = parseInt(timestamp);
82 var dateobj = new Date((timestamp_int + _server_utc_offset) * 1000);
83 dateobj = new Date(dateobj.getTime() + (dateobj.getTimezoneOffset() * 60000));
84 var ret = dateobj.format(_date_format);
88 function format_interval(interval)
90 if (interval < 0) return _('N/A');
92 if (interval % 60 !== 0) str = (interval % 60) + "s " + str;
93 interval = Math.floor(interval / 60);
94 if (interval % 60 !== 0) str = (interval % 60) + "m " + str;
95 interval = Math.floor(interval / 60);
96 if (interval % 24 !== 0) str = (interval % 24) + "h " + str;
97 interval = Math.floor(interval / 24);
98 if (interval !== 0) str = (interval) + "d " + str;
102 function comment_icon( host, service ) {
103 var obj_name = service ? host+';'+service : host;
104 var query = '[comments] host.name="' + host + '"' + (service?' and service.description="'+service+'"':'');
106 link_data.host = host;
108 link_data.service = service;
110 return extinfo_link(link_data)
111 .append(icon16('add-comment', _('Comments')))
112 .css('border', '0px')
113 .qtip($.extend(true, {}, qtip_default, {
115 text: function(ev, api) {
117 url: _site_domain + _index_page + "/ajax/fetch_comments/",
118 data: {host: obj_name}
120 .done(function(html) {
121 api.set('content.text', html);
123 .fail(function(xhr, status, error) {
124 api.set('content.text', status + ': ' + error);
127 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';
133 function pnp_popup(elem, args)
136 for ( var key in args) {
137 get_data.push(key + "=" + encodeURIComponent(args[key].replace(/[ :\/\\]/g, "_")));
140 $(elem).qtip($.extend(true, {}, qtip_default, {
142 text: function(ev, api) {
144 url: _site_domain + _index_page + "/ajax/pnp_image/",
145 data: {param: get_data.join("&")},
148 .done(function(html) {
149 api.set('content.text', html);
151 .fail(function(xhr, status, error) {
152 api.set('content.text', status + ': ' + error);
155 return '<img src="' + _site_domain + loading_img + '" alt="' + _loading_str + '" />';
161 jQuery.fn.update_text = function(text) {
162 if( _escape_html_tags ) {
163 return this.text(text);
165 return this.html(text);
169 jQuery.fn.querylink = function(text) {
170 if( _escape_html_tags ) {
171 return this.text(text);
173 return this.html(text);
177 jQuery.fn.replaceContent = function(new_data) {
179 this.append(new_data);
188 function render_summary_state(ul, state, stats, substates)
190 if (stats.stats[state] === 0) return;
192 var li = $('<li />').append(
193 link_query(stats.queries[state]).append(icon16('shield-' + state))
196 .text(stats.stats[state] + " " + state)));
201 for ( var tag in substates) {
202 var key = state + tag;
203 var type = substates[tag];
205 if (stats.stats[key]) {
207 li.append(link_query(stats.queries[key]).text(
208 stats.stats[key] + ' ' + type));
219 function render_service_status_summary(stats)
221 var ul = $('<ul class="listview-summary" />');
223 render_summary_state(ul, 'ok', stats, {});
224 render_summary_state(ul, 'warning', stats, {
225 '_and_ack': _('acknowledged'),
226 '_and_disabled_active': _('disabled active'),
227 '_and_scheduled': _('scheduled'),
228 '_and_unhandled': _('unhandled'),
229 '_on_down_host': _('on down host')
231 render_summary_state(ul, 'critical', stats, {
232 '_and_ack': _('acknowledged'),
233 '_and_disabled_active': _('disabled active'),
234 '_and_scheduled': _('scheduled'),
235 '_and_unhandled': _('unhandled'),
236 '_on_down_host': _('on down host')
238 render_summary_state(ul, 'unknown', stats, {
239 '_and_ack': _('acknowledged'),
240 '_and_disabled_active': _('disabled active'),
241 '_and_scheduled': _('scheduled'),
242 '_and_unhandled': _('unhandled'),
243 '_on_down_host': _('on down host')
245 render_summary_state(ul, 'pending', stats, {});
250 function render_host_status_summary(stats)
252 var ul = $('<ul class="listview-summary" />');
254 render_summary_state(ul, 'up', stats, {});
255 render_summary_state(ul, 'down', stats, {});
256 render_summary_state(ul, 'unreachable', stats, {});
257 render_summary_state(ul, 'pending', stats, {});
262 var listview_multi_select_header = $('<input type="checkbox" id="select_all" class="listview_multiselect_checkbox_all" />');
264 var listview_multi_select_cell_renderer = function(args)
267 '<input type="checkbox" name="object_select[]" class="listview_multiselect_checkbox" />')
268 .attr('value', args.obj.key);
269 if ( lsfilter_multiselect.box_selected(args.obj.key) ) {
270 checkbox.prop('checked', true);
271 if (args.row.hasClass('odd'))
272 args.row.addClass('selected_odd');
274 args.row.addClass('selected_even');
276 return $('<td style="width: 1em; padding: 0 3px" />').append(checkbox);