mirror of https://github.com/MISP/MISP
chg: [UI] Using generic form in the add event view
parent
0f40cef0f1
commit
832f53a04b
|
@ -2035,41 +2035,47 @@ class EventsController extends AppController
|
|||
}
|
||||
|
||||
$this->request->data['Event']['date'] = date('Y-m-d');
|
||||
if (isset($this->request->data['Event']['distribution'])) {
|
||||
$initialDistribution = $this->request->data['Event']['distribution'];
|
||||
} else {
|
||||
$initialDistribution = 3;
|
||||
if (Configure::read('MISP.default_event_distribution') != null) {
|
||||
$initialDistribution = Configure::read('MISP.default_event_distribution');
|
||||
}
|
||||
}
|
||||
$this->set('initialDistribution', $initialDistribution);
|
||||
|
||||
// combobox for distribution
|
||||
$distributions = array_keys($this->Event->distributionDescriptions);
|
||||
$distributions = $this->_arrayToValuesIndexArray($distributions);
|
||||
$this->set('distributions', $distributions);
|
||||
// tooltip for distribution
|
||||
$info = array();
|
||||
$fieldDesc = array();
|
||||
$distributionLevels = $this->Event->distributionLevels;
|
||||
if (empty($sgs)) {
|
||||
unset($distributionLevels[4]);
|
||||
}
|
||||
$this->set('distributionLevels', $distributionLevels);
|
||||
foreach ($distributionLevels as $key => $value) {
|
||||
$info['distribution'][$key] = array('key' => $value, 'desc' => $this->Event->distributionDescriptions[$key]['formdesc']);
|
||||
$fieldDesc['distribution'][$key] = $this->Event->distributionDescriptions[$key]['formdesc'];
|
||||
}
|
||||
|
||||
// combobox for risks
|
||||
$threat_levels = $this->Event->ThreatLevel->find('all');
|
||||
$this->set('threatLevels', Set::combine($threat_levels, '{n}.ThreatLevel.id', '{n}.ThreatLevel.name'));
|
||||
foreach ($threat_levels as $key => $threat_level) {
|
||||
$info['threat_level'][$threat_level['ThreatLevel']['id']] = array('key' => $threat_level['ThreatLevel']['name'], 'desc' => $threat_level['ThreatLevel']['form_description']);
|
||||
}
|
||||
|
||||
$fieldDesc['threat_level'] = Set::combine($threat_levels, '{n}.ThreatLevel.id', '{n}.ThreatLevel.description');
|
||||
// combobox for analysis
|
||||
$this->set('sharingGroups', $sgs);
|
||||
// tooltip for analysis
|
||||
foreach ($this->Event->analysisLevels as $key => $value) {
|
||||
$info['analysis'][$key] = array('key' => $value, 'desc' => $this->Event->analysisDescriptions[$key]['formdesc']);
|
||||
$analysisLevels = $this->Event->analysisLevels;
|
||||
$this->set('analysisLevels', $analysisLevels);
|
||||
foreach ($analysisLevels as $key => $value) {
|
||||
$fieldDesc['analysis'][$key] = $this->Event->analysisDescriptions[$key]['formdesc'];
|
||||
}
|
||||
if (!$this->_isRest()) {
|
||||
$this->Flash->info(__('The event created will be visible to the organisations having an account on this platform, but not synchronised to other MISP instances until it is published.'));
|
||||
}
|
||||
$this->set('info', $info);
|
||||
$this->set('analysisDescriptions', $this->Event->analysisDescriptions);
|
||||
$this->set('analysisLevels', $this->Event->analysisLevels);
|
||||
$this->set('fieldDesc', $fieldDesc);
|
||||
if (isset($this->params['named']['extends'])) {
|
||||
$this->set('extends_uuid', $this->params['named']['extends']);
|
||||
}
|
||||
|
|
|
@ -1,111 +1,80 @@
|
|||
<div class="events form">
|
||||
<?php echo $this->Form->create('', array('type' => 'file'));?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('Add Event');?></legend>
|
||||
<?php
|
||||
echo $this->Form->input('date', array(
|
||||
'type' => 'text',
|
||||
'class' => 'datepicker'
|
||||
));
|
||||
if (isset($this->request->data['Event']['distribution'])) {
|
||||
$initialDistribution = $this->request->data['Event']['distribution'];
|
||||
} else {
|
||||
$initialDistribution = 3;
|
||||
if (Configure::read('MISP.default_event_distribution') != null) {
|
||||
$initialDistribution = Configure::read('MISP.default_event_distribution');
|
||||
}
|
||||
}
|
||||
echo $this->Form->input('distribution', array(
|
||||
'options' => array($distributionLevels),
|
||||
'label' => __('Distribution ') . $this->element('formInfo', array('type' => 'distribution')),
|
||||
'selected' => $initialDistribution,
|
||||
));
|
||||
$style = $initialDistribution == 4 ? '' : 'style="display:none"';
|
||||
?>
|
||||
<div id="SGContainer" <?php echo $style; ?>>
|
||||
<?php
|
||||
if (!empty($sharingGroups)) {
|
||||
echo $this->Form->input('sharing_group_id', array(
|
||||
'options' => array($sharingGroups),
|
||||
'label' => __('Sharing Group'),
|
||||
));
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
echo '<div class="input clear"></div>';
|
||||
if (empty(Configure::read('MISP.disable_threat_level'))) {
|
||||
if (isset($this->request->data['Event']['threat_level_id'])) {
|
||||
$selected = $this->request->data['Event']['threat_level_id'];
|
||||
} else {
|
||||
$selected = Configure::read('MISP.default_event_threat_level') ? Configure::read('MISP.default_event_threat_level') : '4';
|
||||
}
|
||||
|
||||
echo $this->Form->input('threat_level_id', array(
|
||||
'label' => __('Threat Level ') . $this->element('formInfo', array('type' => 'threat_level')),
|
||||
'selected' => $selected,
|
||||
));
|
||||
}
|
||||
echo $this->Form->input('analysis', array(
|
||||
'label' => __('Analysis ') . $this->element('formInfo', array('type' => 'analysis')),
|
||||
'options' => array($analysisLevels),
|
||||
));
|
||||
echo $this->Form->input('info', array(
|
||||
'label' => __('Event Info'),
|
||||
'div' => 'clear',
|
||||
'type' => 'text',
|
||||
'class' => 'form-control span6',
|
||||
'placeholder' => __('Quick Event Description or Tracking Info')
|
||||
));
|
||||
echo $this->Form->input('extends_uuid', array(
|
||||
'label' => __('Extends event'),
|
||||
'value' => isset($extends_uuid) ? $extends_uuid : '',
|
||||
'div' => 'clear',
|
||||
'class' => 'form-control span6',
|
||||
'placeholder' => __('Event UUID or ID. Leave blank if not applicable.')
|
||||
));
|
||||
?>
|
||||
<div id="extended_event_preview" style="width:446px;"></div>
|
||||
</fieldset>
|
||||
<?php
|
||||
echo $this->Form->button(__('Add'), array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
$modelForForm = 'Event';
|
||||
echo $this->element('genericElements/Form/genericForm', array(
|
||||
'form' => $this->Form,
|
||||
'data' => array(
|
||||
'title' => __('Add Event'),
|
||||
'model' => 'Event',
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'org_id',
|
||||
'class' => 'org-id-picker-hidden-field',
|
||||
'type' => 'text',
|
||||
'hidden' => true
|
||||
),
|
||||
array(
|
||||
'field' => 'date',
|
||||
'class' => 'datepicker',
|
||||
'type' => 'text'
|
||||
),
|
||||
array(
|
||||
'field' => 'distribution',
|
||||
'class' => 'input',
|
||||
'options' => $distributionLevels,
|
||||
'default' => $initialDistribution
|
||||
),
|
||||
array(
|
||||
'field' => 'sharing_group',
|
||||
'class' => 'input',
|
||||
'options' => $sharingGroups,
|
||||
),
|
||||
array(
|
||||
'field' => 'threat_level',
|
||||
'class' => 'input',
|
||||
'options' => $threatLevels
|
||||
),
|
||||
array(
|
||||
'field' => 'analysis',
|
||||
'class' => 'input',
|
||||
'options' => $analysisLevels
|
||||
),
|
||||
array(
|
||||
'field' => 'info',
|
||||
'label' => __('Event info'),
|
||||
'class' => 'input-xxlarge',
|
||||
'type' => 'text',
|
||||
'placeholder' => __('Quick Event Description or Tracking Info')
|
||||
),
|
||||
array(
|
||||
'field' => 'extends_uuid',
|
||||
'class' => 'input-xxlarge',
|
||||
'placeholder' => __('Event UUID or ID. Leave blank if not applicable.')
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'action' => $this->request->params['action']
|
||||
)
|
||||
)
|
||||
));
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'event-collection', 'menuItem' => 'add'));
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
<?php
|
||||
$formInfoTypes = array('distribution' => 'Distribution', 'analysis' => 'Analysis', 'threat_level' => 'ThreatLevelId');
|
||||
echo 'var formInfoFields = ' . json_encode($formInfoTypes) . PHP_EOL;
|
||||
foreach ($formInfoTypes as $formInfoType => $humanisedName) {
|
||||
echo 'var ' . $formInfoType . 'FormInfoValues = {' . PHP_EOL;
|
||||
foreach ($info[$formInfoType] as $key => $formInfoData) {
|
||||
echo '"' . $key . '": "<span class=\"blue bold\">' . h($formInfoData['key']) . '</span>: ' . h($formInfoData['desc']) . '<br />",' . PHP_EOL;
|
||||
}
|
||||
echo '}' . PHP_EOL;
|
||||
}
|
||||
?>
|
||||
|
||||
$('#EventDistribution').change(function() {
|
||||
if ($('#EventDistribution').val() == 4) $('#SGContainer').show();
|
||||
else $('#SGContainer').hide();
|
||||
checkSharingGroup('Event');
|
||||
});
|
||||
|
||||
$("#EventDistribution, #EventAnalysis, #EventThreatLevelId").change(function() {
|
||||
initPopoverContent('Event');
|
||||
});
|
||||
|
||||
$("#EventExtendsUuid").keyup(function() {
|
||||
previewEventBasedOnUuids();
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($('#EventDistribution').val() == 4) $('#SGContainer').show();
|
||||
else $('#SGContainer').hide();
|
||||
initPopoverContent('Event');
|
||||
console.log($('#EventDistribution').val());
|
||||
checkSharingGroup('Event');
|
||||
previewEventBasedOnUuids();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -3652,6 +3652,16 @@ function initPopoverContent(context) {
|
|||
}
|
||||
}
|
||||
|
||||
function checkSharingGroup(context) {
|
||||
if ($('#' + context + 'Distribution').val() == 4) {
|
||||
$('#' + context + 'SharingGroup').show();
|
||||
$('#' + context + 'SharingGroup').closest("div").show();
|
||||
} else {
|
||||
$('#' + context + 'SharingGroup').hide();
|
||||
$('#' + context + 'SharingGroup').closest("div").hide();
|
||||
}
|
||||
}
|
||||
|
||||
function getFormInfoContent(property, field) {
|
||||
var content = window[property + 'FormInfoValues'][$(field).val()];
|
||||
if (content === undefined || content === null) {
|
||||
|
|
Loading…
Reference in New Issue