mirror of https://github.com/MISP/MISP
chg: [taxonomy choice] replace old popup view by the generic pre-picker
parent
1aabdad239
commit
b7c1ce79ba
|
@ -572,26 +572,25 @@ class TagsController extends AppController
|
|||
if (!$this->_isSiteAdmin() && !$this->userRole['perm_tagger']) {
|
||||
throw new NotFoundException('You don\'t have permission to do that.');
|
||||
}
|
||||
|
||||
$choices = array();
|
||||
$favourites = $this->Tag->FavouriteTag->find('count', array('conditions' => array('FavouriteTag.user_id' => $this->Auth->user('id'))));
|
||||
if ($favourites) {
|
||||
$choices[__('Favourite Tags')] = "/tags/selectTag/" . h($id) . "/favourites/" . h($scope);
|
||||
}
|
||||
$choices[__('Tag Collections')] = "/tags/selectTag/" . h($id) . "/collections/" . h($scope);
|
||||
$choices[__('All Tags')] = "/tags/selectTag/" . h($id) . "/all/" . h($scope);
|
||||
|
||||
$this->loadModel('Taxonomy');
|
||||
$options = $this->Taxonomy->find('list', array('conditions' => array('enabled' => true), 'fields' => array('namespace'), 'order' => array('Taxonomy.namespace ASC')));
|
||||
foreach ($options as $k => $option) {
|
||||
$tags = $this->Taxonomy->getTaxonomyTags($k, false, true);
|
||||
if (empty($tags)) {
|
||||
unset($options[$k]);
|
||||
if (!empty($tags)) {
|
||||
$choices[__('Taxonomy Library') . ":" . h($option)] = "/tags/selectTag/" . h($id) . "/" . h($k) . "/" . h($scope);
|
||||
}
|
||||
}
|
||||
$this->set('scope', $scope);
|
||||
$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');
|
||||
$this->set('choices', $choices);
|
||||
$this->render('/Elements/generic_pre_picker');
|
||||
}
|
||||
|
||||
public function selectTag($id, $taxonomy_id, $scope = 'event', $filterData = '')
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/**
|
||||
* Generic select picker from JSON
|
||||
* Required: $options, items
|
||||
* Note: setting `require_choice` to true, disable items
|
||||
*/
|
||||
$defaults_options = array(
|
||||
'select_options' => array(
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* Generic pre select picker from JSON
|
||||
* Required: $choices
|
||||
*/
|
||||
|
||||
/** Config **/
|
||||
$select_threshold = 3;
|
||||
|
||||
/** Global **/
|
||||
$use_select = count($choices) > $select_threshold;
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ($use_select):
|
||||
echo $this->Html->css('chosen.min');
|
||||
echo $this->Html->script('chosen.jquery.min');
|
||||
endif;
|
||||
?>
|
||||
|
||||
<script>
|
||||
function addOptionsToSelect(clicked) {
|
||||
var $clicked = $(clicked);
|
||||
var $wrapper = $clicked.closest('div').find('div.generic-picker-wrapper');
|
||||
$.ajax({
|
||||
dataType:"html",
|
||||
async: true,
|
||||
cache: false,
|
||||
success:function (data, textStatus) {
|
||||
var $arrow = $clicked.closest('div.popover').find('div.arrow');
|
||||
var ar_pos = $arrow.position();
|
||||
$wrapper.html(data);
|
||||
// redraw popover
|
||||
$arrow.css('top', ar_pos.top + 'px');
|
||||
$arrow.css('left', ar_pos.left + 'px');
|
||||
},
|
||||
error:function() {
|
||||
$wrapper.html('<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>');
|
||||
},
|
||||
url: $clicked.data('endpoint')
|
||||
});
|
||||
}
|
||||
|
||||
<?php if ($use_select): ?>
|
||||
function setupChosen(id) {
|
||||
var $elem = $('#'+id);
|
||||
$elem.chosen({disable_search_threshold: 10});
|
||||
$elem.change(function(event, selected) {
|
||||
select = this;
|
||||
$select = $(select);
|
||||
$select.data('endpoint', selected.selected);
|
||||
addOptionsToSelect($select)
|
||||
});
|
||||
}
|
||||
<?php endif; ?>
|
||||
</script>
|
||||
|
||||
|
||||
<?php if ($use_select): ?>
|
||||
<?php $select_id = h(uniqid()); // used to only register the listener on this select (allowing nesting) ?>
|
||||
<select id="<?php echo $select_id; ?>" style="height: 20px; margin-bottom: 0px;">
|
||||
<option></option>
|
||||
<?php foreach ($choices as $name => $endpoint): ?>
|
||||
<option value="<?php echo h($endpoint); ?>"><?php echo h($name); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
setTimeout(function() { // let time for the popup to show
|
||||
setupChosen("<?php echo $select_id; ?>");
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php else: ?>
|
||||
<ul class="nav nav-pills">
|
||||
<?php foreach($choices as $name => $endpoint): ?>
|
||||
<li>
|
||||
<a href="#" data-toggle="pill" class="pill-pre-picker"
|
||||
data-endpoint="<?php echo h($endpoint); ?>"
|
||||
onclick="addOptionsToSelect(this)"
|
||||
>
|
||||
<?php echo h($name); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<div class='generic-picker-wrapper'></div>
|
|
@ -894,6 +894,10 @@ a.proposal_link_red:hover {
|
|||
padding-left:10px;
|
||||
}
|
||||
|
||||
a.pill-pre-picker {
|
||||
background-color: #0000000f;
|
||||
}
|
||||
|
||||
.gray_out {
|
||||
display:none;
|
||||
width: 100%;
|
||||
|
|
Loading…
Reference in New Issue