foreach ($this->_fields as $name => $field) {
if (in_array($field['field_type'], $contactTypes)) {
$fld = explode('-', $field['name']);
- $contactReturnProperties[] = $fld[0];
- $contactFieldMap[$fld[0]] = $field['name'];
+ $contactReturnProperties[$field['name']] = $fld[0];
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
CRM_Core_Resources::singleton()
->addSetting(array('contact' => array(
'return' => implode(',', $contactReturnProperties),
- 'fieldmap' => $contactFieldMap,
+ 'fieldmap' => array_flip($contactReturnProperties),
)));
// don't set the status message when form is submitted.
-//@todo functions partially moved from tpl but still need an enclosure etc
+//@todo functions partially moved from tpl but still need an enclosure / cleanup
+// jslinting etc
+cj(function () {
+ cj('.selector-rows').change(function () {
+ var options = {
+ 'url': CRM.url('civicrm/ajax/batch')
+ };
+
+ cj("#Entry").ajaxSubmit(options);
+
+ // validate rows
+ checkColumns(cj(this));
+ });
+
+ cj('input[name^="soft_credit_contact["]').change(function(){
+ var rowNum = cj(this).attr('id').replace('soft_credit_contact_','');
+ var totalAmount = cj('#field_'+rowNum+'_total_amount').val();
+ //assign total amount as default soft credit amount
+ cj('#soft_credit_amount_'+ rowNum).val(totalAmount);
+ });
+
+ // validate rows
+ validateRow();
+
+ //calculate the actual total for the batch
+ calculateActualTotal();
+
+ cj('input[id*="_total_amount"]').bind('keyup change', function () {
+ calculateActualTotal();
+ });
+
+ if (CRM.batch.type_id == 1) {
+ // hide all dates if send receipt is checked
+ hideSendReceipt();
+
+ // hide the receipt date if send receipt is checked
+ cj('input[id*="][send_receipt]"]').change(function () {
+ showHideReceipt(cj(this));
+ });
+
+ }
+ else{
+ cj('select[id^="member_option_"]').each(function () {
+ if (cj(this).val() == 1) {
+ cj(this).attr('disabled', true);
+ }
+ });
+
+ // set payment info accord to membership type
+ cj('select[id*="_membership_type_0"]').change(function () {
+ setPaymentBlock(cj(this), null);
+ });
+
+ cj('select[id*="_membership_type_1"]').change(function () {
+ setPaymentBlock(cj(this), cj(this).val());
+ });
+
+ }
+
+ // line breaks between radio buttons and checkboxes
+ cj('input.form-radio').next().after('<br />');
+ cj('input.form-checkbox').next().after('<br />');
+
+ //set the focus on first element
+ cj('#primary_contact_1').focus();
+
+});
+
+
+function updateContactInfo(blockNo, prefix) {
+ var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo + ']"]';
+ var contactId = cj(contactHiddenElement).val();
+
+ var profileFields = CRM.contact.fieldmap;
+
+ CRM.api('Contact', 'get', {
+ 'sequential': '1',
+ 'contact_id': contactId,
+ 'return': CRM.contact.return },
+ { success: function (data) {
+ cj.each(data.values[0], function (key, value) {
+ // set the values
+ var actualFldName = profileFields[key];
+ if (key == 'country' || key == 'state_province') {
+ idFldName = key + '_id';
+ value = data.values[0][idFldName];
+ }
+ setFieldValue(actualFldName, value, blockNo)
+ });
+
+ // for membership batch entry based on contact we need to enable / disable
+ // add membership select
+ if(CRM.batch.type_id == 2) {
+ CRM.api('Membership', 'get', {
+ 'sequential': '1',
+ 'contact_id': contactId,
+ },
+ { success: function (data) {
+ if (data.count > 0) {
+ //get the information on membership type
+ var membershipTypeId = data.values[0].membership_type_id;
+ var membershipJoinDate = data.values[0].join_date;
+ CRM.api('MembershipType', 'get', {
+ 'sequential': '1',
+ 'id': membershipTypeId
+ },
+ { success: function (data) {
+ var memTypeContactId = data.values[0].member_of_contact_id;
+ cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
+ cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
+ cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
+ setDateFieldValue('join_date', membershipJoinDate, blockNo)
+ }
+ });
+ }
+ }
+ });
+ }
+ }
+ });
+}
+
function setPaymentBlock(form, memType) {
var rowID = form.closest('div.crm-grid-row').attr('entity_id');
var dataUrl = CRM.url('civicrm/ajax/memType');
</div>
<div class="crm-submit-buttons">{if $fields}{$form._qf_Batch_refresh.html}{/if} {$form.buttons.html}</div>
</div>
-{literal}
-<script type="text/javascript">
-cj(function () {
- cj('.selector-rows').change(function () {
- var options = {
- 'url': CRM.url('civicrm/ajax/batch')
- };
-
- cj("#Entry").ajaxSubmit(options);
-
- // validate rows
- checkColumns(cj(this));
- });
-
- cj('input[name^="soft_credit_contact["]').change(function(){
- var rowNum = cj(this).attr('id').replace('soft_credit_contact_','');
- var totalAmount = cj('#field_'+rowNum+'_total_amount').val();
- //assign total amount as default soft credit amount
- cj('#soft_credit_amount_'+ rowNum).val(totalAmount);
- });
-
- // validate rows
- validateRow();
-
- //calculate the actual total for the batch
- calculateActualTotal();
-
- cj('input[id*="_total_amount"]').bind('keyup change', function () {
- calculateActualTotal();
- });
-
- if (CRM.batch.type_id == 1) {
- // hide all dates if send receipt is checked
- hideSendReceipt();
-
- // hide the receipt date if send receipt is checked
- cj('input[id*="][send_receipt]"]').change(function () {
- showHideReceipt(cj(this));
- });
-
- }
- else{
- cj('select[id^="member_option_"]').each(function () {
- if (cj(this).val() == 1) {
- cj(this).attr('disabled', true);
- }
- });
-
- // set payment info accord to membership type
- cj('select[id*="_membership_type_0"]').change(function () {
- setPaymentBlock(cj(this), null);
- });
-
- cj('select[id*="_membership_type_1"]').change(function () {
- setPaymentBlock(cj(this), cj(this).val());
- });
-
- }
-
- // line breaks between radio buttons and checkboxes
- cj('input.form-radio').next().after('<br />');
- cj('input.form-checkbox').next().after('<br />');
-
- //set the focus on first element
- cj('#primary_contact_1').focus();
-
-});
-
-
-function updateContactInfo(blockNo, prefix) {
- var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo + ']"]';
- var contactId = cj(contactHiddenElement).val();
-
- var profileFields = CRM.contact.fieldmap;
-
- CRM.api('Contact', 'get', {
- 'sequential': '1',
- 'contact_id': contactId,
- 'return': CRM.contact.return },
- { success: function (data) {
- cj.each(data.values[0], function (key, value) {
- // set the values
- var actualFldName = profileFields[key];
- if (key == 'country' || key == 'state_province') {
- idFldName = key + '_id';
- value = data.values[0][idFldName];
- }
- setFieldValue(actualFldName, value, blockNo)
- });
-
- // for membership batch entry based on contact we need to enable / disable
- // add membership select
- if(CRM.batch.type_id == 2) {
- CRM.api('Membership', 'get', {
- 'sequential': '1',
- 'contact_id': contactId,
- },
- { success: function (data) {
- if (data.count > 0) {
- //get the information on membership type
- var membershipTypeId = data.values[0].membership_type_id;
- var membershipJoinDate = data.values[0].join_date;
- CRM.api('MembershipType', 'get', {
- 'sequential': '1',
- 'id': membershipTypeId
- },
- { success: function (data) {
- var memTypeContactId = data.values[0].member_of_contact_id;
- cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
- cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
- cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
- setDateFieldValue('join_date', membershipJoinDate, blockNo)
- }
- });
- }
- }
- });
- }
- }
- });
-}
-
-</script>
-{/literal}
{*include batch copy js js file*}
{include file="CRM/common/batchCopy.tpl"}