DistributorSearch = function( searchOptions ) { let searchOptionDefaults = { applySearch : function( searchParams ) { console.log('this', this) } }; this.searchOptions = $.extend( true, {}, searchOptionDefaults, searchOptions ) this.dataURL = $("link#appDataURL").attr( "href" ), this.dxBasicForm = null; this.dxFlexFieldForm = null; this.dxPopup = null; this.popupPromise = null; this.filterPreferences = {}; // scrum 46030 this.priorityTypes = [ {"prioritycode":"*","desc":"A+"}, {"prioritycode":"A","desc":"A"}, {"prioritycode":"B","desc":"B"}, {"prioritycode":"C","desc":"C"}, {"prioritycode":"D","desc":"D"} ]; //year :previous,current,next this.orderDateYears = [ {"orderYear":getOrderDateYear(-1),"desc":getOrderDateYear(-1)}, {"orderYear":getOrderDateYear(0),"desc":getOrderDateYear(0)}, {"orderYear":getOrderDateYear(1),"desc":getOrderDateYear(1)}, ]; // scrum 46030 - this.init(); } getOrderDateYear = function( num ){ let x = new Date().getFullYear()+num; return x; } DistributorSearch.prototype.constructor = DistributorSearch; DistributorSearch.prototype.createFlexFieldForm = function() { let instance = this; let flexData = { flexFields : null, flexTabs : null } let flexDataPromise = $.Deferred(); flexDataPromise.progress( function( notify ) { flexData[notify.dataField] = notify.value; if( flexData.flexFields && flexData.flexTabs ) { flexData.flexTabs.forEach( function( ft ) { let tabCategories = []; ft.categories.forEach( function( ftc ) { tabCategories.push( ftc.name ); }) ft.fields = []; let remainingFields = []; flexData.flexFields.forEach( function( ff ) { if( tabCategories.includes( ff.category )) { ft.fields.push( ff ); } else { remainingFields.push( ff ) } }) flexData.flexFields = remainingFields; }) if( flexData.flexFields.length ) { let detailFlexTab = { displayName : "Basic Profile", fields : flexData.flexFields } flexData.flexTabs.unshift( detailFlexTab ); } console.log( flexData.flexTabs ); flexDataPromise.resolve( flexData.flexTabs ); } }) let tabsDS = Fse.Data.newDataSource( { object : "CDR.flexTabs", paginate : false, keyField : "displayName", objectParams : { cdr_recordId : 0 } } ); tabsDS.load().done( function( flexTabs ) { flexDataPromise.notify( { dataField : "flexTabs", value : flexTabs } ); console.log( "FlexTabs", flexTabs ); }) let customDS = Fse.Data.newDataSource( { object : "CDR.flexFields", paginate : false, key : "fieldId" } ); customDS.filter( [ "searchable", "=", "Y" ] ); customDS.load().done( function( flexFields ) { flexDataPromise.notify( { dataField : "flexFields", value : flexFields } ); console.log( "flexFields", flexFields ); }); flexDataPromise.done( function( flexTabs ) { instance.dxFlexFieldForm = null; if( flexTabs.length ) { let items = []; let marginTopCSSValue = "0px"; flexTabs.forEach( function( flexTab ) { if( flexTab.fields.length == 0 ) return; items.push( { template : function() { return $("
").append( flexTab.displayName ).css( { "margin-top" : `${marginTopCSSValue}`, "text-align": "left", "xfont-size" : "larger", "font-weight" : "bold" } ) } } ); marginTopCSSValue = "8px"; let data = flexTab.fields; data.forEach( function( fieldDef ) { let label = fieldDef.label; label = label.replace( /\s*\(.*\)/, '' ); let item = { dataField : `${fieldDef.name}$${fieldDef.fieldId}`, label : { text : label }, value : null, editorType : "dxTextBox" }; let lookupValues = fieldDef.lookupValues; if( ( ! lookupValues || ! lookupValues.length ) && fieldDef.config ) { // parse the config value to find build a list of lookup values let configOptions = fieldDef.config.split( "," ); configOptions.forEach( function( co ) { if( ! co.match( /^rows=|^cols=|^size=|^readonly/ ) ) { if( ! lookupValues ) { lookupValues = []; } let lookupElements = co.split( ":" ); if( lookupElements.length > 1 ) { lookupValues.push( { value : lookupElements[0], text : lookupElements[1] } ) } else { lookupValues.push( { value : lookupElements[0], text : lookupElements[0] } ) } } }) } if( Array.isArray( lookupValues ) && lookupValues.length ) { item.editorType = "dxSelectBox", item.editorOptions = { dataSource : lookupValues, displayExpr : "text", valueExpr : "value" } item.editorType = "dxDropDownBox", item.editorOptions = { placeholder : "Select...", dataSource : { store : { type : "array", data : lookupValues, key : "value" }}, showClearButton : true, valueExpr : "value", displayExpr : "text", fieldTemplate : function( value, fieldElement ) { let ddbx = this; let displayText = null; if( value ) { if( ! Array.isArray( value )) { value = [value]; } if( value.length > 1 ) { displayText = "Multiple selected..."; } else if ( value.length == 1 ) { ddbx.getDataSource().store().byKey( value[0] ).done( function( item ) { displayText = item.text; }); } else { displayText = null; } } let field = $("
").dxTextBox( { placeholder : ddbx.option( "placeholder" ), readOnly : true, value : displayText }) fieldElement.append( field ); }, contentTemplate : function( e ) { const v = e.component.option( "value" ); const list = $("
").dxList( { dataSource : e.component.getDataSource(), displayExpr : "text", keyExpr : "value", selectionMode: "multiple", 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(); } } } items.push( item ); }) }) if( items.length ) { instance.dxFlexFieldForm = $("
").dxForm( { items : items } ).dxForm( "instance" ); } } instance.popupPromise.notify( "createFlexFieldForm" ); }); } DistributorSearch.prototype.createBasicForm = function() { let instance = this; let showBRO = Fse.Portal.appConfiguration.STP.ownerType === "MFR"; let showMFR = Fse.Portal.appConfiguration.STP.ownerType === "BRO"; let distributorListsDataSource = Fse.Data.newDataSource( { object : "LST.lists", keyField : "listId", objectParams : { includeStatus : false, partnerTypes : "CDR" }}); distributorListsDataSource.filter( [ [[ "published", "=", 1 ], "and", [ "forSearch", "=", 1 ]] , "or" , [ [ "creator", "=", 1 ], "or", [ "contributor", "=", 1 ]] ]) let distributorItems = []; distributorItems.push( { template : function() { return $("
").append( "CRM" ).css( { "text-align": "left", "xfont-size" : "larger", "font-weight" : "bold" } ) } }, // distributor hierarchy { dataField : "parentCdrRecordId", label : { location : "left", text : `Parent ${getText( 'DISTRIBUTOR' )}` }, editorType : "dxDropDownBox", editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( { dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "CDR.parentDistributors", keyField : "cdr_recordId" } ), searchExpr : "cdr_dstName", searchMode : "contains", displayExpr : "cdr_dstName", multipleSelectedDisplay : `Multiple ${getTextPlural( 'DISTRIBUTOR' )} Selected`, keyExpr : "cdr_recordId", title : `Select Parent ${getTextPlural( 'DISTRIBUTOR' )}` }) }, // buying group { dataField : "bgId", label : { location : "left", text : "Buying Group" }, editorType : "dxDropDownBox", editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( { dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "CDR.buyingGroups", keyField : "uniqueId" } ), searchExpr : "bgId", searchMode : "=", displayExpr : "bgName", multipleSelectedDisplay : "Multiple Buying Groups Selected", keyExpr : "uniqueId", title : "Select Buying Groups" }) }, //{ template : function() { return $("
").append( "Territory" ).css( { "text-align": "left", "font-size" : "larger" } ) } }, { 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( { dataURL : instance.dataURL, object : "TER.salesTerritories", keyField : "territoryPath" } ), searchExpr : "territoryPath", searchMode : "contains", displayExpr : "territoryPath", multipleSelectedDisplay : "Multiple Territories Selected", keyExpr : "territoryPath", title : "Select Territories" }) }, { dataField : "mfr_bsr_id", label : { location : "left", text : "Relationship Manager" }, 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 Relationship Managers Selected", keyExpr : "valueId", title : "Select Relationship Manager" }) }, //{ template : function() { return $("
").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 ); }