Show Designation on COntribution screen on the basis how they are selected from settings

This commit is contained in:
Civiware Solutions 2018-12-20 23:54:17 +00:00
parent 9f05f9fb13
commit f81ec4941b
2 changed files with 25 additions and 5 deletions

View File

@ -207,6 +207,7 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
$form->assign('showElement', $showElement); $form->assign('showElement', $showElement);
$financialTypes = ftoverride_get_financialType($form->getVar('_action')); $financialTypes = ftoverride_get_financialType($form->getVar('_action'));
$form->add('hidden', 'hidden_designation');
$form->add( $form->add(
'select', 'select',
'designation', 'designation',
@ -222,13 +223,17 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
CRM_Core_Region::instance('page-body')->add(array( CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Contribute/Form/ContributionPage/common.tpl', 'template' => 'CRM/Contribute/Form/ContributionPage/common.tpl',
)); ));
if ($form->getVar('_id')) { if ($form->getVar('_id')) {
try { try {
$designations = ftoverride_get_designation($form->getVar('_id')); $designations = ftoverride_get_designation($form->getVar('_id'));
if (empty($designations)) { if (empty($designations)) {
return; return;
} }
$form->setDefaults(['designation' => $designations]); $form->setDefaults([
'designation' => $designations,
'hidden_designation' => implode(',', $designations),
]);
} }
catch (Exception $e) { catch (Exception $e) {
// Ignore // Ignore
@ -252,14 +257,17 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
if (empty($designations)) { if (empty($designations)) {
return; return;
} }
$financialTypes = ftoverride_get_financialType($form->getVar('_action')); $financialTypes = ftoverride_get_financialType($form->getVar('_action'));
$designations = array_flip($designations); $designations = array_flip($designations);
$financialTypes = array_intersect_key($financialTypes, $designations); foreach($designations as $id => &$label) {
$label = $financialTypes[$id];
}
$form->add( $form->add(
'select', 'select',
'designation', 'designation',
ts('Designation'), ts('Designation'),
['' => ts('- select -')] + $financialTypes, ['' => ts('- select -')] + $designations,
FALSE, FALSE,
['class' => 'crm-select2'] ['class' => 'crm-select2']
); );
@ -268,6 +276,10 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
'designation_note', 'designation_note',
'' ''
); );
reset($designations);
$form->setDefaults([
'designation' => key($designations),
]);
CRM_Core_Region::instance('page-body')->add(array( CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl', 'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl',
)); ));
@ -309,8 +321,8 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
'custom_group_id' => "ft_override", 'custom_group_id' => "ft_override",
'name' => "ft_override_designation", 'name' => "ft_override_designation",
]); ]);
$params["custom_{$customFieldId}"] = $params['designation']; $params["custom_{$customFieldId}"] = explode(',', $params['hidden_designation']);
unset($params['designation']); unset($params['designation'], $params['hidden_designation']);
$contributionPage = civicrm_api3('ContributionPage', 'create', $params); $contributionPage = civicrm_api3('ContributionPage', 'create', $params);
$params = ['id' => $contributionPage['id']]; $params = ['id' => $contributionPage['id']];
} }

View File

@ -9,6 +9,14 @@
<script type="text/javascript"> <script type="text/javascript">
CRM.$(function($) { CRM.$(function($) {
$('tr.crm-contribution-contributionpage-settings-form-block-financial_type_id').after($('table.ft_override_designation-block tr')); $('tr.crm-contribution-contributionpage-settings-form-block-financial_type_id').after($('table.ft_override_designation-block tr'));
$('#designation').change(function(e) {
var data = $('#designation').select2('data');
var selectedDesignations = new Array();
$.each(data, function( index, value ) {
selectedDesignations.push(value.id);
});
$('input[name="hidden_designation"]').val(selectedDesignations.join(","));
});
}); });
</script> </script>
{/literal} {/literal}