").dxDataGrid( {
height : "100%",
scrolling : { mode : "virtual" } ,
showBorders : true,
rowAlternationEnabled : true,
grouping : { autoExpandAll : false },
dataSource :{ store : {
type : "array",
data : data,
key : "voidMatrixTargetId"
}},
columns : [
{ dataField : "targetStatus", groupIndex : 0, dataType : "number" },
{ dataField : "companyName", caption : "Operator", width : 200 },
{ dataField : "staffFullName", caption : "Staff Member", width : 150 },
{ dataField : "skuFull", caption : "SKU" },
{ name : "issues", caption : "Reason", width : 250, calculateDisplayValue : function( data ) {
let value = null;
if( data.targetStatus == "SKIP" ) {
let reasons = [];
if( ! data.objectiveId ) {
reasons.push( "No Matching Objective" )
} else if ( data.existingObjectiveTarget == "Y" && data.existingSKU == "Y" ) {
reasons.push( "Existing Target & SKU" );
} else if ( data.existingObjectiveTarget == "Y" && ! data.existingTargetInteractionId ) {
reasons.push( "Existing Target with no Open Calls" );
} else {
if( data.productRestriction == "FAIL" ) reasons.push( "Non-eligible SKU" );
if( data.distributorRestriction == "FAIL" ) reasons.push( "Non-eligible Distributor" );
if( data.segmentRestriction == "FAIL" ) reasons.push( "Non-eligible Segment" );
if( data.memberGroupRestriction == "FAIL" ) reasons.push( "Non-eligible Member Group" );
if( data.memberGroupRestriction == "FAIL" ) reasons.push( "Non-eligible Member Group" );
if( data.classificationRestriction == "FAIL" ) reasons.push( "Non-eligible Classification" );
if( data.priorityRestriction == "FAIL" ) reasons.push( "Non-eligible Priority" );
}
value = reasons.join( ", " );
} else {
if( data.existingObjectiveTarget == "Y" ) {
value = "Existing Target new SKU";
}
}
return value;
}}
// "productRestriction", "distributorRestriction", "segmentRestriction", "memberGroupRestriction", "classificationRestriction", "priorityRestriction"
]
})
}
}).appendTo( $("body") ).dxPopup( "instance" );
popup.show();
}
OperatorVoidMatrix.prototype._select = function( skuId, volumeIdentifier, selected ) {
let instance = this;
let objectParams = {
searchSeq : instance.searchSeq,
picker : {
mode : selected ? 1 : 0,
skuId : skuId,
volumeIdentifier : volumeIdentifier
}
}
let matrixDataSource= Fse.Data.newDataSource( { object : "OPR.voidMatrix", key : "skuId", paginate : false, objectParams : objectParams } );
return matrixDataSource.load().done( function( selections ) {
instance.purchasingPromises = {};
instance.selections = {};
let selectedCount = 0;
selections.forEach( function( selection ) {
instance.selections[selection.selectionKey] = true;
selectedCount++;
})
instance.stats.selectedCount = selectedCount;
instance._updateSelectionCount();
instance._activateCallButtons();
})
}
OperatorVoidMatrix.prototype._applyBulkSelection = function( mode, options ) {
let instance = this;
let objectParams = {
searchSeq : instance.searchSeq,
picker : {
stockingStatus : 'N',
memberGroupApproved : 'N',
territoryTopSKU : 0,
segmentTopSKU : 0,
highlyProfitable : -1,
excludeNoSale : "N",
excludeSale : "N",
mode : mode
}
}
instance.lastPickFormData = options;
if( mode == -1 ) {
instance.lastPickFormData = {}
}
if( instance.lastPickFormData.stocked ) {
objectParams.picker.stockingStatus = 'Y'
}
if( instance.lastPickFormData.approved ) {
objectParams.picker.memberGroupApproved = 'Y'
}
if( instance.lastPickFormData.territoryTop50 ) {
objectParams.picker.territoryTopSKU = 1;
}
if( instance.lastPickFormData.segmentTop50 ) {
objectParams.picker.segmentTopSKU = 1;
}
if( instance.lastPickFormData.profitable ) {
objectParams.picker.highlyProfitable = instance.lowProfitabilityRankThreshold;
}
if( instance.lastPickFormData.excludeSale ) {
objectParams.picker.excludeSale = "Y";
}
if( instance.lastPickFormData.excludeNoSale ) {
objectParams.picker.excludeNoSale = "Y";
}
let loadPanel = $("
").dxLoadPanel( {
message : "Updating selections...",
onHidden : function( e ) {
e.component.element().remove();
}
}).appendTo( $("body") ).dxLoadPanel("instance");
loadPanel.show();
let matrixDataSource= Fse.Data.newDataSource( { object : "OPR.voidMatrix", key : "skuId", paginate : false, objectParams : objectParams } );
return matrixDataSource.load().done( function( selections ) {
instance.purchasingPromises = {};
instance.selections = {};
let selectedCount = 0;
selections.forEach( function( selection ) {
instance.selections[selection.selectionKey] = true;
selectedCount++;
})
instance.stats.selectedCount = selectedCount;
instance.dataGrid.refresh();
instance._updateSelectionCount();
instance._activateCallButtons();
loadPanel.hide();
})
}
OperatorVoidMatrix.prototype._resetAll = function() {
let instance = this;
instance.searchParams = $.extend( true, {}, instance.initialSearchParams );
instance.refresh();
}
OperatorVoidMatrix.prototype.createBreadcrumbs = function() {
let instance = this;
instance.breadcrumbs = new Breadcrumbs( {
onRemove : function( p ) {
// let copySearchParams = $.extend( true, {}, instance.searchParams );
// delete copySearchParams[p];
// // handle any dependent search params
// if( p == "mfr_id" ) {
// delete copySearchParams.productHierarchyPath;
// }
// instance.searchParams = copySearchParams;
instance.showFilters();
},
onOpen : function( p ) {
instance.showFilters();
},
items : [
// first column from search center
{ searchParam : "operatorId",
hint : "OperatorId",
dataObject : { name : "CRM.operatorList", key : "operatorId" },
displayExpr : "companyName",
multipleDisplay : "Multiple Operators",
removable : false
},
{
searchParam : "displayCompanyType", removable : false, displayExpr : function( v ) {
let store = new DevExpress.data.ArrayStore( {
data : [
{ displayCompanyType : "Independent" },
{ displayCompanyType : "Chain HQ" },
{ displayCompanyType : "Unit" }
],
key : "displayCompanyType"
});
let text = null;
store.byKey( v ).done( function( data ) { text = data.displayCompanyType } );
return text;
}
},
{ searchParam : "clientSegPath", removable : false, hint : "Segment", displayExpr : "segmentPath", multipleDisplay : "Multiple Segments", dataObject : { name : "OPR.segments" , key : "clientSegPath" }},
{ searchParam : "classificationId", removable : false, hint : "Classification", displayExpr : "name", multipleDisplay : "Multiple Classifications", dataObject : { name : "OPR.classifications" , key : "classificationId" }},
{ searchParam : "priority", displayExpr : function( v ) {
let values = v;
if( ! Array.isArray( values ) ) {
values = [values];
}
let displayValues = [];
values.forEach( function( priorityValue ) {
if( priorityValue == "*" ) {
displayValues.push( "A+" )
} else {
displayValues.push( priorityValue )
}
})
return displayValues.join( "," );
}},
// middle column from search center
{ searchParam : "territoryPath", removable : false, hint : "Territory", multipleDisplay : "Multiple Territories", dataObject : { name : "TER.salesTerritories", key : "territoryPath" }, displayExpr : "territoryPath" },
{ searchParam : "salesRepId", removable : false, hint : "Account Owner", multipleDisplay : "Multiple Account Owners", dataObject : { name : "CRM.salesRepList", key : "fspro_userId" }, displayExpr : "fullName" },
{ searchParam : "cdr_dstPath", removable : false, hint : "Distributor", multipleDisplay : "Multiple Distributors", dataObject : { name : "CDR.distributors", key : "cdr_dstPath" }, displayExpr : "cdr_dstPath" },
{ searchParam : "gpoId", removable : false, hint : "GPO", multipleDisplay : "Multiple GPOs", dataObject : { name : "OPR.memberGroups", key : "operatorId"}, displayExpr : "companyName" },
{ searchParam : "noGPO", removable : false, displayExpr : function( ) {
return "No GPO"
}},
{ searchParam : "cmcId", removable : false, hint : "CMC", multipleDisplay : "Multiple CMCs", dataObject : { name : "OPR.memberGroups", key : "operatorId"}, displayExpr : "companyName" },
{ searchParam : "noCMC", removable : false, displayExpr : function( ) {
return "Self Managed"
}},
{ searchParam : "operatorListId", removable : false, hint : "List", multipleDisplay : "Multiple Lists", dataObject : { name : "LST.lists", key : "listId"}, displayExpr : "listName" },
{ searchParam : "focusProducts", removable : false, displayExpr : function( v ) {
return "Focus Products";
}},
{ searchParam : "mfr_id", removable : false, hint : "Manufacturer", multipleDisplay : "Multiple Manufacturers", dataObject : { name : "PRD.manufacturers", key : "mfr_id" }, displayExpr : "mfr_name" },
{ searchParam : "productHierarchyPath", removable : false, hint : "Product", multipleDisplay : "Multiple Products", dataObject : { name : "PRD.productHierarchyPaths", key : "productHierarchyPath" }, displayExpr : "productHierarchyPath" },
{
searchParam : "topCount",removable : false,
displayExpr : function( v ) {
return `Top ${v} SKUs`
}
},
{ searchParam : "productSetTags", removable : false, hint : "Product Set", multipleDisplay : "Multiple Product Sets", dataObject : { name : "PRD.productSets", key : "productSetTag" }, displayExpr : "productSetName" },
],
debug : true
})
//instance.rootElement.append( instance.breadcrumbs.element().css( { "padding-top" : "5px" } ) );
instance.breadcrumbs.element().css( { "padding-top" : "5px" } );
}
OperatorVoidMatrixSearch = function( searchOptions ) {
let searchOptionDefaults = {
applySearch : function( searchParams ) {
// default does nothing, caller must override
},
showOperatorFilters : true
};
this.filterPreferences = {}; // scrum 46030
this.searchOptions = $.extend( true, {}, searchOptionDefaults, searchOptions )
this.dxForm = null
this.dxPopup = null;
// this.init(); // scrum 46030
}
OperatorVoidMatrixSearch.prototype.constructor = OperatorVoidMatrixSearch;
/* scrum 46030
OperatorVoidMatrixSearch.prototype.init = function() {
this.createPopup();
}
*/
OperatorVoidMatrixSearch.prototype.createForm = function() {
let instance = this;
let group3Items = [
{ template : function() { return $("
").append( "Product" ).css( { "text-align": "center", "font-size" : "larger" } ) } }
];
let showMFR = Fse.Portal.appConfiguration.STP.ownerType !== "MFR";
let showBRO = Fse.Portal.appConfiguration.STP.ownerType === "MFR";
let showStaffType = Fse.Portal.appConfiguration.STP.ownerType === "MFR";
if( showMFR ) {
group3Items.push(
{ dataField : "mfr_id", label : { location : "left", text : "Manufacturer" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.mfr_id ? 'fx-active-preference' : null, // scrum 46030
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "PRD.manufacturers", key : "mfr_id" } ),
searchExpr : "mfr_name",
searchMode : "contains",
displayExpr : "mfr_name",
multipleSelectedDisplay : "Multiple Manufacturers Selected",
keyExpr : "mfr_id",
title : "Select Manufacturer"
})
});
}
group3Items.push(
{ dataField : "productHierarchyPath", label : { location : "left", text : "Product" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.productHierarchyPath ? 'fx-active-preference' : null, // scrum 46030
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "PRD.productHierarchyPaths", key : "productHierarchyPath", objectParams : { "crmActive" : "Y" } } ),
searchExpr : "productHierarchyPath",
searchMode : "contains",
displayExpr : "productHierarchyPath",
multipleSelectedDisplay : "Multiple Product Hierarchy Paths Selected",
keyExpr : "productHierarchyPath",
title : "Select Product Hierarchy Path",
searchTemplate : function( applyFilters ) {
return Fse.UI.productHierarchyPathMultiSelectSearchTemplate( applyFilters )
}
})
},
{
dataField : "productSetTags", label : { location : "left", text : "Product Set" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.productSetTags ? 'fx-active-preference' : null,
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "PRD.productSets", keyField : "productSetTag" } ),
searchExpr : "productSetName",
searchMode : "contains",
displayExpr : "productSetName",
multipleSelectedDisplay : "Multiple Product Sets Selected",
keyExpr : "productSetTag",
title : "Select Product Set"
})
}
);
group3Items.push(
//focus items
{ dataField : "focusProduct", label : { location : "left", text : "Focus Items" }, editorType : "dxSwitch"}
);
group3Items.push(
{
dataField : "topCount",
label : { text : "Top X SKUs" },
editorType : "dxSelectBox",
editorOptions : {
items : [
{ value : 10, text : "10" },
{ value : 25, text : "25" },
{ value : 50, text : "50" },
{ value : 75, text : "75" },
{ value : 100, text : "100" },
{ value : 150, text : "150" },
{ value : 200, text : "200" }
],
valueExpr : "value",
displayExpr : "text",
value : 25
}
}
// ,
// {
// dataField : "rankBy",
// label : { text : "Ranked By" },
// editorType : "dxSelectBox",
// editorOptions : {
// items : [
// { value : "volume", text : "volume"}
// ],
// displayExpr : "text",
// valueExpr : "value",
// value : "volume"
// }
// }
)
group2Items = [];
group2Items.push(
// start group 2 items
{ template : function() { return $("
").append( "Operator" ).css( { "text-align": "center", "font-size" : "larger" } ) } },
// territoryId
{ dataField : "territoryPath", label : { location : "left", text : "Territory" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.territoryPath ? 'fx-active-preference' : null, // scrum 46030
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "TER.salesTerritories", key : "territoryPath" } ),
searchExpr : "territoryPath",
searchMode : "contains",
displayExpr : "territoryPath",
multipleSelectedDisplay : "Multiple Territories Selected",
keyExpr : "territoryPath",
title : "Select Territories"
})
}
);
// if( showBRO ) {
// group2Items.push(
// // broker_id
// { dataField : "broker_id", label : { location : "left", text : "Broker" }, editorType : "dxDropDownBox",
// editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
// dataSource : Fse.Data.newDataSource( { object : "MFR.brokers", key : "broker_id" } ),
// searchExpr : "broker_name",
// searchMode : "contains",
// displayExpr : "broker_name",
// multipleSelectedDisplay : "Multiple Brokers Selected",
// keyExpr : "broker_id",
// title : "Select Brokers"
// })
// });
// }
group2Items.push(
//sales rep
{ dataField : "salesRepId", label : { location : "left", text : "Sales Rep" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.salesRepId ? 'fx-active-preference' : null, // scrum 46030
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "CRM.salesRepList", key : "valueId" } ),
searchExpr : "valueName",
searchMode : "contains",
displayExpr : "valueName",
multipleSelectedDisplay : "Multiple Sales Reps Selected",
keyExpr : "valueId",
title : "Select Sales Reps"
})
}
// , {
// dataField : "excludeDeletedSalesReps", label : { text : "Exclude Inactive & Deleted Sales Reps" },
// editorType : "dxSwitch"
// }
)
// if( showStaffType ) {
// group2Items.push(
// {
// dataField: "salesRepOwnerType", label : { location : "left", text : "Staff Type" }, editorType : "dxSelectBox",
// cssClass : instance.activeFilterPreferences.salesRepOwnerType ? 'fx-active-preference' : null,
// editorOptions : {
// showClearButton : true,
// placeholder : "Select Staff Type",
// dataSource : { store : { type : "array", key : "value", data : [
// {
// value : "MFR", text : "Manufacturer Staff Only"
// },
// {
// value : "BRO", text : "Broker Staff Only"
// }
// ]}},
// valueExpr : "value",
// displayExpr : "text"
// }
// }
// )
// }
const priorityTypes = [
{"prioritycode":"*","desc":"A+"},
{"prioritycode":"A","desc":"A"},
{"prioritycode":"B","desc":"B"},
{"prioritycode":"C","desc":"C"},
{"prioritycode":"D","desc":"D"}
];
const displayCompanyTypes = [
{ displayCompanyType : "Chain HQ" },
{ displayCompanyType : "Independent" },
{ displayCompanyType : "Unit" }
// { displayCompanyType : "GPO" },
// { displayCompanyType : "CMC" },
// { displayCompanyType : "Holding" },
];
group2Items.push(
// distributor hierarchy
{ dataField : "cdr_dstPath", label : { location : "left", text : "Distributor" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( {object : "CDR.distributorsLight", key : "cdr_dstPath" } ),
searchExpr : "cdr_dstPath",
searchMode : "contains",
displayExpr : "cdr_dstPath",
multipleSelectedDisplay : "Multiple Distributors Selected",
keyExpr : "cdr_dstPath",
title : "Select Distributors"
})
},
// { dataField : "displayCompanyType", label : { text : "Type" },
// editorType : "dxSelectBox",
// editorOptions : {
// dataSource : { store : { type : "array", data : displayCompanyTypes, key : "displayCompanyType" }},
// displayExpr : "displayCompanyType",
// valueExpr : "displayCompanyType",
// showClearButton : true,
// placeholder : "Select Company Type"
// }
// },
{ dataField : "displayCompanyType", label : { location : "left", text : "Type" }, editorType : "dxDropDownBox",
editorOptions : {
placeholder : "Select Company Type...",
dataSource : {
store : {
type : "array",
data : displayCompanyTypes,
key : "displayCompanyType"
}
},
valueExpr : "displayCompanyType", displayExpr : "displayCompanyType",
contentTemplate : function( e ) {
const v = e.component.option( "value" );
const $list = $("
").dxList( {
dataSource : e.component.getDataSource(),
displayExpr : "displayCompanyType",
selectionMode: "all",
showSelectionControls : true,
selectedItemKeys : v,
onSelectionChanged : function( sce ) {
const keys = sce.component.option( "selectedItemKeys" );
e.component.option( "value", keys );
}
})
const list = $list.dxList('instance');
e.component.on('valueChanged', (args) => {
const { value } = args;
list.option( "selectedItemKeys", value );
});
return $list;
}
}
},
{ dataField : "operatorId", label : { location : "left", text : "Operator" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "CRM.operatorList", keyField : "operatorId", filter : [[ "oprCompanyType", '=', '0' ], "or", [ "oprCompanyType", '=', '1' ]] } ),
searchExpr : "companyName",
searchMode : "contains",
displayExpr : "companyName",
multipleSelectedDisplay : "Multiple Operators Selected",
keyExpr : "operatorId",
title : "Select Operator"
})
},
//segments
{ dataField : "clientSegPath", label : { location : "left", text : "Segment" }, editorType : "dxDropDownBox",
cssClass : instance.activeFilterPreferences.clientSegPath ? 'fx-active-preference' : null, // scrum 46030
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "OPR.segments", key : "clientSegPath" } ),
searchExpr : "clientSegPath",
searchMode : "contains",
displayExpr : "clientSegPath",
multipleSelectedDisplay : "Multiple Segments Selected",
keyExpr : "clientSegPath",
title : "Select Segments"
})
},
{ dataField : "priority", label : { location : "left", text : "Priority" }, editorType : "dxDropDownBox",
editorOptions : {
placeholder : "Select Priority",
dataSource : new DevExpress.data.ArrayStore({
data: 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;
}
}
},
{ dataField : "classificationId", label : { text : "Classification" },
editorType : "dxDropDownBox", editorOptions : $.extend( true, {
multiSelectOptions : {
dataSource : Fse.Data.newDataSource( { object : "OPR.classifications", key : "classificationId" }),
keyExpr: "classificationId",
displayExpr : "description",
searchExpr : "description",
searchMode : "contains",
multipleSelectedDisplay : "Multiple Classifications selected",
title : "Select Classifications"
}
}, multiSelectEditorOptions )
},
{ dataField : "gpoId", colSpan : 2, label : { location : "left", text : "GPO" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "OPR.memberGroups", key : "operatorId", objectParams : { "oprCompanyType" : "G" } } ),
searchExpr : "companyName",
searchMode : "contains",
displayExpr : "companyName",
multipleSelectedDisplay : "Multiple GPOs Selected",
keyExpr : "operatorId",
title : "Select GPOs"
})
},
{ dataField : "noGPO", label : { text : "No GPO" }, editorType : "dxSwitch" },
{ dataField : "cmcId", colSpan : 2, label : { location : "left", text : "CMC" }, editorType : "dxDropDownBox",
// cssClass : instance.activeFilterPreferences.clientSegPath ? 'fx-active-preference' : null,
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "OPR.memberGroups", key : "operatorId", objectParams : { "oprCompanyType" : "C" } } ),
searchExpr : "companyName",
searchMode : "contains",
displayExpr : "companyName",
multipleSelectedDisplay : "Multiple CMCs Selected",
keyExpr : "operatorId",
title : "Select CMCs"
})
},
{ dataField : "noCMC", label : { text : "Self Managed" }, editorType : "dxSwitch" },
/*
let operatorListsDataSource = Fse.Data.newDataSource( { object : "LST.lists", keyField : "listId", objectParams : { includeStatus : false, partnerTypes : "OPR" }});
operatorListsDataSource.filter( [[[ "published", "=", 1 ], "and", [ "forSearch", "=", 1 ]], "or" , [ "creator", "=", 1 ], "or", [ "contributor", "=", 1 ]]]);
*/
{
dataField : "operatorListId", label : { location : "left", "text" : "Operator List" }, editorType : "dxSelectBox", editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "LST.lists", filter : [[[ "published", "=", 1 ], "and", [ "forSearch", "=", 1 ]], "or" , [ "creator", "=", 1 ], "or", [ "contributor", "=", 1 ]], key : "listId", objectParams : { includeStatus : false, partnerTypes : "OPR" }}),
displayExpr : "listName",
searchEnabled : true,
searchExpr : "listName",
valueExpr : "listId",
placeholder : "Select",
showClearButton : true
}
}
);
// let group1Items = [];
// group1Items.push(
// { template : function() { return $("
").append( "Options" ).css( { "text-align": "center", "font-size" : "larger" } ) } },
// { dataField : "whitespace", label : { location : "left", text : "Whitespace" }, editorType : "dxSwitch",
// editorOptions: {
// value: false
// }
// },
// { dataField : "ytdPurchasing", label : { location : "left", text : "YTD Purchasing" }, editorType : "dxSwitch",
// editorOptions: {
// value: false
// }
// },
// { dataField : "activeOpportunities", label : { location : "left", text : "Active Opportunities" }, editorType : "dxSwitch",
// editorOptions: {
// value: false
// }
// },
// { dataField : "oneFSRecommended", label : { location : "left", text : "1FS Recommended" }, editorType : "dxSwitch",
// editorOptions: {
// value: false
// }
// }
// );
let formItems = [];
if( instance.searchOptions.showOperatorFilters ) {
formItems.push(
// TERRITORY (AND CUSTOMER)
{ name: "group2", itemType : "group", colCount : 1,
items : group2Items
}
)
}
formItems.push(
// product filters
{ name: "group3", itemType : "group", colCount : 1,
items :group3Items
}
)
instance.dxForm = $("
").dxForm( {
width : "100%",
colCount : instance.searchOptions.showOperatorFilters ? 2 : 1,
items : formItems,
onFieldDataChanged : function ( e ) {
// setObjPathFilter = function( mfr_id, territoryPath ) {
// let objPathEditor = e.component.getEditor( "objPath" );
// let objPathFilters = [];
// if( mfr_id ) {
// if( ! Array.isArray( mfr_id )) {
// mfr_id = [mfr_id];
// }
// objPathFilters.push( [ "objOwnerType", "=", "MFR" ] )
// let objOwnerIdFilter = [];
// objPathFilters.push( "and", objOwnerIdFilter );
// mfr_id.forEach( function( mfr_id_v ) {
// if( objOwnerIdFilter.length ) {
// objOwnerIdFilter.push( "or" );
// }
// objOwnerIdFilter.push( [ "objOwnerId", "=", mfr_id_v ] );
// })
// }
// if( territoryPath ) {
// if( ! Array.isArray( territoryPath )) {
// territoryPath = [territoryPath];
// }
// territoryPathFilters = [];
// territoryPath.forEach( function( territoryPath_v ) {
// if( territoryPathFilters.length ) {
// territoryPathFilters.push( "or" );
// }
// territoryPathFilters.push( [ "territoryPath", "startswith", territoryPath_v ] );
// })
// if( objPathFilters.length ) {
// objPathFilters = [ objPathFilters, "and", territoryPathFilters ];
// } else {
// objPathFilters = territoryPathFilters;
// }
// }
// console.log( "objPathFilters" );
// console.log( objPathFilters );
// objPathEditor.option( "availableFilter", objPathFilters );
// }
if( e.dataField ) {
if( e.dataField === "territoryPath" ) {
let mfrValue = null;
let mfrEditor = e.component.getEditor( "mfr_id" );
if( mfrEditor ) {
mfrValue = mfrEditor.option( "value" );
}
//setObjPathFilter( mfrValue, e.value );
}
if( e.dataField === "mfr_id" ) {
let fields = []
fields.push( e.component.getEditor( "productHierarchyPath" ) );
// fields.push( e.component.getEditor( "budgetCategoryMgr_fspro_userId" ) );
// fields.push( e.component.getEditor( "budgetCategoryId" ) );
fields.push( e.component.getEditor( "brandId" ) );
let fieldOptions = {
value : null
};
if( e.value && e.value != "") {
fieldOptions.disabled = true;
} else {
fieldOptions.disabled = false;
}
fields.forEach( function( f ) {
if( f ) {
f.option( fieldOptions );
}
})
// let territoryPathEditor = e.component.getEditor( "territoryPath" );
//setObjPathFilter( e.value, territoryPathEditor.option( "value" ) );
/*
let objPathEditor = e.component.getEditor( "objPath" );
let objPathFilters = [];
if( e.value ) {
objPathFilters.push( [ "objOwnerType", "=", "MFR" ] )
let objOwnerIdFilter = [];
objPathFilters.push( "and", objOwnerIdFilter );
let v = e.value;
if( ! Array.isArray( v ) ) {
v = [v];
}
v.forEach( function( vv ) {
if( objOwnerIdFilter.length ) {
objOwnerIdFilter.push( "or" );
}
objOwnerIdFilter.push( [ "objOwnerId", "=", vv ] );
})
}
console.log( "objPathFilters" );
console.log( objPathFilters );
objPathEditor.option( "availableFilter", objPathFilters );
*/
}
}
}
}).dxForm("instance");
}
OperatorVoidMatrixSearch.prototype.createPopup = function() {
let instance = this;
instance.createForm();
let bottomToolbarItems = [
{ toolbar : "bottom",
location : "after",
widget : "dxButton", options : { text : "search",
type : "default",
onClick : function( e ) {
let vr = DevExpress.validationEngine.validateGroup( "OperatorVoidMatrixFilters" );
console.log( vr );
if( ! vr.isValid ) return;
let applySearch = instance.searchOptions.applySearch;
let searchParams = instance.dxForm.option( "formData" );
instance.dxPopup.hide();
applySearch( searchParams );
}
}
}
];
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 : "Void Search",
width : "50vw",
height : "auto",
contentTemplate : function() {
let content = $("
").append( instance.dxForm.element());
$("
").dxValidator({ validationGroup : "OperatorVoidMatrixFilters",
adapter : {
getValue : function() {
return instance.dxForm.option( "formData" );
},
applyValidationResults : function( vr ) {
console.log( "applyValidationResults", vr );
if( ! vr.isValid ) {
$("
").dxToast( {
message : vr.brokenRule.message,
displayTime : 2000,
type : "error",
position : { of : instance.dxPopup.element() },
onHidden : function( e ) {
e.component.element().remove();
e.component.dispose();
}
}).appendTo( $("body") ).dxToast("show")
}
}
},
validationRules : [
{ type : "custom",
message : instance.searchOptions.showOperatorFilters ? "At least one Operator filter and at least one Product filter is required" : "At least on Product filter is required",
reevaluate : true,
validationCallback : function( validate ) {
let value = validate.value;
let productValid = ( value.focusProduct || ( value.productSetTags && value.productSetTags.length ) || ( value.productHierarchyPath && value.productHierarchyPath.length )) ? true : false;
let operatorValid = false;
if( instance.searchOptions.showOperatorFilters ) {
operatorValid = (
( value.territoryPath && value.territoryPath.length ) ||
( value.salesRepId && value.salesRepId.length ) ||
( value.cdr_dstPath && value.cdr_dstPath.length ) ||
( value.clientSegPath && value.clientSegPath.length ) ||
( value.priority && value.priority.length ) ||
( value.classificationId && value.classificationId.length ) ||
( value.gpoId && value.gpoId.length ) ||
( value.noGPO ) ||
( value.cmcId && value.cmcId.length ) ||
( value.noCMC ) ||
( value.operatorListId ) ||
( value.operatorId )
) ? true : false;
} else {
operatorValid = true;
}
let isValid = operatorValid && productValid;
return isValid;
}
}
]
} ).appendTo( content );
return content;
},
toolbarItems : bottomToolbarItems,
// on hidden added to cleanup ui objects - scrum 46030
onHidden : function( e ) {
// clean up
e.component.element().remove();
instance.dxForm.dispose();
instance.dxForm = null;
instance.dxPopup.dispose();
instance.dxPopup = null;
}
}).appendTo( "body" ).dxPopup("instance");
}
// scrum 46030
OperatorVoidMatrixSearch.prototype.show = function( searchParams, filterPreferences ) {
this.processFilterPreferences( filterPreferences, searchParams );
console.log("searchParams");
console.log(searchParams);
this.createPopup();
if( searchParams ) {
this.dxForm.updateData( searchParams );
}
this.dxPopup.show();
}
OperatorVoidMatrixSearch.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",
//focusProduct : "focusProduct",
//budgetCategoryId : "budgetCategoryId",
productHierarchyPath : "productHierarchyPath",
mfr_id : "mfr_id",
clientSegPath : "clientSegPath",
//salesRepOwnerType : "staffType",
productSetTags : "productSetTags"
}
return preferenceableFilters;
}
OperatorVoidMatrixSearch.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 );
}