Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-19549 : New pledge data entry page shows hard coded $ for installments #9475

Merged
merged 6 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CRM/Pledge/Form/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,17 @@ public function buildQuickForm() {
$this->addDate('start_date', ts('Payments Start'), TRUE);
}

if (!empty($this->_values['currency'])) {
$this->assign('currency', $this->_values['currency']);
}
elseif (!empty($this->_submitValues['currency'])) {
$this->assign('currency', $this->_submitValues['currency']);
}

if ($this->_id &&
!$this->_isPending
) {
$eachPaymentAmount = $this->_values['original_installment_amount'];
$this->assign('currency', $this->_values['currency']);
$this->assign('eachPaymentAmount', $eachPaymentAmount);
$this->assign('hideCalender', TRUE);
}
Expand Down
67 changes: 44 additions & 23 deletions templates/CRM/Pledge/Form/Pledge.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@
</tr>
<tr class="crm-pledge-form-block-installments">
<td class="label">{$form.installments.label}</td>
<td>{$form.installments.html} {ts}installments of{/ts} {if $action eq 1 or $isPending}{$form.eachPaymentAmount.html|crmMoney:$currency}{elseif $action eq 2 and !$isPending}{$eachPaymentAmount|crmMoney:$currency}{/if}&nbsp;{ts}every{/ts}&nbsp;{$form.frequency_interval.html}&nbsp;{$form.frequency_unit.html}</td></tr>
<td>{$form.installments.html} {ts}installments of{/ts}
<span class='currency-symbol'>
{if $action eq 1 or $isPending}
{$form.eachPaymentAmount.html|crmMoney:$currency}
{elseif $action eq 2 and !$isPending}
{$eachPaymentAmount|crmMoney:$currency}
{/if}
</span>&nbsp;{ts}every{/ts}&nbsp;{$form.frequency_interval.html}&nbsp;{$form.frequency_unit.html}</td></tr>
<tr class="crm-pledge-form-block-frequency_day">
<td class="label nowrap">{$form.frequency_day.label}</td>
<td>{$form.frequency_day.html} {ts}day of the period{/ts}<br />
Expand Down Expand Up @@ -141,33 +148,47 @@
</table>
{literal}
<script type="text/javascript">
// bind first click of accordion header to load crm-accordion-body with snippet
// everything else taken care of by cj().crm-accordions()
cj(document).ready( function() {
cj('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
loadPanes(cj(this).attr('id'));
// bind first click of accordion header to load crm-accordion-body with snippet
// everything else taken care of by $().crm-accordions()
CRM.$(function($) {
$('.crm-ajax-accordion .crm-accordion-header').one('click', function() {
loadPanes($(this).attr('id'));
});
cj('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
loadPanes(cj(this).attr('id'));
});
});
// load panes function calls for snippet based on id of crm-accordion-header
function loadPanes( id ) {
var url = "{/literal}{crmURL p='civicrm/contact/view/pledge' q='snippet=4&formType=' h=0}{literal}" + id;
{/literal}
$('#currency').on('change', function() {
replaceCurrency($('#currency option:selected').text());
});
$('.crm-ajax-accordion:not(.collapsed) .crm-accordion-header').each(function(index) {
loadPanes($(this).attr('id'));
});

function replaceCurrency(val) {
var symbol = '';
var eachPaymentAmout = $('#eachPaymentAmount');
var pos = val.indexOf("(") + 1;
if (pos) {
symbol = val.slice(pos, val.lastIndexOf(")"));
}
$('.currency-symbol').text(symbol).append("&nbsp;").append(eachPaymentAmout);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is an outdated pattern. We no longer use cj.
The way to update this code would be to wrap the whole thing in CRM.$(function($) { ... }); and replace all cj with $.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR to replace the outdated cj and also fixed validation error mentioned in point 1. @pradpnayak Can you please take a look ?

// load panes function calls for snippet based on id of crm-accordion-header
function loadPanes( id ) {
var url = "{/literal}{crmURL p='civicrm/contact/view/pledge' q='snippet=4&formType=' h=0}{literal}" + id;
{/literal}
{if $contributionMode}
url = url + "&mode={$contributionMode}";
url = url + "&mode={$contributionMode}";
{/if}
{literal}
if ( ! cj('div.'+id).html() ) {
var loading = '<img src="{/literal}{$config->resourceBase}i/loading.gif{literal}" alt="{/literal}{ts escape='js'}loading{/ts}{literal}" />&nbsp;{/literal}{ts escape='js'}Loading{/ts}{literal}...';
cj('div.'+id).html(loading);
cj.ajax({
{literal}
if ( ! $('div.'+id).html() ) {
var loading = '<img src="{/literal}{$config->resourceBase}i/loading.gif{literal}" alt="{/literal}{ts escape='js'}loading{/ts}{literal}" />&nbsp;{/literal}{ts escape='js'}Loading{/ts}{literal}...';
$('div.'+id).html(loading);
$.ajax({
url : url,
success: function(data) { cj('div.'+id).html(data).trigger('crmLoad'); }
});
success: function(data) { $('div.'+id).html(data).trigger('crmLoad'); }
});
}
}
}
});
</script>
{/literal}

Expand Down