CRM-13148 preliminary cleanup - move rest of js out of tpl
authoreileen <eileen@fuzion.co.nz>
Sun, 4 Aug 2013 10:18:57 +0000 (22:18 +1200)
committereileen <eileen@fuzion.co.nz>
Sun, 4 Aug 2013 23:32:37 +0000 (11:32 +1200)
CRM/Batch/Form/Entry.php
templates/CRM/Batch/Form/Entry.js
templates/CRM/Batch/Form/Entry.tpl

index 48616eda607c3c417861641c041c1b9ae3c2424d..1454e2ab755e5f656484422e90f78f1977bb9c4d 100644 (file)
@@ -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.
index 0558e329924ec5efc0d016e2bf1fe9ea6f1dea80..6268ea446b56f652e4c154a6cb21a0e6a1243598 100644 (file)
@@ -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('<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');
index ca3a088c6c55e9f5b20fc11818f94834bc1a6d72..b8ce7f0127ce731f5dd9438c658ab040928af8c9 100644 (file)
   </div>
   <div class="crm-submit-buttons">{if $fields}{$form._qf_Batch_refresh.html}{/if} &nbsp; {$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"}