new: [addObject] adding objects is done via the generic_picker

pull/4024/head
mokaddem 2019-01-17 08:36:21 +01:00
parent 4c6dd1d483
commit 7330b33cd1
3 changed files with 39 additions and 23 deletions

View File

@ -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 = '<span href="#">{{=it.name}}</span>';
if (strlen($template['description']) < 80) {
$chosenTemplate .= '<i style="float:right; font-size: smaller;">{{=it.description}}</i>';
} else {
$chosenTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.description}}"></it>';
}
$chosenTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; margin-top: 5px; font-size: smaller;"><i>{{=it.metacateg}}</i></div>';
$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)

View File

@ -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 '<li>';
echo '<a href="#" onclick="popoverPopup(this, ' . h($event['Event']['id']) . ', \'objectTemplates\', \'objectChoice\')"> ' . __('Add Object') . '</a>';
echo '</li>';
echo $this->element('/side_menu_link', array(
'element_id' => 'addAttachment',
'url' => '/attributes/add_attachment/' . $event['Event']['id'],

View File

@ -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';