ObjectiveTargets = function( options ) { let instance = this; instance.objectiveId = options.objectiveId; instance.staffLinkId = null; instance.staffFullName = null; instance.currentView = null; instance.objectiveUnpublishDate = options.unpublishDate; //console.log( "OPTIONS.TERRITORY", options.territory ); let currentUserId = parseInt( Fse.Portal.getConfiguration( "STP.userId" )); if( currentUserId === options.objManagerId || currentUserId === options.objManager2Id || currentUserId === options.objManager3Id ) { console.log( "Objective Manager using Summary View" ); instance.currentView = "summary"; } if ( ! instance.currentView && options.territory && options.territory.teamMembers ) { options.territory.teamMembers.forEach( function( tm ) { if( instance.currentView ) return; if( tm.teamMemberUserId === currentUserId && ( tm.teamMemberRole === "PrimaryManager" || tm.teamMemberRole === "SecondaryManager" || tm.teamMemberRole === "TeamManager" )) { console.log( "Territory Manager using Summary View" ); instance.currentView = "summary"; } }) } if( ! instance.currentView && Fse.Portal.checkPermission( "BCRMObjectiveManagementAdmin" )) { console.log( "Objective Admin Permission using Summary View" ); instance.currentView = "summary"; } if( ! instance.currentView && Array.isArray( options.staff )) { // see if the current user has a staff link options.staff.forEach( function( staff ) { if( staff.fspro_userId == currentUserId ) { instance.staffLinkId = staff.linkId; instance.staffFullName = staff.fullName; instance.currentView = "staff"; console.log( "Staff using Staff View" ); } }) } if( ! instance.currentView ) { console.log( "Defaulting to Summary View" ); instance.currentView = "summary"; } instance.dataReady = $.Deferred(); instance.summaryDataGrid = null; instance.targetDataGrid = null; instance.staffDataGrid = null; instance.multiView = null; } ObjectiveTargets.prototype.constructor = ObjectiveTargets; ObjectiveTargets.prototype.element = function() { let instance = this; if( instance.rootElement ) return instance.rootElement; let objectiveTargetsDataSourceOptions = { object : "BOM.objectiveTargets", key : "staffLinkId", objectParams : { objectiveId : instance.objectiveId } } if( instance.staffLinkId ) { objectiveTargetsDataSourceOptions.filter = [ "staffLinkId", "=", instance.staffLinkId ]; } let objectiveTargetsDataSource = Fse.Data.newDataSource( objectiveTargetsDataSourceOptions ); let loadPanel = $("
| ").text( fault.type == 'warning' ? 'WARNING' : 'INFORMATION' ) ).append( $(" | ").text( fault.description ) ) ).append( $(" |
| ").text( fault.type == 'warning' ? 'CORRECTIVE ACTION' : 'GUIDANCE' ) ).append( $(" | ").text( fault.correctiveAction )
)
)
);
return $(" ").append( table );
},
onHidden : function( e ) {
e.component.element().remove;
},
xshowEvent : {
name : "mouseenter",
},
hideEvent : {
name : "mouseout"
}
}).appendTo( $("body") ).dxTooltip("show");
} )
break;
}
}
}
})
} else {
if( options.data.targetStatus == "Completed" ) {
let icon = $("").addClass( "dx-icon-check" ).css( { "font-size" : "18px" })
if( options.data.targetAchievement ) {
icon.css( { color : "#2b8000" }); // green
} else {
icon.css( { color : "#81878c" }); // grey
}
content.append( icon );
}
}
container.append( content );
}
ObjectiveTargets.prototype._createStaffDataGrid = function() {
let instance = this;
let staffDataGrid = $(" ").dxDataGrid( {
loadPanel : { enabled : false },
filterRow : { visible : true },
headerFilter : { visible : true },
columns : [
{ dataField : "partnerName", caption : "Account", allowHeaderFiltering : false },
{ dataField : "targetStatus", caption : "Status", allowFiltering : false, allowHeaderFiltering : true,
headerFilter : {
dataSource : { store : { type : "array", key : "text", data : [
{ text : "Not Planned", value : [ "targetStatus", "=", "Not Planned" ] },
{ text : "In Progress", value : [ "targetStatus", "=", "In Progress" ] },
{ text : "Completed", value : [[ "targetStatus", "=", "Completed" ], "or", [ "targetStatus", "=", "COMPLETED" ]] },
{ text : "Not Completed", value : [ "targetStatus", "=", "Not Completed" ] }
]}}
}
},
{ dataField : "targetAchievement", caption : "Achievement", dataType : "number", allowHeaderFiltering : false },
{
caption : "", name : "warnings", width : "auto", allowHeaderFiltering : false,
cellTemplate : function( container, options ) {
return instance._warningIconsCellTemplate( container, options );
}
},
{ dataField : "completedCalls", caption : "Completed Calls", dataType : "number", allowHeaderFiltering : false },
{
dataField : "callsToAchievement", caption : "Total Calls (Achievement)", dataType : "number", visible : false, width : "auto", allowHeaderFiltering : false
},
{ dataField : "nextCall", caption : "Next Call", dataType : "date", allowHeaderFiltering : false,
cellTemplate : function( container, options ) {
if( options.data.nextCall ) {
let a = $("").text( DevExpress.localization.formatDate( new Date( options.data.nextCall ), "shortDate" ) ).css( "cursor" , "pointer" )
container.append( a );
}
}
}
],
onCellClick : function( e ) {
if( e.rowType != "data" ) return;
if( e.column.dataField == "nextCall" ) {
if( ! e.data.nextCall ) return;
let interactions = Array.isArray( e.data.interactions ) ? e.data.interactions : [];
for( let ix = 0; ix < interactions.length; ix++ ) {
if( interactions[ix].interactionDate == e.data.nextCall ) {
Fse.CLOS.openInteractionDialog( interactions[ix].interactionId, function() { })
break;
}
}
}
},
onContextMenuPreparing : function( e ) {
if( e.target != "content" ) return;
if( e.row.rowType == "data" ) {
if( ! e.row.data.interactions || e.row.data.interactions.length == 0 ) return;
if (!e.items) e.items = [];
if( e.row.data.partnerType == "OPR" ) {
const operatorId = e.row.data.partnerId;
e.items.push( {
text : "Operator Profile",
onItemClick : function( ee ) {
OperatorProfile.openPopupEditor( operatorId );
}
})
} else if ( e.row.data.partnerType == "CDR" ) {
const cdr_recordId = e.row.data.partnerId;
e.items.push( {
text : "Distributor Profile",
onItemClick : function( ee ) {
DistributorProfile.openPopupEditor( cdr_recordId );
}
})
}
e.row.data.interactions.forEach( function( i ) {
const interactionId = i.interactionId;
let interactionDateText = "TBD"
if( i.interactionDate ) {
interactionDateText = DevExpress.localization.formatDate( new Date( i.interactionDate ), 'shortDate' );
}
let dispositionText = i.disposition == '?' ? 'Planned' : 'Complete'
e.items.push( {
text : `Open Call: ${interactionDateText}: ${dispositionText}`,
onItemClick : function( ee ) {
Fse.CLOS.openInteractionDialog( interactionId,function() { })
}
})
})
}
},
onRowDblClick : function( e ) {
let interactions = Array.isArray( e.data.interactions ) ? e.data.interactions : [];
if( interactions.length ) {
let interactionId = interactions[interactions.length-1].interactionId;
Fse.CLOS.openInteractionDialog( interactionId, function() { })
}
},
scrolling : { mode : "virtual" },
showBorders : true,
rowAlternationEnabled : true,
height : "100%",
width : "100%"
}).dxDataGrid( "instance" );
return staffDataGrid;
}
|