CampaignSearch = function() {
this.dataURL = $("link#appDataURL").attr( "href" );
this.statusTypes = [
{"statusCode":"ACTIVE","desc":"Currently Active"},
{"statusCode":"FUTURE","desc":"Future Campaigns"},
{"statusCode":"CURRENT","desc":"Current Year"}
];
}
CampaignSearch.prototype.constructor = CampaignSearch;
CampaignSearch.prototype.show = function( options ) {
// for testing and debug
console.log( options );
let instance = this;
const mfrDropDown = { dataField : "mfr_id",
label : { location : "left", text : "Manufacturer" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "PRD.manufacturers", keyField : "mfr_id" } ),
searchExpr : "mfr_name",
searchMode : "contains",
displayExpr : "mfr_name",
multipleSelectedDisplay : "Multiple Manufacturers Selected",
keyExpr : "mfr_id",
title : "Select Manufacturer",
disabled : true
})
};
let form = $( "
").dxForm( {
formData : options.searchParams,
colCount : 2,
items : [{
name: "group1", itemType : "group", colCount : 1,
items : [ // start group 1 items
{ dataField : "campaignEnabled", label : { location : "left", text : "Campaign Enabled" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : {
store : { type : "array",
data : [
{ text : "Yes", campaignEnabled : "Y" },
{ text : "No", campaignEnabled : "N" }
],
key : "campaignEnabled"
}
},
showClearButton : true,
placeholder: "Select Campaign Enabled",
displayExpr: "text",
searchEnabled : true,
searchMode : "startswith",
searchExpr : "text",
valueExpr: "campaignEnabled"
}
},
/* { dataField : "campaignEnabled", editorType : "dxRadioGroup", editorOptions : {
items : [
{ text : "Yes", campaignEnabled : "Y" },
{ text : "No", campaignEnabled : "N" }
],
valueExpr : "campaignEnabled",
displayExpr : "text",
layout : "horizontal"
}},*/
{ dataField : "businessOwnerType", label : { location : "left", text : "Business Owner Type" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : {
store : { type : "array",
data : [
{ text : "Manufacturer", businessOwnerType : "MFR" },
{ text : "Int", businessOwnerType : "INT" }
],
key : "businessOwnerType"
}
},
showClearButton : true,
placeholder: "Select Business Owner Type",
displayExpr: "text",
searchEnabled : true,
searchMode : "startswith",
searchExpr : "text",
valueExpr: "businessOwnerType",
onValueChanged(e) {
alert(e.value);
if (e.value === 'MFR') {
alert("hello");
//form.itemOption('HomeAddress', 'visible', true);
mfrDropDown.option("disabled",false);
}
}
}
},
{ dataField : "campaignManagerUserId", label : { location : "left", text : "Campaign Manager" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { object : "CRM.salesRepList", keyField : "fspro_userId", paginate : true, objectParams : { staffOnly : true } } ),
searchExpr : "valueName",
searchMode : "contains",
displayExpr : "valueName",
multipleSelectedDisplay : "Multiple Campaign ManagerS Selected",
keyExpr : "valueId",
title : "Select Campaign Managers"
})
},
{ dataField : "campaignGroupId", label : { location : "left", text : "Campaign Group" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "GTM.allCampaignGroups", keyField : "campaignGroupId" } ),
searchExpr : "campaignGroup",
searchMode : "contains",
displayExpr : "campaignGroup",
multipleSelectedDisplay : "Multiple Campaign Groups Selected",
keyExpr : "campaignGroupId",
title : "Select Campaign Groups"
})
},
/*
{ dataField : "territoryId", label : { location : "left", text : "Top Level Territory" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "GTM.campaigns", keyField : "territoryPath" } ),
searchExpr : "territoryName",
searchMode : "contains",
displayExpr : "territoryName",
multipleSelectedDisplay : "Multiple Territories Selected",
keyExpr : "territoryPath",
title : "Select Territories"
})
},*/
{ dataField : "territoryPath", label : { location : "left", text : "Top Level Territory" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "TER.salesTerritories", keyField : "territoryPath" } ),
searchExpr : "territoryPath",
searchMode : "contains",
displayExpr : "territoryPath",
multipleSelectedDisplay : "Multiple Territories Selected",
keyExpr : "territoryPath",
title : "Select Territories"
})
},
{
dataField : "salesManagerUserId", label : { text : "Sales Mgr." }, isRequired : false, editorType : "dxSelectBox", editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "CRM.salesRepList", keyField : "fspro_userId", paginate : true, objectParams : { staffOnly : true } } ),
valueExpr : "fspro_userId",
displayExpr : "fullName",
searchEnabled : true,
searchExpr : "fullName",
searchMode : "contains",
showClearButton : true
}
}
]},
{
name: "group2", itemType : "group",
items : [
/*{ dataField : "campaignName", editorType : "dxTextBox", editorOptions : {
valueExpr : "campaignName",
displayExpr : "text",
layout : "horizontal"
}
},*/
{ dataField : "targetPartnerType", label : { location : "left", text : "Target Type" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : {
store : { type : "array",
data : [
{ text : "Operator", targetPartnerType : "OPR" },
{ text : "Distributor", targetPartnerType : "CDR" }
],
key : "targetPartnerType"
}
},
showClearButton : true,
placeholder: "Select Target Type",
displayExpr: "text",
searchEnabled : true,
searchMode : "startswith",
searchExpr : "text",
valueExpr: "targetPartnerType"
}
},
{ dataField : "leadType", label : { location : "left", text : "Lead Type" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : {
store : { type : "array",
data : [
{ text : "Sales", leadType : "SALES" },
{ text : "Task", leadType : "TASK" }
],
key : "leadType"
}
},
showClearButton : true,
placeholder: "Select Lead Type",
displayExpr: "text",
searchEnabled : true,
searchMode : "startswith",
searchExpr : "text",
valueExpr: "leadType"
}
},
{
dataField : "campaignTypeId", label : { text : "Campaign Type" }, editorType : "dxSelectBox", isRequired : false, editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "GTM.allCampaignTypes", keyField : "campaignTypeId", paginate : false } ),
displayExpr : "campaignType",
valueExpr : "campaignTypeId",
showClearButton : true
}
},
/* { dataField : "productSpecific", label : { location : "left", text : "Product Specific" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : {
store : { type : "array",
data : [
{ text : "Yes", productSpecific : "Y" },
{ text : "No", productSpecific : "N" }
],
key : "productSpecific"
}
},
showClearButton : true,
placeholder: "Select Product Specific",
displayExpr: "text",
searchEnabled : true,
searchMode : "startswith",
searchExpr : "text",
valueExpr: "productSpecific"
}
},*/
{ dataField : "campaignStatus", label : { location : "left", text : "Status" }, editorType : "dxDropDownBox",
editorOptions : {
placeholder : "Select Status",
dataSource : new DevExpress.data.ArrayStore({
data: instance.statusTypes,
key: "statusCode"
}) ,
valueExpr : "statusCode", 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;
}
}
}
]
} // end group 1
]
}).dxForm( "instance" );
let popup = $("
").dxPopup( {
title : "Campaign Search",
onHidden : function( e ) {
popup.element().remove();
popup.dispose();
form.dispose();
},
contentTemplate : function() {
return form.element()
},
toolbarItems : [
{ toolbar : "bottom", location : "after",
widget : "dxButton", options : {
text : "close",
onClick : function( be ) {
popup.hide();
}
}
},
{ toolbar : "bottom", location : "after",
widget : "dxButton", options : {
text : "search",
onClick : function( be ) {
let searchParams = $.extend( true, {}, form.option( "formData" ));
options.onSearch( searchParams );
popup.hide();
}
}
}
]
}).appendTo( "body" ).dxPopup("instance");
popup.show();
}