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
|
|
|
|
|
*/
|
2019-01-22 05:46:25 -05:00
|
|
|
this.module.on('rendered', this.onRendered);
|
2014-11-30 04:43:09 -05:00
|
|
|
|
2016-12-08 04:16:56 -05:00
|
|
|
this.module.on('focus', 'form input, form textarea, form select', this.formElementFocus);
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
this.module.on('click', 'li.process a.toggle', this.processToggleClick);
|
|
|
|
|
this.module.on('click', 'li.process > div', this.processHeaderClick);
|
2019-01-23 03:16:47 -05:00
|
|
|
this.module.on('end', 'ul.sortable', this.rowDropped);
|
2014-11-30 04:45:05 -05:00
|
|
|
|
2017-01-03 05:10:07 -05:00
|
|
|
this.module.on('click', 'div.tiles > div', this.tileClick);
|
2018-08-01 03:35:46 -04:00
|
|
|
this.module.on('click', '.dashboard-tile', this.dashboardTileClick);
|
2018-12-17 08:40:47 -05:00
|
|
|
this.module.on('end', 'div.tiles.sortable', this.tileDropped);
|
2017-01-03 05:10:07 -05:00
|
|
|
|
2016-12-08 04:16:56 -05:00
|
|
|
this.module.icinga.logger.debug('BP module initialized');
|
2014-10-20 10:26:06 -04:00
|
|
|
},
|
|
|
|
|
|
2016-11-28 18:50:20 -05:00
|
|
|
onRendered: function (event) {
|
|
|
|
|
var $container = $(event.currentTarget);
|
|
|
|
|
this.fixFullscreen($container);
|
2019-01-22 05:46:25 -05:00
|
|
|
this.restoreCollapsedBps($container);
|
2016-12-08 04:16:56 -05:00
|
|
|
this.highlightFormErrors($container);
|
|
|
|
|
this.hideInactiveFormDescriptions($container);
|
2017-01-27 05:53:58 -05:00
|
|
|
this.fixTileLinksOnDashboard($container);
|
2016-11-28 18:50:20 -05:00
|
|
|
},
|
|
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
processToggleClick: function (event) {
|
2014-11-30 04:45:59 -05:00
|
|
|
event.stopPropagation();
|
|
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
var $li = $(event.currentTarget).closest('li.process');
|
|
|
|
|
$li.toggleClass('collapsed');
|
2014-11-30 04:45:59 -05:00
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
var $bpUl = $(event.currentTarget).closest('.content > ul.bp');
|
|
|
|
|
if (! $bpUl.length || !$bpUl.data('isRootConfig')) {
|
2014-11-30 04:45:59 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2019-01-22 05:46:25 -05:00
|
|
|
|
|
|
|
|
var bpName = $bpUl.attr('id');
|
|
|
|
|
if (typeof this.idCache[bpName] === 'undefined') {
|
|
|
|
|
this.idCache[bpName] = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var index = this.idCache[bpName].indexOf($li.attr('id'));
|
|
|
|
|
if ($li.is('.collapsed')) {
|
|
|
|
|
if (index === -1) {
|
|
|
|
|
this.idCache[bpName].push($li.attr('id'));
|
|
|
|
|
}
|
|
|
|
|
} else if (index !== -1) {
|
|
|
|
|
this.idCache[bpName].splice(index, 1);
|
2014-11-30 04:45:59 -05:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
processHeaderClick: function (event) {
|
|
|
|
|
this.processToggleClick(event);
|
|
|
|
|
},
|
|
|
|
|
|
2016-12-08 04:16:56 -05:00
|
|
|
hideInactiveFormDescriptions: function($container) {
|
|
|
|
|
$container.find('dd').not('.active').find('p.description').hide();
|
|
|
|
|
},
|
|
|
|
|
|
2017-01-03 05:10:07 -05:00
|
|
|
tileClick: function(event) {
|
|
|
|
|
$(event.currentTarget).find('> a').first().trigger('click');
|
|
|
|
|
},
|
|
|
|
|
|
2018-08-01 03:35:46 -04:00
|
|
|
dashboardTileClick: function(event) {
|
|
|
|
|
$(event.currentTarget).find('> .bp-link > a').first().trigger('click');
|
|
|
|
|
},
|
|
|
|
|
|
2018-12-17 08:40:47 -05:00
|
|
|
tileDropped: function(event) {
|
|
|
|
|
var evt = event.originalEvent;
|
|
|
|
|
if (evt.oldIndex !== evt.newIndex) {
|
2019-01-15 06:41:02 -05:00
|
|
|
var $source = $(evt.from);
|
|
|
|
|
var actionUrl = icinga.utils.addUrlParams($source.data('actionUrl'), {
|
2018-12-17 08:40:47 -05:00
|
|
|
action: 'move',
|
|
|
|
|
movenode: $(evt.item).data('nodeName')
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-15 06:41:02 -05:00
|
|
|
if (! $source.is('.few') && $('.addnew', $source).length === 2) {
|
2018-12-17 08:40:47 -05:00
|
|
|
// This assumes we're not moving things between different lists
|
|
|
|
|
evt.oldIndex -= 1;
|
|
|
|
|
evt.newIndex -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = {
|
2019-01-15 06:41:02 -05:00
|
|
|
csrfToken: $source.data('csrfToken'),
|
2018-12-17 08:40:47 -05:00
|
|
|
movenode: 'movenode', // That's the submit button..
|
2019-01-15 06:41:02 -05:00
|
|
|
parent: $(evt.to).data('nodeName') || '',
|
2018-12-17 08:40:47 -05:00
|
|
|
from: evt.oldIndex,
|
|
|
|
|
to: evt.newIndex
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-15 06:41:02 -05:00
|
|
|
icinga.loader.loadUrl(actionUrl, $source.closest('.container'), data, 'POST');
|
2018-12-17 08:40:47 -05:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2018-12-20 04:56:05 -05:00
|
|
|
rowDropped: function(event) {
|
2019-01-14 02:49:10 -05:00
|
|
|
var evt = event.originalEvent,
|
|
|
|
|
$source = $(evt.from),
|
|
|
|
|
$target = $(evt.to);
|
2018-12-21 07:58:45 -05:00
|
|
|
|
2019-01-14 02:49:10 -05:00
|
|
|
if (evt.oldIndex !== evt.newIndex || !$target.is($source)) {
|
2019-01-25 04:43:50 -05:00
|
|
|
var $root = $target.closest('.content > ul.bp');
|
2019-01-25 04:44:46 -05:00
|
|
|
$root.addClass('progress')
|
|
|
|
|
.find('ul.bp')
|
|
|
|
|
.add($root)
|
|
|
|
|
.each(function() {
|
|
|
|
|
$(this).data('sortable').option('disabled', true);
|
|
|
|
|
});
|
2019-01-25 04:43:50 -05:00
|
|
|
|
2018-12-20 04:56:05 -05:00
|
|
|
var data = {
|
|
|
|
|
csrfToken: $target.data('csrfToken'),
|
|
|
|
|
movenode: 'movenode', // That's the submit button..
|
2019-01-14 02:49:10 -05:00
|
|
|
parent: $target.parent('.process').data('nodeName') || '',
|
2018-12-20 04:56:05 -05:00
|
|
|
from: evt.oldIndex,
|
|
|
|
|
to: evt.newIndex
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-14 02:49:10 -05:00
|
|
|
var actionUrl = icinga.utils.addUrlParams($source.data('actionUrl'), {
|
|
|
|
|
action: 'move',
|
|
|
|
|
movenode: $(evt.item).data('nodeName')
|
|
|
|
|
});
|
|
|
|
|
|
2019-01-10 09:47:02 -05:00
|
|
|
icinga.loader.loadUrl(actionUrl, $target.closest('.container'), data, 'POST');
|
2019-01-14 02:49:10 -05:00
|
|
|
event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called by Sortable.js while in Tree-View
|
|
|
|
|
*
|
|
|
|
|
* See group option on the sortable elements.
|
|
|
|
|
*
|
|
|
|
|
* @param to
|
|
|
|
|
* @param from
|
|
|
|
|
* @param item
|
|
|
|
|
* @param event
|
2019-01-16 07:38:30 -05:00
|
|
|
* @returns boolean
|
2019-01-14 02:49:10 -05:00
|
|
|
*/
|
|
|
|
|
rowPutAllowed: function(to, from, item, event) {
|
|
|
|
|
if (to.options.group.name === 'root') {
|
|
|
|
|
return $(item).is('.process');
|
2018-12-20 04:56:05 -05:00
|
|
|
}
|
2019-01-16 07:38:30 -05:00
|
|
|
|
|
|
|
|
// Otherwise we're facing a nesting error next
|
|
|
|
|
var $item = $(item),
|
|
|
|
|
childrenNames = $item.find('.process').map(function () {
|
|
|
|
|
return $(this).data('nodeName');
|
|
|
|
|
}).get();
|
|
|
|
|
childrenNames.push($item.data('nodeName'));
|
|
|
|
|
var loopDetected = $(to.el).parents('.process').toArray().some(function (parent) {
|
|
|
|
|
return childrenNames.indexOf($(parent).data('nodeName')) !== -1;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return !loopDetected;
|
2018-12-20 04:56:05 -05:00
|
|
|
},
|
|
|
|
|
|
2017-01-27 05:53:58 -05:00
|
|
|
fixTileLinksOnDashboard: function($container) {
|
2017-01-27 06:58:50 -05:00
|
|
|
if ($container.closest('div.dashboard').length) {
|
2017-01-27 05:53:58 -05:00
|
|
|
$container.find('div.tiles').data('baseTarget', '_next');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2016-11-28 18:50:20 -05:00
|
|
|
fixFullscreen: function($container) {
|
|
|
|
|
var $controls = $container.find('div.controls');
|
|
|
|
|
var $layout = $('#layout');
|
|
|
|
|
var icinga = this.module.icinga;
|
|
|
|
|
if ($controls.hasClass('want-fullscreen')) {
|
|
|
|
|
if (!$layout.hasClass('fullscreen-layout')) {
|
|
|
|
|
|
|
|
|
|
$layout.addClass('fullscreen-layout');
|
|
|
|
|
$controls.removeAttr('style');
|
|
|
|
|
$container.find('.fake-controls').remove();
|
|
|
|
|
icinga.ui.currentLayout = 'fullscreen';
|
|
|
|
|
}
|
2019-01-09 09:28:28 -05:00
|
|
|
} else if (! $container.parent('.dashboard').length) {
|
2016-11-28 18:50:20 -05:00
|
|
|
if ($layout.hasClass('fullscreen-layout')) {
|
|
|
|
|
$layout.removeClass('fullscreen-layout');
|
|
|
|
|
icinga.ui.layoutHasBeenChanged();
|
|
|
|
|
icinga.ui.initializeControls($container);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
restoreCollapsedBps: function($container) {
|
|
|
|
|
var $bpUl = $container.find('.content > ul.bp');
|
|
|
|
|
if (! $bpUl.length || !$bpUl.data('isRootConfig')) {
|
2014-10-20 10:26:06 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2014-11-30 04:40:37 -05:00
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
var bpName = $bpUl.attr('id');
|
|
|
|
|
if (typeof this.idCache[bpName] === 'undefined') {
|
2014-11-30 04:43:09 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2019-01-22 05:46:25 -05:00
|
|
|
var _this = this;
|
|
|
|
|
$bpUl.find('li.process')
|
|
|
|
|
.filter(function () {
|
|
|
|
|
return _this.idCache[bpName].indexOf(this.id) !== -1;
|
|
|
|
|
})
|
|
|
|
|
.addClass('collapsed');
|
2016-12-08 04:16:56 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** BEGIN Form handling, borrowed from Director **/
|
|
|
|
|
formElementFocus: function(ev)
|
|
|
|
|
{
|
|
|
|
|
var $input = $(ev.currentTarget);
|
|
|
|
|
var $dd = $input.closest('dd');
|
|
|
|
|
$dd.find('p.description').show();
|
|
|
|
|
if ($dd.attr('id') && $dd.attr('id').match(/button/)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var $li = $input.closest('li');
|
|
|
|
|
var $dt = $dd.prev();
|
|
|
|
|
var $form = $dd.closest('form');
|
|
|
|
|
|
|
|
|
|
$form.find('dt, dd, li').removeClass('active');
|
|
|
|
|
$li.addClass('active');
|
|
|
|
|
$dt.addClass('active');
|
|
|
|
|
$dd.addClass('active');
|
|
|
|
|
$dd.find('p.description.fading-out')
|
|
|
|
|
.stop(true)
|
|
|
|
|
.removeClass('fading-out')
|
|
|
|
|
.fadeIn('fast');
|
|
|
|
|
|
|
|
|
|
$form.find('dd').not($dd)
|
|
|
|
|
.find('p.description')
|
|
|
|
|
.not('.fading-out')
|
|
|
|
|
.addClass('fading-out')
|
|
|
|
|
.delay(2000)
|
|
|
|
|
.fadeOut('slow', function() {
|
|
|
|
|
$(this).removeClass('fading-out').hide()
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
highlightFormErrors: function($container)
|
|
|
|
|
{
|
|
|
|
|
$container.find('dd ul.errors').each(function(idx, ul) {
|
|
|
|
|
var $ul = $(ul);
|
|
|
|
|
var $dd = $ul.closest('dd');
|
|
|
|
|
var $dt = $dd.prev();
|
|
|
|
|
|
|
|
|
|
$dt.addClass('errors');
|
|
|
|
|
$dd.addClass('errors');
|
|
|
|
|
});
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2016-12-08 04:16:56 -05:00
|
|
|
/** END Form handling **/
|
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));
|
|
|
|
|
|