chg: [UI] WIP - generic_picker deleting tags uses popover

pull/4024/head
mokaddem 2019-01-14 12:30:19 +01:00
parent 19e95cda28
commit 512a8f83d1
5 changed files with 51 additions and 35 deletions

View File

@ -25,7 +25,7 @@
endif;
if ($full):
?>
<div class="tagSecondHalf useCursorPointer noPrint" title="<?php echo __('Remove tag');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag');?>" onClick="removeObjectTagPopup('attribute', '<?php echo h($attributeId); ?>', '<?php echo h($tag['Tag']['id']); ?>');">x</div>
<div class="tagSecondHalf useCursorPointer noPrint" title="<?php echo __('Remove tag');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag');?>" onClick="removeObjectTagPopup(this, 'attribute', '<?php echo h($attributeId); ?>', '<?php echo h($tag['Tag']['id']); ?>');">x</div>
<?php
endif;
?>

View File

@ -13,7 +13,7 @@
<?php
if ($full):
?>
<div class="tagSecondHalf useCursorPointer noPrint" title="<?php echo __('Remove tag');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag');?>" onClick="removeObjectTagPopup('tag_collection', '<?php echo h($tagCollection['TagCollection']['id']); ?>', '<?php echo h($tag['Tag']['id']); ?>');">x</div>
<div class="tagSecondHalf useCursorPointer noPrint" title="<?php echo __('Remove tag');?>" role="button" tabindex="0" aria-label="<?php echo __('Remove tag');?>" onClick="removeObjectTagPopup(this, 'tag_collection', '<?php echo h($tagCollection['TagCollection']['id']); ?>', '<?php echo h($tag['Tag']['id']); ?>');">x</div>
<?php
endif;
?>

View File

@ -15,7 +15,7 @@
$spanRole = "button";
$spanTabIndex = "0";
$spanAriaLabel = __('Remove tag %s', h($tag['Tag']['name']));
$spanOnClick = "removeObjectTagPopup('event', '" . h($event['Event']['id']) . "', '" . h($tag['Tag']['id']) . "')";
$spanOnClick = "removeObjectTagPopup(this, 'event', '" . h($event['Event']['id']) . "', '" . h($tag['Tag']['id']) . "')";
$span2 = sprintf('<span class="%s" title="%s" role="%s" tabindex="%s" aria-label="%s" onClick="%s">x</span>', $spanClass, $spanTitle, $spanRole, $spanTabIndex, $spanAriaLabel, $spanOnClick);
}
$tagData .= '<span style="white-space:nowrap;">' . $span1 . $span2 . '</span> ';

View File

@ -156,7 +156,13 @@ function setupChosen(id) {
} else {
select = this;
$select = $(select);
$select.data('endpoint', selected.selected);
var endpoint;
if (selected !== undefined) {
endpoint = selected.selected;
} else { // for obscure reasons, `selected` variable is not set in some cases
endpoint = $(event.target).val();
}
$select.data('endpoint', endpoint);
fetchRequestedData($select);
}
});

View File

@ -109,6 +109,7 @@ function cancelPrompt(isolated) {
}
$("#confirmation_box").fadeOut();
$("#confirmation_box").empty();
$('.have-a-popover').popover('destroy');
}
function submitDeletion(context_id, action, type, id) {
@ -956,10 +957,9 @@ function loadAttributeTags(id) {
});
}
function removeObjectTagPopup(context, object, tag) {
function removeObjectTagPopup(clicked, context, object, tag) {
$.get( "/" + context + "s/removeTag/" + object + '/' + tag, function(data) {
$("#confirmation_box").html(data);
openPopup("#confirmation_box");
openPopover(clicked, data);
});
}
@ -1394,6 +1394,43 @@ function openPopup(id) {
$(id).fadeIn();
}
function openPopover(clicked, data) {
// popup handling //
var loadingHtml = '<div style="height: 75px; width: 75px;"><div class="spinner"></div><div class="loadingText">Loading</div></div>';
var closeButtonHtml = '<button type="button" class="close" onclick="$(this).closest(\'div.popover\').prev().popover(\'destroy\');">×</button>';
$clicked = $(clicked);
var title = $clicked.attr('title');
var origTitle = $clicked.attr('data-original-title');
if (title !== undefined && title !== "") {
title = title.replace(closeButtonHtml, '');
title = title.length == 0 ? '&nbsp;' : title;
$clicked.attr('title', title + closeButtonHtml);
} else if(title === "" && origTitle !== undefined && origTitle !== "") { // preserve title
title = origTitle.replace(closeButtonHtml, '');
$clicked.attr('title', title + closeButtonHtml);
} else {
$clicked.attr('title', '&nbsp;' + closeButtonHtml);
}
if (!$clicked.data('popover')) {
$clicked.addClass('have-a-popover');
$clicked.popover({
html: true,
trigger: 'manual',
content: loadingHtml
}).popover('show');
} else {
// $clicked.popover('show');
}
var popover = $clicked.data('popover');
if (data === undefined) {
return popover
} else if (popover.options.content !== data) {
popover.options.content = data;
$clicked.popover('show');
}
}
function getMitreMatrixPopup(id) {
cancelPopoverForm();
getPopup(scope_id + '/' + id, 'events', 'viewMitreAttackMatrix', '', '#popover_form_large');
@ -1439,34 +1476,7 @@ function popoverPopup(clicked, id, context, target, admin) {
}
if (target != '') url += "/" + target;
if (id != '') url += "/" + id;
// popup handling //
var loadingHtml = '<div style="height: 75px; width: 75px;"><div class="spinner"></div><div class="loadingText">Loading</div></div>';
var closeButtonHtml = '<button type="button" class="close" onclick="$(this).closest(\'div.popover\').prev().popover(\'destroy\');">×</button>';
$clicked = $(clicked);
var title = $clicked.attr('title');
var origTitle = $clicked.attr('data-original-title');
if (title !== undefined && title !== "") {
title = title.replace(closeButtonHtml, '');
title = title.length == 0 ? '&nbsp;' : title;
$clicked.attr('title', title + closeButtonHtml);
} else if(title === "" && origTitle !== undefined && origTitle !== "") { // preserve title
title = origTitle.replace(closeButtonHtml, '');
$clicked.attr('title', title + closeButtonHtml);
} else {
$clicked.attr('title', '&nbsp;' + closeButtonHtml);
}
if (!$clicked.data('popover')) {
$clicked.popover({
html: true,
trigger: 'manual',
content: loadingHtml
}).popover('show');
} else {
// $clicked.popover('show');
}
var popover = $clicked.data('popover');
var popoverBody = popover.$tip.find('.popover-content');
var popover = openPopover(clicked, undefined);
// actual request //
$.ajax({