return;
}
+ $allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID);
+
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header')
- ->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header');
+ ->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header')
+ ->addVars('relationshipTypes', CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes));
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles');
CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
$this->assign('globalGroupInfo', $globalGroupInfo);
-
// List relationship types for adding an arbitrary new role to the case
- $roleTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID);
- $this->add('select', 'role_type', ts('Relationship Type'), array('' => ts('- select type -')) + $roleTypes, FALSE, array('class' => 'crm-select2 twenty'));
+ $this->add('select',
+ 'role_type',
+ ts('Relationship Type'),
+ array('' => ts('- select type -')) + $allowedRelationshipTypes,
+ FALSE,
+ array('class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}')
+ );
$hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID);
if (is_array($hookCaseSummary)) {
$relationshipList = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId);
// Metadata needed on clientside
- $contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE);
- $jsData = array();
- // Get just what we need to keep the dom small
- $whatWeWant = array_flip(array('contact_type_a', 'contact_type_b', 'contact_sub_type_a', 'contact_sub_type_b'));
+ $this->assign('relationshipData', self::getRelationshipTypeMetadata($relationshipList));
+
foreach ($this->_allRelationshipNames as $id => $vals) {
if ($vals['name_a_b'] === 'Employee of') {
$this->assign('employmentRelationship', $id);
- }
- if (isset($relationshipList["{$id}_a_b"]) || isset($relationshipList["{$id}_b_a"])) {
- $jsData[$id] = array_filter(array_intersect_key($this->_allRelationshipNames[$id], $whatWeWant));
- // Add user-friendly placeholder
- foreach (array('a', 'b') as $x) {
- $type = !empty($jsData[$id]["contact_sub_type_$x"]) ? $jsData[$id]["contact_sub_type_$x"] : CRM_Utils_Array::value("contact_type_$x", $jsData[$id]);
- $jsData[$id]["placeholder_$x"] = $type ? ts('- select %1 -', array(strtolower($contactTypes[$type]['label']))) : ts('- select contact -');
- }
+ break;
}
}
- $this->assign('relationshipData', $jsData);
$this->addField('relationship_type_id', array('options' => array('' => ts('- select -')) + $relationshipList, 'class' => 'huge', 'placeholder' => '- select -'), TRUE);
}
}
+ /**
+ * @param $relationshipList
+ * @return array
+ */
+ public static function getRelationshipTypeMetadata($relationshipList) {
+ $contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE);
+ $allRelationshipNames = CRM_Core_PseudoConstant::relationshipType('name');
+ $jsData = array();
+ // Get just what we need to keep the dom small
+ $whatWeWant = array_flip(array(
+ 'contact_type_a',
+ 'contact_type_b',
+ 'contact_sub_type_a',
+ 'contact_sub_type_b',
+ ));
+ foreach ($allRelationshipNames as $id => $vals) {
+ if (isset($relationshipList["{$id}_a_b"]) || isset($relationshipList["{$id}_b_a"])) {
+ $jsData[$id] = array_filter(array_intersect_key($allRelationshipNames[$id], $whatWeWant));
+ // Add user-friendly placeholder
+ foreach (array('a', 'b') as $x) {
+ $type = !empty($jsData[$id]["contact_sub_type_$x"]) ? $jsData[$id]["contact_sub_type_$x"] : CRM_Utils_Array::value("contact_type_$x", $jsData[$id]);
+ $jsData[$id]["placeholder_$x"] = $type ? ts('- select %1 -', array(strtolower($contactTypes[$type]['label']))) : ts('- select contact -');
+ }
+ }
+ }
+ return $jsData;
+ }
+
}
},
'#addCaseRoleDialog': {
pre: function() {
- $('[name=role_type]', this).val('').change();
- $('[name=add_role_contact_id]', this).val('').crmEntityRef({create: true, api: {params: {contact_type: 'Individual'}}});
+ var $contactField = $('[name=add_role_contact_id]', this);
+ $('[name=role_type]', this)
+ .off('.miniform')
+ .on('change.miniform', function() {
+ var val = $(this).val();
+ $contactField.val('').change().prop('disabled', !val);
+ if (val) {
+ var
+ pieces = val.split('_'),
+ rType = pieces[0],
+ target = pieces[2], // b or a
+ contact_type = CRM.vars.relationshipTypes[rType]['contact_type_' + target],
+ contact_sub_type = CRM.vars.relationshipTypes[rType]['contact_sub_type_' + target],
+ api = {params: {}};
+ if (contact_type) {
+ api.params.contact_type = contact_type;
+ }
+ if (contact_sub_type) {
+ api.params.contact_sub_type = contact_sub_type;
+ }
+ $contactField
+ .data('api-params', api)
+ .data('user-filter', {})
+ .attr('placeholder', CRM.vars.relationshipTypes[rType]['placeholder_' + target])
+ .change();
+ }
+ })
+ .val('')
+ .change();
+ $contactField.val('').crmEntityRef({create: true, api: {params: {contact_type: 'Individual'}}});
},
post: function(data) {
var contactID = $('[name=add_role_contact_id]', this).val(),
<div>{$form.role_type.label}</div>
<div>{$form.role_type.html}</div><br />
<div><label for="add_role_contact_id">{ts}Assign To{/ts}:</label></div>
- <div><input name="add_role_contact_id" placeholder="{ts}- select contact -{/ts}" class="huge" /></div>
+ <div><input name="add_role_contact_id" placeholder="{ts}- first select relationship type -{/ts}" class="huge" /></div>
</div>
{/if}
{/literal}
<div id="deleteCaseRoleDialog" class="hiddenElement">
- {ts}Are you sure you want to delete this case role?{/ts}
+ {ts}Are you sure you want to end this relationship?{/ts}
</div>
</div><!-- /.crm-accordion-body -->