chg: [sighting] Added generic hovering support for `openPopover` + added

support of this feature for sightings
pull/4075/head
mokaddem 2019-01-30 10:59:33 +01:00
parent db772213f0
commit 3ab9b888cc
2 changed files with 30 additions and 6 deletions

View File

@ -9,8 +9,8 @@
<?php
if ($isAclAdd):
?>
<span class="icon-thumbs-up useCursorPointer" title="<?php echo __('Add sighting');?>" role="button" tabindex="0" aria-label="<?php echo __('Add sighting');?>" onClick="flexibleAddSighting(this, '0', '<?php echo h($object['id']); ?>', '<?php echo h($object['event_id']);?>', '<?php echo h($object['value']);?>', '<?php echo h($page); ?>');">&nbsp;</span>
<span class="icon-thumbs-down useCursorPointer" title="<?php echo __('Mark as false-positive');?>" role="button" tabindex="0" aria-label="<?php echo __('Mark as false-positive');?>" onClick="flexibleAddSighting(this, '1', '<?php echo h($object['id']); ?>', '<?php echo h($object['event_id']);?>', '<?php echo h($object['value']);?>', '<?php echo h($page); ?>');">&nbsp;</span>
<span class="icon-thumbs-up useCursorPointer" title="<?php echo __('Add sighting');?>" role="button" tabindex="0" aria-label="<?php echo __('Add sighting');?>" onmouseover="flexibleAddSighting(this, '0', '<?php echo h($object['id']); ?>', '<?php echo h($object['event_id']);?>', '<?php echo h($object['value']);?>', '<?php echo h($page); ?>', 'top');" onclick="addSighting('0', '<?php echo h($object['id']); ?>', '<?php echo h($object['event_id']);?>', '<?php echo h($page); ?>');">&nbsp;</span>
<span class="icon-thumbs-down useCursorPointer" title="<?php echo __('Mark as false-positive');?>" role="button" tabindex="0" aria-label="<?php echo __('Mark as false-positive');?>" onmouseover="flexibleAddSighting(this, '1', '<?php echo h($object['id']); ?>', '<?php echo h($object['event_id']);?>', '<?php echo h($object['value']);?>', '<?php echo h($page); ?>', 'bottom');" onclick="addSighting('1', '<?php echo h($object['id']); ?>', '<?php echo h($object['event_id']);?>', '<?php echo h($page); ?>');">&nbsp;</span>
<span class="icon-wrench useCursorPointer sightings_advanced_add" title="<?php echo __('Advanced sightings');?>" role="button" tabindex="0" aria-label="<?php echo __('Advanced sightings');?>" data-object-id="<?php echo h($object['id']); ?>" data-object-context="attribute">&nbsp;</span>
<?php
endif;

View File

@ -42,13 +42,13 @@ function fetchAddSightingForm(type, attribute_id, page, onvalue) {
});
}
function flexibleAddSighting(clicked, type, attribute_id, event_id, value, page) {
function flexibleAddSighting(clicked, type, attribute_id, event_id, value, page, placement) {
$clicked = $(clicked);
var html = '<div>'
+ '<button class="btn btn-primary" onclick="addSighting(\'' + type + '\', \'' + attribute_id + '\', \'' + event_id + '\', \'' + page + '\')">'+'id'+'</button>'
+ '<button class="btn btn-primary" style="margin-left:5px;" onclick="fetchAddSightingForm(\'' + type + '\', \'' + attribute_id + '\', \'' + page + '\', true)">' + value + '</button>'
+ '</div>';
openPopover(clicked, html);
openPopover(clicked, html, true, placement);
}
function publishPopup(id, type) {
@ -1400,7 +1400,9 @@ function openPopup(id) {
$(id).fadeIn();
}
function openPopover(clicked, data) {
function openPopover(clicked, data, hover, placement) {
hover = hover === undefined ? false : hover;
placement = placement === undefined ? 'right' : placement;
/* popup handling */
var $clicked = $(clicked);
var randomId = $clicked.attr('data-dismissid') !== undefined ? $clicked.attr('data-dismissid') : Math.random().toString(36).substr(2,9); // used to recover the button that triggered the popover (so that we can destroy the popover)
@ -1412,6 +1414,7 @@ function openPopover(clicked, data) {
$clicked.addClass('have-a-popover');
$clicked.popover({
html: true,
placement: placement,
trigger: 'manual',
content: loadingHtml,
container: 'body',
@ -1432,13 +1435,34 @@ function openPopover(clicked, data) {
var popoverTitle = popover.find('h3.popover-title');
popoverTitle.html(title + closeButtonHtml);
})
.popover('show')
.on('keydown.volatilePopover', function(e) {
if(e.keyCode == 27) { // ESC
$(this).popover('destroy');
$(this).off('keydown.volatilePopover');
}
});
if (hover) {
$clicked.on('mouseenter', function() {
var _this = this;
$clicked.popover('show');
$(".popover").on("mouseleave", function() { // close popover when leaving it
$(_this).popover('hide');
});
})
.on('mouseleave', function() { // close popover if button not hovered (timeout)
var _this = this;
setTimeout(function() {
if ($('.popover:hover').length == 0 && !$(_this).is(":hover")) {
$(_this).popover('hide');
}
},
300);
});
} else {
$clicked.popover('show');
}
} else {
// $clicked.popover('show');
}