mirror of https://github.com/MISP/MISP
new: [UI] generic_picker - WIP
parent
b253303edc
commit
1aabdad239
|
@ -3292,6 +3292,18 @@ class EventsController extends AppController
|
|||
$this->set('count', $count);
|
||||
}
|
||||
|
||||
public function genericPicker() {
|
||||
$this->set('options', array(
|
||||
'require_choice' => true,
|
||||
'pre_choices' => array(
|
||||
'Tag Collections' => "'4/collections/attribute', 'tags', 'selectTag'",
|
||||
'All Tags' => "4/all/attribute, 'tags', 'selectTag'",
|
||||
)
|
||||
));
|
||||
$this->set('items', array('item1', 'item2', 'item3'));
|
||||
$this->render('/Elements/generic_picker');
|
||||
}
|
||||
|
||||
public function addTag($id = false, $tag_id = false)
|
||||
{
|
||||
if (!$this->request->is('post')) {
|
||||
|
|
|
@ -585,7 +585,13 @@ class TagsController extends AppController
|
|||
$this->set('object_id', $id);
|
||||
$this->set('options', $options);
|
||||
$this->set('favourites', $favourites);
|
||||
$this->set('scope', $scope);
|
||||
$this->render('ajax/taxonomy_choice');
|
||||
|
||||
// $this->set('options', array());
|
||||
// $items = $options;
|
||||
// $this->set('items', $items);
|
||||
// $this->render('/Elements/generic_picker');
|
||||
}
|
||||
|
||||
public function selectTag($id, $taxonomy_id, $scope = 'event', $filterData = '')
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
$addTagButton = ' ';
|
||||
if ($full) {
|
||||
$addTagButton = sprintf(
|
||||
'<button id="addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;" onClick="getPopup(%s);">+</button>',
|
||||
'<button id="addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;" onClick="popoverPopup(this, %s);">+</button>',
|
||||
sprintf("'%s/attribute', 'tags', 'selectTaxonomy'", h($attributeId))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Generic select picker from JSON
|
||||
* Required: $options, items
|
||||
*/
|
||||
$defaults_options = array(
|
||||
'select_options' => array(
|
||||
// 'multiple' => '', // set to add possibility to pick multiple options in the select
|
||||
//'placeholder' => '' // set to replace the default placeholder text
|
||||
),
|
||||
'chosen_options' => array(
|
||||
//'no_results_text' => '', // set to replace the default no result text after filtering
|
||||
//'max_selected_options' => 'Infinity' // set to replace the max selected options
|
||||
'disable_search_threshold' => 10,
|
||||
'allow_single_deselect' => true,
|
||||
),
|
||||
'require_choice' => false,
|
||||
'pre_choices' => array()
|
||||
);
|
||||
$scope = isset($scope) ? $scope : '';
|
||||
|
||||
// merge options with defaults
|
||||
$defaults = array_replace_recursive($defaults_options, $options);
|
||||
|
||||
function add_select_params($options) {
|
||||
$select_html = '';
|
||||
foreach ($options['select_options'] as $option => $value) {
|
||||
$select_html .= $option . '=' . $value . ' ';
|
||||
}
|
||||
return $select_html;
|
||||
}
|
||||
|
||||
function add_option($name, $param) {
|
||||
$option_html = '<option';
|
||||
if (is_array($param)) {
|
||||
if (in_array('disabled', $param)) {
|
||||
$option_html .= ' disabled';
|
||||
} else if (in_array('selected', $param)) { // nonsense to pre-select if disabled
|
||||
$option_html .= ' selected';
|
||||
}
|
||||
}
|
||||
$option_html .= ' value=' . (is_array($param)? h($name) : h($param));
|
||||
$option_html .= '>';
|
||||
|
||||
$option_html .= is_array($param)? h($name) : h($param);
|
||||
$option_html .= '</option>';
|
||||
return $option_html;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="popover_choice generic_picker">
|
||||
<legend><?php echo __(h($scope));?></legend>
|
||||
|
||||
<select <?php echo h(add_select_params($defaults)); ?>>
|
||||
<?php
|
||||
foreach ($items as $name => $param) {
|
||||
echo add_option($name, $param);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
<div class="overlay_spacing" style="margin: 5px; margin-top: 10px;">
|
||||
<button class="btn btn-primary" onclick="popoverPopup(this, '', 'events', 'genericPicker')">submit</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
echo $this->Html->css('chosen.min');
|
||||
echo $this->Html->script('chosen.jquery.min');
|
||||
?>
|
||||
<script>
|
||||
$('document').ready(function() {
|
||||
var chosen_options = <?php echo json_encode($defaults['chosen_options']); ?>;
|
||||
$(".generic_picker select").chosen(chosen_options);
|
||||
})
|
||||
</script>
|
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 538 B |
Binary file not shown.
After Width: | Height: | Size: 738 B |
|
@ -1427,6 +1427,63 @@ function getPopup(id, context, target, admin, popupType) {
|
|||
});
|
||||
}
|
||||
|
||||
// Same as getPopup function but create a popover to populate first
|
||||
function popoverPopup(clicked, id, context, target, admin) {
|
||||
var url = "";
|
||||
if (typeof admin !== 'undefined' && admin != '') url+= "/admin";
|
||||
if (context != '') {
|
||||
url += "/" + context;
|
||||
}
|
||||
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 ? ' ' : title;
|
||||
$clicked.attr('title', title + closeButtonHtml);
|
||||
} else if(title === "" && origTitle !== undefined) { // preserve title
|
||||
title = origTitle.replace(closeButtonHtml, '');
|
||||
$clicked.attr('title', title + closeButtonHtml);
|
||||
} else {
|
||||
$clicked.attr('title', ' ' + 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');
|
||||
|
||||
// actual request //
|
||||
$.ajax({
|
||||
dataType:"html",
|
||||
async: true,
|
||||
cache: false,
|
||||
success:function (data, textStatus) {
|
||||
if (popover.options.content !== data) {
|
||||
popover.options.content = data;
|
||||
$clicked.popover('show');
|
||||
}
|
||||
},
|
||||
error:function() {
|
||||
popover.options.content = '<div class="alert alert-error" style="margin-bottom: 0px;">Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).</div>';
|
||||
$clicked.popover('show');
|
||||
},
|
||||
url: url
|
||||
});
|
||||
}
|
||||
|
||||
function simplePopup(url) {
|
||||
$("#gray_out").fadeIn();
|
||||
$.ajax({
|
||||
|
|
Loading…
Reference in New Issue