Compare commits

..

2 Commits

Author SHA1 Message Date
Civiware Solutions
9f05f9fb13 added validation 2018-11-01 22:59:22 +05:30
Civiware Solutions
2d8ca3f2a3 added 'other' option for designation 2018-11-01 22:51:40 +05:30
2 changed files with 52 additions and 6 deletions

View File

@ -240,6 +240,9 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
$submitValues = $form->_params; $submitValues = $form->_params;
if (!empty($submitValues['designation'])) { if (!empty($submitValues['designation'])) {
$form->assign('contribution_designation', $submitValues['designation']); $form->assign('contribution_designation', $submitValues['designation']);
if ($submitValues['designation'] == 'other_financial_type') {
$form->_params['contribution_note'] = $submitValues['designation_note'];
}
} }
} }
@ -260,6 +263,11 @@ function ftoverride_civicrm_buildForm($formName, &$form) {
FALSE, FALSE,
['class' => 'crm-select2'] ['class' => 'crm-select2']
); );
$form->add(
'text',
'designation_note',
''
);
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',
)); ));
@ -280,8 +288,12 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
if ($op == 'create' && $objectName == 'Contribution' && !empty($params['contribution_page_id'])) { if ($op == 'create' && $objectName == 'Contribution' && !empty($params['contribution_page_id'])) {
$designation = CRM_Core_Smarty::singleton()->get_template_vars('contribution_designation'); $designation = CRM_Core_Smarty::singleton()->get_template_vars('contribution_designation');
if (!empty($designation)) { if (!empty($designation)) {
if ($designation == 'other_financial_type') {
// Ignore
}
else {
$params['financial_type_id'] = $designation; $params['financial_type_id'] = $designation;
CRM_Core_Smarty::singleton()->assign('contribution_designation', ''); }
} }
} }
@ -304,6 +316,22 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
} }
} }
/**
* Implements hook_civicrm_validateForm().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_validateForm
*/
function ftoverride_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if ('CRM_Contribute_Form_Contribution_Main' == $formName) {
if (!empty($fields['designation'])
&& $fields['designation'] == 'other_financial_type'
&& empty($fields['designation_note'])
) {
$errors['designation_note'] = ts('Please provide other information about designation.');
}
}
}
/** /**
* Implements hook_civicrm_buildAmount(). * Implements hook_civicrm_buildAmount().
* *
@ -312,7 +340,7 @@ function ftoverride_civicrm_pre($op, $objectName, $id, &$params) {
function ftoverride_civicrm_buildAmount($pageType, &$form, &$amount) { function ftoverride_civicrm_buildAmount($pageType, &$form, &$amount) {
if (!empty($amount) && $form->_flagSubmitted) { if (!empty($amount) && $form->_flagSubmitted) {
$submitValues = $form->_submitValues; $submitValues = $form->_submitValues;
if (!empty($submitValues['designation'])) { if (!empty($submitValues['designation']) && $submitValues['designation'] != 'other_financial_type') {
foreach ($amount as &$priceFields) { foreach ($amount as &$priceFields) {
foreach ($priceFields['options'] as &$options) { foreach ($priceFields['options'] as &$options) {
$options['financial_type_id'] = $submitValues['designation']; $options['financial_type_id'] = $submitValues['designation'];
@ -338,6 +366,9 @@ function ftoverride_get_designation($pageId) {
function ftoverride_get_financialType($action) { function ftoverride_get_financialType($action) {
$financialTypes = []; $financialTypes = [];
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $action); CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $action);
if (empty($financialTypes)) {
return $financialTypes;
}
$result = civicrm_api3('FinancialType', 'get', [ $result = civicrm_api3('FinancialType', 'get', [
'return' => ["description"], 'return' => ["description"],
'description' => ['!=' => ""], 'description' => ['!=' => ""],
@ -347,5 +378,5 @@ function ftoverride_get_financialType($action) {
if (!empty($result['values'])) { if (!empty($result['values'])) {
$descFinancialType = array_column($result['values'], 'description', 'id'); $descFinancialType = array_column($result['values'], 'description', 'id');
} }
return $descFinancialType + $financialTypes; return $descFinancialType + $financialTypes + ['other_financial_type' => ts('Other')];
} }

View File

@ -2,11 +2,26 @@
<div class="label">{$form.designation.label}</div> <div class="label">{$form.designation.label}</div>
<div class="content">{$form.designation.html}</div> <div class="content">{$form.designation.html}</div>
<div class="clear"></div> <div class="clear"></div>
</div> <div class="content designation_note-div">{$form.designation_note.html}</div>
<div class="clear"></div>
</div>
{literal} {literal}
<script type="text/javascript"> <script type="text/javascript">
CRM.$(function($) { CRM.$(function($) {
$('div#priceset:first').after($('div.ft_override_designation-section')); $('div#priceset:first').after($('div.ft_override_designation-section'));
hideShowDesignation();
$('#designation').change(hideShowDesignation);
function hideShowDesignation() {
var fT = $('#designation').val();
if (fT == 'other_financial_type') {
$('div.ft_override_designation-section div.designation_note-div').show();
}
else {
$('div.ft_override_designation-section div.designation_note-div').hide();
}
}
}); });
</script> </script>
{/literal} {/literal}