var crmMailing2 = angular.module('crmMailing2');
- crmMailing2.directive('crmMailingReviewBool', function(){
+ crmMailing2.directive('crmMailingReviewBool', function () {
return {
scope: {
crmOn: '@',
crmTitle: '@'
},
template: '<span ng-class="spanClasses"><span class="icon" ng-class="iconClasses"></span>{{crmTitle}} </span>',
- link: function(scope, element, attrs){
+ link: function (scope, element, attrs) {
function refresh() {
if (scope.$parent.$eval(attrs.crmOn)) {
scope.spanClasses = {'crmMailing2-active': true};
scope.iconClasses = {'ui-icon-check': true};
- } else {
+ }
+ else {
scope.spanClasses = {'crmMailing2-inactive': true};
scope.iconClasses = {'ui-icon-close': true};
}
scope.crmTitle = scope.$parent.$eval(attrs.crmTitle);
}
+
refresh();
scope.$parent.$watch(attrs.crmOn, refresh);
scope.$parent.$watch(attrs.crmTitle, refresh);
/// Convert MySQL date ("yyyy-mm-dd hh:mm:ss") to JS date object
scope.parseDate = function (date) {
- if (!angular.isString(date))
+ if (!angular.isString(date)) {
return date;
+ }
var p = date.split(/[\- :]/);
return new Date(p[0], p[1], p[2], p[3], p[4], p[5]);
};
if (option.mode == 'exclude') {
scope.mailing[typeKey].exclude.push(option.entity_id);
arrayRemove(scope.mailing[typeKey].include, option.entity_id);
- } else {
+ }
+ else {
scope.mailing[typeKey].include.push(option.entity_id);
arrayRemove(scope.mailing[typeKey].exclude, option.entity_id);
}
$(element).on("select2-removing", function (e) {
var option = convertValueToObj(e.val);
var typeKey = option.entity_type == 'civicrm_mailing' ? 'mailings' : 'groups';
- scope.$parent.$apply(function(){
+ scope.$parent.$apply(function () {
arrayRemove(scope.mailing[typeKey][option.mode], option.entity_id);
});
e.preventDefault();
// so the UI must do some adaptation. The crmFromAddresses provides a richer way to slice/dice
// the available "From:" addrs. Records are like the underlying OptionValues -- but add "email"
// and "author".
- crmMailing2.factory('crmFromAddresses', function($q, crmApi) {
+ crmMailing2.factory('crmFromAddresses', function ($q, crmApi) {
var emailRegex = /^"(.*)" \<([^@\>]*@[^@\>]*)\>$/;
- var addrs = _.map(CRM.crmMailing.fromAddress, function(addr){
+ var addrs = _.map(CRM.crmMailing.fromAddress, function (addr) {
var match = emailRegex.exec(addr.label);
return _.extend({}, addr, {
email: match ? match[2] : '(INVALID)',
author: match ? match[1] : '(INVALID)'
});
});
+
function first(array) {
return (array.length == 0) ? null : array[0];
}
},
getByAuthorEmail: function getByAuthorEmail(author, email, autocreate) {
var result = null;
- _.each(addrs, function(addr){
+ _.each(addrs, function (addr) {
if (addr.author == author && addr.email == email) {
result = addr;
}
getByEmail: function getByEmail(email) {
return first(_.where(addrs, {email: email}));
},
- getByLabel: function(label) {
+ getByLabel: function (label) {
return first(_.where(addrs, {label: label}));
},
getDefault: function getDefault() {
};
});
- crmMailing2.factory('crmMsgTemplates', function($q, crmApi) {
- var tpls = _.map(CRM.crmMailing.mesTemplate, function(tpl){
+ crmMailing2.factory('crmMsgTemplates', function ($q, crmApi) {
+ var tpls = _.map(CRM.crmMailing.mesTemplate, function (tpl) {
return _.extend({}, tpl, {
//id: tpl parseInt(tpl.id)
});
return {
// @return Promise MessageTemplate (per APIv3)
get: function get(id) {
- id = ''+id; // parseInt(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 {
+ }
+ else {
dfr.reject(id);
}
return dfr.promise;
// Save a template
// @param tpl MessageTemplate (per APIv3) For new templates, omit "id"
// @return Promise MessageTemplate (per APIv3)
- save: function(tpl) {
- return crmApi('MessageTemplate', 'create', tpl).then(function(response){
+ save: function (tpl) {
+ return crmApi('MessageTemplate', 'create', tpl).then(function (response) {
if (!tpl.id) {
- tpl.id = ''+response.id; //parseInt(response.id);
+ tpl.id = '' + response.id; //parseInt(response.id);
tpls.push(tpl);
}
lastModifiedTpl = tpl
});
},
// @return Object MessageTemplate (per APIv3)
- getLastModifiedTpl: function() {
+ getLastModifiedTpl: function () {
return lastModifiedTpl;
},
getAll: function getAll() {
});
// The crmMailingMgr service provides business logic for loading, saving, previewing, etc
- crmMailing2.factory('crmMailingMgr', function($q, crmApi, crmFromAddresses) {
+ crmMailing2.factory('crmMailingMgr', function ($q, crmApi, crmFromAddresses) {
var pickDefaultMailComponent = function pickDefaultMailComponent(type) {
var mcs = _.where(CRM.crmMailing.headerfooterList, {
- component_type:type,
+ component_type: type,
is_default: "1"
});
return (mcs.length >= 1) ? mcs[0].id : null;
},
// @return Promise Mailing (per APIv3)
get: function get(id) {
- return crmApi('Mailing', 'getsingle', {id: id}).then(function(mailing){
- return crmApi('MailingGroup', 'get', {mailing_id: id}).then(function(groupResult){
+ return crmApi('Mailing', 'getsingle', {id: id}).then(function (mailing) {
+ return crmApi('MailingGroup', 'get', {mailing_id: id}).then(function (groupResult) {
mailing.groups = {include: [], exclude: []};
mailing.mailings = {include: [], exclude: []};
- _.each(groupResult.values, function(mailingGroup) {
+ _.each(groupResult.values, function (mailingGroup) {
var bucket = (mailingGroup.entity_table == 'civicrm_group') ? 'groups' : 'mailings';
var entityId = parseInt(mailingGroup.entity_id);
mailing[bucket][mailingGroup.group_type].push(entityId);
// @param mailing Object (per APIv3)
// @return Promise
- 'delete': function(mailing) {
+ 'delete': function (mailing) {
if (mailing.id) {
return crmApi('Mailing', 'delete', {id: mailing.id});
- } else {
+ }
+ else {
var d = $q.defer();
d.resolve();
return d.promise;
// @return Promise an object with "subject", "body_text", "body_html"
preview: function preview(mailing) {
var params = _.extend({}, mailing, {
- options: {force_rollback: 1},
+ options: {force_rollback: 1},
'api.Mailing.preview': {
id: '$value.id'
}
});
- return crmApi('Mailing', 'create', params).then(function(result){
+ return crmApi('Mailing', 'create', params).then(function (result) {
// changes rolled back, so we don't care about updating mailing
return result.values[result.id]['api.Mailing.preview'].values;
});
// To get list of recipients, we tentatively save the mailing and
// get the resulting recipients -- then rollback any changes.
var params = _.extend({}, mailing, {
- options: {force_rollback: 1},
+ options: {force_rollback: 1},
'api.mailing_job.create': 1, // note: exact match to API default
'api.MailingRecipients.get': {
mailing_id: '$value.id',
'api.email.getvalue': {'return': 'email'}
}
});
- return crmApi('Mailing', 'create', params).then(function(recipResult){
+ return crmApi('Mailing', 'create', params).then(function (recipResult) {
// changes rolled back, so we don't care about updating mailing
return recipResult.values[recipResult.id]['api.MailingRecipients.get'].values;
});
// Save a (draft) mailing
// @param mailing Object (per APIv3)
// @return Promise
- save: function(mailing) {
+ save: function (mailing) {
var params = _.extend({}, mailing, {
'api.mailing_job.create': 0 // note: exact match to API default
});
// is therefore not allowed. Remove this after fixing Mailing.create's contract.
delete params.scheduled_date;
- return crmApi('Mailing', 'create', params).then(function(result){
- if (result.id && !mailing.id) mailing.id = result.id; // no rollback, so update mailing.id
+ return crmApi('Mailing', 'create', params).then(function (result) {
+ if (result.id && !mailing.id) {
+ mailing.id = result.id;
+ } // no rollback, so update mailing.id
// Perhaps we should reload mailing based on result?
return result.values[result.id];
});
'api.mailing_job.create': 0 // note: exact match to API default
});
return crmApi('Mailing', 'create', params).then(function (result) {
- if (result.id && !mailing.id) mailing.id = result.id; // no rollback, so update mailing.id
+ if (result.id && !mailing.id) {
+ mailing.id = result.id;
+ } // no rollback, so update mailing.id
_.extend(mailing, changes); // Perhaps we should reload mailing based on result?
return result.values[result.id];
});
// @param testEmail string
// @param testGroup int (id#)
// @return Promise for a list of delivery reports
- sendTest: function(mailing, testEmail, testGroup) {
+ sendTest: function (mailing, testEmail, testGroup) {
var params = _.extend({}, mailing, {
// options: {force_rollback: 1}, // Test mailings include tracking features, so the mailing must be persistent
'api.Mailing.send_test': {
// is therefore not allowed. Remove this after fixing Mailing.create's contract.
delete params.scheduled_date;
- return crmApi('Mailing', 'create', params).then(function(result){
- if (result.id && !mailing.id) mailing.id = result.id; // no rollback, so update mailing.id
+ return crmApi('Mailing', 'create', params).then(function (result) {
+ if (result.id && !mailing.id) {
+ mailing.id = result.id;
+ } // no rollback, so update mailing.id
return result.values[result.id]['api.Mailing.send_test'].values;
});
}
return CRM.resourceUrls['civicrm'] + '/partials/crmMailing2/' + relPath;
};
- var crmMailing2 = angular.module('crmMailing2', ['crmUtil', 'crmAttachment', 'ngRoute', 'ui.utils', 'crmUi', 'dialogService']); // TODO ngSanitize, unsavedChanges
+ var crmMailing2 = angular.module('crmMailing2', [
+ 'crmUtil', 'crmAttachment', 'ngRoute', 'ui.utils', 'crmUi', 'dialogService'
+ ]); // TODO ngSanitize, unsavedChanges
// Time to wait before triggering AJAX update to recipients list
var RECIPIENTS_DEBOUNCE_MS = 100;
var RECIPIENTS_PREVIEW_LIMIT = 10000;
- crmMailing2.config(['$routeProvider',
+ crmMailing2.config([
+ '$routeProvider',
function ($routeProvider) {
$routeProvider.when('/mailing2', {
template: '<div></div>',
templateUrl: partialUrl('edit.html'),
controller: 'EditMailingCtrl',
resolve: {
- selectedMail: function selectedMail($route, crmMailingMgr) { return crmMailingMgr.getOrCreate($route.current.params.id); }
+ selectedMail: function selectedMail($route, crmMailingMgr) {
+ return crmMailingMgr.getOrCreate($route.current.params.id);
+ }
}
});
$routeProvider.when('/mailing2/:id/unified', {
templateUrl: partialUrl('edit-unified.html'),
controller: 'EditMailingCtrl',
resolve: {
- selectedMail: function selectedMail($route, crmMailingMgr) { return crmMailingMgr.getOrCreate($route.current.params.id); }
+ selectedMail: function selectedMail($route, crmMailingMgr) {
+ return crmMailingMgr.getOrCreate($route.current.params.id);
+ }
}
});
$routeProvider.when('/mailing2/:id/unified2', {
templateUrl: partialUrl('edit-unified2.html'),
controller: 'EditMailingCtrl',
resolve: {
- selectedMail: function selectedMail($route, crmMailingMgr) { return crmMailingMgr.getOrCreate($route.current.params.id); }
+ selectedMail: function selectedMail($route, crmMailingMgr) {
+ return crmMailingMgr.getOrCreate($route.current.params.id);
+ }
}
});
$routeProvider.when('/mailing2/:id/wizard', {
templateUrl: partialUrl('edit-wizard.html'),
controller: 'EditMailingCtrl',
resolve: {
- selectedMail: function selectedMail($route, crmMailingMgr) { return crmMailingMgr.getOrCreate($route.current.params.id); }
+ selectedMail: function selectedMail($route, crmMailingMgr) {
+ return crmMailingMgr.getOrCreate($route.current.params.id);
+ }
}
});
}
crmMailing2.controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmFromAddresses, crmStatus, CrmAttachments) {
$scope.mailing = selectedMail;
- $scope.attachments = new CrmAttachments(function() {
+ $scope.attachments = new CrmAttachments(function () {
return {entity_table: 'civicrm_mailing', entity_id: $scope.mailing.id};
});
$scope.crmMailingConst = CRM.crmMailing;
};
// Transition URL "/mailing2/new" => "/mailing2/123" as soon as ID is known
- $scope.$watch('mailing.id', function(newValue, oldValue) {
+ $scope.$watch('mailing.id', function (newValue, oldValue) {
if (newValue && newValue != oldValue) {
var parts = $location.path().split('/'); // e.g. "/mailing2/new" or "/mailing2/123/wizard"
parts[2] = newValue;
$scope.fromPlaceholder = {
label: crmFromAddresses.getByAuthorEmail($scope.mailing.from_name, $scope.mailing.from_email, true).label
};
- $scope.$watch('fromPlaceholder.label', function(newValue){
+ $scope.$watch('fromPlaceholder.label', function (newValue) {
var addr = crmFromAddresses.getByLabel(newValue);
$scope.mailing.from_name = addr.author;
$scope.mailing.from_email = addr.email;
$scope.recipients = null;
$scope.getRecipientsEstimate = function () {
var ts = $scope.ts;
- if ($scope.recipients == null)
+ if ($scope.recipients == null) {
return ts('(Estimating)');
- if ($scope.recipients.length == 0)
+ }
+ if ($scope.recipients.length == 0) {
return ts('No recipients');
- if ($scope.recipients.length == 1)
+ }
+ if ($scope.recipients.length == 1) {
return ts('~1 recipient');
- if (RECIPIENTS_PREVIEW_LIMIT > 0 && $scope.recipients.length >= RECIPIENTS_PREVIEW_LIMIT)
+ }
+ if (RECIPIENTS_PREVIEW_LIMIT > 0 && $scope.recipients.length >= RECIPIENTS_PREVIEW_LIMIT) {
return ts('>%1 recipients', {1: RECIPIENTS_PREVIEW_LIMIT});
+ }
return ts('~%1 recipients', {1: $scope.recipients.length});
};
- $scope.getIncludesAsString = function() {
+ $scope.getIncludesAsString = function () {
var first = true;
var names = '';
- _.each($scope.mailing.groups.include, function(id){
- if (!first) names = names + ', ';
- var group = _.where(CRM.crmMailing.groupNames, {id: ''+id});
+ _.each($scope.mailing.groups.include, function (id) {
+ if (!first) {
+ names = names + ', ';
+ }
+ var group = _.where(CRM.crmMailing.groupNames, {id: '' + id});
names = names + group[0].title;
first = false;
});
- _.each($scope.mailing.mailings.include, function(id){
- if (!first) names = names + ', ';
- var oldMailing = _.where(CRM.crmMailing.civiMails, {id: ''+id});
+ _.each($scope.mailing.mailings.include, function (id) {
+ if (!first) {
+ names = names + ', ';
+ }
+ var oldMailing = _.where(CRM.crmMailing.civiMails, {id: '' + id});
names = names + oldMailing[0].name;
first = false;
});
return names;
};
- $scope.getExcludesAsString = function() {
+ $scope.getExcludesAsString = function () {
var first = true;
var names = '';
- _.each($scope.mailing.groups.exclude, function(id){
- if (!first) names = names + ', ';
- var group = _.where(CRM.crmMailing.groupNames, {id: ''+id});
+ _.each($scope.mailing.groups.exclude, function (id) {
+ if (!first) {
+ names = names + ', ';
+ }
+ var group = _.where(CRM.crmMailing.groupNames, {id: '' + id});
names = names + group[0].title;
first = false;
});
- _.each($scope.mailing.mailings.exclude, function(id){
- if (!first) names = names + ', ';
- var oldMailing = _.where(CRM.crmMailing.civiMails, {id: ''+id});
+ _.each($scope.mailing.mailings.exclude, function (id) {
+ if (!first) {
+ names = names + ', ';
+ }
+ var oldMailing = _.where(CRM.crmMailing.civiMails, {id: '' + id});
names = names + oldMailing[0].name;
first = false;
});
$scope.previewDialog = function previewDialog(template) {
var p = crmMailingMgr
.preview($scope.mailing)
- .then(function(content){
+ .then(function (content) {
var options = {
autoOpen: false,
modal: true,
};
dialogService.open('previewDialog', template, content, options);
});
- CRM.status({start: ts('Previewing'), success: ''}, CRM.toJqPromise(p));
+ CRM.status({start: ts('Previewing'), success: ''}, CRM.toJqPromise(p));
};
$scope.sendTestToContact = function sendTestToContact() {
$scope.sendTest($scope.mailing, $scope.attachments, $scope.testContact.email, null);
var ts = $scope.ts = CRM.ts('CiviMail');
$scope.previewComponent = function previewComponent(title, componentId) {
- var component = _.where(CRM.crmMailing.headerfooterList, {id: ""+componentId});
+ var component = _.where(CRM.crmMailing.headerfooterList, {id: "" + componentId});
if (!component || !component[0]) {
CRM.alert(ts('Invalid component ID (%1)', {
1: componentId
title: ts('Save Template')
};
return dialogService.open('saveTemplateDialog', partialUrl('dialog/saveTemplate.html'), model, options)
- .then(function(item){
+ .then(function (item) {
$parse('mailing.msg_template_id').assign($scope, item.id);
return item;
});
};
dialogService.setButtons('saveTemplateDialog', buttons);
}
+
setTimeout(scopeApply(init), 0);
});