From 803b2aa34dec7075458487e0fd51854f3b7819db Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 8 Dec 2016 10:16:56 +0100 Subject: [PATCH] js: add Director-related JavaScript helpers --- public/js/module.js | 54 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/public/js/module.js b/public/js/module.js index 0504318..197a983 100644 --- a/public/js/module.js +++ b/public/js/module.js @@ -26,19 +26,22 @@ this.module.on('click', 'table.bp.process > tbody > tr:first-child > td > a:last-child', this.processTitleClick); this.module.on('click', 'table.bp > tbody > tr:first-child > th', this.processOperatorClick); + this.module.on('focus', 'form input, form textarea, form select', this.formElementFocus); 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('mouseenter', 'table.node.missing > tbody > tr > td > span', this.procMouseOver); this.module.on('mouseleave', 'div.bp', this.procMouseOut); - this.module.icinga.logger.debug('BP module loaded'); + this.module.icinga.logger.debug('BP module initialized'); }, onRendered: function (event) { var $container = $(event.currentTarget); this.fixFullscreen($container); this.fixOpenedBps($container); + this.highlightFormErrors($container); + this.hideInactiveFormDescriptions($container); }, processTitleClick: function (event) { @@ -70,6 +73,10 @@ } }, + hideInactiveFormDescriptions: function($container) { + $container.find('dd').not('.active').find('p.description').hide(); + }, + /** * Add 'hovered' class to hovered title elements * @@ -202,7 +209,52 @@ } this.idCache[$bpName] = ids; + }, + + /** 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'); + }); } + /** END Form handling **/ }; Icinga.availableModules.businessprocess = Bp;