chg: [analyst-data:add] Added support of picker for relationship type and improved UI for sharing-group

notes
Sami Mokaddem 2024-01-29 11:01:02 +01:00
parent ffdb21d58f
commit 990b574867
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 52 additions and 9 deletions

View File

@ -57,6 +57,9 @@ class AnalystDataController extends AppController
return $this->restResponsePayload;
}
$this->_setViewElements();
if ($type == 'Relationship') {
$this->set('existingRelations', $this->AnalystData->getExistingRelationships());
}
$this->set('menuData', array('menuList' => 'analyst_data', 'menuItem' => 'add'));
$this->render('add');
}
@ -72,6 +75,9 @@ class AnalystDataController extends AppController
return $this->restResponsePayload;
}
$this->_setViewElements();
if ($type == 'Relationship') {
$this->set('existingRelations', $this->AnalystData->getExistingRelationships());
}
$this->set('menuData', array('menuList' => 'analyst_data', 'menuItem' => 'edit'));
$this->render('add');
}

View File

@ -133,4 +133,20 @@ class AnalystData extends AppModel
}
return $analystData;
}
public function getExistingRelationships()
{
$existingRelationships = $this->find('column', [
'recursive' => -1,
'fields' => ['relationship_type'],
'unique' => true,
]);
$this->ObjectRelationship = ClassRegistry::init('ObjectRelationship');
$objectRelationships = $this->ObjectRelationship->find('column', [
'recursive' => -1,
'fields' => ['name'],
'unique' => true,
]);
return array_unique(array_merge($existingRelationships, $objectRelationships));
}
}

View File

@ -45,7 +45,9 @@ class Relationship extends AnalystData
}
}
foreach ($results as $i => $v) {
$results[$i][$this->alias]['related_object'] = $this->getRelatedElement($this->__currentUser, $v[$this->alias]['related_object_type'], $v[$this->alias]['related_object_uuid']);
if (!empty($v[$this->alias]['related_object_type']) && !empty($v[$this->alias]['related_object_uuid'])) {
$results[$i][$this->alias]['related_object'] = $this->getRelatedElement($this->__currentUser, $v[$this->alias]['related_object_type'], $v[$this->alias]['related_object_uuid']);
}
}
return $results;
}

View File

@ -71,10 +71,13 @@ if ($modelSelection === 'Note') {
],
[
'field' => 'related_object_type',
'class' => 'span2',
'class' => 'span4',
'options' => $dropdownData['valid_targets'],
'type' => 'dropdown',
'stayInLine' => 1
'type' => 'text',
'picker' => array(
'text' => __('Pick type'),
'function' => 'pickerTypes',
)
],
[
'field' => 'related_object_uuid',
@ -160,6 +163,11 @@ if (!$ajax) {
}
$(document).ready(function() {
$('#NoteDistribution').change(function() {
checkSharingGroup('Note');
});
checkSharingGroup('Note');
$('#RelationshipRelatedObjectType').change(function(e) {
if ($('#RelationshipRelatedObjectUuid').val().length == 36) {
fetchAndDisplayRelatedObject($('#RelationshipRelatedObjectType').val(),$('#RelationshipRelatedObjectUuid').val())
@ -172,12 +180,23 @@ if (!$ajax) {
})
})
$(function() {
$('#NoteDistribution').change(function() {
checkSharingGroup('Note');
function pickerTypes() {
var existingRelationTypes = <?= json_encode(array_values($existingRelations)) ?> ;
var $select = $('<select id="pickerTypeSelect"/>');
existingRelationTypes.forEach(function(type) {
$select.append($('<option/>').val(type).text(type))
})
var html = '<div>' + $select[0].outerHTML + '</div>';
var that = this
openPopover(this, html, false, 'right', function($popover) {
$popover.find('select').chosen({
width: '300px',
}).on('change', function(evt, param) {
$('#RelationshipRelatedObjectType').val($('#pickerTypeSelect').val());
$(that).popover('hide')
});
});
checkSharingGroup('Note');
});
}
</script>
<style>