fix: [UI] Cleanup for reference bulk add

pull/8670/head
Jakub Onderka 2022-10-15 09:30:03 +02:00
parent cf25698a5f
commit d09455f640
2 changed files with 17 additions and 26 deletions

View File

@ -217,11 +217,6 @@ class ObjectReferencesController extends AppController
} }
$selectedAttributeIDs = $this->_jsonDecode($selectedAttributes); $selectedAttributeIDs = $this->_jsonDecode($selectedAttributes);
$event = $this->ObjectReference->Object->Event->find('first', array(
'recursive' => -1,
'fields' => array('Event.id', 'Event.uuid', 'Event.orgc_id', 'Event.user_id', 'Event.publish_timestamp'),
'conditions' => array('Event.id' => $eventId)
));
$event = $this->ObjectReference->Object->Event->fetchEvent($this->Auth->user(), [ $event = $this->ObjectReference->Object->Event->fetchEvent($this->Auth->user(), [
'eventid' => $eventId, 'eventid' => $eventId,
]); ]);
@ -233,33 +228,28 @@ class ObjectReferencesController extends AppController
throw new ForbiddenException(__('You do not have permission to do that.')); throw new ForbiddenException(__('You do not have permission to do that.'));
} }
$eventObjects = [];
$validSourceUuid = [];
foreach ($event['Object'] as $object) {
$validSourceUuid[$object['uuid']] = sprintf('[%s] %s ', $object['id'], $object['name']);
$eventObjects[$object['uuid']] = $object;
}
$selectedAttributes = []; $selectedAttributes = [];
foreach ($event['Attribute'] as $attribute) { foreach ($event['Attribute'] as $attribute) {
if (in_array($attribute['id'], $selectedAttributeIDs)) { if (in_array($attribute['id'], $selectedAttributeIDs)) {
$selectedAttributes[$attribute['id']] = $attribute; $selectedAttributes[$attribute['id']] = $attribute;
} }
} }
if (empty($selectedAttributes)) {
throw new BadRequestException(__('No attribute selected.'));
}
if ($this->request->is('post')) { if ($this->request->is('post')) {
$conditions = [ $conditions = [
'Object.deleted' => 0, 'Object.deleted' => 0,
'Object.event_id' => $eventId,
'Object.uuid' => $this->data['ObjectReference']['source_uuid'], 'Object.uuid' => $this->data['ObjectReference']['source_uuid'],
]; ];
$object = $this->ObjectReference->Object->find('first', array( $object = $this->ObjectReference->Object->find('first', array(
'conditions' => $conditions, 'conditions' => $conditions,
'recursive' => -1, 'recursive' => -1,
'contain' => array(
'Event' => array(
'fields' => array('Event.id', 'Event.orgc_id', 'Event.user_id', 'Event.extends_uuid')
)
)
)); ));
if (empty($object) || !$this->__canModifyEvent($object)) { if (empty($object)) {
throw new NotFoundException('Invalid object.'); throw new NotFoundException('Invalid object.');
} }
@ -310,6 +300,12 @@ class ObjectReferencesController extends AppController
} }
} }
$eventObjects = [];
$validSourceUuid = [];
foreach ($event['Object'] as $object) {
$validSourceUuid[$object['uuid']] = sprintf('[%s] %s ', $object['id'], $object['name']);
$eventObjects[$object['uuid']] = $object;
}
$this->loadModel('ObjectRelationship'); $this->loadModel('ObjectRelationship');
$relationships = $this->ObjectRelationship->find('column', array( $relationships = $this->ObjectRelationship->find('column', array(

View File

@ -13,6 +13,7 @@ $fields = [
[ [
'field' => 'relationship_type_select', 'field' => 'relationship_type_select',
'type' => 'dropdown', 'type' => 'dropdown',
'title' => __('Relationship type'),
'class' => 'span6', 'class' => 'span6',
'options' => $relationships, 'options' => $relationships,
'picker' => true, 'picker' => true,
@ -41,9 +42,9 @@ $fields = [
[ [
'field' => 'comment', 'field' => 'comment',
'type' => 'textarea', 'type' => 'textarea',
'class' => 'input span6' 'class' => 'input span6',
'rows' => 3,
], ],
]; ];
echo $this->element('genericElements/Form/genericForm', [ echo $this->element('genericElements/Form/genericForm', [
'data' => [ 'data' => [
@ -57,16 +58,10 @@ echo $this->element('genericElements/Form/genericForm', [
] ]
] ]
]); ]);
if (!$ajax) {
echo $this->element('/genericElements/SideMenu/side_menu', $menuData);
}
?> ?>
<script> <script>
var validSourceUuid = <?= JsonTool::encode($eventObjects) ?>; var validSourceUuid = <?= JsonTool::encode($eventObjects) ?>;
$(document).ready(function() { $(function() {
$("#ObjectReferenceRelationshipTypeSelect").change(function() { $("#ObjectReferenceRelationshipTypeSelect").change(function() {
objectReferenceCheckForCustomRelationship() objectReferenceCheckForCustomRelationship()
}); });