From 979bb370e7b8d5bf01dd95b95ebfdcf7ca1ff842 Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 16 Apr 2014 15:52:25 +0200 Subject: [PATCH] next step in the ajaxification - multiselect / multidelete - some additional UI changes for the event view --- app/Controller/AttributesController.php | 88 ++++++--- app/Controller/EventsController.php | 3 - app/View/Attributes/view.ctp | 2 + app/View/Elements/eventattribute.ctp | 73 ++++++-- app/View/Elements/eventattributerow.ctp | 18 +- app/View/Elements/eventdiscussion.ctp | 238 ++++++++++++------------ app/View/Events/view.ctp | 6 +- app/webroot/css/main.css | 26 +++ app/webroot/js/ajaxification.js | 47 ++++- 9 files changed, 323 insertions(+), 178 deletions(-) create mode 100644 app/View/Attributes/view.ctp 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 @@ - - - - - - - - - - - - - - $object): - echo $this->element('eventattributerow', array('object' => $object)); - endforeach; - ?> -
DateCategoryTypeValueCommentRelated EventsIDSDistributionActions
+ +
+
+ + + +
+ + + + + + + + + + + + + + + + $object): + echo $this->element('eventattributerow', array('object' => $object, 'mayModify' => $mayModify, 'mayPublish' => $mayPublish)); + endforeach; + ?> +
DateCategoryTypeValueCommentRelated EventsIDSDistributionActions
+
1): ?>

Page of , showing records out of total, starting on , ending on

@@ -97,6 +108,20 @@ +
+ Form->create('Attribute', array('id' => 'delete_selected', 'action' => 'deleteSelected')); + echo $this->Form->input('ids', array( + 'type' => 'text', + 'value' => 'test', + 'style' => 'display:none;', + 'label' => false, + )); + echo $this->Form->end(); + ?> +
+ + + Js->writeBuffer(); ?> \ No newline at end of file diff --git a/app/View/Elements/eventattributerow.ctp b/app/View/Elements/eventattributerow.ctp index 1939087f8..d61a5883d 100644 --- a/app/View/Elements/eventattributerow.ctp +++ b/app/View/Elements/eventattributerow.ctp @@ -11,7 +11,13 @@ if ($object['objectType'] == 0 ) { if ($object['objectType'] == 1) $extra2 = '1'; ?> - + + + + + + + Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_category_form', 'action' => 'editField', 'onSubmit=\'activateField("' . $currentType . '", "' . $object['id'] . '", "' . $event['Event']['id'] . '")\'')); + echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_category_form', 'action' => 'editField')); ?>
@@ -44,7 +50,7 @@ if ($object['objectType'] == 1) $extra2 = '1'; Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_type_form', 'action' => 'editField', 'onSubmit=\'activateField("' . $currentType . '", "' . $object['id'] . '", "' . $event['Event']['id'] . '")\'')); + echo $this->Form->create($currentType, array('class' => 'inline-form inline-field-form', 'id' => $currentType . '_' . $object['id'] . '_type_form', 'action' => 'editField')); ?>
@@ -158,10 +164,8 @@ if ($object['objectType'] == 1) $extra2 = '1';
diff --git a/app/View/Elements/eventdiscussion.ctp b/app/View/Elements/eventdiscussion.ctp index c2fd9b7d4..1d730b925 100644 --- a/app/View/Elements/eventdiscussion.ctp +++ b/app/View/Elements/eventdiscussion.ctp @@ -2,127 +2,129 @@ -
- - > - - - - - - - - - + +
-
- - - - - -
- - - Top | - class = "whitelink"># -
-
-
- 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->options(array( + 'update' => '#top', + 'evalScripts' => true, + 'before' => '$(".loading").show()', + 'complete' => '$(".loading").hide()', + )); + + echo $this->Paginator->prev('« ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span')); + echo $this->Paginator->numbers(array('modulus' => 10, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span')); + echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span')); + ?> + + +
+ + > + + + + + + + + + - -
+
+ + + + + +
+ + + Top | + class = "whitelink"># +
+
+
+ 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']) . ''; + } + ?> +
+ + + + - -
+ + + Html->link('', array('controller' => 'posts', 'action' => 'edit', h($post['Post']['id'])), array('class' => 'icon-edit', 'title' => 'Edit')); + echo $this->Form->postLink('', array('controller' => 'posts', 'action' => 'delete', h($post['Post']['id'])), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete this post?')); + } else { + ?> + + Html->link('', array('controller' => 'posts', 'action' => 'edit', h($post['Post']['id'])), array('class' => 'icon-edit', 'title' => 'Edit')); echo $this->Form->postLink('', array('controller' => 'posts', 'action' => 'delete', h($post['Post']['id'])), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete this post?')); - } else { - ?> - - + + Html->link('', array('controller' => 'posts', 'action' => 'edit', h($post['Post']['id'])), array('class' => 'icon-edit', 'title' => 'Edit')); - echo $this->Form->postLink('', array('controller' => 'posts', 'action' => 'delete', h($post['Post']['id'])), array('class' => 'icon-trash', 'title' => 'Delete'), __('Are you sure you want to delete this post?')); - ?> - - -
-
-
- -
-

- Paginator->counter(array( - 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') - )); - ?> -

- + ?> +
+
+
+ +
+

+ Paginator->counter(array( + 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') + )); + ?> +

+ +
Form->create('Post');?>
diff --git a/app/View/Events/view.ctp b/app/View/Events/view.ctp index a327b5821..779f9daef 100755 --- a/app/View/Events/view.ctp +++ b/app/View/Events/view.ctp @@ -201,10 +201,6 @@ $mayPublish = ($isAclPublish && $event['Event']['orgc'] == $me['org']);
1) echo $this->element('pivot'); ?>
-
- Add Attribute -
-