Dynamically load the content of Message templates in CiviMail when selected rather...
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 7 Aug 2015 00:27:40 +0000 (00:27 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 7 Aug 2015 00:27:40 +0000 (00:27 +0000)
CRM/Mailing/Info.php
ang/crmMailing/services.js

index 2bed417cb922f85de163ef06fa749257311f1ec8..41bc8c8baa0466b97ab9191d02e37b903c488333 100644 (file)
@@ -131,11 +131,10 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info {
       'contact_id' => $contactID,
     ));
 
-    // FIXME: Loading the contents of every template into the dom does not scale well
     $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array(
       'sequential' => 1,
       'is_active' => 1,
-      'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"),
+      'return' => array("id", "msg_title"),
       'workflow_id' => array('IS NULL' => ""),
     ));
     $mailTokens = civicrm_api3('Mailing', 'gettokens', array(
index 6a155c93b05b21d270ff1a6aa313b1a2f82a5b7f..af30fb845eac7081e51bd1e596c1bfa4eb0e7313 100644 (file)
     window.tpls = tpls;
     var lastModifiedTpl = null;
     return {
+      // Get a template
+      // @param id MessageTemplate id  (per APIv3)
       // @return Promise MessageTemplate (per APIv3)
       get: function get(id) {
-        id = '' + id; // parseInt(id);
         var dfr = $q.defer();
-        var tpl = _.where(tpls, {id: id});
-        if (id && tpl && tpl[0]) {
-          dfr.resolve(tpl[0]);
-        }
-        else {
-          dfr.reject(id);
-        }
+        var tpl = CRM.api3('MessageTemplate', 'get', {
+          "sequential": 1,
+           "return": "id,msg_subject,msg_html,msg_title,msg_text",
+           "id": id
+        }).done(function(result) {
+          if (result.is_error) {
+            dfr.reject(id); 
+          }
+          else {
+            dfr.resolve(result['values'][0]);
+          }
+        });
         return dfr.promise;
       },
       // Save a template