").dxDataGrid( {
showBorders : true,
filterRow : { visible : true },
scrolling : { mode : "virtual" },
rowAlternationEnabled : true,
remoteOperations : {
filtering : true,
paging : true,
sorting : true
},
height : 500,
onRowDblClick : function( rdce ) {
if( rdce.rowType != "data" ) {
return;
}
instance.pickPartner();
},
selection : { mode : "single" },
onSelectionChanged : function( e ) {
if( e.selectedRowsData.length ) {
instance.submitButton.option( "disabled", false );
} else {
instance.submitButton.option( "disabled", true );
}
},
dataSource : Fse.Data.newDataSource( { object : "CRM.contactList", keyField : "fspro_userId", paginate : true, pageSize : 50, objectParams : { partnerTypes : partnerType } } ),
columns : [
{ dataField : "partnerName", caption : "Operator Name", visible : true },
{ dataField : "fullName", caption : "Contact Name", visible : true },
{ dataField : "email", caption : "Email", visible : true },
{ dataField : "title", caption : "Title", visible : true }
]
}).dxDataGrid( "instance" );
return contactsDataGrid;
}
PartnerPicker.prototype.createDistributorDataGrid = function() {
let instance = this;
let distributorDataGrid = $("
").dxDataGrid( {
showBorders : true,
filterRow : { visible : true },
scrolling : { mode : "virtual" },
rowAlternationEnabled : true,
remoteOperations : {
filtering : true,
paging : true,
sorting : true
},
height : 500,
onRowDblClick : function( rdce ) {
if( rdce.rowType != "data" ) {
return;
}
instance.pickPartner();
},
selection : { mode : "single" },
onSelectionChanged : function( e ) {
if( e.selectedRowsData.length ) {
instance.submitButton.option( "disabled", false );
} else {
instance.submitButton.option( "disabled", true );
}
},
dataSource : Fse.Data.newDataSource( { object : "CRM.distributorList", keyField : "cdr_recordId", paginate : true, pageSize : 50 } ),
columns : [
{ dataField : "displayCompanyType", caption : "Account Type", width : 110 },
{ dataField : "cdr_dstname", caption : "Distributor Name", visible : true },
{ dataField : "cdr_dstaddress1", caption : "Street", visible : true },
{ dataField : "cdr_dstcity", caption : "City", visible : true },
{ dataField : "cdr_dststate", caption : "State", visible : true },
{ dataField : "cdr_dstzip", caption : "Zip Code", visible : true, width : 70 },
]
}).dxDataGrid( "instance" );
return distributorDataGrid;
}
PartnerPicker.prototype.refreshView = function() {
let instance = this;
let selectedView = instance.multiview.option( "selectedItem" );
console.log( "SelectedView", selectedView );
instance.partnerType = selectedView.partnerType;
let popupTitle = "Pick...";
if( instance.partnerType == "OPR" ) {
popupTitle = "Pick Operator";
} else if ( instance.partnerType == "OPRC" ) {
popupTitle = "Pick Operator Contact";
} else if ( instance.partnerType == "CDR" ) {
popupTitle = "Pick Distributor";
} else if ( instance.partnerType == "CDRC" ) {
popupTitle = "Pick Distributor Contact";
}
instance.popup.option( "title", popupTitle );
instance.dataGrid = selectedView.dataGrid;
let myAccounts = instance.myAccountsCheckBox.option( "value" );
let favorties = instance.favoritesCheckBox.option( "value" );
let filters = [];
if( favorties ) {
filters.push( [ "isUserFlagged", "=", 1 ])
}
if( instance.partnerType == "OPR" ) {
if( myAccounts ) {
if( filters.length ) {
filters.push( "and")
}
filters.push( [ "salesRepId", "=", Fse.Portal.appConfiguration.STP.userId])
}
} else {
if( myAccounts ) {
if( filters.length ) {
filters.push( "and")
}
filters.push( [ "mfr_bsr_id", "=", Fse.Portal.appConfiguration.STP.userId])
}
}
instance.dataGrid.getDataSource().filter(filters);
instance.dataGrid.refresh();
let selectedRowKeys = instance.dataGrid.option( "selectedRowKeys");
if( selectedRowKeys.length ) {
instance.submitButton.option( "disabled", false );
} else {
instance.submitButton.option( "disabled", true );
}
let newPartnerButtonOptions = {
text : "New...",
visible : false
}
if( instance.partnerType == "OPR" ) {
newPartnerButtonOptions.text = "New Operator...";
} else if ( instance.partnerType == "CDR" ) {
newPartnerButtonOptions.text = "New Distributor...";
} else if ( instance.partnerType == "OPRC" ) {
newPartnerButtonOptions.text = "New Operator Contact...";
} else if ( instance.partnerType == "CDRC" ) {
newPartnerButtonOptions.text = "New Distributor Contact...";
}
if( instance.allowAdd ) {
if( instance.partnerType == "OPR" ) {
if( Fse.Portal.checkPermission( "OperatorManagementAdd") ) {
newPartnerButtonOptions.visible = true;
}
} else if ( instance.partnerType == "CDR" ) {
if( Fse.Portal.checkPermission( "DistributorManagementAdd") ) {
newPartnerButtonOptions.visible = true;
}
}
}
instance.newPartnerButton.option( newPartnerButtonOptions )
}
PartnerPicker.prototype.show = function() {
let instance = this;
instance.returnPromise = $.Deferred();
let toolbarItems = [];
toolbarItems.push( {
toolbar : "bottom",
location : "before",
template : function() {
instance.newPartnerButton = $("
").dxButton( {
text : "New...",
visible : false,
onClick : function( e ) {
instance.newPartner();
}
}).dxButton( "instance");
return instance.newPartnerButton.element();
}
})
toolbarItems.push(
{
toolbar : "bottom",
location : "after",
widget : "dxButton",
options : {
text : "Cancel",
type : "normal",
onClick : function( e ) {
instance.popup.hide();
}
}
},
{
toolbar : "bottom",
location : "after",
template : function() {
instance.submitButton = $("
").dxButton( {
text : "Select",
type : "default",
disabled : true,
onClick : function( e ) {
instance.pickPartner();
}
}).dxButton( "instance" );
return instance.submitButton.element();
}
}
)
instance.popup = $("
").dxPopup( {
title : "Pick...", // instance.partnerType == "OPR" ? "Pick Operator" : "Pick Distributor",
height : "auto",
onHidden : function( e ) {
e.component.dispose();
},
onShown : function( e ) {
instance.refreshView();
},
hideOnOutsideClick : true,
toolbarItems : toolbarItems,
contentTemplate : function() {
let content = $("
");
$("
").dxToolbar( {
items : [
{
location : "before",
widget : "dxSelectBox",
options : {
items : instance.availablePartnerTypes,
width : 200,
displayExpr : "text",
valueExpr : "value",
value : instance.partnerType,
onValueChanged : function( e ) {
console.log( e );
if( e.value ) {
let selectedItem = e.component.option( "selectedItem" );
instance.multiview.option( "selectedIndex", selectedItem.multiViewIndex )
}
}
}
}
,{
location : "after",
template : function() {
instance.myAccountsCheckBox = $("
").dxCheckBox( {
text : "My Accounts",
value : false,
onValueChanged : function( e ) {
instance.refreshView();
}
}).dxCheckBox( "instance" );
return instance.myAccountsCheckBox.element();
}
}
,{
location : "after",
template : function() {
instance.favoritesCheckBox = $("
").dxCheckBox( {
text : "Favorites",
value : false,
onValueChanged : function( e ) {
instance.refreshView();
}
}).dxCheckBox( "instance" );
return instance.favoritesCheckBox.element();
}
}
]
}).appendTo( content ).css( { "margin-bottom" : "5px" } );
let multiViewItems = [];
instance.availablePartnerTypes.forEach( function( partnerTypeItem ) {
if( partnerTypeItem.partnerType == "OPR" ) {
partnerTypeItem.multiViewIndex = multiViewItems.length;
multiViewItems.push(
{
partnerType : "OPR",
template : function( itemData ) {
itemData.dataGrid = instance.createOperatorDataGrid();
return itemData.dataGrid.element();
}
}
)
}
if( partnerTypeItem.partnerType == "OPRC" ) {
partnerTypeItem.multiViewIndex = multiViewItems.length;
multiViewItems.push(
{
partnerType : "OPRC",
template : function( itemData ) {
itemData.dataGrid = instance.createContactDataGrid( 'OPR' );
return itemData.dataGrid.element();
}
}
)
}
if( partnerTypeItem.partnerType == "CDR" ) {
partnerTypeItem.multiViewIndex = multiViewItems.length;
multiViewItems.push(
{
partnerType : "CDR",
template : function( itemData ) {
itemData.dataGrid = instance.createDistributorDataGrid();
return itemData.dataGrid.element();
}
}
)
}
if( partnerTypeItem.partnerType == "CDRC" ) {
partnerTypeItem.multiViewIndex = multiViewItems.length;
multiViewItems.push(
{
partnerType : "CDRC",
template : function( itemData ) {
itemData.dataGrid = instance.createContactDataGrid( 'CDR' );
return itemData.dataGrid.element();
}
}
)
}
})
instance.multiview = $("
").dxMultiView( {
swipeEnabled: true,
selectedIndex : 0,
items : multiViewItems,
onSelectionChanged : function( e ) {
instance.refreshView();
}
}).dxMultiView( "instance" );
content.append( instance.multiview.element() );
return content;
}
}).dxPopup("instance");
$("body").append( instance.popup.element() )
instance.popup.show()
return instance.returnPromise;
}