Show Designation on COntribution screen on the basis how they are selected from settings
This commit is contained in:
parent
9f05f9fb13
commit
f81ec4941b
@ -207,6 +207,7 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
||||
|
||||
$form->assign('showElement', $showElement);
|
||||
$financialTypes = ftoverride_get_financialType($form->getVar('_action'));
|
||||
$form->add('hidden', 'hidden_designation');
|
||||
$form->add(
|
||||
'select',
|
||||
'designation',
|
||||
@ -222,13 +223,17 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
||||
CRM_Core_Region::instance('page-body')->add(array(
|
||||
'template' => 'CRM/Contribute/Form/ContributionPage/common.tpl',
|
||||
));
|
||||
|
||||
if ($form->getVar('_id')) {
|
||||
try {
|
||||
$designations = ftoverride_get_designation($form->getVar('_id'));
|
||||
if (empty($designations)) {
|
||||
return;
|
||||
}
|
||||
$form->setDefaults(['designation' => $designations]);
|
||||
$form->setDefaults([
|
||||
'designation' => $designations,
|
||||
'hidden_designation' => implode(',', $designations),
|
||||
]);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Ignore
|
||||
@ -252,14 +257,17 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
||||
if (empty($designations)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$financialTypes = ftoverride_get_financialType($form->getVar('_action'));
|
||||
$designations = array_flip($designations);
|
||||
$financialTypes = array_intersect_key($financialTypes, $designations);
|
||||
foreach($designations as $id => &$label) {
|
||||
$label = $financialTypes[$id];
|
||||
}
|
||||
$form->add(
|
||||
'select',
|
||||
'designation',
|
||||
ts('Designation'),
|
||||
['' => ts('- select -')] + $financialTypes,
|
||||
['' => ts('- select -')] + $designations,
|
||||
FALSE,
|
||||
['class' => 'crm-select2']
|
||||
);
|
||||
@ -268,6 +276,10 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
|
||||
'designation_note',
|
||||
''
|
||||
);
|
||||
reset($designations);
|
||||
$form->setDefaults([
|
||||
'designation' => key($designations),
|
||||
]);
|
||||
CRM_Core_Region::instance('page-body')->add(array(
|
||||
'template' => 'CRM/Contribute/Form/ContributionMain/common.tpl',
|
||||
));
|
||||
@ -309,8 +321,8 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
|
||||
'custom_group_id' => "ft_override",
|
||||
'name' => "ft_override_designation",
|
||||
]);
|
||||
$params["custom_{$customFieldId}"] = $params['designation'];
|
||||
unset($params['designation']);
|
||||
$params["custom_{$customFieldId}"] = explode(',', $params['hidden_designation']);
|
||||
unset($params['designation'], $params['hidden_designation']);
|
||||
$contributionPage = civicrm_api3('ContributionPage', 'create', $params);
|
||||
$params = ['id' => $contributionPage['id']];
|
||||
}
|
||||
|
@ -9,6 +9,14 @@
|
||||
<script type="text/javascript">
|
||||
CRM.$(function($) {
|
||||
$('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>
|
||||
{/literal}
|
||||
|
Loading…
Reference in New Issue
Block a user