From 0388b3fe88d4c245bff191a39c1b1456933037db Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 19 Feb 2015 19:50:31 -0800 Subject: [PATCH] CRM-15801 - crmMailing - Special formatting for recipients based on searches. --- css/angular-crmMailing.css | 3 ++ js/angular-crmMailing/directives.js | 44 +++++++++++++++++-- partials/crmMailing/directive/recipients.html | 3 ++ partials/crmMailing/recipients.html | 1 + 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/css/angular-crmMailing.css b/css/angular-crmMailing.css index d5536a58e2..dd24aec8db 100644 --- a/css/angular-crmMailing.css +++ b/css/angular-crmMailing.css @@ -26,6 +26,9 @@ span.crmMailing-exclude { color: #600; text-decoration: line-through; } +span.crmMailing-mandatory { + color: #866304; +} .crmMailing input[name=preview_test_email], .crmMailing-preview select[name=preview_test_group] { width: 80%; diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index 4767e3ccfc..340ea4a868 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -225,13 +225,14 @@ // example: // FIXME: participate in ngModel's validation cycle - angular.module('crmMailing').directive('crmMailingRecipients', function () { + angular.module('crmMailing').directive('crmMailingRecipients', function (crmUiAlert) { return { restrict: 'AE', require: 'ngModel', scope: { crmAvailGroups: '@', // available groups crmAvailMailings: '@', // available mailings + crmMandatoryGroups: '@', // hard-coded/mandatory groups ngRequired: '@' }, templateUrl: '~/crmMailing/directive/recipients.html', @@ -239,8 +240,9 @@ scope.recips = ngModel.$viewValue; scope.groups = scope.$parent.$eval(attrs.crmAvailGroups); scope.mailings = scope.$parent.$eval(attrs.crmAvailMailings); + refreshMandatory(); - scope.ts = CRM.ts(null); + var ts = scope.ts = CRM.ts(null); /// Convert MySQL date ("yyyy-mm-dd hh:mm:ss") to JS date object scope.parseDate = function (date) { @@ -285,11 +287,31 @@ return r; } + function refreshMandatory() { + if (ngModel.$viewValue.groups) { + scope.mandatoryGroups = _.filter(scope.$parent.$eval(attrs.crmMandatoryGroups), function(grp) { + return _.contains(ngModel.$viewValue.groups.include, parseInt(grp.id)); + }); + scope.mandatoryIds = _.map(_.pluck(scope.$parent.$eval(attrs.crmMandatoryGroups), 'id'), function(n) { + return parseInt(n); + }); + } + else { + scope.mandatoryGroups = []; + scope.mandatoryIds = []; + } + } + + function isMandatory(grpId) { + return _.contains(scope.mandatoryIds, parseInt(grpId)); + } + var refreshUI = ngModel.$render = function refresuhUI() { scope.recips = ngModel.$viewValue; if (ngModel.$viewValue) { $(element).select2('val', convertMailingToValues(ngModel.$viewValue)); validate(); + refreshMandatory(); } }; @@ -302,6 +324,9 @@ var option = convertValueToObj(item.id); var icon = (option.entity_type === 'civicrm_mailing') ? 'EnvelopeIn.gif' : 'group.png'; var spanClass = (option.mode == 'exclude') ? 'crmMailing-exclude' : 'crmMailing-include'; + if (option.entity_type != 'civicrm_mailing' && isMandatory(option.entity_id)) { + spanClass = 'crmMailing-mandatory'; + } return " " + item.text + ""; } @@ -344,6 +369,14 @@ $(element).on("select2-removing", function (e) { var option = convertValueToObj(e.val); var typeKey = option.entity_type == 'civicrm_mailing' ? 'mailings' : 'groups'; + if (typeKey == 'groups' && isMandatory(option.entity_id)) { + crmUiAlert({ + text: ts('This mailing was generated based on search results. The search results cannot be removed.'), + title: ts('Required') + }); + e.preventDefault(); + return; + } scope.$parent.$apply(function () { arrayRemove(ngModel.$viewValue[typeKey][option.mode], option.entity_id); }); @@ -357,12 +390,15 @@ scope.$watchCollection("recips.mailings.exclude", refreshUI); setTimeout(refreshUI, 50); - scope.$watchCollection(attrs.crmAvailGroups, function(){ + scope.$watchCollection(attrs.crmAvailGroups, function() { scope.groups = scope.$parent.$eval(attrs.crmAvailGroups); }); - scope.$watchCollection(attrs.crmAvailMailings, function(){ + scope.$watchCollection(attrs.crmAvailMailings, function() { scope.mailings = scope.$parent.$eval(attrs.crmAvailMailings); }); + scope.$watchCollection(attrs.crmMandatoryGroups, function() { + refreshMandatory(); + }); } }; }); diff --git a/partials/crmMailing/directive/recipients.html b/partials/crmMailing/directive/recipients.html index bc12d7ae06..9d84e93931 100644 --- a/partials/crmMailing/directive/recipients.html +++ b/partials/crmMailing/directive/recipients.html @@ -2,6 +2,9 @@ Directive: crmMailingRecipients -->