TasksStatusSummaryWidget = function( widgetOptions ) { let filterUserIds = []; let userId = parseInt( Fse.Portal.appConfiguration.STP.userId ); filterUserIds.push( userId ); this.widgetOptions = widgetOptions; let configDefaults = this.getDefaultConfig(); this.widgetOptions.config = $.extend( true, {}, configDefaults, this.widgetOptions.config ); this.config = this.widgetOptions.config; this.barChart = null; // keeps track of the active filterPreferences this.activeFilterPreferences = {}; this.readyPromise = $.Deferred(); this.init(); } TasksStatusSummaryWidget.prototype.getDefaultConfig = function( ) { let userId = parseInt( Fse.Portal.appConfiguration.STP.userId ); let userPermissions = Fse.Portal._userPermissions; let visibilityScope = "self"; //console.log(userPermissions); if( Fse.Portal.checkPermission( "TaskManagementAdmin" )) { // || Fse.Portal.checkPermission( "TaskManagementReassign" ) visibilityScope = "all"; } let dueDate = null; if( Fse.Portal.appConfiguration.STP.ownerType === "BRO" ) { dueDate = Fse.CRM.dateRanges.rangeByKey( "N,TY" ); // fiscal this year } else { dueDate = Fse.CRM.dateRanges.rangeByKey( "F,TY" ); // fiscal this year } return { userId : userId, dueDateStart : dueDate.startDate, dueDateEnd : dueDate.endDate, dueDate : dueDate.rangeKey, visibilityScope : visibilityScope } } TasksStatusSummaryWidget.prototype.constructor = TasksStatusSummaryWidget; TasksStatusSummaryWidget.prototype.element = function() { return this.barChart.element(); } TasksStatusSummaryWidget.prototype.ready = function() { return this.readyPromise; } TasksStatusSummaryWidget.prototype.edit = function( applyFn) { let widget = this; if( ! this.preferencesPopup ) { const items = []; let staffDatasource = Fse.Data.newDataSource( { dataURL : widget.dataURL, object : "CRM.salesRepList", keyField : "fspro_userId" } ); if( widget.widgetOptions.config.visibilityScope == 'self'){ let assignedTo = widget.widgetOptions.config.assignedTo; staffDatasource.filter( [ [ "fspro_userId", "=", assignedTo] ] ); } else{ console.log("inside else"); console.log(widget.widgetOptions.config); } //console.log('TaskSummaryidget',widget) items.push( { dataField : "assignedTo", label : { location : "left", text : "Assigned To" }, editorType : "dxSelectBox", cssClass : widget.widgetOptions.config.assignedTo ? 'fx-active-preference' : null, editorOptions : { dataSource :staffDatasource, searchExpr : "fullName", searchMode : "contains", displayExpr : "fullName", valueExpr : "fspro_userId", title : "Select Assignee", showClearButton : true, searchEnabled : true, } }, { dataField : "createdBy", label : { location : "left", text : "Task Owner" }, editorType : "dxSelectBox", cssClass : widget.widgetOptions.config.createdBy ? 'fx-active-preference' : null, editorOptions : { dataSource : Fse.Data.newDataSource( { dataURL : widget.dataURL, object : "FSPro.members", keyField : "fspro_userId" } ), searchExpr : "fullName", searchMode : "contains", displayExpr : "fullName", valueExpr : "fspro_userId", title : "Select Creator", showClearButton : true, searchEnabled : true, } }) items.push( { dataField : "dueDate", label : { location : "left", text : "Due Date" }, editorType : "dxDropDownBox", editorOptions : Fse.UI.dateRangePickerOptions( { dateRangeOptions : { periodTypes : { "Y" : true, "M" : true, "Q" : true, "W" : true , "H" :false, "T" : false }, rangeRelationships : { "T" : true, "N" : true , "L" : false}, calendarTypes : { "F" : true, "N" : true }, includeCustom : true }, applyCustomDateRange : function( startDate, endDate ) { widget.preferencesForm.updateData( { dueDateStart : startDate, dueDateEnd : endDate } ) } } ) } ) // annotate the preference editor to let user know there are active filter preferences - scrum 46030 if( Object.keys( widget.activeFilterPreferences ).length ) { items.push( { template : function() { let annotation = $("
").append( $("").addClass( "dx-field-item-label-text" ).append( "*filter preference active")).addClass( "fx-active-preference" ).css( { "cursor" : "pointer" } ); 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; } }) } const formData = { assignedTo : widget.widgetOptions.config.assignedTo, createdBy : widget.widgetOptions.config.createdBy, dueDateStart : widget.widgetOptions.config.dueDateStart, dueDateEnd : widget.widgetOptions.config.dueDateEnd, dueDate : widget.widgetOptions.config.dueDate, } console.log("formData"); console.log(formData); this.preferencesPopup = $("
").dxPopup( { title : "Task Status Summary Preferences", width : 500, height : "auto", position : { my : "right top", at : "right top", of : widget.widgetOptions.portlet }, hideOnOutsideClick : true, contentTemplate : function() { widget.preferencesForm = $("
").dxForm( { formData : formData, colCount : 1, items : items, } ).dxForm("instance"); return widget.preferencesForm.element(); }, toolbarItems : [ { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Use Defaults", type : "normal", onClick : function() { widget.preferencesPopup.hide(); applyFn( widget.getDefaultConfig() ); } } }, { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Apply", type : "default", onClick : function() { widget.preferencesPopup.hide(); applyFn( widget.preferencesForm.option( "formData" ) ); } } } ] } ).dxPopup( "instance" ); this.preferencesPopup.element().appendTo( "body" ); } this.preferencesPopup.show(); } TasksStatusSummaryWidget.prototype.gotoTaskManager = function(pointData) { let instance = this; //console.log("in task manager"); //console.log(pointData); //console.log( instance.objectParams ); //if(instance.objectParams.createdBy) let taskSearch = $.extend( true, { statusDisplay : pointData.display }, instance.objectParams ); taskSearch.app = "WRK.taskManager"; let baseURL = $("link#PortalDocRootURL").attr( "href" ) + '/index.cfm' let goToURL = Fse.Util.updateURL2( baseURL, taskSearch ); window.location.href = goToURL; //this.widgetOptions.dashboard.tabSearch( "OpportunityAnalyzer", pipelineSearch ); //https://dev.fsenablers.com/fse/salesteamportal/kellanovafoodawayfromhome/index.cfm?app=WRK.taskManager } TasksStatusSummaryWidget.prototype.init = function() { let widget = this; let objectParams = { //userId : widget.widgetOptions.config.salesRepId, } if( widget.widgetOptions.config.createdBy ) { objectParams.requestedBy = widget.widgetOptions.config.createdBy; } if( widget.widgetOptions.config.dueDateStart ) { objectParams.dueDateStart = widget.widgetOptions.config.dueDateStart; } if( widget.widgetOptions.config.dueDateEnd ) { objectParams.dueDateEnd = widget.widgetOptions.config.dueDateEnd; } if( widget.widgetOptions.config.dueDate ) { objectParams.dueDate = widget.widgetOptions.config.dueDate; } if( widget.widgetOptions.config.visibilityScope ) { objectParams.visibilityScope = widget.widgetOptions.config.visibilityScope; } if(objectParams.visibilityScope == "self") { objectParams.assignedTo = widget.widgetOptions.config.userId; widget.widgetOptions.config.assignedTo = widget.widgetOptions.config.userId; } else{ if( widget.widgetOptions.config.assignedTo ) { objectParams.assignedTo = widget.widgetOptions.config.assignedTo; } } //console.log("in line 286"); //console.log(objectParams); // when the global filters are expressed with different variable names, they need to translated to this widgets variable names const globalFilterTranslation = { // widgetVariableName : "globalFilterVariableName" //effectiveRepId : "salesRepId" //accountOwner_ownerType : "staffType" } let newConfig = $.extend( true, {}, objectParams ); for( let p in objectParams ) { 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( globalFilterTranslation[p] ) { gp = globalFilterTranslation[p]; } // if the global filter preferences have the propery and it has a value, update the objectparams if( widget.widgetOptions.filterPreferences.hasOwnProperty( gp ) && widget.widgetOptions.filterPreferences[gp]) { if( objectParams[p] == null ) { objectParams[p] = widget.widgetOptions.filterPreferences[gp]; widget.activeFilterPreferences[p] = objectParams[p]; // indicate that this widget parameter has an active filter preference - used when displaying the edit page //console.log("coming here"); //console.log(objectParams[p]); /*if(Array.isArray(objectParams[p])) newConfig[p] = objectParams[p][0]; else*/ newConfig[p] = objectParams[p]; } } } let filter = [] if( newConfig.assignedTo ) { filterUserIds = []; filterUserIds.push( newConfig.assignedTo ) } if(this.visibilityScope == "all"){ let s = "salesRepId"; if( widget.widgetOptions.filterPreferences.salesRepId != null){ filterUserIds = []; widget.widgetOptions.filterPreferences.salesRepId.forEach( function( salesRepValue ) { filterUserIds.push( parseInt( salesRepValue ) ); widget.widgetOptions.config.assignedTo = filterUserIds }) widget.activeFilterPreferences[s] = widget.widgetOptions.config.assignedTo; newConfig[s] = widget.activeFilterPreferences[s]; } } console.log("new config"); console.log(newConfig); widget.objectParams = $.extend( true, {}, newConfig ); let dataSource = Fse.Data.newDataSource( { object : "WRK.taskStatusSummary", objectParams : widget.objectParams } ); //console.log(dataSource); widget.barChart = $("
").dxChart({ dataSource : dataSource, legend: { visible: false }, tooltip: { enabled: true }, rotated:true, height : 150, customizePoint() { if (this.argument == 'Past Due') { return { color: '#db4425', hoverStyle: { color: '#db4425' } }; } if (this.argument == 'Open') { return { color: '#776bcd', hoverStyle: { color: '#776bcd' } }; } if (this.argument == 'Cancelled') { return { color: '#5ad45a', hoverStyle: { color: '#5ad45a' } }; } if (this.argument == 'On Hold') { return { color: '#f99600', hoverStyle: { color: '#f99600' } }; } if (this.argument == 'Completed') { return { color: '#27aeef', hoverStyle: { color: '#27aeef' } }; } //console.log(this); return { color: '#008e72', hoverStyle: { color: '#008e72' } }; }, onPointClick: function (clickedBar) { let pointData = clickedBar.target.data; //console.log(pointData); widget.gotoTaskManager(pointData); } , series: { minBarSize : 2, argumentField: 'display', valueField: 'taskNumbers', name: 'Task Status Summary', type: 'bar', }, }).dxChart( "instance" );; } Fse.Portal.addWidgetFactory( "TasksStatusSummaryWidget", function( widgetDef ) { return new TasksStatusSummaryWidget( widgetDef ); })