mirror of https://github.com/MISP/MISP
chg: [generic_picker] use php generic_picker elements for constructing
the template server side. - WIP Previously, it was done client sidepull/4041/head
parent
324eb3c061
commit
7cfe1d87a9
|
@ -0,0 +1 @@
|
|||
<div class="apply_css_arrow" style="padding-left: 5px; font-size: smaller;"><i><?php echo h($infoContextual);?></i></div>
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
<?php if (!is_array($infoExtra)): ?>
|
||||
<?php if (strlen($infoExtra) < 50): ?>
|
||||
<i style="float:right; font-size: smaller;margin-right: 5px;"><?php echo h($infoExtra); ?></i>
|
||||
<?php else: ?>
|
||||
<it class="fa fa-info-circle" style="float:right;margin-top:5px;margin-right: 5px;line-height:13px;" title="<?php echo h($infoExtra); ?>"></it>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php elseif (isset($infoExtra['type'])): // same as if infoExtra is not an array ?>
|
||||
<?php if ($infoExtra['type'] === 'text'): ?>
|
||||
<?php if (strlen($infoExtra) < 50): ?>
|
||||
<i style="float:right;font-size: smaller;margin-right: 5px;"><?php echo h($infoExtra); ?></i>
|
||||
<?php else: ?>
|
||||
<it class="fa fa-info-circle" style="float:right;margin-top:5px;line-height:13px; margin-right: 5px;" title="<?php echo h($infoExtra); ?>"></it>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php elseif ($infoExtra['type'] === 'check'): ?>
|
||||
<?php $checkType = isset($infoExtra['checked']) && $infoExtra['checked'] == true ? 'fa-check' : 'fa-times'; ?>
|
||||
<?php $checkColor = isset($infoExtra['checked']) && $infoExtra['checked'] == true ? '#449d44' : '#c9302c'; ?>
|
||||
<it class="generic-picker-item-element-check" style="background-color: <?php echo $checkColor; ?>">
|
||||
<it>
|
||||
<?php echo isset($infoExtra['text']) ? h($infoExtra['text']) : ""; ?>
|
||||
</it>
|
||||
<it style="margin-right: 0px;line-height:13px;" class="fa <?php echo $checkType; ?>"></it>
|
||||
</it>
|
||||
|
||||
<?php elseif ($infoExtra['type'] === 'table'): ?>
|
||||
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
|
@ -0,0 +1 @@
|
|||
<it class="fa <?php echo h($preIcon); ?>"></it>
|
|
@ -3,7 +3,7 @@
|
|||
* Generic select picker
|
||||
*/
|
||||
/** Config **/
|
||||
$select_threshold = 7; // threshold above which pills will be replace by a select (unused if multiple is > 1)
|
||||
$select_threshold = 0; // threshold above which pills will be replace by a select (unused if multiple is > 1)
|
||||
$defaults_options = array(
|
||||
'select_options' => array(
|
||||
// 'multiple' => '', // set to add possibility to pick multiple options in the select
|
||||
|
@ -117,10 +117,10 @@ function redrawChosenWithTemplate($select, $chosenContainer) {
|
|||
var res = "";
|
||||
if (template !== undefined && template !== '') {
|
||||
var template = atob(template);
|
||||
var temp = doT.template(template);
|
||||
var templateData = JSON.parse(atob($option.data('templatedata')));
|
||||
res = temp(templateData);
|
||||
$item.html(res);
|
||||
// var temp = doT.template(template);
|
||||
// var templateData = JSON.parse(atob($option.data('templatedata')));
|
||||
// res = temp(templateData);
|
||||
$item.html(template);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ class GenericPickerHelper extends AppHelper {
|
|||
}
|
||||
|
||||
if (isset($param['template'])) {
|
||||
$option_html .= ' data-template=' . base64_encode($param['template']);
|
||||
// $option_html .= ' data-template=' . base64_encode($param['template']);
|
||||
$template = $this->build_template($param);
|
||||
$option_html .= ' data-template=' . base64_encode($template);
|
||||
}
|
||||
if (isset($param['templateData'])) {
|
||||
$option_html .= ' data-templatedata=' . base64_encode(json_encode($param['templateData']));
|
||||
|
@ -95,5 +97,23 @@ class GenericPickerHelper extends AppHelper {
|
|||
$pill_html .= '</li>';
|
||||
return $pill_html;
|
||||
}
|
||||
|
||||
function build_template($param) {
|
||||
$template = "";
|
||||
if(isset($param['template'])) {
|
||||
$templateParam = $param['template'];
|
||||
if (isset($templateParam['preIcon'])) {
|
||||
$template .= $this->_View->element('genericPickerElements/pre_icon', array('preIcon' => $templateParam['preIcon']));
|
||||
}
|
||||
$template .= h($templateParam['name']);
|
||||
if (isset($templateParam['infoExtra'])) {
|
||||
$template .= $this->_View->element('genericPickerElements/info_extra', array('infoExtra' => $templateParam['infoExtra']));
|
||||
}
|
||||
if (isset($templateParam['infoContextual'])) {
|
||||
$template .= $this->_View->element('genericPickerElements/info_contextual', array('infoContextual' => $templateParam['infoContextual']));
|
||||
}
|
||||
}
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -49,11 +49,6 @@
|
|||
<?php
|
||||
$items = array();
|
||||
if (!empty($event['Object'])){
|
||||
$template = '<it class="fa fa-th-large"></it> ';
|
||||
$template .= '{{=it.name}}';
|
||||
$template .= '<it class="fa fa-info-circle" style="float:right;margin-top:5px;line-height:13px;" title="{{=it.attributes}}"></it>';
|
||||
$template .= '<div class="apply_css_arrow" style="padding-left: 5px; font-size: smaller;"><i>{{=it.metaCategory}}</i></div>';
|
||||
|
||||
foreach ($event['Object'] as $object) {
|
||||
$combinedFields = __('Object');
|
||||
$combinedFields .= '/' . h($object['meta-category']);
|
||||
|
@ -74,12 +69,11 @@
|
|||
'additionalData' => array(
|
||||
'type' => 'Object'
|
||||
),
|
||||
'template' => $template,
|
||||
'templateData' => array(
|
||||
'type' => __('Object'),
|
||||
'name' => h($object['name']),
|
||||
'metaCategory' => h($object['meta-category']),
|
||||
'attributes' => h($attributesValues),
|
||||
'template' => array(
|
||||
'name' => $object['name'],
|
||||
'preIcon' => 'fa-th-large',
|
||||
'infoExtra' => $attributesValues,
|
||||
'infoContextual' => $object['meta-category']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -100,13 +94,15 @@
|
|||
'additionalData' => array(
|
||||
'type' => 'Attribute'
|
||||
),
|
||||
'template' => $template,
|
||||
'templateData' => array(
|
||||
'value' => h($attribute['value']),
|
||||
'category' => h($attribute['category']),
|
||||
'type' => h($attribute['type']),
|
||||
'ids' => $attribute['to_ids'] ? 'check' : 'times'
|
||||
)
|
||||
'template' => array(
|
||||
'name' => $attribute['value'],
|
||||
'infoExtra' => array(
|
||||
'type' => 'check',
|
||||
'checked' => $attribute['to_ids'],
|
||||
'text' => 'ids'
|
||||
),
|
||||
'infoContextual' => $attribute['category'] . ' : ' . $attribute['type'],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -118,38 +114,6 @@
|
|||
echo $this->element('generic_picker', array('items' => $items, 'options' => $options));
|
||||
?>
|
||||
|
||||
<!-- <select id="targetSelect" size="10" style="width:100%;height:200px;">
|
||||
<?php
|
||||
if (!empty($event['Object'])):
|
||||
foreach ($event['Object'] as $object):
|
||||
$combinedFields = __('Object');
|
||||
$combinedFields .= '/' . h($object['meta-category']);
|
||||
$combinedFields .= '/' . h($object['name']);
|
||||
foreach ($object['Attribute'] as $attribute) {
|
||||
$combinedFields .= '/' . $attribute['value'];
|
||||
$combinedFields .= '/' . $attribute['id'];
|
||||
}
|
||||
?>
|
||||
<option value="<?php echo h($object['uuid']);?>" data-type="Object"><?php echo $combinedFields; ?></option>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
if (!empty($event['Attribute'])):
|
||||
foreach ($event['Attribute'] as $attribute):
|
||||
$combinedFields = __('Attribute');
|
||||
$combinedFields .= '/' . h($attribute['category']);
|
||||
$combinedFields .= '/' . h($attribute['type']);
|
||||
$combinedFields .= '/' . h($attribute['value']);
|
||||
$combinedFields .= '/' . h($attribute['id']);
|
||||
?>
|
||||
<option class="selectOption" value="<?php echo h($attribute['uuid']);?>" data-type="Attribute"><?php echo $combinedFields; ?></option>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
</select> -->
|
||||
|
||||
|
||||
</div>
|
||||
<div class="span6">
|
||||
<label for="selectedData"><?php echo __('Target Details');?></label>
|
||||
|
|
|
@ -932,12 +932,27 @@ a.pill-pre-picker {
|
|||
float: left;
|
||||
}
|
||||
|
||||
.chosen-single .apply_css_arrow{
|
||||
display: none !important;
|
||||
.generic-picker-item-element-check {
|
||||
float: right;
|
||||
border: 1px solid #999;
|
||||
background-color: #ddd;
|
||||
border-radius: 9px;
|
||||
padding: 2px;
|
||||
margin-top: 5px;
|
||||
color: #fff;
|
||||
line-height: 13px;
|
||||
}
|
||||
.generic-picker-item-element-check .fa:before {
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
.active-result .fa:before {
|
||||
margin-right: 5px;
|
||||
.chosen-single .generic-picker-item-element-check {
|
||||
margin-top: 2px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.chosen-single .apply_css_arrow{
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.chosen-container .chosen-results li {
|
||||
|
|
Loading…
Reference in New Issue