").dxForm( {
items : items,
readOnly : instance.readOnly,
trackChanges : false,
onFieldDataChanged : function( e ) {
/*
if( e.dataField == "scheduled" ) {
let itemOptions = e.component.itemOption( "runDate" );
itemOptions.disabled = ! e.value;
itemOptions.isRequired = ! itemOptions.disabled;
e.component.updateData( { runDate : null } )
e.component.itemOption( "runDate", itemOptions );
}
*/
if( trackChanges ) {
instance.changes.insert( `details.${e.dataField}` );
}
}
}).dxForm( "instance" );
let fieldsToGet = [ "campaignName", "emailFrom", "emailFromDisplay", "emailSubject", "useInternalContact", "includeUnsubscribe" ]; // removed "scheduled", "runDate",
if( data.gtmCampaignId ) {
fieldsToGet.push( "gtmCampaignId", "gtmCampaignName", "gtmCampaignDescription", "gtmCampaignManagerDisplay", "gtmSalesManagerDisplay", "gtmLeadType", "gtmTargetPartnerType", "gtmTerritoryName" );
}
let dataToUse = instance.getData( data, fieldsToGet )
console.log( "DataToUse");
console.log( dataToUse );
instance.detailsForm.updateData( dataToUse );
trackChanges = true;
let sv = $("
").append( instance.detailsForm.element() ).dxScrollView( { height : instance.height } );
template.append( sv );
if( data.campaignId ) {
if( data.spoofingResolved ) {
$("
").css( { "font-style" : "italic" } )
.append( "Note: Email From address will be " )
.append( $("" ).append( data.resolvedEmailFrom ).css( { color : "blue" } ) )
.append( " and Email Subject will be " )
.append( $("").append( data.resolvedEmailSubject ).css( { color : "blue" } ) )
.appendTo( template );
}
let unsubscribeNote = $("")
if( data.containsUnsubscribe ) {
unsubscribeNote.text( "This email campaign contains an unsubscribe link." );
} else {
unsubscribeNote.text( "This email campaign does not contain an unsubscribe link. You can add one from the \"Special Links\" option in the editor." );
unsubscribeNote.css( { color : "#FFB600" } );
}
template.append( unsubscribeNote );
if( data.campaignType === "CRM" && ! data.gtmCampaignId ) {
let leadWarning = $("
")
leadWarning.text( "The responses to this email will not be routed to your lead dashboard. To route to your lead dashboard, please generate this email via the Campaigns tab." );
leadWarning.css( { color : "#FFB600" } );
template.append( leadWarning );
}
}
return template;
}
EmailCampaignEditor.prototype.getDetailsTabData = function() {
let instance = this;
let d = $.Deferred();
let validationResult = instance.detailsForm.validate();
if( validationResult.status === "pending" ) {
validationResult.complete.then( function( r ) {
if( r.status === "valid" ) {
d.resolve( instance.detailsForm.option( "formData" ) );
} else {
d.resolve( null );
}
})
} else {
if( validationResult.isValid ) {
d.resolve( instance.detailsForm.option( "formData" ) );
} else {
d.resolve( null );
}
}
return d;
}
EmailCampaignEditor.prototype.defaultsTabTemplate = function( data ) {
let instance = this;
let template = $("
").css( "padding", "10px 10px 10px 10px" );
let items = [];
items.push( {
dataField : "message1Default", label : { text : "Message 1 Default" }, editorType : "dxTextArea", editorOptions : { height: "5em", maxLength : 1000 }
},{
dataField : "message2Default", label : { text : "Message 2 Default" }, editorType : "dxTextArea", editorOptions : { height : "5em", maxLength : 1000 }
}
)
let trackChanges = true;
instance.defaultsForm = $("
").dxForm( {
formData : instance.getData( data, [ "message1Default", "message2Default" ] ),
items : items,
readOnly : instance.readOnly,
onFieldDataChanged : function( e ) {
if( trackChanges ) {
instance.changes.insert( `defaults.${e.dataField}` );
}
}
}).dxForm( "instance" );
let sv = $("
").append( instance.defaultsForm.element() ).dxScrollView( { height : instance.height } );
template.append( "
Message Defaults
" );
template.append( sv );
return template;
}
EmailCampaignEditor.prototype.getDefaultsTabData = function() {
let instance = this;
if( instance.defaultsForm.validate().isValid ) {
return instance.defaultsForm.option( "formData" );
} else {
instance.gotoTab( "Defaults" );
return null;
}
}
EmailCampaignEditor.prototype.getData = function( source, fieldsToGet ) {
let copyCampaignData = $.extend( true, {}, source );
let returnData = {};
fieldsToGet.forEach( function( f ) {
returnData[f] = copyCampaignData[f];
})
return returnData;
}
EmailCampaignEditor.prototype.executeCampaign = function() {
let instance = this;
let campaignData = instance.campaignData;
let d = $.Deferred()
.done( function( response ) {
if( ! response.success ) {
instance.showSystemMessage( "warning", "Email Campaign not scheduled. Probably due to a concurrent modification by another user or process. The Email campaign has been reloaded with fresh data." );
} else {
instance.showSystemMessage( "info", "Email Campaign scheduled for immediate execution." )
}
instance.refreshEditor();
})
.fail( function() {
instance.refreshEditor();
instance.showSystemMessage( "error", "An Error Occurred. The operation may not have been successful. Please review and try again." );
})
// do the save
let saveURL = Fse.Util.updateURL2( $("link#appActionURL").attr( "href" ), { object : "GTM.executeEmailCampaign" } );
$.ajax( {
url : saveURL,
method : "post",
data : { campaign : JSON.stringify( campaignData ) }
})
.done( function( returnData ) {
d.resolve( returnData );
})
.fail( function() {
d.reject()
})
}
EmailCampaignEditor.prototype.sendTestEmail = function() {
let instance = this;
let data = $.extend( true, {}, instance.testForm.option( "formData" ));
data.campaignId = instance.campaignData.campaignId;
let saveURL = Fse.Util.updateURL2( $("link#appActionURL").attr( "href" ), { object : "GTM.sendEmailCampaignTestEmail" } );
$.ajax( {
url : saveURL,
method : "post",
data : { campaign : JSON.stringify( data ) }
})
.done( function( returnData ) {
let toastType = "info";
let toastMessage = "The test email has been sent.";
if( ! returnData.success ) {
toastType = "error";
toastMessage = "Unable to send the test email.";
}
instance.showSystemMessage( toastType, toastMessage );
});
}
EmailCampaignEditor.prototype.createClicksByDayChart = function( data ) {
let clicksByDayStyle = {
"width":"500px",
"height":"150px",
"margin-left":"10px",
"background-color":"white",
"xbox-shadow": "3px 3px 3px #b3b3b3",
"padding": "5px"
}
let clicksByDayChart = $("
")
.css( clicksByDayStyle )
.dxChart({
dataSource : Fse.Data.newDataSource( { object : 'GTM.clicksByDay', objectParams : { campaignId : data.campaignId }, keyField : "daynum" } ),
legend: { visible: false },
tooltip: { enabled: true },
height : 150,
series: {
minBarSize : 2,
argumentField: 'day',
valueField: 'clicks',
name: 'Click History',
type: 'bar',
color: '#b3d9ff',
},
});
return clicksByDayChart.dxChart( "instance" );
}
EmailCampaignEditor.prototype.createClicksByTypeChart = function( data ) {
let clicksByTypeStyle = {
"width":"200px",
"height":"150px",
"background-color":"white",
"xbox-shadow": "3px 3px 3px #b3b3b3",
"padding": "5px 0px 0px 0px"
}
let clicksByTypeChart = $("
")
.css( clicksByTypeStyle )
.dxPieChart({
dataSource : Fse.Data.newDataSource( { object : 'GTM.clicksByRecipientType', objectParams : { campaignId : data.campaignId }, keyField : "type" } ),
palette: ['#b3d9ff', '#ffd480', '#b3b3ff', '#d98cb3', '#ff9999'],
tooltip: { enabled: true },
legend: {
visible: true,
verticalAlignment: 'bottom',
horizontalAlignment: 'center',
itemTextPosition: 'right',
rowCount: 1,
},
series: [
{
argumentField: 'type',
valueField: 'clicks',
}
]
});
return clicksByTypeChart.dxPieChart( "instance" );
}
EmailCampaignEditor.prototype.createToplineStatsElement = function( data ) {
let topLineStats = $("
").dxBox( {
direction : "row",
items : [
{
template : function() {
let element = $("
")
.append( $("
").text( "Total Recipients:" ) )
.append( $("").text( DevExpress.localization.formatNumber( data.recipientCount, { type : "fixedPoint", precision : 0 } ) ) );
return element;
},
ratio : 1
},
{
template : function() {
let element = $("")
.append( $("
").text( "Total Opens:" ) )
.append( $("").text( DevExpress.localization.formatNumber( data.opens, { type : "fixedPoint", precision : 0 } ) ) );
return element;
},
ratio : 1
},
{
template : function() {
let element = $("")
.append( $("
").text( "Total Clicks:" ) )
.append( $("").text( DevExpress.localization.formatNumber( data.clicks, { type : "fixedPoint", precision : 0 } ) ) );
return element;
},
ratio : 1
},
{
template : function() {
let element = $("")
.append( $("
").text( "Total Unsubscribes:" ) )
.append( $("").text( DevExpress.localization.formatNumber( data.unsubscribes, { type : "fixedPoint", precision : 0 } ) ) );
return element;
},
ratio : 1
}
]
});
return topLineStats;
}
EmailCampaignEditor.prototype.createRecipientsDataGrid = function( data ) {
let instance = this;
let recipientsDataGridConfig = null;
if( data.statusCd == "PEN" ) {
recipientsDataGridConfig = {
height : 400,
dataSource: Fse.Data.newDataSource( { object : 'GTM.emailCampaignTargetRecipients', objectParams : { campaignId : data.campaignId }, keyField : "fspro_userId" } ),
columns: [
{
caption: "Name",
name : "name",
calculateCellValue: function(rowData) {
return rowData.firstName + " " + rowData.lastName;
},
allowFiltering: true
},
{
caption: "Email",
dataField:"emailAddress",
width: 230,
allowFiltering: true,
cellTemplate: function(container, options) {
if ("Private Address" == options.data.emailAddress) {
container.append( $("").text( options.data.emailAddress ));
} else {
container.append(options.data.emailAddress);
}
}
},
{
caption: "Organization",
dataField:"organizationName",
allowFiltering: true
},
{ // tse-535
caption: "Invalid Email",
dataField:"knownBadEmail",
cellTemplate: function(container, options) {
let template = $("").text( options.displayValue );
if( options.value == 'Yes' ) {
template.css( { "color" : "red" })
}
container.append( template );
},
width: 100,
},
{
caption: "Opened",
name:"isOpened",
lookup : {
dataSource : {
store : {
type : "array",
key : "value",
data : [
{ value : 1, text :'Yes' },
{ value : 0, text :'No' }
]
}
},
displayExpr : "text",
valueExpr : "value"
},
cellTemplate: function(container, options) {
let template = $("
").text( options.displayValue );
if( options.value == 0 ) {
template.css( { "color" : "red" })
} else if (options.value == 1 ) {
template.css( { "color" : "green" })
}
container.append( template );
},
width: 90
},
{
caption: "Unsubscribed",
name:"isUnsubscribed",
lookup : {
dataSource : {
store : {
type : "array",
key : "value",
data : [
{ value : 1, text :'Yes' },
{ value : 0, text :'No' }
]
}
},
displayExpr : "text",
valueExpr : "value"
},
cellTemplate: function(container, options) {
let template = $("
").text( options.displayValue );
if( options.value == 0 ) {
template.css( { "color" : "red" })
} else if (options.value == 1 ) {
template.css( { "color" : "green" })
}
container.append( template );
},
width: 110
}
],
scrolling : {
mode : "virtual"
},
summary: {
totalItems: [
{ column: "fspro_userId", showInColumn : "name", summaryType: "count", displayFormat : "Tentative Recipients : {0}", valueFormat : { type : "fixedPoint", precision : 0 } }
]
},
showColumnHeaders: true,
filterRow: {
visible: true
},
// export: { enabled: true },
onToolbarPreparing : function( e ) {
if( ! e.toolbarOptions.items ) {
e.toolbarOptions.items = [];
}
let toolbarItems = e.toolbarOptions.items;
toolbarItems.push( {
location : "after",
widget : "dxButton",
options : {
icon : "exportxlsx",
onClick : function( ee ) {
Fse.UI.DataGridHelper.exportDataGrid( { dataGrid : e.component, fileName : "recipients.xlsx" });
}
}
})
},
onRowDblClick : function( e ) {
if( e.rowType != "data" ) {
return;
}
if( e.data.emailId ) {
EmailCampaignManager.showRecipientMessage( e.data );
}
}
};
} else {
recipientsDataGridConfig = {
height : 400,
dataSource: Fse.Data.newDataSource( { object : 'GTM.emailCampaignRecipients', objectParams : { campaignId : data.campaignId }, keyField : "recipientId" } ),
columns: [
{
caption: "Name",
name : "name",
calculateCellValue: function(rowData) {
return rowData.firstName + " " + rowData.lastName;
},
allowFiltering: true
},
{
caption: "Email",
dataField:"emailAddress",
width: 230,
allowFiltering: true,
cellTemplate: function(container, options) {
if ("Private Address" == options.data.emailAddress) {
container.append( $("
").text( options.data.emailAddress ));
} else {
container.append(options.data.emailAddress);
}
}
},
{
caption: "Organization",
dataField:"organizationName",
allowFiltering: true
},
{
caption: "Opened",
dataField:"isOpened",
lookup : {
dataSource : {
store : {
type : "array",
key : "value",
data : [
{ value : 1, text :'Yes' },
{ value : 0, text :'No' }
]
}
},
displayExpr : "text",
valueExpr : "value"
},
cellTemplate: function(container, options) {
let template = $("").text( options.displayValue );
if( options.value == 0 ) {
template.css( { "color" : "red" })
} else if (options.value == 1 ) {
template.css( { "color" : "green" })
}
container.append( template );
},
width: 90
},
{
caption: "Unsubscribed",
dataField:"isUnsubscribed",
lookup : {
dataSource : {
store : {
type : "array",
key : "value",
data : [
{ value : 1, text :'Yes' },
{ value : 0, text :'No' }
]
}
},
displayExpr : "text",
valueExpr : "value"
},
cellTemplate: function(container, options) {
let template = $("
").text( options.displayValue );
if( options.value == 0 ) {
template.css( { "color" : "red" })
} else if (options.value == 1 ) {
template.css( { "color" : "green" })
}
container.append( template );
},
width: 110
}
],
scrolling : {
mode : "virtual"
},
summary: {
totalItems: [
{ column: "recipientId", showInColumn : "name", summaryType: "count", displayFormat : "Total Recipients : {0}", valueFormat : { type : "fixedPoint", precision : 0 } },
{ column: "isOpened", summaryType: "sum", displayFormat: "Opened: {0}", valueFormat : { type : "fixedPoint", precision : 0 } },
{ column: "isUnsubscribed", summaryType: "sum", displayFormat: "Unsubscribed: {0}", valueFormat : { type : "fixedPoint", precision : 0 } }
]
},
showColumnHeaders: true,
filterRow: {
visible: true
},
// export: { enabled: true },
onToolbarPreparing : function( e ) {
if( ! e.toolbarOptions.items ) {
e.toolbarOptions.items = [];
}
let toolbarItems = e.toolbarOptions.items;
toolbarItems.push( {
location : "after",
widget : "dxButton",
options : {
icon : "exportxlsx",
onClick : function( ee ) {
Fse.UI.DataGridHelper.exportDataGrid( { dataGrid : e.component, fileName : "recipients.xlsx" });
}
}
})
},
onRowDblClick : function( e ) {
if( e.rowType != "data" ) {
return;
}
if( e.data.emailId ) {
EmailCampaignManager.showRecipientMessage( e.data );
}
}
};
}
let recipientsDataGrid = $("
").dxDataGrid( recipientsDataGridConfig );
if( data.statusCd == "PEN" ) {
recipientsDataGrid.append( $("
* Invalid email indicates if previous emails to this address were undeliverable. Invalid emails will be skipped in this campaign. Visit the contact record to modify the email address.
")
.css({"font-style" : "bold" , "font-style" : "italic"}) );
}
return recipientsDataGrid.dxDataGrid( "instance" );
}
EmailCampaignEditor.prototype.element = function() {
return this.rootElement;
}
EmailCampaignEditor.prototype.dispose = function() {
if( this.intervalId ) {
window.clearInterval( this.intervalId );
this.intervalId = 0;
}
if( this.tabPanel ) {
this.tabPanel.element().remove();
this.tabPanel.dispose();
this.tabPanel = null;
}
if( this.rootElement ) {
this.rootElement.remove();
this.rootElement = null
}
}
EmailCampaignEditor.prototype.getCurrentTabIndex = function() {
if( this.tabPanel ) {
return this.tabPanel.option( "selectedIndex" );
} else {
return this.options.tabIndex;
}
}
/*
EmailCampaignEditor.prototype.showRecipientMessage = function( data ) {
$("
").dxPopup( {
title : data.emailSubject,
height : 640,
hideOnOutsideClick : true,
contentTemplate : function() {
let content = $("
");
// email header
let emailHeader = $("
").css( { "display" : "grid", "grid-template-columns" : "70px auto", "margin-bottom" : "18px" } );
emailHeader
.append( "
TO:
")
.append( $("
").text( data.emailTo ))
.append( "
FROM:
" )
.append( $("
").text( data.emailFrom ))
.append( "
SENT:
")
.append( $("
").text( DevExpress.localization.formatDate( new Date( Date.parse( data.emailDate )), "longDateLongTime" ) ));
content.append( emailHeader );
// actual email
let emailBodyURL = Fse.Util.updateURL2( $("link#PortalDocRootURL").attr( "href") + "/index.cfm?app=GTM.emailManager",
{ operation : "getEmailBody", campaignId : data.campaignId, recipientId : data.recipientId, emailId : data.emailId }
);
let emailMessageViewer = $("