BookOfBusinessNoReachWidget = function( widgetOptions ) { this.dataGrid = null; this.rootElement = null; this.activeFilterPreferences = {}; this.widgetOptions = widgetOptions; this.widgetOptions.config = $.extend( true, {}, this.getDefaultConfig(), widgetOptions.config ); } BookOfBusinessNoReachWidget.prototype.constructor = BookOfBusinessNoReachWidget; BookOfBusinessNoReachWidget.prototype.element = function() { if( this.rootElement ) return this.rootElement; let instance = this; instance.dataGrid = $("
").dxDataGrid( { showBorders : true, scrolling : { mode : "virtual" }, rowAlternationEnabled : true, height : 100, columns : [ { dataField : "partnerName", caption : "Account" }, {dataField : "priority", width : 65}, {dataField : "lastInteractionDate", caption : "Last Interaction", dataType : "date", width : 100} ], onContextMenuPreparing : function( e ) { if( e.target != "content" ) return; if( ! e.items ) e.items = []; /* let partnerTypeLabel = null; let goToURLBase = null; let goToParams = { "do" : "gotoMyCustomer" } if( e.row.data.partnerType == "OPR") { goToURLBase = $("#oprHandlerLink").attr( "href" ); goToParams.operatorId = e.row.data.partnerId; goToParams.operatorTk = e.row.data.partnerTk; partnerTypeLabel = 'Operator'; } else if ( e.row.data.partnerType == "CDR" ) { goToURLBase = $("#cdrHandlerLink").attr( "href" ); goToParams.distributorId = e.row.data.partnerId; goToParams.distributorTk = e.row.data.partnerTk; partnerTypeLabel = 'Distributor'; } if( goToURLBase != null ) { let goToURL = Fse.Util.updateURL2( goToURLBase, goToParams ); e.items.push( { text: `Go to ${partnerTypeLabel}`, onItemClick: function( e ) { window.location.href = goToURL; } }); } */ let gotoURL = Fse.CRM.buildGotoProfileURL( e.row.data ); if( gotoURL ) { let partnerTypeLabel = "Operator"; if( e.row.data.partnerType == "CDR") { partnerTypeLabel = "Distributor"; } e.items.push( { text: `Go to ${partnerTypeLabel}`, onItemClick: function( e ) { window.location.href = gotoURL; } }); } let allowAddCalls = Fse.Portal.appConfiguration.CRM.salesCallUnifiedPlatform.enabled === 'true' && Fse.Portal.checkPermission( "BCRMCallTracking" ); if( allowAddCalls ) { e.items.push({ text: `Plan Sales Call...`, onClick : function( ee ) { Fse.CLOS.createAccountInteraction( e.row.data.partnerId, e.row.data.partnerType, function(){}, 0 ); } }) } }, onToolbarPreparing : function( e ) { if( ! e.toolbarOptions.items ) e.toolbarOptions.items = []; e.toolbarOptions.items.push( { location : "after", widget : "dxButton", options : { icon : "export", hint : "Excel Export", onClick : function( ee ) { Fse.UI.DataGridHelper.exportDataGrid( { dataGrid : e.component, fileName : "BookOfBusinessNoReach.xlsx" } ); } } }) } }).dxDataGrid( "instance" ); instance.rootElement = $("
").addClass( "BookOfBusinessNoReachWidget" ); instance.rootElement.append( instance.dataGrid.element() ) instance.applyFilters(); return instance.rootElement } BookOfBusinessNoReachWidget.prototype.edit = function( applyFn ) { let widgetPreferenceEditor = new BookOfBusinessWidgetPreferences( this ); widgetPreferenceEditor.show( applyFn ); } BookOfBusinessNoReachWidget.prototype.onDashboardLayout = function( layout ) { this.dataGrid.option( "height", layout.portletContentHeight - 15 ); } BookOfBusinessNoReachWidget.prototype.getDefaultConfig = function() { let estOrderDateRange = Fse.CRM.dateRanges.rangeByKey( "F,TY" ); // fiscal this year return { territoryPath : null, productHierarchyPath : null, estOrderDateStart : estOrderDateRange.startDate, estOrderDateEnd : estOrderDateRange.endDate, estOrderDateRange : estOrderDateRange.rangeKey, clientSegPath : null, productSetTags : null, partnerType : null, salesRepId : null, objPath : null } } BookOfBusinessNoReachWidget.prototype.applyPreferences = function( preferences ) { this.widgetOptions.config = $.extend( true, {}, preferences ); this.applyFilters(); } BookOfBusinessNoReachWidget.prototype.applyFilters = function() { let instance = this; let widgetFilters = $.extend( true, {}, instance.widgetOptions.config ); let filterPreferences = instance.widgetOptions.filterPreferences; let activeFilterPreferences = instance.activeFilterPreferences; // global filters suppored by this widget, when the global filters are expressed with different variable names, they need to translated to this widgets variable names const globalFilters = { // widgetVariableName : "globalFilterVariableName" salesRepId : "salesRepId", territoryPath : "territoryPath", productHierarchyPath : "productHierarchyPath", productSetTags : "productSetTags", clientSegPath : "clientSegPath" }; for( let p in globalFilters ) { // apply translation - global filter param is not the same name as widget param let gp = globalFilters[p]; // if the global filter preferences have the propery and it has a value, update the objectparams if( filterPreferences.hasOwnProperty( gp ) && filterPreferences[gp]) { if( widgetFilters[p] == null ) { widgetFilters[p] = filterPreferences[gp]; activeFilterPreferences[p] = widgetFilters[p]; // indicate that this widget parameter has an active filter preference - used when displaying the edit page } } } let opportunityFilters = []; let accountFilters = []; let salesRepFilterActive = false; if( widgetFilters.estOrderDateStart && widgetFilters.estOrderDateEnd ) { opportunityFilters.push( [ [ "estOrderDate", ">=", widgetFilters.estOrderDateStart ], "and", [ "estOrderDate", "<=", widgetFilters.estOrderDateEnd ] ]) } if( widgetFilters.productSetTags ) { let filter = []; widgetFilters.productSetTags.forEach( function( ve ) { if( filter.length ) { filter.push( "or" ); } filter.push( [ "productSetTags", "contains", ve ] ); }) if( filter.length ) { if( opportunityFilters.length ) opportunityFilters.push( "and" ); opportunityFilters.push( filter ); } } if( widgetFilters.productHierarchyPath ) { let filter = []; widgetFilters.productHierarchyPath.forEach( function( ve ) { if( filter.length ) { filter.push( "or" ); } filter.push( [ "productHierarchyPath", "startswith", ve ] ); }) if( filter.length ) { if( opportunityFilters.length ) opportunityFilters.push( "and" ); opportunityFilters.push( filter ); } } if( widgetFilters.objPath ) { let objPaths = widgetFilters.objPath; // there are 5 objective path fields to search if( ! Array.isArray( objPaths ) ) { objPaths = [objPaths]; } filter = []; objPaths.forEach( function( objPath ) { let objPathFilter = [ ["objPath1", "startswith", objPath], "or", ["objPath2", "startswith", objPath], "or", ["objPath3", "startswith", objPath], "or", ["objPath4", "startswith", objPath], "or", ["objPath5", "startswith", objPath] ] if( filter.length ) { filter.push( "or" ) } filter.push( objPathFilter ); }) if( filter.length ) { if( opportunityFilters.length ) opportunityFilters.push( "and" ); opportunityFilters.push( filter ); } } if( widgetFilters.territoryPath ) { let filter = []; widgetFilters.territoryPath.forEach( function( ve ) { if( filter.length ) { filter.push( "or" ); } filter.push( [ "territoryPath", "startswith", ve ] ); }) if( filter.length ) { if( accountFilters.length ) accountFilters.push( "and" ); accountFilters.push( filter ); } } if( widgetFilters.clientSegPath ) { let filter = []; widgetFilters.clientSegPath.forEach( function( ve ) { if( filter.length ) { filter.push( "or" ); } filter.push( [ "clientSegPath", "startswith", ve ] ); }) if( filter.length ) { if( accountFilters.length ) accountFilters.push( "and" ); accountFilters.push( filter ); } } if( widgetFilters.salesRepId ) { let filter = []; widgetFilters.salesRepId.forEach( function( ve ) { if( filter.length ) { filter.push( "or" ); } filter.push( [ "salesRepId", "=", ve ] ); }) if( filter.length ) { if( accountFilters.length ) accountFilters.push( "and" ); accountFilters.push( filter ); salesRepFilterActive = true; } } if( widgetFilters.partnerType ) { if( accountFilters.length ) accountFilters.push( "and" ); accountFilters.push( [ "partnerType", "=", widgetFilters.partnerType ] ); } objectParams = { salesRepFilterActive : salesRepFilterActive }; if( opportunityFilters.length ) { objectParams.opportunityFilters = opportunityFilters; } if( accountFilters.length ) { objectParams.accountFilters = accountFilters; } instance.dataGrid.option( "dataSource", Fse.Data.newDataSource( { object : "SPL.bookOfBusinessNoReach", paginate : false, objectParams : objectParams }) ); } Fse.Portal.addWidgetFactory( "BookOfBusinessNoReachWidget", function( widgetDef ) { return new BookOfBusinessNoReachWidget( widgetDef ); })