CRM-15278 - Fix email signature on itinial form load
authorColeman Watts <coleman@civicrm.org>
Wed, 17 Sep 2014 04:08:22 +0000 (00:08 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 17 Sep 2014 04:08:22 +0000 (00:08 -0400)
CRM/Contact/Form/Task/EmailCommon.php
templates/CRM/Mailing/Form/InsertTokens.tpl

index cfb2f051ec780f928d8778876729e72d0569f1b6..91d71388e82426f5bd88b11d1035b806e2380c83 100644 (file)
@@ -46,7 +46,7 @@ class CRM_Contact_Form_Task_EmailCommon {
   public $_toContactEmails = array();
 
   /**
-   * @param $form
+   * @param CRM_Core_Form $form
    */
   static function preProcessFromAddress(&$form) {
     $form->_single = FALSE;
@@ -116,6 +116,17 @@ class CRM_Contact_Form_Task_EmailCommon {
     }
 
     $form->_fromEmails = CRM_Utils_Array::crmArrayMerge($emails, $domainEmails);
+
+    // Add signature
+    $defaultEmail = civicrm_api3('email', 'getsingle', array('id' => key($form->_fromEmails)));
+    $defaults = array();
+    if (!empty($defaultEmail['signature_html'])) {
+      $defaults['html_message'] = '<br/><br/>--' . $defaultEmail['signature_html'];
+    }
+    if (!empty($defaultEmail['signature_text'])) {
+      $defaults['text_message'] = "\n\n--\n" . $defaultEmail['signature_text'];
+    }
+    $form->setDefaults($defaults);
   }
 
   /**
index 9e6129463cb033e9d0ff42aef4467cf682ae634f..f7a3b68d2b244afded631ae1cebbf0090aa60df9 100644 (file)
@@ -433,14 +433,7 @@ CRM.$(function($) {
       }, 'json');
     }
   }
-  if (!$().find('div.crm-error').text()) {
-    $(window).load(function () {
-      setSignature();
-    });
-  }
-  $("#fromEmailAddress").change( function( ) {
-    setSignature( );
-  });
+  $("#fromEmailAddress", form).change(setSignature);
 });
 
 </script>