From: eileen Date: Sun, 4 Aug 2013 10:18:57 +0000 (+1200) Subject: CRM-13148 preliminary cleanup - move rest of js out of tpl X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5b1666f719104eff3ee4da634a9992711f7d19b1;p=civicrm-core.git CRM-13148 preliminary cleanup - move rest of js out of tpl --- diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 48616eda60..1454e2ab75 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -207,8 +207,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { 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); @@ -222,7 +221,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { 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. diff --git a/templates/CRM/Batch/Form/Entry.js b/templates/CRM/Batch/Form/Entry.js index 0558e32992..6268ea446b 100644 --- a/templates/CRM/Batch/Form/Entry.js +++ b/templates/CRM/Batch/Form/Entry.js @@ -1,4 +1,125 @@ -//@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('
'); + cj('input.form-checkbox').next().after('
'); + + //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'); diff --git a/templates/CRM/Batch/Form/Entry.tpl b/templates/CRM/Batch/Form/Entry.tpl index ca3a088c6c..b8ce7f0127 100644 --- a/templates/CRM/Batch/Form/Entry.tpl +++ b/templates/CRM/Batch/Form/Entry.tpl @@ -101,130 +101,6 @@
{if $fields}{$form._qf_Batch_refresh.html}{/if}   {$form.buttons.html}
-{literal} - -{/literal} {*include batch copy js js file*} {include file="CRM/common/batchCopy.tpl"}