").dxButton( {
text : "Send",
type : "default",
onClick : function() {
instance.send().done( function() {
instance.popup.hide();
});
}
}).dxButton( "instance" );
return instance.sendButton.element();
}
}
]
}).appendTo( $("body") ).dxPopup( "instance" );
instance.popup.show();
}
EmailRecipientPicker = function( options ) {
let instance = this;
instance.submitButton = null;
instance.popup = null;
instance.pickPromise = null;
instance.staffDataGrid = null;
instance.selectedEmails = {};
instance.otherDataGrid = null;
instance.interactionInfo = null;
instance.otherDataSource = options.otherDataSource;
instance.otherLabel = options.otherLabel;
instance.readyToShow = $.Deferred();
if( options.subjectType == "CLL" || options.subjectId) {
let interactionInfoDataSource = Fse.Data.newDataSource( { object : "BCM.interactionInfo", objectParams : { interactionId : options.subjectId } });
interactionInfoDataSource.load().done( function( ii ) {
instance.interactionInfo = ii[0];
// console.log( "interactionInfo", instance.interactionInfo );
instance.readyToShow.resolve();
})
} else {
instance.readyToShow.resolve();
}
// this is where we may need to load some data to determine who to scope the picker and load the lists
}
EmailRecipientPicker.prototype.constructor = EmailRecipientPicker;
EmailRecipientPicker.prototype._onSelectionChanged = function( e ) {
let instance = this;
e.currentSelectedRowKeys.forEach( function( email ) {
instance.selectedEmails[email] = email;
})
e.currentDeselectedRowKeys.forEach( function( email ) {
delete instance.selectedEmails[email];
})
let submitDisabled = true;
for( let email in instance.selectedEmails ) {
submitDisabled = false;
break;
}
instance.submitButton.option( "disabled", submitDisabled );
}
EmailRecipientPicker.prototype._createDataGrid = function( dataSource, type ) {
const instance = this;
let dataGrid = $("
").dxDataGrid( {
height : 300,
columns : [
{ dataField : "fullName", caption : "Name" },
{ dataField : "title", caption : "Title" },
{ dataField : type == "partner" ? "partnerName" : "companyName", caption : "Company" },
{ dataField : "primaryContactId", caption : "Primary Contact", visible : type == "partner" ? true : false, width : 125 },
{ dataField : "contactDecisionMaker", caption : "Decision Maker", visible : type == "partner" ? true : false, width : 100 },
{ dataField : "email", width : 300,
cellTemplate : function( container, options ) {
container.append( options.text );
if( options.data.knownBadEmail == "Y" ) {
container.css( {
color : "#f53611"
}).attr( { title : "Past messages sent to this address have failed!" })
}
}
}
//, { dataField : "knownBadEmail", caption : "Failed Email", width : 80 }
],
filterRow : { visible : true },
dataSource : dataSource,
remoteOperations : {
paging : true,
filtering : true,
sorting : true
},
scrolling : { mode : "virtual" },
showBorders : true,
selection : {
allowSelectAll : false,
mode : "multiple",
showCheckBoxesMode : "always"
},
onSelectionChanged : function( e ) {
instance._onSelectionChanged( e );
},
onRowClick : function( e ) {
let email = e.data.email;
if( e.isSelected ) {
e.component.deselectRows( [ email ]);
} else {
e.component.selectRows( [ email ], true );
}
}
}).dxDataGrid("instance");
return dataGrid;
}
EmailRecipientPicker.prototype._createContent = function() {
let instance = this;
let contentRoot = $("
");
let multiViewItems = [];
// operator contacts
if( instance.interactionInfo && instance.interactionInfo.partnerType == "OPR" ) {
let operatorId = instance.interactionInfo.partnerId;
let cdr_recordId = instance.interactionInfo.cdrDistributorId;
multiViewItems.push( {
label : "Call Contacts",
template : function() {
let operatorContactsDataSource = Fse.Data.newDataSource( { object : "CRM.partnerContacts", keyField : "email", objectParams : { partnerType : 'OPR', partnerId : operatorId } });
operatorContactsDataSource.filter( [ "email", "isnotblank" ] );
instance.contactsDataGrid = instance._createDataGrid( null, "partner" );
if( ! cdr_recordId ) {
instance.contactsDataGrid.option( "dataSource", operatorContactsDataSource );
} else {
Fse.Ajax.showWait( 0, "Loading..." );
let combinedContacts = [];
operatorContactsDataSource.load().done( function( operatorContacts ) {
operatorContacts.forEach( function( contact ) {
combinedContacts.push( contact );
})
let distributorContactsDataSource = Fse.Data.newDataSource( { object : "CRM.partnerContacts", keyField : "email", objectParams : { partnerType : 'CDR', partnerId : cdr_recordId } });
distributorContactsDataSource.filter( [ "email", "isnotblank" ] );
distributorContactsDataSource.load().done( function( distributorContacts ) {
distributorContacts.forEach( function( contact ) {
combinedContacts.push( contact );
})
let sortedCominedContacts = DevExpress.data.query(combinedContacts)
.sortBy("fullName")
.toArray();
let combinedDataSource = new DevExpress.data.DataSource( {
store : { type : "array", data : sortedCominedContacts, key : "email" }
})
Fse.Ajax.hideWait();
instance.contactsDataGrid.option( "dataSource", combinedDataSource );
})
})
}
return instance.contactsDataGrid.element();
}
} )
}
// distributor contacts
if( instance.interactionInfo && instance.interactionInfo.partnerType == "CDR" ) {
let cdr_recordId = instance.interactionInfo.partnerId;
multiViewItems.push( {
label : "Call Contacts",
template : function() {
let partnerContactsDataSource = Fse.Data.newDataSource( { object : "CRM.partnerContacts", keyField : "email", objectParams : { partnerType : 'CDR', partnerId : cdr_recordId } });
partnerContactsDataSource.filter( [ "email", "isnotblank" ] );
instance.distributorContactsDataGrid = instance._createDataGrid( partnerContactsDataSource, "partner" );
return instance.distributorContactsDataGrid.element();
}
} )
}
if( instance.otherDataSource ) {
// add the other tab
multiViewItems.push( {
label : instance.otherLabel ? instance.otherLabel : "Other Contacts",
template : function() {
instance.otherDataSource.filter( [ "email", "isnotblank" ] );
instance.otherDataSource.sort( [ "fullName" ] );
instance.otherDataGrid = instance._createDataGrid( instance.otherDataSource, "other" );
return instance.otherDataGrid.element();
}
} )
} else {
// add the staff tab
multiViewItems.push( {
label : "Internal Contacts",
template : function() {
let staffDataSource = Fse.Data.newDataSource( { object : "CRM.salesRepList", keyField : "email", objectParams : { staffOnly : true, loginEnabledOnly : true, useTerritoryVisibility : false, useSalesRepVisibility : false } });
staffDataSource.filter( [ "email", "isnotblank" ] );
staffDataSource.sort( [ "fullName" ] );
instance.staffDataGrid = instance._createDataGrid( staffDataSource, "staff" );
return instance.staffDataGrid.element();
}
} )
// add the broker staff tab
if( Fse.Portal.appConfiguration.STP.ownerType === "MFR" ) {
multiViewItems.push( {
label : "Broker Contacts",
template : function() {
let staffDataSource = Fse.Data.newDataSource( { object : "CRM.salesRepList", keyField : "email", objectParams : { brokerStaffOnly : true, loginEnabledOnly : true } });
staffDataSource.filter( [ "email", "isnotblank" ] );
instance.staffDataGrid = instance._createDataGrid( staffDataSource, "staff" );
return instance.staffDataGrid.element();
}
} )
}
}
let radioGroupItems = [];
for( let x = 0; x < multiViewItems.length; x++ ) {
mvi = multiViewItems[x];
let rgi = {
text : mvi.label,
multiViewIdx : x
}
radioGroupItems.push( rgi );
}
let toolbar = $("
").dxToolbar( {
items : [
{
location : "before",
widget : "dxRadioGroup",
options : {
layout : "horizontal",
items : radioGroupItems,
displayExpr : "text",
value : radioGroupItems[0],
onValueChanged : function( e ) {
instance.multiView.option( "selectedIndex", e.value.multiViewIdx );
}
}
}
]
}).appendTo( contentRoot ).css( { "margin-bottom" : "5px" });
instance.multiView = $("
").dxMultiView( {
items : multiViewItems,
selectedIndex : 0,
swipeEnabled : false
}).dxMultiView( "instance" );
contentRoot.append( instance.multiView.element() );
return contentRoot;
}
EmailRecipientPicker.prototype._cancel = function() {
let instance = this;
instance.popup.hide();
instance.pickPromise.reject();
}
EmailRecipientPicker.prototype._submit = function() {
let instance = this;
let emailList = [];
for( let email in instance.selectedEmails ) {
emailList.push( email );
}
instance.pickPromise.resolve( emailList );
instance.popup.hide();
}
EmailRecipientPicker.prototype.show = function() {
let instance = this;
instance.pickPromise = $.Deferred();
instance.popup = $("
").dxPopup( {
title : "Select Email Recipients",
width : "70vw",
height : "auto",
hideOnOutsideClick : true,
contentTemplate : function() {
return instance._createContent();
},
onHidden : function( e ) {
e.component.element().remove();
e.component.dispose();
},
toolbarItems : [
{
toolbar : "bottom",
location : "after",
widget : "dxButton",
options : {
text : "Cancel",
onClick : function(e) {
instance._cancel();
instance.popup.hide();
}
}
},
{
toolbar : "bottom",
location : "after",
template : function() {
instance.submitButton = $("
").dxButton( {
text : "Submit",
type : "default",
disabled : true,
onClick : function( e ) {
instance._submit();
}
}).dxButton( "instance" );
return instance.submitButton.element();
}
}
]
}).appendTo( $("body") ).dxPopup("instance");
instance.readyToShow.done( function() {
instance.popup.show();
})
return instance.pickPromise;
}