mirror of https://github.com/MISP/MISP
chg: [UI] Simplify category mapping data
parent
d4ca7f1987
commit
13d98012d9
|
@ -100,8 +100,8 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
var notice_list_triggers = <?php echo $notice_list_triggers; ?>;
|
||||
var category_type_mapping = <?php echo json_encode(array_map(function($value) {
|
||||
return array_combine($value['types'], $value['types']);
|
||||
var category_type_mapping = <?= json_encode(array_map(function(array $value) {
|
||||
return $value['types'];
|
||||
}, $categoryDefinitions)); ?>;
|
||||
|
||||
$('#AttributeDistribution').change(function() {
|
||||
|
@ -168,4 +168,4 @@
|
|||
});
|
||||
</script>
|
||||
<?php echo $this->element('form_seen_input'); ?>
|
||||
<?php echo $this->Js->writeBuffer(); // Write cached scripts
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ echo $this->Form->create('Attribute', array('id', 'url' => $baseurl . '/attribut
|
|||
'class' => 'input-xxlarge',
|
||||
'label' => __('Values')
|
||||
));
|
||||
$this->Js->get('#AttributeCategory')->event('change', 'formCategoryChanged("#AttributeCategory")');
|
||||
$this->Js->get('#AttributeCategory')->event('change', 'formCategoryChanged()');
|
||||
?>
|
||||
<div class="input clear"></div>
|
||||
</div>
|
||||
|
@ -51,30 +51,20 @@ echo $this->Form->create('Attribute', array('id', 'url' => $baseurl . '/attribut
|
|||
?>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
<script>
|
||||
//
|
||||
//Generate Category / Type filtering array
|
||||
//
|
||||
var category_type_mapping = new Array();
|
||||
<?php
|
||||
foreach ($categoryDefinitions as $category => $def) {
|
||||
echo "category_type_mapping['" . addslashes($category) . "'] = {";
|
||||
$first = true;
|
||||
foreach ($def['types'] as $type) {
|
||||
if ($first) $first = false;
|
||||
else echo ', ';
|
||||
echo "'" . addslashes($type) . "' : '" . addslashes($type) . "'";
|
||||
}
|
||||
echo "}; \n";
|
||||
}
|
||||
?>
|
||||
var category_type_mapping = <?= json_encode(array_map(function(array $value) {
|
||||
return $value['types'];
|
||||
}, $categoryDefinitions)); ?>;
|
||||
|
||||
function formCategoryChanged(id) {
|
||||
function formCategoryChanged() {
|
||||
// fill in the types
|
||||
var options = $('#AttributeType').prop('options');
|
||||
$('option', $('#AttributeType')).remove();
|
||||
$.each(category_type_mapping[$('#AttributeCategory').val()], function(val, text) {
|
||||
options[options.length] = new Option(text, val);
|
||||
$.each(category_type_mapping[$('#AttributeCategory').val()], function(index, val) {
|
||||
options.add(new Option(val, val));
|
||||
});
|
||||
// enable the form element
|
||||
$('#AttributeType').prop('disabled', false);
|
||||
|
|
|
@ -50,8 +50,8 @@
|
|||
</div>
|
||||
<?php echo $this->element('form_seen_input'); ?>
|
||||
<script type="text/javascript">
|
||||
var category_type_mapping = <?= json_encode(array_map(function($value) {
|
||||
return array_combine($value['types'], $value['types']);
|
||||
var category_type_mapping = <?= json_encode(array_map(function(array $value) {
|
||||
return $value['types'];
|
||||
}, $categoryDefinitions)); ?>;
|
||||
|
||||
//
|
||||
|
|
|
@ -80,8 +80,8 @@ if (!$ajax) {
|
|||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var category_type_mapping = <?= json_encode(array_map(function($value) {
|
||||
return array_combine($value['types'], $value['types']);
|
||||
var category_type_mapping = <?= json_encode(array_map(function(array $value) {
|
||||
return $value['types'];
|
||||
}, $categoryDefinitions)); ?>;
|
||||
|
||||
$('#ShadowAttributeCategory').change(function() {
|
||||
|
|
|
@ -102,19 +102,9 @@
|
|||
//
|
||||
//Generate Category / Type filtering array
|
||||
//
|
||||
var category_type_mapping = new Array();
|
||||
<?php
|
||||
foreach ($categoryDefinitions as $category => $def) {
|
||||
echo "category_type_mapping['" . addslashes($category) . "'] = {";
|
||||
$first = true;
|
||||
foreach ($def['types'] as $type) {
|
||||
if ($first) $first = false;
|
||||
else echo ', ';
|
||||
echo "'" . addslashes($type) . "' : '" . addslashes($type) . "'";
|
||||
}
|
||||
echo "}; \n";
|
||||
}
|
||||
?>
|
||||
var category_type_mapping = <?= json_encode(array_map(function(array $value) {
|
||||
return $value['types'];
|
||||
}, $categoryDefinitions)); ?>;
|
||||
|
||||
$(function() {
|
||||
$("#ShadowAttributeCategory").on('change', function(e) {
|
||||
|
@ -127,4 +117,4 @@ $(function() {
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<?php echo $this->Js->writeBuffer(); // Write cached scripts
|
||||
|
||||
|
|
|
@ -3997,18 +3997,19 @@ function formCategoryChanged(id) {
|
|||
optionsToPush = {};
|
||||
for (var category in category_type_mapping) {
|
||||
for (var type in category_type_mapping[category]) {
|
||||
optionsToPush[type] = category_type_mapping[category][type];
|
||||
optionsToPush[type] = type;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
optionsToPush = category_type_mapping[selectedCategory];
|
||||
}
|
||||
|
||||
$.each(optionsToPush, function (val, text) {
|
||||
options[options.length] = new Option(text, val);
|
||||
$.each(optionsToPush, function (index, val) {
|
||||
var option = new Option(val, val);
|
||||
if (val === alreadySelected) {
|
||||
options[options.length - 1].selected = true;
|
||||
option.selected = true;
|
||||
}
|
||||
options.add(option);
|
||||
});
|
||||
// enable the form element
|
||||
$type.prop('disabled', false);
|
||||
|
|
Loading…
Reference in New Issue