icingaweb2-module-businessp.../public/js/module.js

152 lines
4.6 KiB
JavaScript
Raw Normal View History

(function(Icinga) {
var Bp = function(module) {
/**
* YES, we need Icinga
*/
this.module = module;
2014-11-30 04:40:37 -05:00
this.idCache = {};
this.initialize();
this.module.icinga.logger.debug('BP module loaded');
};
Bp.prototype = {
initialize: function()
{
/**
* Tell Icinga about our event handlers
*/
this.module.on('beforerender', this.rememberOpenedBps);
this.module.on('rendered', this.fixOpenedBps);
this.module.on('click', 'table.businessprocess th', this.titleClicked);
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);
this.module.on('mouseleave', 'div.bp', this.procMouseOut);
this.module.icinga.logger.debug('BP module loaded');
},
/**
* Add 'hovered' class to hovered title elements
*
* TODO: Skip on tablets
*/
2014-11-30 04:45:05 -05:00
procMouseOver: function (event) {
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');
},
/**
* 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');
},
/**
* 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');
}
});
/*$container.data('refreshParams', {
opened: self.listOpenedBps($container)
});*/
},
fixOpenedBps: function(event) {
var $container = $(event.currentTarget);
2014-11-30 04:40:37 -05:00
var container_id = $container.attr('id');
if (typeof this.idCache[container_id] === 'undefined') {
return;
}
2014-11-30 04:40:37 -05:00
var $procs = $('table.process', $container);
$.each(this.idCache[$container.attr('id')], function(idx, id) {
var $el = $('#' + id);
$procs = $procs.not($el);
$el.parents('table.process').each(function (idx, el) {
$procs = $procs.not($(el));
});
});
2014-11-30 04:40:37 -05:00
$procs.addClass('collapsed');
},
/**
* Get a list of all currently opened BPs.
*
* Only get the deepest nodes to keep requests as small as possible
*/
rememberOpenedBps: function (event) {
var $container = $(event.currentTarget);
var ids = [];
$('table.process', $container)
.not('table.process.collapsed')
.not('table.process.collapsed table.process')
.each(function (key, el) {
ids.push($(el).attr('id'));
});
if (ids.length === 0) {
return;
}
this.idCache[$container.attr('id')] = ids;
}
};
Icinga.availableModules.bpapp = Bp;
}(Icinga));