From 7330b33cd12fc111e37efe9e775621f8f8e93b3a Mon Sep 17 00:00:00 2001 From: mokaddem Date: Thu, 17 Jan 2019 08:36:21 +0100 Subject: [PATCH] new: [addObject] adding objects is done via the generic_picker --- app/Controller/ObjectTemplatesController.php | 47 +++++++++++++------- app/View/Elements/side_menu.ctp | 10 ++--- app/webroot/js/misp.js | 5 +++ 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/app/Controller/ObjectTemplatesController.php b/app/Controller/ObjectTemplatesController.php index dcea02953..6d2e5768d 100644 --- a/app/Controller/ObjectTemplatesController.php +++ b/app/Controller/ObjectTemplatesController.php @@ -17,7 +17,7 @@ class ObjectTemplatesController extends AppController 'recursive' => -1 ); - public function objectChoice($event_id) + public function objectChoice($event_id, $category=false) { $this->ObjectTemplate->populateIfEmpty($this->Auth->user()); $templates_raw = $this->ObjectTemplate->find('all', array( @@ -27,22 +27,37 @@ class ObjectTemplatesController extends AppController 'contain' => array('Organisation.name'), 'order' => array('ObjectTemplate.name asc') )); - $templates = array('all' => array()); - foreach ($templates_raw as $k => $template) { - unset($template['ObjectTemplate']['meta-category']); - $template['ObjectTemplate']['org_name'] = $template['Organisation']['name']; - $templates[$templates_raw[$k]['ObjectTemplate']['meta-category']][] = $template['ObjectTemplate']; - $templates['all'][] = $template['ObjectTemplate']; + + $items = array(); + foreach($templates_raw as $template) { + $template = $template['ObjectTemplate']; + $chosenTemplate = '{{=it.name}}'; + if (strlen($template['description']) < 80) { + $chosenTemplate .= '{{=it.description}}'; + } else { + $chosenTemplate .= ''; + } + $chosenTemplate .= '
{{=it.metacateg}}
'; + + $items[$template['name']] = array( + 'value' => $template['id'], + 'additionalData' => array('event_id' => h($event_id)), + 'template' => $chosenTemplate, + 'templateData' => array( + 'name' => h($template['name']), + 'description' => h($template['description']), + 'metacateg' => __('Category') . ': ' . h($template['meta-category']) + ) + ); } - foreach ($templates as $category => $template_list) { - $templates[$category] = Hash::sort($templates[$category], '{n}.name'); - } - $template_categories = array_keys($templates); - $this->layout = false; - $this->set('template_categories', $template_categories); - $this->set('eventId', $event_id); - $this->set('templates', $templates); - $this->render('ajax/object_choice'); + + $fun = 'redirectAddObject'; + $this->set('items', $items); + $this->set('options', array( + 'functionName' => $fun, + 'multiple' => 0, + )); + $this->render('/Elements/generic_picker'); } public function view($id) diff --git a/app/View/Elements/side_menu.ctp b/app/View/Elements/side_menu.ctp index ea207f929..23ae02d17 100644 --- a/app/View/Elements/side_menu.ctp +++ b/app/View/Elements/side_menu.ctp @@ -53,13 +53,9 @@ 'url' => '/attributes/add/' . $event['Event']['id'], 'text' => __('Add Attribute') )); - echo $this->element('/side_menu_link', array( - 'onClick' => array( - 'function' => 'getPopup', - 'params' => array($event['Event']['id'], 'objectTemplates', 'objectChoice') - ), - 'text' => __('Add Object') - )); + echo '
  • '; + echo ' ' . __('Add Object') . ''; + echo '
  • '; echo $this->element('/side_menu_link', array( 'element_id' => 'addAttachment', 'url' => '/attributes/add_attachment/' . $event['Event']['id'], diff --git a/app/webroot/js/misp.js b/app/webroot/js/misp.js index 8c008f921..6f15b2a8c 100644 --- a/app/webroot/js/misp.js +++ b/app/webroot/js/misp.js @@ -999,6 +999,11 @@ function removeObjectTag(context, object, tag) { return false; } +function redirectAddObject(templateId, additionalData) { + var eventId = additionalData['event_id']; + window.location = '/objects/add/' + eventId + '/' + templateId; +} + function clickCreateButton(event, type) { var destination = 'attributes'; if (type == 'Proposal') destination = 'shadow_attributes';