2014-10-20 10:26:06 -04:00
|
|
|
|
|
|
|
|
(function(Icinga) {
|
|
|
|
|
|
|
|
|
|
var Bp = function(module) {
|
|
|
|
|
/**
|
|
|
|
|
* YES, we need Icinga
|
|
|
|
|
*/
|
|
|
|
|
this.module = module;
|
|
|
|
|
|
2014-11-30 04:40:37 -05:00
|
|
|
this.idCache = {};
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
this.initialize();
|
|
|
|
|
|
|
|
|
|
this.module.icinga.logger.debug('BP module loaded');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bp.prototype = {
|
|
|
|
|
|
|
|
|
|
initialize: function()
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Tell Icinga about our event handlers
|
|
|
|
|
*/
|
2014-11-30 04:43:09 -05:00
|
|
|
this.module.on('beforerender', this.rememberOpenedBps);
|
2015-10-07 10:48:59 -04:00
|
|
|
this.module.on('rendered', this.rendered);
|
2014-11-30 04:43:09 -05:00
|
|
|
|
2015-03-03 07:55:33 -05:00
|
|
|
this.module.on('click', 'table.bp.process > tbody > tr:first-child > td > a:last-child', this.processTitleClick);
|
2014-11-30 04:45:59 -05:00
|
|
|
this.module.on('click', 'table.bp > tbody > tr:first-child > th', this.processOperatorClick);
|
2015-10-07 10:48:59 -04:00
|
|
|
this.module.on('click', '.bp-overlay-controls a', this.closeOverlay);
|
|
|
|
|
this.module.on('click', 'a', this.checkOverlay);
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2014-11-30 04:45:05 -05:00
|
|
|
this.module.on('mouseenter', 'table.bp > tbody > tr > td > a', this.procMouseOver);
|
|
|
|
|
this.module.on('mouseenter', 'table.bp > tbody > tr > th', this.procMouseOver);
|
2015-03-16 04:08:00 -04:00
|
|
|
this.module.on('mouseenter', 'table.node.missing > tbody > tr > td > span', this.procMouseOver);
|
2014-11-30 04:45:05 -05:00
|
|
|
this.module.on('mouseleave', 'div.bp', this.procMouseOut);
|
2015-10-07 10:48:59 -04:00
|
|
|
if ($('#bp-overlay').length < 1) {
|
|
|
|
|
$('#layout').append('<div id="bp-module-overlay" class="icinga-module module-businessprocess"><div id="bp-overlay-container"><div class="bp-overlay-controls"><a href="">X</a></div><div id="bp-overlay" class="container"></div></div></div>');
|
|
|
|
|
}
|
2014-11-30 04:45:05 -05:00
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
this.module.icinga.logger.debug('BP module loaded');
|
|
|
|
|
},
|
|
|
|
|
|
2015-10-07 10:48:59 -04:00
|
|
|
closeOverlay: function(event) {
|
|
|
|
|
$('#bp-overlay-container').hide();
|
|
|
|
|
$('#bp-overlay').html('');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
checkOverlay: function(event) {
|
|
|
|
|
$el = $(event.currentTarget);
|
|
|
|
|
$sourceContainer = $el.closest('.container');
|
|
|
|
|
$target = $el.closest('[data-base-target]');
|
|
|
|
|
if ($target.length < 1) { return; }
|
|
|
|
|
|
|
|
|
|
targetId = $target.data('baseTarget');
|
|
|
|
|
if ($target.data('baseTarget') !== 'bp-overlay') { return; }
|
|
|
|
|
|
|
|
|
|
$('#bp-overlay').data('sourceContainer', $sourceContainer.attr('id'));
|
|
|
|
|
$('#bp-overlay-container').css({
|
|
|
|
|
'display': 'block'
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2014-11-30 04:45:59 -05:00
|
|
|
processTitleClick: function (event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
var $el = $(event.currentTarget).closest('table.bp');
|
|
|
|
|
$el.toggleClass('collapsed');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
processOperatorClick: function (event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
var $el = $(event.currentTarget).closest('table.bp');
|
|
|
|
|
|
|
|
|
|
// Click on arrow
|
|
|
|
|
$el.removeClass('collapsed');
|
|
|
|
|
|
|
|
|
|
var children = $el.find('> tbody > tr > td > table.bp.process');
|
|
|
|
|
if (children.length === 0) {
|
|
|
|
|
$el.toggleClass('collapsed');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (children.filter('.collapsed').length) {
|
|
|
|
|
children.removeClass('collapsed');
|
|
|
|
|
} else {
|
|
|
|
|
children.each(function(idx, el) {
|
|
|
|
|
var $el = $(el);
|
|
|
|
|
$el.addClass('collapsed');
|
|
|
|
|
$el.find('table.bp.process').addClass('collapsed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
/**
|
|
|
|
|
* Add 'hovered' class to hovered title elements
|
|
|
|
|
*
|
|
|
|
|
* TODO: Skip on tablets
|
|
|
|
|
*/
|
2014-11-30 04:45:05 -05:00
|
|
|
procMouseOver: function (event) {
|
2014-10-20 10:26:06 -04:00
|
|
|
event.stopPropagation();
|
2014-11-30 04:45:05 -05:00
|
|
|
var $hovered = $(event.currentTarget);
|
|
|
|
|
var $el = $hovered.closest('table.bp');
|
|
|
|
|
|
|
|
|
|
if ($el.is('.operator')) {
|
|
|
|
|
if (!$hovered.closest('tr').is('tr:first-child')) {
|
|
|
|
|
// Skip hovered space between cols
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('table.bp.hovered').not($el.parents('table.bp')).removeClass('hovered'); // not self & parents
|
|
|
|
|
$el.addClass('hovered');
|
|
|
|
|
$el.parents('table.bp').addClass('hovered');
|
2014-10-20 10:26:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove 'hovered' class from hovered title elements
|
|
|
|
|
*
|
|
|
|
|
* TODO: Skip on tablets
|
|
|
|
|
*/
|
2014-11-30 04:45:05 -05:00
|
|
|
procMouseOut: function (event) {
|
|
|
|
|
$('table.bp.hovered').removeClass('hovered');
|
2014-10-20 10:26:06 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle clicks on operator or title element
|
|
|
|
|
*
|
|
|
|
|
* Title shows subelement, operator unfolds all subelements
|
|
|
|
|
*/
|
|
|
|
|
titleClicked: function (event) {
|
|
|
|
|
var self = this;
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
var $el = $(event.currentTarget),
|
|
|
|
|
affected = []
|
|
|
|
|
$container = $el.closest('.container');
|
|
|
|
|
if ($el.hasClass('operator')) {
|
|
|
|
|
$affected = $el.closest('table').children('tbody')
|
|
|
|
|
.children('tr.children').children('td').children('table');
|
|
|
|
|
|
|
|
|
|
// Only if there are child BPs
|
|
|
|
|
if ($affected.find('th.operator').length < 1) {
|
|
|
|
|
$affected = $el.closest('table');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$affected = $el.closest('table');
|
|
|
|
|
}
|
|
|
|
|
$affected.each(function (key, el) {
|
|
|
|
|
var $bptable = $(el).closest('table');
|
|
|
|
|
$bptable.toggleClass('collapsed');
|
|
|
|
|
if ($bptable.hasClass('collapsed')) {
|
|
|
|
|
$bptable.find('table').addClass('collapsed');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-11-30 04:41:11 -05:00
|
|
|
/*$container.data('refreshParams', {
|
2014-10-20 10:26:06 -04:00
|
|
|
opened: self.listOpenedBps($container)
|
2014-11-30 04:41:11 -05:00
|
|
|
});*/
|
2014-10-20 10:26:06 -04:00
|
|
|
},
|
|
|
|
|
|
2015-10-07 10:48:59 -04:00
|
|
|
rendered: function(event) {
|
2014-10-20 10:26:06 -04:00
|
|
|
var $container = $(event.currentTarget);
|
2015-10-07 10:48:59 -04:00
|
|
|
if ($container.attr('id') === 'bp-overlay') {
|
|
|
|
|
this.onOverlayRendered();
|
|
|
|
|
}
|
|
|
|
|
this.fixOpenedBps($container);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fixOpenedBps: function($container) {
|
2014-11-30 04:40:37 -05:00
|
|
|
var container_id = $container.attr('id');
|
|
|
|
|
|
|
|
|
|
if (typeof this.idCache[container_id] === 'undefined') {
|
2014-10-20 10:26:06 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2014-11-30 04:40:37 -05:00
|
|
|
var $procs = $('table.process', $container);
|
2015-10-07 10:48:59 -04:00
|
|
|
$.each(this.idCache[container_id], function(idx, id) {
|
2014-11-30 04:40:37 -05:00
|
|
|
var $el = $('#' + id);
|
|
|
|
|
$procs = $procs.not($el);
|
|
|
|
|
|
|
|
|
|
$el.parents('table.process').each(function (idx, el) {
|
|
|
|
|
$procs = $procs.not($(el));
|
2014-10-20 10:26:06 -04:00
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-11-30 04:40:37 -05:00
|
|
|
|
|
|
|
|
$procs.addClass('collapsed');
|
2014-10-20 10:26:06 -04:00
|
|
|
},
|
|
|
|
|
|
2015-10-07 10:48:59 -04:00
|
|
|
onOverlayRendered: function()
|
|
|
|
|
{
|
|
|
|
|
// close overlay if required:
|
|
|
|
|
$overlay = $('#bp-overlay');
|
|
|
|
|
$overlayContainer = $('#bp-overlay-container');
|
|
|
|
|
if ($overlayContainer.css('display') === 'block' && $overlay.html().match(/^__CLOSEME__/)) {
|
|
|
|
|
$source = $('#' + $overlay.data('sourceContainer'));
|
|
|
|
|
$overlayContainer.hide();
|
|
|
|
|
self.icinga.loader.loadUrl($source.data('icingaUrl'), $source, undefined, undefined, undefined, true);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
/**
|
|
|
|
|
* Get a list of all currently opened BPs.
|
|
|
|
|
*
|
|
|
|
|
* Only get the deepest nodes to keep requests as small as possible
|
|
|
|
|
*/
|
2014-11-30 04:43:09 -05:00
|
|
|
rememberOpenedBps: function (event) {
|
|
|
|
|
var $container = $(event.currentTarget);
|
2014-10-20 10:26:06 -04:00
|
|
|
var ids = [];
|
2014-11-30 04:43:09 -05:00
|
|
|
$('table.process', $container)
|
|
|
|
|
.not('table.process.collapsed')
|
|
|
|
|
.not('table.process.collapsed table.process')
|
|
|
|
|
.each(function (key, el) {
|
|
|
|
|
ids.push($(el).attr('id'));
|
2014-10-20 10:26:06 -04:00
|
|
|
});
|
2014-11-30 04:43:09 -05:00
|
|
|
if (ids.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2014-11-30 04:43:09 -05:00
|
|
|
this.idCache[$container.attr('id')] = ids;
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
Icinga.availableModules.businessprocess = Bp;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
|
|
|
|
}(Icinga));
|
|
|
|
|
|