MfrCallSharingOptionsEditor = function( mfr_id ) { /* let searchOptionDefaults = { applySearch : function( searchParams ) { // default does nothing, caller must override } }; this.searchOptions = $.extend( true, {}, searchOptionDefaults, searchOptions ) */ this.mfr_id = mfr_id this.dataURL = $("link#appDataURL").attr( "href" ), this.dxForm = null this.dxPopup = null; this.customerTypes = [ {"partnerType":"OPR","desc":"Operator"}, {"partnerType":"CDR","desc":"Distributor"} ]; this.init(); } MfrCallSharingOptionsEditor.prototype.constructor = MfrCallSharingOptionsEditor; MfrCallSharingOptionsEditor.prototype.init = function() { this.createPopup(); } MfrCallSharingOptionsEditor.prototype.createForm = function() { let instance = this; /* let showMFR = Fse.Portal.appConfiguration.STP.ownerType !== "MFR"; let showBudgetCategory = Fse.Portal.appConfiguration.STP.ownerType === "MFR"; let useDetailReasons = Fse.Portal.appConfiguration.CRM.detailedReasonsEnabled === "true" && Fse.Portal.checkPermission( "DetailedReasonReporting" ); */ let configFields = [] configFields.push( { dataField : "enabled", editorType : "dxSwitch", label : { text : "Sharing Enabled", location : "left" } }); /* configFields.push( // territoryId { dataField : "territoryPath", label : { location : "left", text : "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" }) } ); */ configFields.push( { dataField : "cutoffDate", label : { location : "left", text : "Starting Call Date" }, editorType : "dxDateBox", isRequired : true }) configFields.push( { dataField : "objectiveOption", editorType : "dxSelectBox", disabled : false, editorOptions : { showClearButton : true, dataSource : { store : { type : "array", data : [ { value : "LINKED", text : "Objective Calls Only" }, { value : "REFNUM", text : "Objective Calls w/Reference Number Only" }, { value : "PATHS", text : "Specific Objective Selections" } ], key : "value" }, }, displayExpr : "text", valueExpr : "value", keyExpr : "value", placeholder : "All Calls (Objective related or not)" } }); let objectivesDataSource = Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "BOM.objectives", keyField : "objPath" } ) objectivesDataSource.filter( [["objOwnerType", "=", "MFR"], "and", ["objOwnerId", "=", instance.mfr_id ]] ); configFields.push( { dataField : "objPath", label : { location : "left", text : "Objectives" }, editorType : "dxDropDownBox", isRequired : false, disabled : true, editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( { dataSource : objectivesDataSource, searchExpr : "objPath", searchMode : "contains", displayExpr : "objPath", searchTemplate : function( userFilterCallback ) { // this is a custom search widget for the available side let searchWidget = $( "
" ).dxForm( { formData : { status : null, objPath : null }, items : [ { dataField : "status", label : { visible : false }, editorType : "dxSelectBox", editorOptions : { showClearButton : true, items : [ "Active","Future","Past" ], placeholder : "Objective Status" } }, { dataField : "objPath", label : { visible : false }, editorType : "dxTextBox", editorOptions : { showClearButton : true, placeholder : "Objective Name" } } ], onFieldDataChanged : function( fdce ) { let searchParams = fdce.component.option( "formData" ); let userFilters = []; for( let p in searchParams ) { let v = searchParams[p]; if( v ){ let op = "="; if( p === "objPath" ) { op = "contains"; } if( userFilters.length ) { userFilters.push( "and" ); } userFilters.push( [ p, op, v ] ) } } userFilterCallback( userFilters ); } } ); return searchWidget; }, multipleSelectedDisplay : "Multiple Objectives Selected", keyExpr : "objPath", title : "Select Objective" }) } /* , { dataField : "objectiveItemsOnly", label : { location : "left", text : "Objective Items Only" }, editorType : "dxSwitch", editorOptions: { value: false } } */ ) configFields.push( // Customer Type { disabled : false, dataField : "partnerType", label : { location : "left", text : "Customer Type" }, editorType : "dxSelectBox", editorOptions: { dataSource: instance.customerTypes, showClearButton : true, placeholder: "Choose Customer Type", displayExpr: "desc", valueExpr: "partnerType" } } ); configFields.push( { disabled : false, dataField : "disposition", label : { location : "left", text : "Call Status" }, editorType : "dxSelectBox", editorOptions : { showClearButton : true, dataSource : { store : { type : "array", data : [ { dispositionCode : "?", dispositionDesc : "OPEN" }, { dispositionCode : "X", dispositionDesc : "FINALIZED" } ], key : "dispositionCode" } }, keyExpr : "dispositionCode", displayExpr : "dispositionDesc", valueExpr : "dispositionCode" } } ) configFields.push( { disabled : false, dataField : "detailDisposition", label : { location : "left", text : "Item Status" }, editorType : "dxDropDownBox", editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( { dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "CRM.interactionDetailDispositions", keyField : "dispositionCode" } ), searchExpr : "dispositionDesc", searchMode : "contains", displayExpr : "dispositionDesc", multipleSelectedDisplay : "Multiple Item Status Selected", keyExpr : "dispositionCode", title : "Select Item Status" }) } ); instance.dxForm = $("
").dxForm( { items : configFields, width : 400, 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 ) { let formData = e.component.option( "formData" ); /* 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 === "objectiveOption" ) { let objPathDisabled = true; if( formData.objectiveOption === "PATHS" ) { objPathDisabled = false; } e.component.itemOption( "objPath", { "disabled" : objPathDisabled, "isRequired" : ! objPathDisabled }); } if( e.dataField === "enabled" ) { // this should set the disable field appropriate but does not seem to do so let enabled = false; if( formData.enabled ) { enabled = true; } const itemOptions = { disabled : enabled ? false : true } let fieldNames = [ "objectiveOption", "disposition", "detailDisposition", "partnerType" ]; fieldNames.forEach( function( f ) { e.component.itemOption( f, itemOptions ); }) } } } }).dxForm("instance"); } MfrCallSharingOptionsEditor.prototype.createPopup = function() { let instance = this; instance.createForm(); instance.message = $("
").css( "color" , "red" ); instance.saveButton = $("
").dxButton({ text : "Save Options", type : "default", onClick : function( e ) { // do the save let vr = instance.dxForm.validate(); if( ! vr.isValid ) { return; } let mfrCallSharingOptions = instance.dxForm.option( "formData" ); let saveURL = Fse.Util.updateURL2( $("link#appActionURL").attr( "href" ), { object : "CRM.saveMfrCallSharingOptions" } ); $.ajax( { url : saveURL, method : "post", data : { mfr_id : instance.mfr_id, mfrCallSharingOptions : JSON.stringify( mfrCallSharingOptions ) } }) .done( function( returnData ) { console.log( returnData ); instance.savePromise.resolve(); }) instance.dxPopup.hide(); } }).dxButton( "instance" ); instance.dxPopup = $("
").dxPopup( { title : "Call Sharing Options", width : "auto", height : "auto", hideOnOutsideClick : false, contentTemplate : function() { return instance.dxForm.element() }, toolbarItems : [ { toolbar : "bottom", location : "before", template : function() { return instance.message } }, { toolbar : "bottom", location : "after", template : function() { return instance.saveButton.element() } } ] }).appendTo( "body" ).dxPopup("instance"); } MfrCallSharingOptionsEditor.prototype.show = function() { let instance = this; let dataSource = Fse.Data.newDataSource( { object : "CRM.mfrCallSharingOptions", objectParams : { "mfr_id" : instance.mfr_id } }); dataSource.store().load().done( function( data ) { instance.dxPopup.option( "title", `${data.mfr_name} - Call Sharing Options` ); console.log( data.mfr_1fs_enabled ); if( data.mfr_1fs_enabled !== "Y" ) { instance.saveButton.option( { disabled : true, text : "blank" } ); instance.message.text( "Manufacturer is not 1FS Enabled" ); } instance.dxForm.updateData( data ); }) instance.savePromise = $.Deferred(); instance.dxPopup.show(); return instance.savePromise; }