Further work on the ajaxification

- mass deletes / mass edits

- tagging now done via ajax

- also, several small unrelated issues fixed
pull/274/head
iglocska 2014-04-24 15:10:08 +02:00
parent c88bfc11b2
commit 303de0e3aa
13 changed files with 406 additions and 270 deletions

View File

@ -156,7 +156,12 @@ class AttributesController extends AppController {
if ($this->request->is('ajax')) {
$this->autoRender = false;
// handle it if some of them failed!!!!
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
if ($fails) {
$error_message = 'The lines' . $fails . ' could not be saved. Please, try again.';
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $error_message)), 'status' => 200));
} else {
return new CakeResponse(array('body'=> json_encode(array('saved' => true)), 'status' => 200));
}
} else {
// we added all the attributes,
if ($fails) {
@ -215,7 +220,7 @@ class AttributesController extends AppController {
$this->render('view');
} elseif ($this->request->is('ajax')) {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
return new CakeResponse(array('body'=> json_encode(array('saved' => true)),'status'=>200));
} else {
// inform the user and redirect
$this->Session->setFlash(__('The attribute has been saved'));
@ -228,7 +233,7 @@ class AttributesController extends AppController {
$this->render('view');
} elseif ($this->request->is('ajax')) {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode($this->Attribute->validationErrors),'status'=>200));
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => $this->Attribute->validationErrors)),'status'=>200));
} else {
if (!CakeSession::read('Message.flash')) {
$this->Session->setFlash(__('The attribute could not be saved. Please, try again.'));
@ -811,10 +816,10 @@ class AttributesController extends AppController {
$res = $this->Attribute->Event->save($event, array('fieldList' => array('published', 'timestamp', 'info')));
file_put_contents('/tmp/event.txt', serialize($res));
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
return new CakeResponse(array('body'=> json_encode(array('saved' => true)),'status'=>200));
} else {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('fail'),'status'=>400));
return new CakeResponse(array('body'=> json_encode(array('fail' => false, 'errors' => $this->Attribute->validationErrors)),'status'=>200));
}
}
@ -929,19 +934,102 @@ class AttributesController extends AppController {
}
public function deleteSelected() {
//if (!$this->request->is('post') && !$this->request->is('ajax')) {
if (!$this->request->is('post')) {
public function deleteSelected($id) {
if (!$this->request->is('post') && !$this->request->is('ajax')) {
//if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
// get a json object with a list of attribute IDs to be deleted
// check each of them and return a json object with the successful deletes and the failed ones.
$ids = json_decode($this->request->data['Attribute']['ids']);
foreach ($ids as $id) {
$this->__delete($id);
if (!$this->_isSiteAdmin()) {
$event = $this->Attribute->Event->find('first', array(
'conditions' => $id,
'recursive' => -1,
'fields' => array('id', 'orgc', 'user_id')
));
if ($event['Event']['orgc'] != $this->Auth->user('org') || (!$this->userRole['perm_modify_org'] && !($this->userRole['perm_modify'] && $event['Event']['user_id'] == $this->Auth->user('id')))) {
throw new MethodNotAllowedException('Invalid Event.');
}
}
// find all attributes from the ID list that also match the provided event ID.
$attributes = $this->Attribute->find('all', array(
'recursive' => -1,
'conditions' => array('id' => $ids, 'event_id' => $id),
'fields' => array('id', 'event_id')
));
foreach ($attributes as $a) {
$this->__delete($a['Attribute']['id']);
}
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200));
return new CakeResponse(array('body'=> json_encode(array('saved' => true)),'status'=>200));
}
public function editSelected($id) {
if (!$this->request->is('ajax')) throw new MethodNotAllowedException('This method can only be accessed via AJAX.');
if ($this->request->is('post')) {
$event = $this->Attribute->Event->find('first', array(
'conditions' => array('id' => $id),
'recursive' => -1,
'fields' => array('id', 'orgc', 'user_id')
));
if (!$this->_isSiteAdmin()) {
if ($event['orgc'] != $this->Auth->user('org') || (!$this->userRole['perm_modify_org'] && !($this->userRole['perm_modify'] && $event['user_id'] == $this->Auth->user('id')))) {
throw new MethodNotAllowedException('You are not authorized to edit this event.');
}
}
$attribute_ids = json_decode($this->request->data['Attribute']['attribute_ids']);
$attributes = $this->Attribute->find('all', array(
'conditions' => array(
'id' => $attribute_ids,
'event_id' => $id,
),
//to_ids = true/false, distribution = [0,1,2,3]
//'fields' => array('id', 'event_id', 'comment', 'to_ids', 'timestamp', 'distribution'),
'recursive' => -1,
));
if ($this->request->data['Attribute']['to_ids'] == 2 && $this->request->data['Attribute']['distribution'] == 4 && $this->request->data['Attribute']['comment'] == null) {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode(array('saved' => true)),'status' => 200));
}
if ($this->request->data['Attribute']['to_ids'] != 2) {
foreach ($attributes as &$attribute) $attribute['Attribute']['to_ids'] = ($this->request->data['Attribute']['to_ids'] == 0 ? false : true);
}
if ($this->request->data['Attribute']['distribution'] != 4) {
foreach ($attributes as &$attribute) $attribute['Attribute']['distribution'] = $this->request->data['Attribute']['distribution'];
}
if ($this->request->data['Attribute']['comment'] != null) {
foreach ($attributes as &$attribute) $attribute['Attribute']['comment'] = $this->request->data['Attribute']['comment'];
}
$date = new DateTime();
$timestamp = $date->getTimestamp();
foreach ($attributes as &$attribute) $attribute['Attribute']['timestamp'] = $timestamp;
if($this->Attribute->saveMany($attributes)) {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode(array('saved' => true)),'status' => 200));
} else {
$this->autoRender = false;
return new CakeResponse(array('body'=> json_encode(array('saved' => false)),'status' => 200));
}
} else {
if (!isset($id)) throw new MethodNotAllowedException('No event ID provided.');
$this->layout = 'ajax';
$this->set('id', $id);
$this->set('distributionLevels', $this->Attribute->distributionLevels);
$this->set('distributionDescriptions', $this->Attribute->distributionDescriptions);
$this->set('attrDescriptions', $this->Attribute->fieldDescriptions);
$this->render('ajax/attributeEditMassForm');
}
}
/**

View File

@ -2135,7 +2135,7 @@ class EventsController extends AppController {
$this->redirect(array('controller' => 'pages', 'action' => 'display', 'administration'));
}
public function addTag() {
public function addTag($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException('You don\'t have permission to do that.');
}
@ -2158,14 +2158,16 @@ class EventsController extends AppController {
),
'recursive' => -1,
));
$this->autoRender = false;
if (!empty($found)) {
$this->Session->setFlash('Tag already assigned to this event.');
$this->redirect(array('action' => 'view', $id));
return;
//$this->Session->setFlash('Tag already assigned to this event.');
//$this->redirect(array('action' => 'view', $id));
}
$this->Event->EventTag->create();
$this->Event->EventTag->save(array('event_id' => $id, 'tag_id' => $tag_id));
$this->Session->setFlash('Tag added.');
$this->redirect(array('action' => 'view', $id));
//$this->Session->setFlash('Tag added.');
//$this->redirect(array('action' => 'view', $id));
}
public function removeTag($id, $tag_id) {
@ -2185,9 +2187,10 @@ class EventsController extends AppController {
),
'recursive' => -1,
));
$this->autoRender = false;
if (empty($eventTag)) throw new NotFoundException('Invalid event - tag combination.');
$this->Event->EventTag->delete($eventTag['EventTag']['id']);
$this->Session->setFlash('Tag removed.');
$this->redirect(array('action' => 'view', $id));
//$this->Session->setFlash('Tag removed.');
//$this->redirect(array('action' => 'view', $id));
}
}

View File

@ -80,4 +80,27 @@ class TagsController extends AppController {
}
$this->redirect(array('action' => 'index'));
}
public function showEventTag($id) {
$this->helpers[] = 'TextColour';
$this->loadModel('EventTag');
$tags = $this->EventTag->find('all', array(
'conditions' => array(
'event_id' => $id
),
'contain' => 'Tag',
'fields' => array('Tag.id', 'Tag.colour', 'Tag.name'),
));
$this->set('tags', $tags);
$tags = $this->Tag->find('all', array('recursive' => -1));
$tagNames = array('None');
foreach ($tags as $k => $v) {
$tagNames[$v['Tag']['id']] = $v['Tag']['name'];
}
$this->set('allTags', $tagNames);
$event['Event']['id'] = $id;
$this->set('event', $event);
$this->layout = 'ajax';
$this->render('/Events/ajax/ajaxTags');
}
}

View File

@ -66,7 +66,7 @@
<table>
<tr>
<td style="vertical-align:top">
<span id="submitButton" class="btn btn-primary" onClick="submitForm()">Submit</span>
<span id="submitButton" class="btn btn-primary" onClick="submitPopoverForm('<?php echo $event_id;?>', 'add')">Submit</span>
</td>
<td style="width:540px;">
<p style="color:red;font-weight:bold;display:none;text-align:center" id="warning-message">Warning: You are about to share data that is of a classified nature (Attribution / targeting data). Make sure that you are authorised to share this.</p>
@ -204,90 +204,5 @@ $(document).ready(function() {
<?php endif; ?>
});
// Submit button should post the form results to the add action and check the response
function submitForm() {
$.ajax({
data: $("#submitButton").closest("form").serialize(),
success:function (data, textStatus) {
handleAjaxResponse(data);
},
type:"post",
url:"/attributes/add/<?php echo $event_id; ?>"
});
};
function handleAjaxResponse(response) {
if (response === "\"saved\"") {
$("#gray_out").hide();
$("#attribute_add_form").hide();
updateAttributeIndexOnSuccess();
} else {
var savedArray = saveValuesForPersistance();
$.ajax({
async:true,
dataType:"html",
success:function (data, textStatus) {
$("#attribute_add_form").html(data);
responseArray = JSON.parse(response);
handleValidationErrors(responseArray);
if (!isEmpty(responseArray)) {
$("#formWarning").show();
$("#formWarning").html('The attribute could not be saved. Please, try again.');
}
recoverValuesFromPersistance(savedArray);
},
url:"/attributes/add/<?php echo $event_id; ?>"
});
}
}
function isEmpty(obj) {
var name;
for (name in obj) {
return false;
}
return true;
}
function updateAttributeIndexOnSuccess() {
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
dataType:"html",
success:function (data, textStatus) {
$(".loading").hide();
$("#attributes_div").html(data);
},
url:"/events/view/<?php echo $event_id; ?>/attributesPage:1"
});
}
// before we update the form (in case the action failed), we want to retrieve the data from every field, so that we can set the fields in the new form that we fetch
function saveValuesForPersistance() {
var formPersistanceArray = new Array();
for (i = 0; i < fieldsArrayAttribute.length; i++) {
formPersistanceArray[fieldsArrayAttribute[i]] = document.getElementById(fieldsArrayAttribute[i]).value;
}
return formPersistanceArray;
}
function recoverValuesFromPersistance(formPersistanceArray) {
for (i = 0; i < fieldsArrayAttribute.length; i++) {
document.getElementById(fieldsArrayAttribute[i]).value = formPersistanceArray[fieldsArrayAttribute[i]];
}
}
function handleValidationErrors(responseArray) {
for (var k in responseArray) {
var elementName = k.charAt(0).toUpperCase() + k.slice(1);
$("#Attribute" + elementName).parent().addClass("error");
$("#Attribute" + elementName).parent().append("<div class=\"error-message\">" + responseArray[k] + "</div>");
}
}
</script>
<?php echo $this->Js->writeBuffer(); // Write cached scripts

View File

@ -30,6 +30,7 @@
<?php else: ?>
<li class="next"><a href="" id = "anext">next »</a></li>
<?php endif; ?>
</ul>
<ul style="margin-left:20px;">
<?php if ($page == 'all'): ?>
<li class="all"><span>View All</span></li>
@ -37,7 +38,6 @@
<li class="all"><a href="" id = "aall">View All</a></li>
<?php endif; ?>
</ul>
</ul>
</div>
<br />
<?php
@ -45,7 +45,7 @@
?>
<div id="attributeList" class="attributeListContainer">
<div class="tabMenu">
<span id="create-button" class="icon-plus" onClick="clickCreateButton();"></span>
<span id="create-button" class="icon-plus" onClick="clickCreateButton(<?php echo $event['Event']['id']; ?>);"></span>
<span id="multi-edit-button" class="icon-edit mass-select" onClick="editSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
<span id="multi-delete-button" class = "icon-trash mass-select" onClick="deleteSelectedAttributes(<?php echo $event['Event']['id']; ?>);"></span>
</div>
@ -88,7 +88,7 @@
<?php
else:
?>
<li><span id = "apageCurrent"><?php echo $i; ?></span></li>
<li><span id = "bpageCurrent"><?php echo $i; ?></span></li>
<?php
endif;
endfor;
@ -178,8 +178,9 @@
}
endif;
?>
<script>
<script type="text/javascript">
$(document).ready(function(){
$('input:checkbox').removeAttr('checked');
$('.mass-select').hide();
$('input[type="checkbox"]').click(function(){
attributeListAnyCheckBoxesChecked();

View File

@ -89,10 +89,9 @@ if ($object['objectType'] == 1) $extra2 = '1';
if ($object['objectType'] == 0) {
if ($isSiteAdmin || $mayModify) {
echo $this->Form->create('Attribute', array('class' => 'inline-delete', 'id' => $currentType . '_' . $object['id'] . '_delete', 'action' => 'delete'));
echo $this->Form->end();
?>
<a href="/attributes/edit/<?php echo $object['id']; ?>" title="Edit" class="icon-edit"></a>
<span id = "<?php echo $currentType . '_' . $object['id'] . '_delete'; ?>" class="icon-trash" onClick="deleteObject('attributes', '<?php echo $object['id']; ?>', '<?php echo $event['Event']['id']; ?>');"></span>
<span class="icon-trash" onClick="deleteObject('attributes', '<?php echo $object['id']; ?>', '<?php echo $event['Event']['id']; ?>');"></span>
<?php
echo $this->Form->end();
} else {

View File

@ -1,8 +1,10 @@
<div id="top">
<div class="pagination">
<ul>
<?php
if (!empty($posts)):
?>
<ul>
<?php
$this->Paginator->options(array(
'update' => '#top',
'evalScripts' => true,

View File

@ -11,8 +11,7 @@
<?php if ($me != false ):?>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="/" style="color:white">Home
</a></li>
<li><a href="/" style="color:white">Home</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Event Actions
@ -30,9 +29,9 @@
<li><a href="/shadow_attributes/index">View Proposals</a></li>
<li><a href="/events/proposalEventIndex">Events with proposals</a></li>
<li class="divider"></li>
<li><a href="/tags/index">List Tags</a>
<li><a href="/tags/index">List Tags</a></li>
<?php if ($isAclTagger): ?>
<li><a href="/tags/add">Add Tag</a>
<li><a href="/tags/add">Add Tag</a></li>
<?php endif; ?>
<li class="divider"></li>
<li><a href="/events/export">Export</a></li>
@ -175,7 +174,7 @@
</div>
</div>
</div>
<script>
<script type="text/javascript">
window.onload = resizeLogo;
window.onresize = resizeLogo;

View File

@ -17,7 +17,7 @@ $imgRelativePath = 'orgs/' . $imgId . '.png';
$imgAbsolutePath = APP . WEBROOT_DIR . DS . 'img' . DS . $imgRelativePath;
$imgExtraOptions = $imgStyle;
if (file_exists($imgAbsolutePath)) {
echo $this->Html->image($imgRelativePath, Set::merge(array('alt' => $imgId,'width' => $imgSize, 'height' => $imgStyle, 'title' => $imgId), $imgExtraOptions));
echo $this->Html->image($imgRelativePath, Set::merge(array('alt' => $imgId,'width' => $imgSize, 'height' => $imgSize, 'title' => $imgId), $imgExtraOptions));
} else {
echo $this->Html->tag('span', $imgId, Set::merge(array('class' => 'img'), $imgExtraOptions));
}

View File

@ -72,15 +72,17 @@
<th class="filter">
<?php echo $this->Paginator->sort('published');?>
<a onclick="$('#searchpublished').toggle();" class="icon-search"></a>
<span id="searchpublished"><br/>
<?php
// on change jquery will submit the form
echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden'));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden'));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden'));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden'));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden'));
<?php
// on change jquery will submit the form
echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden', 'id' => false));
?>
<span id="searchpublished">
<?php
echo $this->Form->input('searchpublished', array(
'options' => array('0' => 'No', '1' => 'Yes', '2' => 'Any'),
'default' => 2,
@ -90,33 +92,35 @@
));
?>
<input type="submit" style="visibility:collapse;" />
<?php
echo $this->Form->end();
?>
</span>
<?php
echo $this->Form->end();
?>
</th>
<?php
if ('true' == Configure::read('MISP.showorg') || $isAdmin) { ?>
<th class="filter"><?php echo $this->Paginator->sort('org'); ?>
<a onclick="toggleField('#searchorg')" class="icon-search"></a>
<span id="searchorg"><br/>
<?php
echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px'));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden'));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden'));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden'));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden'));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden'));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden', 'id' => false));
?>
<span id="searchorg">
<?php
echo $this->Form->input('searchorg', array(
'value' => $this->passedArgs['searchorg'],
'label' => '',
'class' => 'input-mini'));
?>
<input type="submit" style="visibility:collapse;" />
</span>
<?php
echo $this->Form->end();
?>
</span>
</th>
<?php
}
@ -130,14 +134,16 @@
<?php if (Configure::read('MISP.tagging')): ?>
<th class="filter">Tags
<a onclick="toggleField('#searchtag')" class="icon-search"></a>
<span id="searchtag"><br/>
<?php
echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden'));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden'));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden'));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden'));
?>
<span id="searchtag">
<?php
echo $this->Form->input('searchtag', array(
'options' => array($tags),
'value' => $this->passedArgs['searchtag'],
@ -146,10 +152,10 @@
'class' => 'input-large'));
?>
<input type="submit" style="visibility:collapse;" />
</span>
<?php
echo $this->Form->end();
?>
</span>
</th>
<?php endif; ?>
<th><?php echo $this->Paginator->sort('attribute_count', '#Attr.');?></th>
@ -163,10 +169,10 @@
<div id="searchdate" class="input-append input-prepend">
<?php
echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden'));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden'));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden'));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDatefrom', array(
'value' => $this->passedArgs['searchDatefrom'],
'label' => false,
@ -198,24 +204,28 @@
<th class="filter">
<?php echo $this->Paginator->sort('info');?>
<a onclick="toggleField('#searchinfo')" class="icon-search"></a>
<span id="searchinfo"><br/>
<?php
echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden'));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden'));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden'));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden'));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden'));
echo $this->Form->input('searchorg', array('value' => $this->passedArgs['searchorg'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchpublished', array('value' => $this->passedArgs['searchpublished'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchDatefrom'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchDateuntil'], 'type' => 'hidden', 'id' => false));
echo $this->Form->input('searchtag', array('value' => $this->passedArgs['searchtag'], 'type' => 'hidden', 'id' => false));
?>
<span id="searchinfo">
<?php
echo $this->Form->input('searchinfo', array(
'value' => $this->passedArgs['searchinfo'],
'label' => '',
'class' => 'input-large'));
'class' => 'input-large',
'div' => false
));
?>
<input type="submit" style="visibility:collapse;" />
</span>
<?php
echo $this->Form->end();
?>
</span>
</th>
<?php if ('true' == Configure::read('MISP.sync')): ?>
<th title="<?php echo $eventDescriptions['distribution']['desc'];?>">
@ -267,7 +277,7 @@
<?php if (Configure::read('MISP.tagging')): ?>
<td class="short">
<?php foreach ($event['EventTag'] as $tag):?>
<span class=tag style="background-color:<?php echo $tag['Tag']['colour']?>" title="<?php echo $tag['Tag']['name']; ?>">&nbsp</span>
<span class=tag style="background-color:<?php echo $tag['Tag']['colour']?>" title="<?php echo $tag['Tag']['name']; ?>">&nbsp;</span>
<?php endforeach; ?>
</td>
<?php endif; ?>

View File

@ -70,51 +70,8 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
<?php
if (Configure::read('MISP.tagging')): ?>
<dt>Tags</dt>
<dd>
<table>
<tr>
<?php
foreach ($tags as $tag): ?>
<td style="padding-right:0px;">
<?php if ($isAclTagger): ?>
<a href="/events/index/searchtag:<?php echo $tag['Tag']['id']; ?>" class=tagFirstHalf style="background-color:<?php echo $tag['Tag']['colour'];?>;color:<?php echo $this->TextColour->getTextColour($tag['Tag']['colour']);?>"><?php echo h($tag['Tag']['name']); ?></a>
<?php else: ?>
<a href="/events/index/searchtag:<?php echo $tag['Tag']['id']; ?>" class=tag style="background-color:<?php echo $tag['Tag']['colour'];?>;color:<?php echo $this->TextColour->getTextColour($tag['Tag']['colour']);?>"><?php echo h($tag['Tag']['name']); ?></a>
<?php endif; ?>
</td>
<?php if ($isAclTagger): ?>
<td style="padding-left:0px;padding-right:5px;">
<?php
echo $this->Form->postLink('x', array('action' => 'removeTag', $event['Event']['id'], $tag['Tag']['id']), array('class' => 'tagSecondHalf', 'title' => 'Delete'), ('Are you sure you want to delete this tag?'));
?>
</td>
<?php endif; ?>
<?php
endforeach;
if ($isAclTagger) : ?>
<td id ="addTagTD" style="display:none;">
<?php
echo $this->Form->create('', array('action' => 'addTag', 'style' => 'margin:0px;'));
echo $this->Form->hidden('id', array('value' => $event['Event']['id']));
echo $this->Form->input('tag', array(
'options' => array($allTags),
'value' => 0,
'label' => false,
'style' => array('height:22px;padding:0px;margin-bottom:0px;'),
'onChange' => 'this.form.submit()',
'class' => 'input-large'));
echo $this->Form->end();
?>
</td>
<td>
<button id="addTagButton" class="btn btn-inverse" style="line-height:10px; padding: 4px 4px;">+</button>
</td>
<?php else:
if (empty($tags)) echo '&nbsp;';
endif; ?>
</tr>
</table>
<dd class="eventTagContainer">
<?php echo $this->element('ajaxTags', array('event' => $event, 'tags' => $tags)); ?>
</dd>
<?php endif; ?>
<dt>Date</dt>
@ -221,6 +178,7 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
<script type="text/javascript">
// tooltips
$(document).ready(function () {
//loadEventTags("<?php echo $event['Event']['id']; ?>");
$("th, td, dt, div, span, li").tooltip({
'placement': 'top',
'container' : 'body',
@ -262,12 +220,4 @@ $(document).ready(function () {
$('#addTagButton').hide();
});
});
function clickCreateButton() {
$.get( "/attributes/add/<?php echo $event['Event']['id']; ?>", function(data) {
$("#attribute_add_form").show();
$("#gray_out").show();
$("#attribute_add_form").html(data);
});
}
</script>

View File

@ -1,4 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
@ -55,6 +55,7 @@
>
<?php echo $this->fetch('content'); ?>
</div>
</div>
<?php
echo $this->element('footer');
echo $this->element('sql_dump');

View File

@ -8,6 +8,7 @@ function deleteObject(type, id, event) {
updateAttributeIndexOnSuccess(event);
},
type:"post",
cache: false,
url:"/" + type + "/delete/" + id,
});
}
@ -19,6 +20,7 @@ function updateAttributeIndexOnSuccess(event) {
$(".loading").show();
},
dataType:"html",
cache: false,
success:function (data, textStatus) {
$(".loading").hide();
$("#attributes_div").html(data);
@ -35,6 +37,7 @@ function updateAttributeFieldOnSuccess(name, type, id, field, event) {
}
},
dataType:"html",
cache: false,
success:function (data, textStatus) {
if (field != 'timestamp') {
$(".loading").hide();
@ -56,6 +59,7 @@ function activateField(type, id, field, event) {
$(".loading").show();
},
dataType:"html",
cache: false,
success:function (data, textStatus) {
$(".loading").hide();
$(name + '_placeholder').html(data);
@ -65,6 +69,8 @@ function activateField(type, id, field, event) {
});
}
//if someone clicks an inactive field, replace it with the hidden form field. Also, focus it and bind a focusout event, so that it gets saved if the user clicks away.
//If a user presses enter, submit the form
function postActivationScripts(name, type, id, field, event) {
$(name + '_field').focus();
inputFieldButtonActive(name + '_field');
@ -103,51 +109,6 @@ function postActivationScripts(name, type, id, field, event) {
$(name + '_solid').hide();
}
// if someone clicks an inactive field, replace it with the hidden form field. Also, focus it and bind a focusout event, so that it gets saved if the user clicks away.
// If a user presses enter, submit the form
function activateField2(type, id, field, event) {
resetForms();
var name = '#' + type + '_' + id + '_' + field;
$(name + '_form').show();
$(name + '_field').focus();
inputFieldButtonActive(name + '_field');
if (field == 'value' || field == 'comment') {
$(name + '_field').on('keyup mouseover', function () {
autoresize(this);
});
}
$(name + '_form').submit(function(e){
e.preventDefault();
submitForm(type, id, field, event);
return false;
});
$(name + '_form').bind("focusout", function() {
inputFieldButtonPassive(name + '_field');
});
$(name + '_form').bind("focusin", function(){
inputFieldButtonActive(name + '_field');
});
$(name + '_form').bind("keydown", function(e) {
if (e.ctrlKey && (e.keyCode == 13 || e.keyCode == 10)) {
submitForm(type, id, field, event);
}
});
$(name + '_field').closest('.inline-input-container').children('.inline-input-accept').bind('click', function() {
submitForm(type, id, field, event);
});
$(name + '_field').closest('.inline-input-container').children('.inline-input-decline').bind('click', function() {
resetForms();
});
$(name + '_solid').hide();
}
function resetForms() {
$('.inline-field-solid').show();
$('.inline-field-placeholder').empty();
@ -173,7 +134,8 @@ function autoresize(textarea) {
function submitForm(type, id, field, event) {
var name = '#' + type + '_' + id + '_' + field;
$.ajax({
data: $(name + '_field').closest("form").serialize(),
data: $(name + '_field').closest("form").serialize(),
cache: false,
success:function (data, textStatus) {
handleAjaxEditResponse(data, name, type, id, field, event);
},
@ -189,33 +151,48 @@ function submitForm(type, id, field, event) {
return false;
};
function submitTagForm(id) {
$.ajax({
data: $('#EventTag').closest("form").serialize(),
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
success:function (data, textStatus) {
loadEventTags(id);
},
error:function() {
alert('Could not add tag.');
loadEventTags(id);
},
complete:function() {
$(".loading").hide();
},
type:"post",
url:"/events/addTag/" + id
});
return false;
}
function handleAjaxEditResponse(data, name, type, id, field, event) {
if (data == "\"saved\"") {
responseArray = JSON.parse(data);
if (responseArray.saved) {
updateAttributeFieldOnSuccess(name, type, id, field, event);
updateAttributeFieldOnSuccess(name, type, id, 'timestamp', event);
} else {
alert(responseArray.errors[field]);
updateAttributeFieldOnSuccess(name, type, id, field, event);
}
}
function handleAjaxMassDeleteResponse(data, event) {
if (data == "\"saved\"") updateAttributeIndexOnSuccess(event);
else {
responseArray = JSON.parse(data);
if (responseArray.saved) {
updateAttributeIndexOnSuccess(event);
} else {
updateAttributeIndexOnSuccess(event);
}
}
$(function(){
$('a:contains("Delete")').removeAttr('onclick');
$('a:contains("Delete")').click(function(e){
e.preventDefault();
var form = $(this).prev();
url = $(form).attr("action");
$.post(url);
return false;
});
});
function toggleAllAttributeCheckboxes() {
if ($(".select_all").is(":checked")) {
$(".select_attribute").prop("checked", true);
@ -244,12 +221,180 @@ function deleteSelectedAttributes(event) {
var formData = $('#delete_selected').serialize();
$.ajax({
data: formData,
cache: false,
type:"POST",
url:"/attributes/deleteSelected/",
url:"/attributes/deleteSelected/" + event,
success:function (data, textStatus) {
handleAjaxMassDeleteResponse(data, event);
},
});
}
return false;
}
function editSelectedAttributes(event) {
$.get("/attributes/editSelected/"+event, function(data) {
$("#attribute_add_form").show();
$("#gray_out").show();
$("#attribute_add_form").html(data);
});
}
function getSelected() {
var selected = [];
$(".select_attribute").each(function() {
if ($(this).is(":checked")) {
var test = $(this).data("id");
selected.push(test);
}
});
return JSON.stringify(selected);
}
function editSelectedAttributes2(event) {
var selected = [];
$(".select_attribute").each(function() {
if ($(this).is(":checked")) {
var test = $(this).data("id");
selected.push(test);
}
});
$('#AttributeIds').attr('value', JSON.stringify(selected));
var formData = $('#delete_selected').serialize();
$.ajax({
data: formData,
cache: false,
type:"POST",
url:"/attributes/editSelected/"+event,
success:function (data, textStatus) {
$("#attribute_add_form").show();
$("#gray_out").show();
$("#attribute_add_form").html(data);
//handleAjaxMassDeleteResponse(data, event);
},
});
}
function loadEventTags(id) {
$.ajax({
dataType:"html",
cache: false,
success:function (data, textStatus) {
$(".eventTagContainer").html(data);
},
url:"/tags/showEventTag/" + id,
});
}
function removeEventTag(event, tag) {
var answer = confirm("Are you sure you want to remove this tag from the event?");
if (answer) {
var formData = $('#removeTag_' + tag).serialize();
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
},
data: formData,
type:"POST",
cache: false,
url:"/events/removeTag/" + event + '/' + tag,
success:function (data, textStatus) {
loadEventTags(event);
//handleAjaxMassDeleteResponse(data, event);
},
complete:function() {
$(".loading").hide();
}
});
}
return false;
}
function clickCreateButton(event) {
$.get( "/attributes/add/" + event, function(data) {
$("#attribute_add_form").show();
$("#gray_out").show();
$("#attribute_add_form").html(data);
});
}
function submitPopoverForm(event, referer) {
var url = null;
if (referer == 'add') url = "/attributes/add/" + event;
if (referer == 'massEdit') url = "/attributes/editSelected/" + event;
if (url !== null) {
$.ajax({
beforeSend: function (XMLHttpRequest) {
$(".loading").show();
$("#gray_out").hide();
$("#attribute_add_form").hide();
},
data: $("#submitButton").closest("form").serialize(),
success:function (data, textStatus) {
handleAjaxPopoverResponse(data, event, url);
$(".loading").show();
},
type:"post",
url:url
});
}
};
function handleAjaxPopoverResponse(response, event, url) {
responseArray = JSON.parse(response);
if (responseArray.saved) {
updateAttributeIndexOnSuccess(event);
} else {
var savedArray = saveValuesForPersistance();
$.ajax({
async:true,
dataType:"html",
success:function (data, textStatus) {
$("#gray_out").show();
$("#attribute_add_form").show();
$("#attribute_add_form").html(data);
handleValidationErrors(responseArray.errors);
if (!isEmpty(responseArray)) {
$("#formWarning").show();
$("#formWarning").html('The attribute(s) could not be saved. Please, try again.');
}
recoverValuesFromPersistance(savedArray);
$(".loading").hide();
},
url:url
});
}
}
function isEmpty(obj) {
var name;
for (name in obj) {
return false;
}
return true;
}
//before we update the form (in case the action failed), we want to retrieve the data from every field, so that we can set the fields in the new form that we fetch
function saveValuesForPersistance() {
var formPersistanceArray = new Array();
for (i = 0; i < fieldsArrayAttribute.length; i++) {
formPersistanceArray[fieldsArrayAttribute[i]] = document.getElementById(fieldsArrayAttribute[i]).value;
}
return formPersistanceArray;
}
function recoverValuesFromPersistance(formPersistanceArray) {
for (i = 0; i < fieldsArrayAttribute.length; i++) {
document.getElementById(fieldsArrayAttribute[i]).value = formPersistanceArray[fieldsArrayAttribute[i]];
}
}
function handleValidationErrors(responseArray) {
for (var k in responseArray) {
var elementName = k.charAt(0).toUpperCase() + k.slice(1);
$("#Attribute" + elementName).parent().addClass("error");
$("#Attribute" + elementName).parent().append("<div class=\"error-message\">" + responseArray[k] + "</div>");
}
}