").append( "CRM" ).css( { "text-align": "left", "font-size" : "larger" } ) } },
{ dataField : "cdr_priority", label : { location : "left", text : "Priority" }, editorType : "dxDropDownBox",
editorOptions : {
placeholder : "Select Priority",
dataSource : new DevExpress.data.ArrayStore({
data: instance.priorityTypes,
key: "prioritycode"
}) ,
valueExpr : "prioritycode", displayExpr : "desc",
contentTemplate : function( e ) {
const v = e.component.option( "value" );
const $list = $("
").dxList( {
dataSource : e.component.getDataSource(),
displayExpr : "desc",
selectionMode: "all",
showSelectionControls : true,
selectedItemKeys : v,
onSelectionChanged : function( sce ) {
const keys = sce.component.option( "selectedItemKeys" );
e.component.option( "value", keys );
}
})
list = $list.dxList('instance');
e.component.on('valueChanged', (args) => {
const { value } = args;
list.option( "selectedItemKeys", value );
});
return $list;
}
}
},
// classification
{ dataField : "classificationId", label : { location : "left", text : "Classification" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "CDR.classifications", keyField : "classificationId" } ),
searchExpr : "classificationName",
searchMode : "contains",
displayExpr : "classificationName",
multipleSelectedDisplay : "Multiple Classifications Selected",
keyExpr : "classificationId",
title : "Select Classifications"
})
},
{
dataField : "distributorListId", label : { location : "left", "text" : `${getText( 'DISTRIBUTOR' )} List` }, editorType : "dxSelectBox", editorOptions : {
dataSource : distributorListsDataSource, // Fse.Data.newDataSource( { object : "LST.lists", keyField : "listId", objectParams : { includeStats : false, detailLists : true, partnerTypes : 'OPR', listUses : "SEARCH" } }),
displayExpr : "listName",
searchEnabled : true,
searchExpr : "listName",
valueExpr : "listId",
placeholder : "Select",
showClearButton : true
}
},
{
dataField : "includeFavoritesOnly", label : { location : "left", text : "My Favorites Only" }, editorType : "dxCheckBox"
},
{
dataField : "includeMyAccountsOnly", label : { location : "left", text : "My Accounts Only" }, editorType : "dxCheckBox"
},
// { // TSE-1660
// dataField : "hasActiveAgreements", label : { location : "left", text : "Has Active Agreements" }, editorType : "dxSwitch"
// }
{ dataField : "agreementStatus", label : { location : "left", text : "Agreement Status" }, editorType : "dxSelectBox",
editorOptions : {
showClearButton : true,
placeholder : "Select...",
dataSource : { store : { type : "array",
data : [ { agreementStatus : "Active" }, { agreementStatus : "Expired" },{ agreementStatus : "None" }],
key : "agreementStatus"
}},
valueExpr : "agreementStatus",
displayExpr : "agreementStatus"
}
} // TSE-1660
)
distributorItems.push(
{ template : function() { return $("
").append( "Tasks" ).css( { "margin-top" : "8px", "text-align": "left", "xfont-size" : "larger", "font-weight" : "bold" } ) } },
{
dataField : "withOpenTasks",
label : { location : "left", text : "with Open Tasks" },
editorType : "dxCheckBox"
},
{ dataField : "tasksAssignedTo", label : { text : "Assigned To" },
editorType : "dxSelectBox",
editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "FSPRO.members", keyField : "fspro_userId", paginate : true } ),
valueExpr : "fspro_userId",
displayExpr : "fullName",
searchEnabled : true,
searchExpr : "fullName",
searchMode : "contains",
showClearButton : true,
disabled : true
}
}
)
let crmItems = [];
crmItems.push(
{ template : function() { return $("
").append( "Pipeline" ).css( { "text-align": "left", "xfont-size" : "larger", "font-weight" : "bold" } ) } },
{
dataField : "stageId", label : { location : "left", text : "Stage" },
editorType : "dxDropDownBox",
editorOptions : {
placeholder : "Select Stage",
dataSource : Fse.Data.newDataSource( { object : "SPL.stages", keyField : "stageId" } ),
valueExpr : "stageId",
displayExpr : "stageNameFull",
contentTemplate : function( e ) {
const v = e.component.option( "value" );
const list = $("
").dxList( {
dataSource : e.component.getDataSource(),
displayExpr : "stageNameFull",
selectionMode: "all",
showSelectionControls : true,
selectedItemKeys : v,
onSelectionChanged : function( sce ) {
const keys = sce.component.option( "selectedItemKeys" );
e.component.option( "value", keys );
}
}).dxList( "instance");
e.component.on('valueChanged', (args) => {
const { value } = args;
list.option( "selectedItemKeys", value );
});
return list.element();
}
}
});
crmItems.push(
{ dataField : "orderYear", label : { location : "left", text : "Esimated Order Date" }, editorType : "dxDropDownBox",
editorOptions : {
showClearButton : true,
placeholder : "Select Year",
dataSource : new DevExpress.data.ArrayStore({
data: instance.orderDateYears,
key: "orderYear"
}) ,
valueExpr : "orderYear", displayExpr : "desc",
contentTemplate : function( e ) {
const v = e.component.option( "value" );
const $list = $("
").dxList( {
dataSource : e.component.getDataSource(),
displayExpr : "desc",
selectionMode: "single",
showSelectionControls : true,
selectedItemKeys : v,
onSelectionChanged : function( sce ) {
const keys = sce.component.option( "selectedItemKeys" );
e.component.option( "value", keys );
}
})
list = $list.dxList('instance');
e.component.on('valueChanged', (args) => {
const { value } = args;
list.option( "selectedItemKeys", value );
});
return $list;
}
}},
{ // sales rep
dataField : "opportunityEffectiveRepId", label : { location : "left", text : "Opportunity Owner" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.effectiveRepId ? 'fx-active-preference' : null, // scrum 46030
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "CRM.salesRepList", keyField : "valueId" } ),
searchExpr : "valueName",
searchMode : "contains",
displayExpr : "valueName",
multipleSelectedDisplay : "Multiple Opportunity Owners Selected",
keyExpr : "valueId",
title : "Select Opportunity Owners"
})
},
);
crmItems.push(
//{ template : function() { return $("
").append( "Interactions" ).css( { "text-align": "left", "font-size" : "larger" } ) } },
/*
{ dataField : "lastInteractionDays", label : { location : "left", text : "Interaction Date"}, editorType : "dxSelectBox", editorOptions : {
dataSource : {
store : {
type : "array",
data : [
{ value : '30', text : "Past 30 days"},
{ value : '60', text : "Past 60 days" },
{ value : '90', text : "Past 90 days" },
{ value : '120', text : "Past 120 days" },
{ value : '365', text : "Past year" },
{ value : '-30', text : "Not in past 30 days"},
{ value : '-60', text : "Not in past 60 days"},
{ value : '-90', text : "Not in past 90 days"},
{ value : '-120', text : "Not in past 120 days"},
{ value : '-365', text : "Not in past year"},
{ value : 'NEVER', text : "Never"},
],
key : "value"
}
},
displayExpr : "text",
keyExpr : "value",
valueExpr : "value",
placeholder : "Select...",
showClearButton : true,
}
*/
{ template : function() { return $("
").append( "Interactions" ).css( { "text-align": "left", "xfont-size" : "larger", "font-weight" : "bold" } ) } },
{ dataField : "lastInteractionDays", label : { location : "left", text : "Last Interaction"}, editorType : "dxSelectBox", editorOptions : {
dataSource : {
store : {
type : "array",
data : [
{ value : 30, text : "Past 30 days"},
{ value : 60, text : "Past 60 days" },
{ value : 90, text : "Past 90 days" },
{ value : 120, text : "Past 120 days" },
{ value : 365, text : "Past year" }
/*
{ value : -30, text : "Next 30 days"},
{ value : -60, text : "Next 60 days" },
{ value : -90, text : "Next 90 days" },
{ value : -120, text : "Next 120 days" }
*/
],
key : "value"
}
},
displayExpr : "text",
keyExpr : "value",
valueExpr : "value",
placeholder : "Select...",
showClearButton : true
}
});
crmItems.push(
{ dataField : "interactionStatus", label : { location : "left", text : "Interaction Status"}, editorType : "dxSelectBox", editorOptions : {
dataSource : {
store : {
type : "array",
data : [
{ value : '?', text : "Planned"},
{ value : 'X', text : "Completed" }
],
key : "value"
}
},
displayExpr : "text",
keyExpr : "value",
valueExpr : "value",
placeholder : "Select...",
showClearButton : true
}}
);
/*
crmItems.push(
//{ template : function() { return $("
").append( "Purchasing" ).css( { "text-align": "left", "font-size" : "larger" } ) } },
{ dataField : "productStatus", label : { location : "left", text : "Status" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : { store : { type : "array", key : "value", data : [
{ value : "B", text : "Buying" },
{ value : "N", text : "Not Buying" }
]}
},
valueExpr : "value",
displayExpr : "text",
showClearButton : true,
keyExpr : "value",
placeholder : "Select Purchasing Status"
}
}
);
*/
if( showMFR ) {
crmItems.push(
{ dataField : "productStatusMfrId", label : { location : "left", text : "Manufacturer" }, editorType : "dxSelectBox",
editorOptions : {
disabled : false,
dataSource : Fse.Data.newDataSource( { object : "PRD.manufacturers", keyField : "mfr_id" } ),
searchExpr : "mfr_name",
searchMode : "contains",
displayExpr : "mfr_name",
multipleSelectedDisplay : "Multiple Manufacturers Selected",
keyExpr : "mfr_id",
valueExpr : "mfr_id",
title : "Select Manufacturer",
showClearButton : true,
searchEnabled : true,
}
}
);
}
if( showBRO ) {
crmItems.push(
{ template : function() { return $("
").append( "Stocking" ).css( { "text-align": "left", "xfont-size" : "larger", "font-weight" : "bold" } ) } },
)
crmItems.push(
{ dataField : "productBudgetCategoryId", label : { location : "left", text : "Budget Category" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "PRD.budgetCategories", keyField : "budgetCategoryId" } ),
disabled : false,
showClearButton : true,
searchExpr : "budgetCategory",
searchMode : "contains",
displayExpr : "budgetCategory",
multipleSelectedDisplay : "Multiple Budget Categories Selected",
XkeyExpr : "budgetCategoryId",
valueExpr : "budgetCategoryId",
title : "Select Budget Categories"
}
}
)
crmItems.push(
{ dataField : "productStatusProductHierarchyPath", label : { location : "left", text : "Product" }, editorType : "dxDropDownBox",
editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "PRD.productHierarchyPaths", keyField : "productHierarchyPath" } ),
disabled : false,
valueExpr : "productHierarchyPath",
displayExpr : "productHierarchyPath",
contentTemplate : function( options ) {
let list = $("
").dxList( {
dataSource : options.component.getDataSource(), // Fse.Data.newDataSource( { object : "PRD.productHierarchyPaths", keyField : "productHierarchyPath" } ),
itemTemplate : function( itemData ) {
let pathParts = itemData.productHierarchyPath.split( "/" );
let item = $("
").text( pathParts[pathParts.length-1] );
let indents = pathParts.length - 1;
if( indents ) {
item.css( { "padding-left" : `${indents*10}px` })
}
return item;
},
pageLoadMode : "scrollBottom",
onItemClick : function( e ) {
options.component.option( "value", e.itemData.productHierarchyPath );
options.component.close();
},
searchEnabled : true,
searchExpr : "productHierarchyPath",
searchMode : "contains"
})
return list;
},
showClearButton : true,
displayValueFormatter : function( itemData ) {
let formattedDisplayValue = null;
if( Array.isArray( itemData ) && itemData.length ) {
let pathParts = itemData[0].split( "/" );
let prefix = "";
if( pathParts.length > 1 ) {
prefix = ".../";
}
formattedDisplayValue = `${prefix}${pathParts[pathParts.length-1]}`;
}
return formattedDisplayValue;
},
placeholder : "Select Product"
}
},
);
}
instance.dxBasicForm = $("
").dxForm( {
//items : distributorItems,
colCount : 2,
items : [
{ name : "distributor", itemType : "group", items : distributorItems },
{ name : "crm", itemType : "group", items : crmItems }
],
onFieldDataChanged : function( e ) {
switch ( e.dataField ) {
case "withOpenTasks" :
let tasksAssignedTo = e.component.getEditor( "tasksAssignedTo" );
if( e.value ) {
tasksAssignedTo.option( "disabled", false );
} else {
tasksAssignedTo.option( { "disabled" : true, "value" : null } );
}
break;
case "productStatusMfrId" : {
let productStatusProductHierarchyPathDisabled = true;
//let productStatusNoSaleReasonIdDisabled = true;
if( e.value ) {
productStatusProductHierarchyPathDisabled = false;
}
if( e.value == "N" ) {
productStatusNoSaleReasonIdDisabled = false;
}
let form = e.component;
let nullValues = {};
let performUpdateData = false;
if( productStatusProductHierarchyPathDisabled ) {
nullValues.productStatusProductHierarchyPath = null;
performUpdateData = true;
}
/*
if( productStatusNoSaleReasonIdDisabled ) {
nullValues.productStatusNoSaleReasonId = null;
performUpdateData = true;
}
*/
if( performUpdateData ) {
form.updateData( nullValues );
}
//form.getEditor( "productStatusNoSaleReasonId" ).option( "disabled", productStatusNoSaleReasonIdDisabled ) ;
//form.getEditor( "productStatusProductHierarchyPath" ).option( "disabled", productStatusProductHierarchyPathDisabled ) ;
} break;
case "XXproductStatus" : {
if( showMFR ) {
let productStatusMfrIdDisabled = true;
if( e.value ) {
productStatusMfrIdDisabled = false;
}
let form = e.component;
if( productStatusMfrIdDisabled ) {
form.updateData( { "productStatusMfrId": null } );
}
form.getEditor( "productStatusMfrId" ).option( "disabled", productStatusMfrIdDisabled ) ;
} else {
let productStatusProductHierarchyPathDisabled = true;
let productStatusNoSaleReasonIdDisabled = true;
if( e.value ) {
productStatusProductHierarchyPathDisabled = false;
}
if( e.value == "N" ) {
productStatusNoSaleReasonIdDisabled = false;
}
let form = e.component;
let nullValues = {};
let performUpdateData = false;
if( productStatusProductHierarchyPathDisabled ) {
nullValues.productStatusProductHierarchyPath = null;
performUpdateData = true;
}
if( productStatusNoSaleReasonIdDisabled ) {
nullValues.productStatusNoSaleReasonId = null;
performUpdateData = true;
}
if( performUpdateData ) {
form.updateData( nullValues );
}
form.getEditor( "productStatusNoSaleReasonId" ).option( "disabled", productStatusNoSaleReasonIdDisabled ) ;
form.getEditor( "productStatusProductHierarchyPath" ).option( "disabled", productStatusProductHierarchyPathDisabled ) ;
}
} break;
}
}
}).dxForm("instance");
this.popupPromise.notify( "createBasicForm" )
}
DistributorSearch.prototype.createPopup = function( applyPromise ) {
let instance = this;
instance.popupPromise = $.Deferred();
instance.popupPromise.createBasicForm = false;
instance.popupPromise.createFlexFieldForm = false;
instance.popupPromise.progress( function( operation ) {
instance.popupPromise[operation] = true;
if( instance.popupPromise.createBasicForm && instance.popupPromise.createFlexFieldForm ) {
instance.popupPromise.resolve();
}
});
instance.createBasicForm();
instance.createFlexFieldForm();
// scrum 46030 - moved outside of dxPopup creation
let bottomToolbarItems = [
{
toolbar : "bottom",
location : "after",
widget : "dxButton", options : { text : "clear",
onClick : function( e ) {
instance.dxBasicForm.option( "formData", { includeSubTerritories : true } );
if( instance.dxFlexFieldForm ) {
instance.dxFlexFieldForm.option( "formData", {} );
}
}
}
},
{
toolbar : "bottom",
location : "after",
widget : "dxButton", options : { text : "search",
type : "default",
onClick : function( e ) {
let applySearch = instance.searchOptions.applySearch;
let searchParams = instance.dxBasicForm.option( "formData" );
if( instance.dxFlexFieldForm ) {
searchParams.flexFields = instance.dxFlexFieldForm.option( "formData" );
//filterPreferences = $.extend( true, searchParams, searchParams.flexFields );
}
instance.dxPopup.hide();
applySearch( searchParams );
if( applyPromise ) {
applyPromise.resolve();
}
}
}
}
];
// scrum 46030
if( Object.keys( this.activeFilterPreferences ).length ) {
bottomToolbarItems.push( {
toolbar : "bottom",
location : "before",
template : function() {
let annotation = $("
").append( $("
").addClass( "dx-field-item-label-text" ).append( "*filter preference active")).addClass( "fx-active-preference" ).css( { "cursor" : "pointer" } );
/* TODO: bring up the global preferences
annotation.on( "click", function( e ) {
// if the global filter preferences are applied, then close this popup
let onSaveFilterPreferences = function() {
widget.preferencesPopup.hide();
}
widget.widgetOptions.dashboard.editFilterPreferences( onSaveFilterPreferences );
})
*/
return annotation;
}
})
}
instance.dxPopup = $("").dxPopup( {
title : `${getText( 'DISTRIBUTOR' )} Search`,
width : "90vw",
contentTemplate : function() {
if( instance.dxFlexFieldForm ) {
let tabs = $("
").dxTabPanel( {
items : [
{ title : "Basic",
template : function() {
let basic = $("
")
basic.append( instance.dxBasicForm.element().css( "padding", "15px" ));
return basic.dxScrollView( { height : '100%', xheight : 545 } );
// return instance.dxBasicForm.element();
}
},
{ title : "Custom",
template : function() {
let custom = $("
");
custom.append( instance.dxFlexFieldForm.element().css( "padding", "15px" ) );
return custom.dxScrollView( { height : "100%", xheight : 545 } );
}
}
]
});
return tabs;
} else {
return instance.dxBasicForm.element();
}
},
toolbarItems : bottomToolbarItems,
// on hidden added to cleanup ui objects - scrum 46030
onHidden : function( e ) {
// clean up
e.component.element().remove();
instance.dxBasicForm.dispose();
instance.dxBasicForm = null;
instance.dxPopup.dispose();
instance.dxPopup = null;
}
}).appendTo( "body" ).dxPopup("instance");
return this.popupPromise;
}
// scrum 46030
DistributorSearch.prototype.show = function( searchParams, filterPreferences ) {
let instance = this;
instance.processFilterPreferences( filterPreferences, searchParams );
let applyPromise = $.Deferred();
instance.createPopup( applyPromise ).done( function() {
if( searchParams ) {
instance.dxBasicForm.updateData( searchParams );
if( searchParams.flexFields && instance.dxFlexFieldForm ) {
instance.dxFlexFieldForm.updateData( searchParams.flexFields )
}
}
instance.dxPopup.show();
} );
return applyPromise;
}
// scrum 46030
DistributorSearch.prototype.getPreferenceableFilters = function() {
// when the global filters are expressed with different variable names, they need to translated to this widgets variable names
const preferenceableFilters = {
// widgetVariableName : "globalFilterVariableName"
territoryPath : "territoryPath",
salesRepId : "salesRepId",
budgetCategoryId : "productBudgetCategoryId",
clientSegPath : "clientSegPath"
}
return preferenceableFilters;
}
// scrum 46030
DistributorSearch.prototype.processFilterPreferences = function( filterPreferencesIn, searchParamsIn ) {
let filterPreferences = {}
if( filterPreferencesIn ) {
filterPreferences = $.extend( true, {}, filterPreferencesIn );
}
let searchParams = {};
if( searchParamsIn ) {
searchParams = $.extend( true, {}, searchParamsIn );
}
this.activeFilterPreferences = {};
// when the global filters are expressed with different variable names, they need to translated to this widgets variable names
let preferenceableFilters = this.getPreferenceableFilters();
for( let p in preferenceableFilters ) {
let gp = p; // global filter param is the same name as widget param
// apply translation - global filter param is not the same name as widget param
if( preferenceableFilters[p] ) {
gp = preferenceableFilters[p];
}
// if the global filter preferences have the propery and it has a value, update the objectparams
if( filterPreferences.hasOwnProperty( gp ) && filterPreferences[gp]) {
if( searchParams[p] == null ) {
this.activeFilterPreferences[p] = filterPreferences[gp];
}
}
}
console.log( "ACTIVE FILTER PREFERENCES" );
console.log( this.activeFilterPreferences );
}