From 3637550fc4afc6de76684ddbf9ffb0b0f6f658a9 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 7 Aug 2015 00:27:40 +0000 Subject: [PATCH] Dynamically load the content of Message templates in CiviMail when selected rather than load on inital load --- CRM/Mailing/Info.php | 3 +-- ang/crmMailing/services.js | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CRM/Mailing/Info.php b/CRM/Mailing/Info.php index 2bed417cb9..41bc8c8baa 100644 --- a/CRM/Mailing/Info.php +++ b/CRM/Mailing/Info.php @@ -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( diff --git a/ang/crmMailing/services.js b/ang/crmMailing/services.js index 6a155c93b0..af30fb845e 100644 --- a/ang/crmMailing/services.js +++ b/ang/crmMailing/services.js @@ -60,17 +60,23 @@ 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 -- 2.25.1