diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index 940de2e4d..56d85d0ca 100755 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -153,23 +153,28 @@ class AttributesController extends AppController { // debug(tru); } } - // we added all the attributes, - if ($fails) { - // list the ones that failed - if (!CakeSession::read('Message.flash')) { - $this->Session->setFlash(__('The lines' . $fails . ' could not be saved. Please, try again.', true), 'default', array(), 'error'); - } else { - $existingFlash = CakeSession::read('Message.flash'); - $this->Session->setFlash(__('The lines' . $fails . ' could not be saved. ' . $existingFlash['message'], true), 'default', array(), 'error'); + 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)); + } else { + // we added all the attributes, + if ($fails) { + // list the ones that failed + if (!CakeSession::read('Message.flash')) { + $this->Session->setFlash(__('The lines' . $fails . ' could not be saved. Please, try again.', true), 'default', array(), 'error'); + } else { + $existingFlash = CakeSession::read('Message.flash'); + $this->Session->setFlash(__('The lines' . $fails . ' could not be saved. ' . $existingFlash['message'], true), 'default', array(), 'error'); + } } + if ($successes) { + // list the ones that succeeded + $this->Session->setFlash(__('The lines' . $successes . ' have been saved', true)); + } + + $this->redirect(array('controller' => 'events', 'action' => 'view', $this->request->data['Attribute']['event_id'])); } - if ($successes) { - // list the ones that succeeded - $this->Session->setFlash(__('The lines' . $successes . ' have been saved', true)); - } - - $this->redirect(array('controller' => 'events', 'action' => 'view', $this->request->data['Attribute']['event_id'])); - } else { if (isset($this->request->data['Attribute']['uuid'])) { // TODO here we should start RESTful dialog // check if the uuid already exists and also save the existing attribute for further checks @@ -860,18 +865,38 @@ class AttributesController extends AppController { if (!$this->request->is('post') && !$this->_isRest()) { throw new MethodNotAllowedException(); } - + if ($this->__delete($id)) { + $this->Session->setFlash(__('Attribute deleted')); + } else { + $this->Session->setFlash(__('Attribute was not deleted')); + } + + if (!$this->_isRest()) $this->redirect($this->referer()); // TODO check + else $this->redirect(array('action' => 'index')); + } + +/** + * unification of the actual delete for the multi-select + * + * @param unknown $id + * @throws NotFoundException + * @throws MethodNotAllowedException + * @return boolean + * + * returns true/false based on success + */ + private function __delete($id) { $this->Attribute->id = $id; if (!$this->Attribute->exists()) { throw new NotFoundException(__('Invalid attribute')); } - + if ('true' == Configure::read('MISP.sync')) { // find the uuid $result = $this->Attribute->findById($id); $uuid = $result['Attribute']['uuid']; } - + // check for permissions if (!$this->_isSiteAdmin()) { $this->Attribute->read(); @@ -885,7 +910,7 @@ class AttributesController extends AppController { } } } - + // attachment will be deleted with the beforeDelete() function in the Model if ($this->Attribute->delete()) { // delete the attribute from remote servers @@ -893,17 +918,30 @@ class AttributesController extends AppController { // find the uuid $this->__deleteAttributeFromServers($uuid); } - + // We have just deleted the attribute, let's also check if there are any shadow attributes that were attached to it and delete them $this->loadModel('ShadowAttribute'); $this->ShadowAttribute->deleteAll(array('ShadowAttribute.old_id' => $id), false); - $this->Session->setFlash(__('Attribute deleted')); + return true; } else { - $this->Session->setFlash(__('Attribute was not deleted')); + return false; } - - if (!$this->_isRest()) $this->redirect($this->referer()); // TODO check - else $this->redirect(array('action' => 'index')); + + } + + public function deleteSelected() { + //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); + } + $this->autoRender = false; + return new CakeResponse(array('body'=> json_encode('saved'),'status'=>200)); } /** diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 2ac27b62d..6cb7459fe 100755 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -433,9 +433,6 @@ class EventsController extends AppController { $this->set('currentEvent', $id); } - private function __view() { - - } private function __startPivoting($id, $info, $date){ $this->Session->write('pivot_thread', null); diff --git a/app/View/Attributes/view.ctp b/app/View/Attributes/view.ctp new file mode 100644 index 000000000..cdd1629e6 --- /dev/null +++ b/app/View/Attributes/view.ctp @@ -0,0 +1,2 @@ +element('eventattributerow', array('object' => $object)); \ No newline at end of file diff --git a/app/View/Elements/eventattribute.ctp b/app/View/Elements/eventattribute.ctp index 663341b7c..7afb28df8 100644 --- a/app/View/Elements/eventattribute.ctp +++ b/app/View/Elements/eventattribute.ctp @@ -1,4 +1,5 @@ Html->script('ajaxification'); $mayModify = (($isAclModify && $event['Event']['user_id'] == $me['id'] && $event['Event']['orgc'] == $me['org']) || ($isAclModifyOrg && $event['Event']['orgc'] == $me['org'])); $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']); if (!empty($eventArray)): @@ -41,25 +42,35 @@ -
- | Date | -Category | -Type | -Value | -Comment | -Related Events | -IDS | -Distribution | -Actions | -
---|
+ + | Date | +Category | +Type | +Value | +Comment | +Related Events | +IDS | +Distribution | +Actions | +
---|
Page of , showing records out of total, starting on , ending on
@@ -97,6 +108,20 @@ +
-
-
-
|
- |||||||||||
- Html->image('orgs/' . h($post['User']['org']) . '.png', array('alt' => h($post['User']['org']), 'title' => h($post['User']['org']), 'style' => 'width:48px; height:48px')); - else echo $this->Html->tag('span', h($post['User']['org']), array('class' => 'welcome', 'style' => 'float:center;')); - ?> - | -
- Command->convertQuotes(nl2br(h($post['Post']['contents'])));
- if ($post['Post']['post_id'] !=0 || ($post['Post']['date_created'] != $post['Post']['date_modified'])) {
- ?>
- - - - In reply to post - ># - - Message edited at ' . h($post['Post']['date_modified']) . ''; - } - ?> - |
- ||||||||||
-
|
+
+ Paginator->counter(array( + 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') + )); + ?> +
+