CRM-13863 - Soft credit js - move back to a template
authorColeman Watts <coleman@civicrm.org>
Sat, 25 Jan 2014 07:06:51 +0000 (23:06 -0800)
committerColeman Watts <coleman@civicrm.org>
Sat, 25 Jan 2014 07:06:51 +0000 (23:06 -0800)
CRM/Contribute/Form/Contribution.php
templates/CRM/Contribute/Form/SoftCredit.js [deleted file]
templates/CRM/Contribute/Form/SoftCredit.tpl

index 4db4bdea08db1fbd8a89d6a97e4f32d39c9bc686..3350b78bbb388a248d6a862f40233fac0bb021d3 100644 (file)
@@ -163,9 +163,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     $config = CRM_Core_Config::singleton();
-    $resources = CRM_Core_Resources::singleton();
-    $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js');
-    $resources->addSetting(array('monetaryThousandSeparator' => $config->monetaryThousandSeparator));
 
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
 
diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js
deleted file mode 100644 (file)
index b8159a4..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// http://civicrm.org/licensing
-cj(function($) {
-  $('#showPCP, #showSoftCredit').click(function(){
-    return showHideSoftCreditAndPCP();
-  });
-
-  function showHideSoftCreditAndPCP() {
-    $('.crm-contribution-pcp-block').toggle();
-    $('.crm-contribution-pcp-block-link').toggle();
-    $('.crm-contribution-form-block-soft_credit_to').toggle();
-    return false;
-  }
-
-  $('#addMoreSoftCredit').live('click', function () {
-    $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement');
-    if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
-      $('#addMoreSoftCredit').hide();
-    }
-    return false;
-  });
-
-  var pcpURL = CRM.url('civicrm/ajax/rest',
-    'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
-  $('#pcp_made_through').autocomplete(pcpURL,
-    { width : 360, selectFirst : false, matchContains: true
-  }).result( function(event, data, formatted) {
-      $("#pcp_made_through_id" ).val( data[1]);
-    });
-
-  var rowCnt = 1;
-  $('input[name^="soft_credit_contact_select_id["]').each(function(){
-    if ($(this).val()){
-      var dataUrl = CRM.url('civicrm/ajax/rest',
-        'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&id=' + $(this).val());
-      $.ajax({
-        url     : dataUrl,
-        async   : false,
-        success : function(html){
-          htmlText = html.split( '|' , 2);
-          $('#soft_credit_contact_' + rowCnt).val(htmlText[0]);
-          rowCnt++;
-        }
-      });
-    }
-  });
-
-  $('.crm-soft-credit-block tr span').each(function () {
-    if ($(this).hasClass('crm-error')) {
-      $(this).parents('tr').show();
-    }
-  });
-
-  $('.delete-link').click(function(){
-    var row = $(this).attr('row-no');
-    $('#soft-credit-row-' + row).hide().find('input').val('');
-    $('input[name="soft_credit_contact_select_id['+row+']"]').val('');
-    return false;
-  });
-
-  $('input[name^="soft_credit_contact["]').change(function(){
-    var rowNum = $(this).prop('id').replace('soft_credit_contact_','');
-    var totalAmount = $('#total_amount').val();
-    //assign total amount as default soft credit amount
-    $('#soft_credit_amount_'+ rowNum).val(totalAmount);
-    var thousandMarker = CRM.monetaryThousandSeparator;
-    $('#soft_credit_type_'+ rowNum).val($('#sct_default_id').val());
-    totalAmount = Number(totalAmount.replace(thousandMarker,''));
-    if (rowNum > 1) {
-      var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,''));
-      if (scAmount < totalAmount) {
-     //if user enters less than the total amount and adds another soft credit row, 
-     //the soft credit amount default will be left empty 
-        $('#soft_credit_amount_'+ rowNum).val(''); 
-      }
-    }
-  });
-
-});
index 71bec1c2b4509beb1af412182ce6f61b05352bb3..91eb2b773058398a9ff26d4097c08cf5ea154283 100644 (file)
   </tr>
 </table>
 {/if}
+{literal}
+<script type="text/javascript">
+  cj(function($) {
+    $('#showPCP, #showSoftCredit').click(function(){
+      return showHideSoftCreditAndPCP();
+    });
+
+    function showHideSoftCreditAndPCP() {
+      $('.crm-contribution-pcp-block').toggle();
+      $('.crm-contribution-pcp-block-link').toggle();
+      $('.crm-contribution-form-block-soft_credit_to').toggle();
+      return false;
+    }
+
+    $('#addMoreSoftCredit').on('click', function () {
+      $('.crm-contribution-form-block-soft_credit_to tr.hiddenElement').filter(':first').show().removeClass('hiddenElement');
+      if ($('.crm-soft-credit-block tr.hiddenElement').length < 1) {
+        $('#addMoreSoftCredit').hide();
+      }
+      return false;
+    });
+
+    var pcpURL = CRM.url('civicrm/ajax/rest',
+      'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
+    $('#pcp_made_through').autocomplete(pcpURL,
+      { width : 360, selectFirst : false, matchContains: true
+      }).result( function(event, data, formatted) {
+        $("#pcp_made_through_id" ).val( data[1]);
+      });
+
+    var rowCnt = 1;
+    $('input[name^="soft_credit_contact_select_id["]').each(function(){
+      if ($(this).val()){
+        var dataUrl = CRM.url('civicrm/ajax/rest',
+          'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&id=' + $(this).val());
+        $.ajax({
+          url     : dataUrl,
+          async   : false,
+          success : function(html){
+            htmlText = html.split( '|' , 2);
+            $('#soft_credit_contact_' + rowCnt).val(htmlText[0]);
+            rowCnt++;
+          }
+        });
+      }
+    });
+
+    $('.crm-soft-credit-block tr span').each(function () {
+      if ($(this).hasClass('crm-error')) {
+        $(this).parents('tr').show();
+      }
+    });
+
+    $('.delete-link').click(function(){
+      var row = $(this).attr('row-no');
+      $('#soft-credit-row-' + row).hide().find('input').val('');
+      $('input[name="soft_credit_contact_select_id['+row+']"]').val('');
+      return false;
+    });
+
+    $('input[name^="soft_credit_contact["]').change(function(){
+      var rowNum = $(this).prop('id').replace('soft_credit_contact_','');
+      var totalAmount = $('#total_amount').val();
+      //assign total amount as default soft credit amount
+      $('#soft_credit_amount_'+ rowNum).val(totalAmount);
+      var thousandMarker = {/literal}{$config->monetaryThousandSeparator|json_encode}{literal};
+      $('#soft_credit_type_'+ rowNum).val($('#sct_default_id').val());
+      totalAmount = Number(totalAmount.replace(thousandMarker,''));
+      if (rowNum > 1) {
+        var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,''));
+        if (scAmount < totalAmount) {
+          //if user enters less than the total amount and adds another soft credit row,
+          //the soft credit amount default will be left empty
+          $('#soft_credit_amount_'+ rowNum).val('');
+        }
+      }
+    });
+
+  });
+</script>
+{/literal}