OperatorPortfolio = function() { let instance = this; this.rootElement = null; this.operatorList = null; this.listRefreshNeeded = false; OperatorPortfolio._operatorPortfolioInstance = this; Fse.CRM.addViewProfileHandler( { viewProfile : function( profileURL ) { let urlParams = Fse.Util.getURLParams( profileURL ); console.log( "urlParams" ); console.log( urlParams ); if( ! urlParams.app || urlParams.app != 'OPR.portfolio' ) { return false; } let operatorId = 0; if( urlParams.operatorId ) { operatorId = urlParams.operatorId } else if ( urlParams.partnerId && urlParams.partnerType == "OPR" ) { operatorId = urlParams.partnerId; } else if ( instance.operatorList ) { let listSearch = {}; let listSearchPromise = $.Deferred(); if( urlParams.includeMyAccountsOnly ) { listSearch.includeMyAccountsOnly = true; } if( urlParams.operatorListId ) { listSearch.operatorListId = parseInt( urlParams.operatorListId ); let listStore = Fse.Data.newDataSource( { object : "LST.lists", keyField : "listId", paginate : false } ).store(); listStore.byKey( listSearch.operatorListId ).done( function( listItem ) { if( listItem && listItem.listId == listSearch.operatorListId ) { listSearchPromise.resolve(); } else { listSearchPromise.reject(); } }) } else { listSearchPromise.resolve(); } listSearchPromise.done( function() { if( Object.keys(listSearch).length !== 0 ) { // make sure the portfolio is on the list view instance.multiView.option( "selectedIndex", 0 ); // if( urlParams.perspective ) { // instance.operatorList.showPerspective( urlParams.perspective ); // } instance.operatorList.showPerspective( "operator" ); instance.operatorList.search( listSearch ); return true; } }).fail( function() { console.log( "listSearch rejected" ); }) } else { return false; } console.log( `Handling: ${profileURL}`) if( operatorId ) { let tabId = urlParams.tab; if( tabId ) { const validTabs = { "detail" : "detail", "contact" : "contact", "purchasing" : "purchasing", "interactions" : "interactions", "units" : "units", "members" : "members", "opportunities" : "opportunities", "objectives" : "objectives", "trade" : "trade", "bids" : "bids", "notes" : "notes", "files" : "files", // legacy tab translations "dtl" : "detail", "cntct" : "contact", "pp" : "purchasing", "inits" : "interactions", "tpm" : "trade", "affiliates" : "members" // legacy tabs that do not need a translations // "opportunities" : "opportunities", // "units" : "units", // "objectives" : "objectives", // "bids" : "bids", // "notes" : "notes", // "files" : "files" } if( validTabs[tabId] ) { tabId = validTabs[tabId]; } else { tabId = null; // null to use current tab or detail tab } } OperatorPortfolio.getOperatorDetails( operatorId ).done( function( data ) { instance.currentOperator = data; console.log( instance.currentOperator ); instance.gotoProfile( data, tabId, true ); // fullData = true }) return true; } return false; }}) } OperatorPortfolio.getHandler = function() { var oLink = document.getElementById( "oprHandlerLink" ); return oLink.getAttribute( "href" ); }; OperatorPortfolio.openOperatorSummaryPDF = function( operatorId ){ let pdfURL = Fse.Util.updateURL2( OperatorPortfolio.getHandler(), { operatorId : operatorId, view : "operatorSummaryPDF", mode : "direct" }) window.open( pdfURL, "_blank", "noopener noreferrer" ); } OperatorPortfolio.showOperatorProfileDialog = function( nOperatorId ) { let sURL = Fse.Util.updateURL( OperatorPortfolio.getHandler() + "?get=operatorProfileDialog&mode=direct", { operatorId : nOperatorId } ); let oOptions = { title : "Operator Profile Quick View", width : "500px", src : sURL }; Fse.DialogManager.show( "operatorProfileDialog$", oOptions ); } OperatorPortfolio.getOperatorDetails = function( operatorId ) { let d = $.Deferred(); let operatorDataStore = Fse.Data.newDataSource( { object : "OPR.operatorDetails", paginate : false, keyField : "operatorId", objectParams : { operatorId : operatorId } }).store(); operatorDataStore.byKey( operatorId ).done( function( data ) { if( data ) { d.resolve( data ) } else { d.resolve( null ); } }) return d; } OperatorPortfolio.showDeleteOperatorDialog = function ( operatorId, operatorTk, onSuccess ) { let checkDeleteDataSource = Fse.Data.newDataSource( { object : "OPR.checkOperatorDelete", paginate : false, keyField : "operatorId", objectParams : { operatorId : operatorId } }); checkDeleteDataSource.load().done( function( checkDelete ) { if( Array.isArray( checkDelete ) ) { checkDelete = checkDelete[0]; } OperatorPortfolio.getOperatorDetails( operatorId ).done( function( operatorData ) { let actionButton = null; let popup = null; let deleteForm = null; if( checkDelete.allowDelete ) { actionButton = $("
").html( "You are about to DELETE the following operator from the Operator Porfolio:" )); let operatorElement = $("
").html( html )); } }, { label : { text : "Deleted By" }, dataField : "deletedBy", editorOptions : { readOnly : true } }, { label : { text : "Reason" }, dataField : "deleteReason", isRequired : true, editorType : "dxSelectBox", editorOptions : { items : [ "Duplicate", "No longer in business", "Low volume", "Not my Account", "Not within market range", "Other" ] } }, { label : { text : "Details" }, dataField : "deleteDetails", isRequired : true, editorType : "dxTextArea", editorOptions : { maxLength : 200 } } ] }).dxForm( "instance" ); content.append( deleteForm.element() ); } else { if( checkDelete.dependencies.length ) { content.append( $("
" ).text( "This Operator cannot be deleted because it has the following dependents:").css( { "font-weight" : "bold" } ) ); $("
").addClass( "fse-alert" );
restrictionsElement.append( `You can not delete this ${getText( 'OPERATOR' )} because there are ` );
for( x = 0; x < checkDelete.restrictions.length; x++ ) {
if( x > 0 ) {
if( x == checkDelete.restrictions.length - 1 ) {
restrictionsElement.append( " and ")
} else {
restrictionsElement.append( ", " );
}
}
restrictionsElement.append( checkDelete.restrictions[x] )
}
restrictionsElement.append( "." );
restrictionsElement.append( $("
") );
restrictionsElement.append( "Click the Cancel button to close this dialog box.")
content.append( restrictionsElement );
}
}
return content;
},
toolbarItems : [
{ toolbar : "bottom", location : "after",
template : function() {
return actionButton.element();
}
}
],
onHidden : function( e ) {
e.component.element().remove();
e.component.dispose();
}
}).appendTo( "body" ).dxPopup("instance");
popup.show();
})
})
}
OperatorPortfolio.prototype.constructor = OperatorPortfolio;
OperatorPortfolio.prototype.element = function() {
let instance = this;
if( instance.multiView ) {
return instance.multiView.element();
}
instance.multiView = $("
").text( callOptions.message ).appendTo( content ); } dataGrid = $("