-//@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);
+ //assign soft credit type default value if any
+ cj('#field_'+rowNum+'_soft_credit_type').val(cj('#sct_default_id').val());
+ });
+
+ // 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).prop('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 + '"]').prop('disabled', false).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');