mirror of https://github.com/MISP/MISP
iglocska's magic (Added kind of ajax support in attribute/edit)
C (\. \ ,/) \( |\ )/ //\ | \ /\\ (/ /\_#oo#_/\ \) \/\ #### /\/ `##' Ojopull/3063/head
parent
1057ccbf84
commit
a812757f73
|
@ -368,6 +368,7 @@ class AttributesController extends AppController {
|
|||
$this->set('typeDefinitions', $this->Attribute->typeDefinitions);
|
||||
$this->set('categoryDefinitions', $this->Attribute->categoryDefinitions);
|
||||
$this->set('published', $events['Event']['published']);
|
||||
$this->set('action', $this->action);
|
||||
}
|
||||
|
||||
public function download($id = null) {
|
||||
|
@ -816,6 +817,14 @@ class AttributesController extends AppController {
|
|||
$this->Attribute->Object->updateTimestamp($existingAttribute['Attribute']['object_id']);
|
||||
} else {
|
||||
$result = $this->Attribute->save($this->request->data);
|
||||
if ($this->request->is('ajax')) {
|
||||
$this->autoRender = false;
|
||||
if ($result) {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Attribute updated.')),'status' => 200, 'type' => 'json'));
|
||||
} else {
|
||||
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Could not update attribute, reason: ' . json_encode($this->Attribute->validationErrors))),'status' => 200, 'type' => 'json'));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($result) {
|
||||
$this->Session->setFlash(__('The attribute has been saved'));
|
||||
|
@ -864,6 +873,7 @@ class AttributesController extends AppController {
|
|||
// enabling / disabling the distribution field in the edit view based on whether user's org == orgc in the event
|
||||
$this->loadModel('Event');
|
||||
$this->Event->id = $eventId;
|
||||
$this->set('event_id', $eventId);
|
||||
$this->Event->read();
|
||||
$this->set('published', $this->Event->data['Event']['published']);
|
||||
// needed for RBAC
|
||||
|
@ -878,6 +888,7 @@ class AttributesController extends AppController {
|
|||
$this->set('types', $types);
|
||||
// combobox for categories
|
||||
$this->set('currentDist', $this->Event->data['Event']['distribution']);
|
||||
$this->set('ajax', $this->request->is('ajax'));
|
||||
|
||||
$this->loadModel('SharingGroup');
|
||||
$sgs = $this->SharingGroup->fetchAllAuthorised($this->Auth->user(), 'name', 1);
|
||||
|
@ -916,6 +927,9 @@ class AttributesController extends AppController {
|
|||
}
|
||||
$this->set('categories', $categories);
|
||||
$this->set('categoryDefinitions', $categoryDefinitions);
|
||||
$this->set('compositeTypes', $this->Attribute->getCompositeTypes());
|
||||
$this->set('action', $this->action);
|
||||
$this->render('add');
|
||||
}
|
||||
|
||||
// ajax edit - post a single edited field and this method will attempt to save it and return a json with the validation errors if they occur.
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<div class="attributes <?php if (!isset($ajax) || !$ajax) echo 'form';?>">
|
||||
<?php
|
||||
echo $this->Form->create('Attribute', array('id', 'url' => '/attributes/add/' . $event_id));
|
||||
$url_params = $action == 'add' ? 'add/' . $event_id : 'edit/' . $attribute['Attribute']['id'];
|
||||
echo $this->Form->create('Attribute', array('id', 'url' => '/attributes/' . $url_params));
|
||||
?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('Add Attribute'); ?></legend>
|
||||
<legend><?php echo $action == 'add' ? __('Add Attribute') : __('Edit Attribute'); ?></legend>
|
||||
<div id="formWarning" class="message ajaxMessage"></div>
|
||||
<div id="compositeWarning" class="message <?php echo !empty($ajax) ? 'ajaxMessage' : '';?>" style="display:none;">Did you consider adding an object instead of a composite attribute?</div>
|
||||
<div class="add_attribute_fields">
|
||||
|
@ -82,7 +83,7 @@
|
|||
<table>
|
||||
<tr>
|
||||
<td style="vertical-align:bottom">
|
||||
<span id="submitButton" class="btn btn-primary" title="<?php echo __('Submit'); ?>" role="button" tabindex="0" aria-label="<?php echo __('Submit'); ?>" onClick="submitPopoverForm('<?php echo $event_id;?>', 'add')"><?php echo __('Submit'); ?></span>
|
||||
<span id="submitButton" class="btn btn-primary" title="<?php echo __('Submit'); ?>" role="button" tabindex="0" aria-label="<?php echo __('Submit'); ?>" onClick="submitPopoverForm('<?php echo $action == 'add' ? $event_id : $attribute['Attribute']['id'];?>', '<?php echo $action; ?>')"><?php echo __('Submit'); ?></span>
|
||||
</td>
|
||||
<td style="width:540px;margin-bottom:0px;">
|
||||
<p style="color:red;font-weight:bold;display:none;text-align:center;margin-bottom:0px;" id="warning-message"><?php echo __('Warning: You are about to share data that is of a classified nature. Make sure that you are authorised to share this.'); ?></p>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div class="attributes form">
|
||||
<div class="attributes <?php if (!isset($ajax) || !$ajax) echo 'form';?>">
|
||||
<?php echo $this->Form->create('Attribute');?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('Edit Attribute'); ?></legend>
|
||||
|
@ -68,9 +68,11 @@
|
|||
?>
|
||||
</div>
|
||||
<?php
|
||||
$event['Event']['id'] = $this->request->data['Attribute']['event_id'];
|
||||
$event['Event']['published'] = $published;
|
||||
echo $this->element('side_menu', array('menuList' => 'event', 'menuItem' => 'addAttribute', 'event' => $event));
|
||||
if (!$ajax) {
|
||||
$event['Event']['id'] = $this->request->data['Attribute']['event_id'];
|
||||
$event['Event']['published'] = $published;
|
||||
echo $this->element('side_menu', array('menuList' => 'event', 'menuItem' => 'addAttribute', 'event' => $event));
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var fieldsArray = new Array('AttributeCategory', 'AttributeType', 'AttributeValue', 'AttributeDistribution', 'AttributeComment', 'AttributeToIds', 'AttributeBatchImport', 'AttributeSharingGroupId');
|
||||
|
|
|
@ -844,6 +844,9 @@ function submitPopoverForm(context_id, referer, update_context_id) {
|
|||
case 'add':
|
||||
url = "/attributes/add/" + context_id;
|
||||
break;
|
||||
case 'edit':
|
||||
url = "/attributes/edit/" + context_id;
|
||||
break;
|
||||
case 'propose':
|
||||
url = "/shadow_attributes/add/" + context_id;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue