From 8099bfee795744fab272171d34b05d69da0e139e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 26 Mar 2015 14:17:37 -0400 Subject: [PATCH] CRM-16155 - Use enityRef for mailing campaigns widget --- CRM/Mailing/Info.php | 13 ++++------ js/angular-crm-ui.js | 41 ++++++++++++++++++++++++++++++++ partials/crmMailing/summary.html | 12 ++++------ partials/crmMailingAB/setup.html | 12 ++++------ 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/CRM/Mailing/Info.php b/CRM/Mailing/Info.php index 14e9ccee7a..ece34db0cb 100644 --- a/CRM/Mailing/Info.php +++ b/CRM/Mailing/Info.php @@ -92,6 +92,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { ), ); + $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); @@ -105,18 +106,14 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { 'options' => array( 'limit' => 500, 'sort' => 'is_archived asc, scheduled_date desc', - ) + ), )); // Generic params $params = array( 'options' => array('limit' => 0), 'sequential' => 1, ); - - $campNames = civicrm_api3('Campaign', 'get', $params + array( - 'is_active' => 1, - 'return' => 'title', - )); + $groupNames = civicrm_api3('Group', 'get', $params + array( 'is_active' => 1, 'return' => array('title', 'visibility', 'group_type', 'is_hidden'), @@ -142,7 +139,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { $mailGrp = civicrm_api3('MailingGroup', 'get', $params); $mailTokens = civicrm_api3('Mailing', 'gettokens', array( 'entity' => array('contact', 'mailing'), - 'sequential' => 1 + 'sequential' => 1, )); $fromAddress = civicrm_api3('OptionValue', 'get', $params + array( 'option_group_id' => "from_email_address", @@ -151,7 +148,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { ->addSetting(array( 'crmMailing' => array( 'civiMails' => $civiMails['values'], - 'campNames' => $campNames['values'], + 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), 'groupNames' => $groupNames['values'], 'headerfooterList' => $headerfooterList['values'], 'mesTemplate' => $mesTemplate['values'], diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index f055ca6c7d..3e821bb7e5 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -631,6 +631,47 @@ }; }) + // Render a crmEntityRef widget + // usage: + .directive('crmEntityref', function ($parse, $timeout) { + return { + require: '?ngModel', + scope: { + crmEntityref: '=' + }, + link: function (scope, element, attrs, ngModel) { + // In cases where UI initiates update, there may be an extra + // call to refreshUI, but it doesn't create a cycle. + + ngModel.$render = function () { + $timeout(function () { + // ex: msg_template_id adds new item then selects it; use $timeout to ensure that + // new item is added before selection is made + element.select2('val', ngModel.$viewValue); + }); + }; + function refreshModel() { + var oldValue = ngModel.$viewValue, newValue = element.select2('val'); + if (oldValue != newValue) { + scope.$parent.$apply(function () { + ngModel.$setViewValue(newValue); + }); + } + } + + function init() { + // TODO watch options + // TODO can we infer "entity" from model? + element.crmEntityRef(scope.crmEntityref || {}); + element.on('change', refreshModel); + $timeout(ngModel.$render); + } + + init(); + } + }; + }) + // example
...content...
// WISHLIST: use a full Angular component instead of an incomplete jQuery wrapper .directive('crmUiTab', function($parse) { diff --git a/partials/crmMailing/summary.html b/partials/crmMailing/summary.html index d843e7840b..6050e448a2 100644 --- a/partials/crmMailing/summary.html +++ b/partials/crmMailing/summary.html @@ -17,17 +17,13 @@ FIXME: Don't hardcode table-based layout! name="mailingName" /> -
- - - + />
diff --git a/partials/crmMailingAB/setup.html b/partials/crmMailingAB/setup.html index ba5d83a775..bed1989d90 100644 --- a/partials/crmMailingAB/setup.html +++ b/partials/crmMailingAB/setup.html @@ -12,18 +12,14 @@ placeholder="A/B Test Name" required/> -
- + />
-- 2.25.1