/* TODO : revisit serialize() to see if the standard jquery works TODO : look at Fse.CLOS._loadProfileTab = function( bForce ) to figure out the purpose of force, etc... */ CallEntryPopup = function( options ) { let instance = this; instance.interactionID = options.interactionID ? parseInt( options.interactionID ) : 0; instance.objID = options.objID ? parseInt( options.objID ) : 0; instance.stfID = options.stfID ? parseInt( options.stfID ) : 0; instance.interactionEditable = options.intEditable == undefined ? true : options.intEditable ? true : false; instance.highlightSKUId = options.highlightSKUId ? parseInt( options.highlightSKUId ) : 0; instance.callback = options.fnCallback ? options.fnCallback : function() { /* empty call back */ } instance.recapEnabled = false; if( Fse.Portal.checkPermission( 'BCRMSendCallRecap') && Fse.Portal.getConfiguration( "CRM.SalesCallRecapEnabled" ) == "true" ) { instance.recapEnabled = true; } instance.loadPromise = $.Deferred(); instance.data = {}; instance.distributorPurchasingTabEnabled = Fse.Portal.getConfiguration( "102.profile.purchasingTabEnabled" ) == "true" ? true : false; if( instance.interactionID ) { let interactionInfoStore = Fse.Data.newDataSource( { object : "BCM.interactionInfo", keyField : "interactionId", paginate : false, objectParams : { interactionId : instance.interactionID } } ).store() interactionInfoStore.byKey(instance.interactionID).done( function( interactionData ) { //console.log( "interactionData", interactionData ); instance.data = interactionData; instance.partnerId = interactionData.partnerId; instance.partnerType = interactionData.partnerType; instance.companyType = interactionData.companyType; instance.oneFSId = interactionData.oneFSId; instance.intDisposition = instance.data.disposition; instance.loadPromise.resolve(); }) // let interactionDataSource = Fse.Data.newDataSource( { object : "CRM.interactions", keyField : "interactionId", paginate : false } ) // interactionDataSource.select( ["partnerId","partnerType","partnerName","territoryName","interactionDate","interactionId","disposition", "salesRepFullName" ]); // interactionDataSource.filter( [ "interactionId", "=", instance.interactionID ]); // interactionDataSource.load().done( function( interactionData ) { // console.log( "interactionData", interactionData ); // instance.data = interactionData[0]; // instance.intDisposition = instance.data.disposition; // instance.loadPromise.resolve(); // }) } else { instance.loadPromise.resolve(); } instance.baseURL = $("link#bcmHandlerLink").attr( "href" ); instance.callDetailsToolbarItems = []; instance._initializeTabPanelItems(); // process tracking variables instance.productsUpdated = true; instance.intDisposition = "?"; } CallEntryPopup.prototype.constructor = CallEntryPopup; CallEntryPopup.prototype._resetQuickAdd = function() { let instance = this; if( instance.quickAddToolbar ) { instance.quickAddToolbar.beginUpdate(); instance.quickAddToolbar.option( "items[0].visible", true ); // text box instance.quickAddToolbar.option( "items[1].visible", false ); // cancel link instance.quickAddToolbar.option( "items[2].visible", false ); // select box instance.quickAddSKUSelect.option( { dataSource : null, value : null } ); instance.quickAddSKUText.option( "value", null ); instance.quickAddToolbar.endUpdate(); } } CallEntryPopup.prototype.cancelQuickAdd = function() { let instance = this; document.forms.frmInteraction.elements.inProcess.value = 'yes'; instance._resetQuickAdd(); instance.quickAddStatusMsg.empty(); } CallEntryPopup.prototype.submitQuickAdd = function( skuId ) { let instance = this; let dataToSend = { interactionID : instance.interactionID, useJSON : true }; if( skuId ) { dataToSend.skuId = skuId; } else { let sku = instance.quickAddSKUText.option( "value" ); if( ! sku ) { return; } dataToSend.sku = sku; instance.quickAddStatusMsg.empty().text( "Searching..." ); document.forms.frmInteraction.elements.inProcess.value = 'yes'; } instance.saveBrief().done( function() { let ajaxOptions = { url : Fse.Util.updateURL( instance.baseURL, { do : "interaction-dialog-action-quick-add-product", mode : "direct" }), method : "POST", data : dataToSend, headers : { fseAjax : true } } $.ajax( ajaxOptions ).done( function( result ) { if( result.addStatus == "yes" ) { instance.refreshProductsDisplay(); instance._resetQuickAdd(); instance.quickAddStatusMsg.empty().text( "SKU Added" ); } else if( result.addStatus == "mult") { instance.quickAddStatusMsg.empty().text( "Multiple found" ); let dataSource = new DevExpress.data.DataSource( { store : { type : "array", data : result.data, key : "skuId" } }) instance.quickAddSKUSelect.option( { "dataSource" : dataSource } ); instance.quickAddToolbar.beginUpdate(); instance.quickAddToolbar.option( "items[0].visible", false ); // text box instance.quickAddToolbar.option( "items[1].visible", true ); // cancel link instance.quickAddToolbar.option( "items[2].visible", true ); // select box instance.quickAddToolbar.endUpdate(); } else { instance.quickAddStatusMsg.empty().text( result.msgText ); } }) }) // Spry.Utils.setInnerHTML( "divQuickAddStatus", "Searching..." ); // document.frmInteraction.inProcess.value = 'yes'; // document.frmQuickAddProd.interactionID.value = document.frmInteraction.interactionID.value; // set interaction id to h idden form field // Fse.CLOS.saveBrief(); //must do first - saves salesrep - important when linking to objectives // // submit add form // var oRequest1 = Fse.Ajax.sendForm( document.frmQuickAddProd ); // //if (oRequest1.getResponseHeader('addStatus') == 'yes') { // if (Fse.CLOS.parseResponse(oRequest1.responseText,1) == 'yes') { // var interactionID = document.frmInteraction.interactionID.value; // Spry.Utils.setInnerHTML( "divProductsForm", "" ); // var fnCallBack = function() { // Fse.DialogManager.initializePopupCalendarHandler(document.getElementById("divProductsForm")); // } // Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-products-form&mode=direct&interactionID='+interactionID+'&editMode='+Fse.CLOS.interactionEditable, 'divProductsForm', null, fnCallBack ); // Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-quickadd-input&mode=direct', 'divQuickAddSKU' ); // Spry.Utils.setInnerHTML( "divQuickAddStatus", "SKU Added" ); // } else if (Fse.CLOS.parseResponse(oRequest1.responseText,1) == 'mult') { // Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-quickadd-select&mode=direct&sku='+document.frmQuickAddProd.sku.value, 'divQuickAddSKU' ); // Spry.Utils.setInnerHTML( "divQuickAddStatus", "Multiple Found" ); // } else { // Spry.Utils.setInnerHTML( "divQuickAddStatus", Fse.CLOS.parseResponse(oRequest1.responseText,0) ); // } } CallEntryPopup.prototype.convertPRDtoSKU = function( interactionDetailId, mfrId, prodId ) { let instance = this; instance.saveBrief().done( function() { let ppOptions = { mfr_id : mfrId, pick : [ "SKU" ], prodId : prodId, unlockL2 : true, selectMode : "multiple", onProductsPicked : function( ppe ) { // console.log( "productsPickedEvent", ppe ); if( ppe.selectedItems.length && ppe.selectedItems[0].catalogType == "SKU" ) { // let skuId = ppe.selectedItems[0].catalogId; let skuIds = []; ppe.selectedItems.forEach( function( si ) { if( si.catalogType == "SKU" ) { skuIds.push( si.catalogId ); } }) let skuId = skuIds.join( "," ); //Fse.CLOS.baseURL+"?do=interaction-dialog-convert-cat-to-sku&interactionId="+interactionId+"&itemDetailId="+itemDetailId, $.ajax( { url : Fse.Util.updateURL( instance.baseURL, { do : "interaction-dialog-convert-cat-to-sku", interactionId :instance.interactionID, itemDetailId : interactionDetailId }), method : "POST", data : { skuId : skuId }, headers : { fseAjax : true } }) // then refresh product list instance.refreshProductsDisplay(); } } } let pp = new ProductPicker( ppOptions ); pp.show(); }) return ; var currentList = ''; var listid = 0; var fndCallBack = function(oRequest) { var fnCallBack = function() { Fse.DialogManager.initializePopupCalendarHandler(document.getElementById("divProductsForm")); } var interactionID = document.frmInteraction.interactionID.value; Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-products-form&mode=direct&interactionID='+interactionID+'&editMode='+Fse.CLOS.interactionEditable, 'divProductsForm', null, fnCallBack ); } var oOptions = { selectMode : "multiple", pickLevel : 1, closeAction : Fse.CLOS.baseURL+"?do=interaction-dialog-convert-cat-to-sku&interactionId="+interactionId+"&itemDetailId="+itemDetailId, onSuccess : fndCallBack, disabledIdList: currentList, xscope: 'mfr:'+mfrId, scope: 'prd:'+prodId+',mfr:'+mfrId, useLegacy : true }; Fse.CLOS.saveBrief(); Fse.FND.showProductLookup( oOptions ); }; CallEntryPopup.prototype.savePurchasingProfile = function() { let instance = this; let savePPPromise = $.Deferred(); if( instance.operatorPurchasing ) { instance.operatorPurchasing.saveUnconfirmed(); } else if ( instance.distributorPurchasing ) { alert( "Distributor Purchasing cannot be saved "); } else { /* savePPPromise.done( function() { instance.refreshTab( instance.PURCHASING_TAB ) }); Fse.OPR.savePurchasingProfile( function() { savePPPromise.resolve(); }) */ } return savePPPromise; } CallEntryPopup.prototype.updateAudit = function() { let instance = this; return instance.salesCallAudit.save().done( function() { instance.popup.hide(); instance.callbck(); }) // let updateAuditPromise = $.Deferred(); // updateAuditPromise.done( function() { // instance.popup.hide(); // instance.callback(); // }) // if( document.forms.frmInteractionAudit ) { // if ( Fse.FormManager.submit( document.forms.frmInteractionAudit, false )) { // document.forms.frmInteractionAudit.elements.saleConfirmedNotifyNote.disabled = false; // instance.setButtonAreaMessage( "Saving audit data..." ); // let frmInteractionAudit = $(document.forms.frmInteractionAudit); // let ajaxOptions = { // url : frmInteractionAudit.attr( "action" ), // method : frmInteractionAudit.attr( "method" ), // data : frmInteractionAudit.serialize(), // headers : { fseAjax : true } // } // $.ajax( ajaxOptions ).done( function( result ) { // updateAuditPromise.resolve(); // }) // } else { // updateAuditPromise.reject(); // } // } else { // updateAuditPromise.reject(); // } // return updateAuditPromise; } CallEntryPopup.prototype.ineractionDialogSaveProfile = function() { let saveProfilePromise = $.Deferred(); let instance = this; if( Fse.FormManager.submit( document.forms.frm_profileUpdatePanel, false )) { let frm_profileUpdatePanel = $(document.forms.frm_profileUpdatePanel); let ajaxOptions = { url : frm_profileUpdatePanel.attr( "action"), method : frm_profileUpdatePanel.attr( "method"), data : frm_profileUpdatePanel.serialize(), headers : { fseAjax : true } } $.ajax( ajaxOptions ).done( function( result ) { instance.refreshTab( instance.PROFILE_TAB ) saveProfilePromise.resolve(); }) } else { saveProfilePromise.reject(); } return saveProfilePromise; }; CallEntryPopup.prototype.interactionDialogSendEmail = function() { let instance = this; let sendEmailPromise = instance.emailSender.send(); sendEmailPromise.done( function() { alert('Sales Call Email Sent.'); }).fail( function( reason ) { if( reason ) { alert( reason ) } }) return sendEmailPromise; // let sendEmailPromise = $.Deferred(); // if (Fse.FormManager.submit( document.forms.frmEmailSalesCall, false )) { // let frmEmailSalesCall = $(document.frmEmailSalesCall); // let ajaxOptions = { // url : frmEmailSalesCall.attr( "action"), // method : frmEmailSalesCall.attr( "method"), // data : frmEmailSalesCall.serialize(), // headers : { fseAjax : true } // }; // $.ajax( ajaxOptions ).done( function( result, statusText, jqXHR ) { // if( jqXHR.getResponseHeader( "call-notify-status" ) == "good" ) { // alert('Sales Call Email Sent.'); // sendEmailPromise.resolve(); // } else { // alert('Invalid email format. Enter addresse(s) in this format: jsmith@abc.com; jjones@abc.com'); // sendEmailPromise.reject(); // } // }) // // var oRequest = Fse.Ajax.sendForm( document.frmEmailSalesCall ); // // if (oRequest.getResponseHeader('call-notify-status') == 'good') { // // alert('Sales Call Email Sent.'); // // } else { // // alert('Invalid email format. Enter addresse(s) in this format: jsmith@abc.com; jjones@abc.com'); // // } // } else { // sendEmailPromise.reject(); // } // return sendEmailPromise; } CallEntryPopup.prototype.submitAddProducts = function( continueSearch ) { let instance = this; continueSearch = continueSearch ? true : false; document.forms.frmInteraction.elements.inProcess.value = 'yes'; document.forms.frmAddProds.elements.interactionID.value = document.forms.frmInteraction.elements.interactionID.value; // set interaction id to hidden form field if ( continueSearch ) { document.forms.frmAddProds.elements.updateObjectiveLinks.value = 'false'; //document.getElementById( "divProductsForm" ).setAttribute( "FSE:productsUpdated", "false" ); instance.productsUpdated = false; } else { document.forms.frmAddProds.elements.updateObjectiveLinks.value = 'true'; // document.getElementById( "divProductsForm" ).setAttribute( "FSE:productsUpdated", "true" ); instance.productsUpdated = true; } // mandatory brief save instance.saveBrief().done( function() { // // submit form. FSE:addItemStatus is used by test software. // document.getElementById( "divProductsForm" ).setAttribute( "FSE:addItemStatus", "inprocess" ); // var oRequest = Fse.Ajax.sendForm( document.frmAddProds ); // document.getElementById( "divProductsForm" ).setAttribute( "FSE:addItemStatus", "complete" ); // save the products! instance.addItemStatus = "inprocess"; let addProductsForm = $( document.forms.frmAddProds ); let ajaxOptions = { url : addProductsForm.attr( "action" ), method : addProductsForm.attr( "method" ), data : Fse.Ajax.serialize( addProductsForm[0] ), headers : { fseAjax : true } } $.ajax( ajaxOptions ).done( function( result ) { // the save is complete instance.addItemStatus = "complete"; // var interactionID = document.frmInteraction.interactionID.value; // var fnCallBack = function() { // Fse.DialogManager.initializePopupCalendarHandler(document.getElementById("divProductsForm")); // } // if (continueSearch == false) { // Spry.Utils.setInnerHTML( "divProductsForm", "loading..." ); // Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-products-form&mode=direct&interactionID='+interactionID+'&editMode='+Fse.CLOS.interactionEditable, 'divProductsForm', null, fnCallBack ); // } if( ! continueSearch ) { // not continuing the search, so refresh the products instance.refreshProductsDisplayRaw().done( function() { // async requires no follow up }); } // set checked items to disabled (replaces search submit to have server side disable checked items) var elements = document.getElementsByName("addProducts"); for (var i = 0 ; i < elements.length ; i++) { if(elements[i].checked == true) { elements[i].disabled = true; } } if (continueSearch == false) { // if (instance.intDisposition == '?') { // //Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-buttons-detail-pend&edit='+Fse.CLOS.interactionEditable, 'divInteractionDialogButtonSet' ); // if (instance.interactionEditable) { // Fse.setInteractionButtons('interaction-dialog-buttons-detail-pend-edit'); // } else { // Fse.setInteractionButtons('interaction-dialog-buttons-close'); // } // } else { // //Fse.Ajax.updateContent( Fse.CLOS.baseURL+'?view=interaction-dialog-buttons-detail-closed&edit='+Fse.CLOS.interactionEditable, 'divInteractionDialogButtonSet' ); // if (instance.interactionEditable) { // Fse.setInteractionButtons('interaction-dialog-buttons-detail-closed-edit'); // } else { // Fse.setInteractionButtons('interaction-dialog-buttons-close'); // } // } // Fse.CLOS.interactionDialogTabs.set('activeIndex', 0); // Fse.CLOS.setHelpIcon(); instance.gotoCallDetailsTab(); } else { // must do focus() and select() before submit. causes IE crash otherwise if (document.getElementById("srchType-prod").checked) { document.frmInteractionSrchProds.srchKeyword.focus(); document.frmInteractionSrchProds.srchKeyword.select(); } var scrollPos = document.getElementById("divAddProductsResults").scrollTop; // save current top pos document.getElementById("divAddProductsResults").scrollTop = scrollPos; } }) }) } CallEntryPopup.prototype.submitInteraction = function() { let instance = this; let submitPromise = $.Deferred(); let frmInteraction = document.forms.frmInteraction; // document.frmInteraction.action = Fse.CLOS.baseURL+'?do=interaction-dialog-action-update'; let oItemsTable = document.getElementById( "call-products" ); // var _purchProfileLookback = oItemsTable.getAttribute( "FSE:purchProfileLookback" ); // if changing from open to closed, then check for follow up items, otherwise, updating a prev // closed interaction- don't bother with this process again // SCRUM 24885: we are now doing the follow up check on call update too. if ( true || instance.intDisposition == '?' ) { // var arSkus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); var arSkus = $("select.sku-status-fu-chk"); var fuFound = false; for (i=0;i<=arSkus.length-1;i=i+1) { if ((arSkus[i].value == 'FU' || arSkus[i].value == 'TODO') && arSkus[i].getAttribute("sourceType") != 'SPL' ) { fuFound = true; } } var emptyObjectives = instance.chkEmptyObjectives(); if ( frmInteraction.elements.followupDate.value == '' && (fuFound == true || emptyObjectives == true)) { var strFuMsg = 'This call requires a follow up date:'; if (fuFound==true) { strFuMsg = strFuMsg + '\n- At least one item was identified for Follow Up or To Do.'; } if (emptyObjectives == true) { strFuMsg = strFuMsg + '\n- At least one Objective was not addressed with the items presented.'; } alert(strFuMsg); frmInteraction.elements.followupDate.focus(); submitPromise.reject(); return submitPromise; } /* disabled purch profile warning. we are no handling this with the sale type selection (incremental or existing business). if ( Fse.CLOS.alreadyBuying() ) { //return false; if (!confirm('Warning! The red highlighted item(s) have already been reported as sold within the last '+_purchProfileLookback+' days.\nUnless you have sold additional cases, please delete the highlighted item(s), or you will be\noverstating sales on this item. If this is a new or incremental sale, you may proceed.\n\nClick OK if you wish to proceed as is, or Cancel to further review and edit this call.')) { return false; } } */ if ( instance.categoryLevelItemsExist() ) { submitPromise.reject(); return submitPromise; } var _followupDate = frmInteraction.elements.followupDate.value; var _followupDateDownloadReq = document.getElementById("followupDate").getAttribute("fse:followupDownloadRequired").toUpperCase(); var _followupDownloaded = document.getElementById("followupDate").getAttribute("fse:followupDownloaded").toUpperCase(); if ( _followupDate != "" && _followupDateDownloadReq == "TRUE" && _followupDownloaded == "FALSE") { alert("Follow up call has not been downloaded to your calendar."); submitPromise.reject(); return submitPromise; } } // make sure any new opportunities are fully defined if ( instance.chkNewOpportunities() == false ) { submitPromise.reject(); return submitPromise; } if ( instance.chkObjSelections() == false ) { submitPromise.reject(); return submitPromise; } if ( frmInteraction.elements.interactionPurposeId ) { if ( frmInteraction.elements.interactionPurposeId.options[frmInteraction.elements.interactionPurposeId.selectedIndex].getAttribute('fse:allowNoProducts') == 'N' && instance.chkEmptyItems() == true ) { alert('Selected call type requires at least one item presentation.'); submitPromise.reject(); return submitPromise; } } if ( !instance.soldItemsDatesMaxDateCheck() ) { submitPromise.reject(); return submitPromise; } // check sold item order dates if ( !instance.soldItemsDatesOk() ) { if ( !confirm('At least one sold item has an Est Order Date prior to Call Date. Click OK to continue, or Cancel to adjust.') ) { submitPromise.reject(); return submitPromise; } } // check for future call date var oSalesCallDate = new Date( frmInteraction.elements.interactionDate.value ); var oNow = new Date(); var oToday = new Date( oNow.getFullYear(), oNow.getMonth(), oNow.getDate() ); if( oSalesCallDate.getTime() > oToday.getTime() ) { alert( "You cannot close an interaction with a future Sales Call Date - " + frmInteraction.elements.interactionDate.value ); submitPromise.reject(); return submitPromise; } frmInteraction.elements.inProcess.value = 'no'; if (frmInteraction.elements.newFirstName.value == 'First Name') { frmInteraction.elements.newFirstName.value = ''; } if (frmInteraction.elements.newLastName.value == 'Last Name') { frmInteraction.elements.newLastName.value = ''; } frmInteraction.elements.currentObjective.value = instance.objID; if (Fse.FormManager.submit( frmInteraction, false )) { // distributor check - only gets here if client config says distributor not a required field if (frmInteraction.elements.cdrDistributorID.selectedIndex != undefined) { if (frmInteraction.elements.cdrDistributorID[frmInteraction.elements.cdrDistributorID.selectedIndex].value == '0') { if (confirm('No distributor selected. Click OK to continue, or Cancel to select distributor.') == false) { submitPromise.reject(); return submitPromise; } } } // submit let $frmInteraction = $( frmInteraction ); instance.setButtonAreaMessage( "Saving call data..."); $.ajax( { url : Fse.Util.updateURL( instance.baseURL, { do : "interaction-dialog-action-update" } ), method : $frmInteraction.attr( "method" ), data : Fse.Ajax.serialize( $frmInteraction[0] ), headers : { fseAjax : true } }).done( function( result ) { instance.setButtonAreaMessage( "" ); submitPromise.resolve(); }) } else { submitPromise.reject(); } return submitPromise; } CallEntryPopup.prototype.saveInteraction = function() { let instance = this; let savePromise = $.Deferred(); let _callDtStatus = Fse.FormManager.checkField(document.forms.frmInteraction.elements.interactionDate); let _followupDtStatus = Fse.FormManager.checkField(document.forms.frmInteraction.elements.followupDate); if (document.forms.frmInteraction.elements.newFirstName.value == 'First Name') { document.forms.frmInteraction.elements.newFirstName.value = ''; } if (document.forms.frmInteraction.elements.newLastName.value == 'Last Name') { document.forms.frmInteraction.elements.newLastName.value = ''; } if (_callDtStatus >= 2) { alert('Enter a valid call date in the format mm/dd/yyyy.'); savePromise.reject(); return savePromise; } if (_followupDtStatus >= 2) { alert('Enter a valid follow up date in the format mm/dd/yyyy.'); savePromise.reject(); return savePromise; } // other misc checks if ( instance.chkNewOpportunities() == false ) { savePromise.reject(); return savePromise; } if ( instance.chkObjSelections() == false ) { savePromise.reject(); return savePromise; } if (document.frmInteraction.dispositionUserID.selectedIndex == 0) { alert('You must select a Sales Rep.'); document.forms.frmInteraction.element.dispositionUserID.focus(); savePromise.reject(); return savePromise; } // attempt to save document.forms.frmInteraction.elements.inProcess.value = 'yes'; let frmInteraction = $(document.forms.frmInteraction); instance.setButtonAreaMessage( "Saving call data..." ); $.ajax( { url : Fse.Util.updateURL( instance.baseURL, { do : "interaction-dialog-action-update" } ), method : frmInteraction.attr( "method" ), data : Fse.Ajax.serialize( frmInteraction[0] ), headers : { fseAjax : true } }).done( function( result ) { //console.log( "saveInteraction", result ); instance.setButtonAreaMessage( "" ); savePromise.resolve(); }) return savePromise; } CallEntryPopup.prototype.setButtonAreaMessage = function( message ) { let instance = this; instance.buttonAreaMessage.empty(); if( message != "" ) instance.buttonAreaMessage.text( message ); } CallEntryPopup.prototype.saveBrief = function() { let instance = this; $.Deferred(); let saveBriefURL = Fse.Util.updateURL( instance.baseURL, { do : "interaction-dialog-action-update-brief" }); let saveBriefPromise = $.ajax( { url : saveBriefURL, method : "POST", data : Fse.Ajax.serialize( document.forms.frmInteraction ), }) saveBriefPromise.done( function( result, statusText, jqXhr ) { // console.log( "saveBrief", jqXhr ); }) return saveBriefPromise; } CallEntryPopup.prototype.categoryLevelItemsExist = function() { let codesReqSkuList = document.getElementById("call-products").getAttribute("FSE:stageCodesReqSku"); let arCodesReqSku = codesReqSkuList.split(","); // var arItmStatus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); let arItmStatus = $("select.sku-status-fu-chk"); for (i=0;i<=arItmStatus.length-1;i=i+1) { // check sale status sku requirement if ( arItmStatus[i].value == 'STD' && arItmStatus[i].getAttribute("fse:itemtype") == 'PRD' && arCodesReqSku.indexOf("C") >= 0 ) { alert('Sold items at a category level must be converted to a SKU.'); return true; } // check no sale status sku requirement if ( arItmStatus[i].value == 'NS' && arItmStatus[i].getAttribute("fse:itemtype") == 'PRD' && arCodesReqSku.indexOf("R") >= 0 ) { alert('No Sale items at a category level must be converted to a SKU.'); return true; } } return false; } CallEntryPopup.prototype.chkEmptyObjectives = function(objId) { // check for any objectives without items presented (make sure status not delete) //var objList = document.frmInteraction.objectiveList.value; let objList = document.forms.frmInteraction.elements.ActiveObjectiveList.value; if (objList != '') { let arObjectives = objList.split(","); for(let i=0; i < arObjectives.length; i++) { // check items with status selection let noItems = true; // var arItmStatus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); let arItmStatus = $("select.sku-status-fu-chk"); for (var j=0; j < arItmStatus.length; j++) { let itmObj = arItmStatus[j].getAttribute("FSE:obj"); let itmRef = arItmStatus[j].getAttribute("reference"); let itemStatus = document.getElementById("itemStatus_"+itmRef); if (itemStatus.value != 'DLT' && itmObj == arObjectives[i]) { noItems = false; } } if (noItems == true) { // if not found, check items without status selection - those identified as "multiple objectives" // reference back to original item status to make sure not set to delete // var arMultiItems = YAHOO.util.Dom.getElementsByClassName('multi-item-here', 'div'); let arMultiItems = $("div.multi-item-here" ); for (let k=0; k < arMultiItems.length; k++) { let multiItmObj = arMultiItems[k].getAttribute("FSE:obj"); let origItmRef = arMultiItems[k].getAttribute("reference"); let itemStatus = document.getElementById("itemStatus_"+origItmRef); if (itemStatus && itemStatus.value != 'DLT' && multiItmObj == arObjectives[i]) { noItems = false; } } if (noItems == true) { return true; } } } } return false; } CallEntryPopup.prototype.soldItemsDatesOk = function() { // if any sold items have an order date prior to call date, returns false // scrum 19029 // exit and return true if order date is not part of the client configuration let oItemsTable = document.getElementById( "call-products" ); let sConfig = oItemsTable.getAttribute( "FSE:statusConfig" ); if ( sConfig.indexOf("OD|") == -1 && sConfig.indexOf("|OD") == -1 ) { return true; } let dtSalesCallDate = new Date( document.forms.frmInteraction.elements.interactionDate.value ); // var arItmStatus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); let arItmStatus = $("select.sku-status-fu-chk"); for (i=0;i<=arItmStatus.length-1;i=i+1) { if ( arItmStatus[i].value == 'STD' ) { let itmRef = arItmStatus[i].getAttribute("reference"); let oAvailableDate = document.getElementById("availableDate_"+itmRef); if (oAvailableDate) { let dtAvailDate = new Date( oAvailableDate.value ); let tmAvailDate = dtAvailDate.getTime(); if (!isNaN(tmAvailDate) && tmAvailDate < dtSalesCallDate.getTime() ) { return false; } } } } return true; } CallEntryPopup.prototype.soldItemsDatesMaxDateCheck = function() { let oItemsTable = document.getElementById( "call-products" ); let maxDaysOutSetting = oItemsTable.getAttribute( "FSE:availableDateOffsetMax" ); let maxDaysOut = parseInt( maxDaysOutSetting ); if ( maxDaysOut == -1 ) { return true; } let dtSalesCallDate = new Date( document.forms.frmInteraction.elements.interactionDate.value ); // var arItmStatus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); let arItmStatus = $("select.sku-status-fu-chk"); for (i=0;i<=arItmStatus.length-1;i=i+1) { if ( arItmStatus[i].value == 'STD' ) { let itmRef = arItmStatus[i].getAttribute("reference"); let oAvailableDate = document.getElementById("availableDate_"+itmRef); if (oAvailableDate) { let dtAvailDate = new Date( oAvailableDate.value ); if (!isNaN(dtAvailDate) && parseInt((dtAvailDate - dtSalesCallDate) / (1000 * 60 * 60 * 24), 10) > maxDaysOut ) { if ( maxDaysOut == 0 ) { alert('Est order date cannot exceed the call date.'); } else { alert('Est order date cannot be more than ' + maxDaysOutSetting + ' days out from the call date.'); } oAvailableDate.focus(); return false; } } } } return true; } CallEntryPopup.prototype.chkEmptyItems = function() { //var arItmStatus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); let arItmStatus = $("select.sku-status-fu-chk" ); for (i=0;i<=arItmStatus.length-1;i=i+1) { // check to see if item was "presented" let _itemId = arItmStatus[i].getAttribute("id"); let _start = _itemId.indexOf("_"); let _len = _itemId.length; let _itemIdentifier = _itemId.slice(_start,_len) let e = document.getElementById("presented" + _itemIdentifier + "_y"); let _presented = true; if (e) { _presented = ( e.checked ); } else { _presented = true; } if ( arItmStatus[i].value != 'DLT' && _presented ) { return false; } } return true; } CallEntryPopup.prototype.chkObjSelections = function() { // var arObjStatus = YAHOO.util.Dom.getElementsByClassName('sku-objective-chk', 'select'); let arObjStatus = $("select.sku-objective-chk"); for (i=0;i<=arObjStatus.length-1;i=i+1) { if (arObjStatus[i].value == '0') { let itmRef = arObjStatus[i].getAttribute("reference"); let itemStatus = document.getElementById("itemStatus_"+itmRef); if (itemStatus.value != 'DLT') { alert('Select objective for item.'); arObjStatus[i].focus(); return false; } } } return true; } CallEntryPopup.prototype.chkNewOpportunities = function() { // var arItmStatus = YAHOO.util.Dom.getElementsByClassName('sku-status-fu-chk', 'select'); let arItmStatus = $( "select.sku-status-fu-chk" ); for (i=0;i<=arItmStatus.length-1;i=i+1) { // the opportunity options all start with OPP + the percent likelihood if (arItmStatus[i].value.substring(0,3) == 'OPP' ) { let itmRef = arItmStatus[i].getAttribute("reference"); // if idea stage (0 likelihood), then let slide on requirement for date and volume if (arItmStatus[i].value.substring(3) != '0' ) { let estCloseDate = document.getElementById("estclosedate_"+itmRef); if (estCloseDate.value == '') { alert('Est. Close Date must be specified for New Opportunities.'); estCloseDate.focus(); return false; } let casesWK = document.getElementById("casesWK_"+itmRef); if (casesWK.value == '' || casesWK.value == '0') { alert('Volume quantity must be specified for New Opportunities.'); casesWK.focus(); return false; } } let itemComment = document.getElementById("itemComment_"+itmRef); if (itemComment.value == '') { alert('Comment must be entered for New Opportunities.'); itemComment.focus(); return false; } } } return true; } CallEntryPopup.prototype.refreshProductsDisplay = function() { let instance = this; let refreshPromise = $.Deferred(); instance.saveBrief().done( function() { let scrollPos = document.getElementById("divProductsForm").scrollTop; // save current top pos instance.refreshProductsDisplayRaw().done( function() { document.getElementById("divProductsForm").scrollTop = scrollPos; refreshPromise.resolve(); }) }) return refreshPromise; } CallEntryPopup.prototype.refreshProductsDisplayRaw = function() { let instance = this; let divProductsForm = $("#divProductsForm"); divProductsForm.empty().text( "loading..." ); return $.ajax( { url : Fse.Util.updateURL( instance.baseURL, { view : "interaction-dialog-products-form", interactionID : instance.interactionID, editMode : instance.interactionEditable, updateObjectiveLinks : instance.productsUpdated ? 'false' : 'true', mode : "direct" }), headers : { fseAjax : true } }).done( function( result ) { divProductsForm.empty().append( result ); Fse.DialogManager.initializePopupDateBoxes( divProductsForm ) let expandLink = divProductsForm.find( "#prdlist-expand-lnk"); if( expandLink.length ) { expandLink.on( "click", function() { instance.toggleCallProductsDiv(); }) } instance._bindConvertPRDtoSKU( divProductsForm ); // document.getElementById( "divProductsForm" ).setAttribute( "FSE:productsUpdated", "true" ); instance.productsUpdated = true; }) } CallEntryPopup.prototype.getCallDetailsToolbarItems = function() { let instance = this; if (instance.intDisposition == '?') { if (instance.interactionEditable) { instance.buttonSet = 'interaction-dialog-buttons-detail-pend-edit'; } else { instance.buttonSet = 'interaction-dialog-buttons-close'; } } else { if (instance.interactionEditable) { instance.buttonSet = 'interaction-dialog-buttons-detail-closed-edit'; } else { instance.buttonSet = 'interaction-dialog-buttons-close'; } } let finalizeText = "Complete Call"; let saveAsOpenText = "Save as Planned"; let callDetailsToolbarItems = []; callDetailsToolbarItems.push( instance._helpToolbarItem() ); let buttonAreaMessageItem = { toolbar : "bottom", location : "before", template : function() { instance.buttonAreaMessage = $("
").css( { "width" : 350 } ) return instance.buttonAreaMessage } }; let addSKUItem = { toolbar : "bottom", location : "before", template : function() { let quickAddToolbar = $("
").dxToolbar( { items : [ { location : "before", template : function() { let textBox = $("
").dxTextBox( { placeholder : "add sku", width : 200, onValueChanged : function( e ) { if( e.value && e.value != "" ) { instance.submitQuickAdd(); } } }).dxTextBox( "instance") instance.quickAddSKUText = textBox; return textBox.element(); } }, { location : "before", visible : false, template : function() { return $("").text( "Cancel" ).css( { "text-decoration" : "underline", "cursor" : "pointer" }).on( "click", function( je ) { instance.cancelQuickAdd(); }); } }, { location : "before", visible : false, template : function() { let selectBox = $("
").dxSelectBox({ width : 300, placeholder : "-- Select SKU From List --", valueExpr : "skuId", displayExpr : function( skuData ) { if( ! skuData ) return; return `${skuData.sku} - ${skuData.skuDesc} ${skuData.packSizeDesc}` }, onValueChanged : function( e ) { if( e.value ) { instance.submitQuickAdd( e.value ); } } }).dxSelectBox( "instance" ); instance.quickAddSKUSelect = selectBox; return selectBox.element(); } }, { location : "before", template : function() { let msgBox = $("
").css( { width : 200 } ); instance.quickAddStatusMsg = msgBox; return msgBox; } } ] }).dxToolbar("instance"); instance.quickAddToolbar = quickAddToolbar; return quickAddToolbar.element(); } }; let exportPDFItem = { toolbar : "bottom", location : "after", template : function() { let icon = $("").addClass( "dx-icon-pdffile" ).attr( { "title" : "Download Sales Call as PDF" } ).css( { "cursor" : "pointer", "font-size" : "16px", "margin-right" : "10px" } ).on( "click" , function( je ) { instance.exportToPDF(); }) return icon; } } let editProfileItem = { toolbar : "bottom", location : "after", // widget : "dxButton", // options : { // icon : "edit", // text : "Account Profile", // onClick : function( e ) { // instance.interactionEditProfile(); // } // }, template : function() { let icon = $("").addClass( "dx-icon-card" ).attr( { "title" : "Edit Account Profile" } ).css( { "cursor" : "pointer", "font-size" : "16px", "margin-right" : "10px" } ).on( "click" , function( je ) { instance.interactionEditProfile(); }) return icon; } } let emailItem = { toolbar : "bottom", location : "after", template : function() { let icon = $("").addClass( "dx-icon-email" ).attr( { "title" : "Email Sales Call" } ).css( { "cursor" : "pointer", "font-size" : "16px", "margin-right" : "10px" } ).on( "click" , function( je ) { instance.emailNotify(); }) return icon; } } // let testButtonItem = { // toolbar : "bottom", // location : "before", // widget : "dxButton", // options : { // text : "Test Button", // onClick : function( e ) { // const formData = new FormData( document.forms.frmInteraction ); // // Display the keys // for (const key of formData.keys()) { // console.log(key); // } // } // } // } // callDetailsToolbarItems.push( testButtonItem ); if( instance.buttonSet == "interaction-dialog-buttons-detail-pend-edit" ) { callDetailsToolbarItems.push( addSKUItem ); callDetailsToolbarItems.push( buttonAreaMessageItem ); callDetailsToolbarItems.push( editProfileItem ); callDetailsToolbarItems.push( emailItem ); callDetailsToolbarItems.push( exportPDFItem ); callDetailsToolbarItems.push( { toolbar : "bottom", location : "after", widget : "dxButton", options : { type : "default", text : saveAsOpenText, onClick : function( e ) { instance.reduceCallProductsDiv(); instance.saveInteraction().done( function() { instance.popup.hide(); instance.callback(); }); } } }) callDetailsToolbarItems.push( { toolbar : "bottom", location : "after", widget : "dxButton", options : { type : "default", text : finalizeText, onClick : function( e ) { instance.submitInteraction().done( function() { instance.popup.hide(); if ( instance.recapEnabled ){ // document.getElementById("divInteractionRecapDialog") instance.openInteractionRecapDialog(); }else{ instance.callback(); } }) } } } ) } else if ( instance.buttonSet == "interaction-dialog-buttons-detail-closed-edit" ) { callDetailsToolbarItems.push( buttonAreaMessageItem ); callDetailsToolbarItems.push( editProfileItem ); callDetailsToolbarItems.push( emailItem ); callDetailsToolbarItems.push( exportPDFItem ); if( instance.recapEnabled ) { callDetailsToolbarItems.push({ toolbar : "bottom", location : "after", widget : "dxButton", options : { xtype : "default", text : "Send Recap", onClick : function( e ) { instance.openInteractionRecapDialog(); } } } ) } callDetailsToolbarItems.push( { toolbar : "bottom", location : "after", widget : "dxButton", options : { xtype : "default", text : "Back to Planned", onClick : function( e ) { instance.reduceCallProductsDiv(); instance.saveInteraction().done( function() { instance.popup.hide(); instance.callback(); }); } } }) callDetailsToolbarItems.push( { toolbar : "bottom", location : "after", widget : "dxButton", options : { xtype : "default", text : "Update Call", onClick : function( e ) { instance.submitInteraction().done( function() { instance.popup.hide(); if ( instance.recapEnabled ){ // document.getElementById("divInteractionRecapDialog") instance.openInteractionRecapDialog(); }else{ instance.callback(); } }) } } } ) } else { // interaction-dialog-buttons-close callDetailsToolbarItems.push ( { toolbar : "bottom", location : "after", widget : "dxButton", options : { type : "default", text : "Close Window", onClick : function( e ) { instance.popup.hide(); } } } ) } instance.callDetailsToolbarItems = callDetailsToolbarItems; return instance.callDetailsToolbarItems; } CallEntryPopup.prototype.gotoCallDetailsTab = function() { // Fse.CLOS.interactionDialogTabs.set('activeIndex', 0); // Fse.CLOS.setHelpIcon(); this.tabPanel.option( "selectedIndex", this.CALL_DETAILS_TAB ); } CallEntryPopup.prototype.toggleCallProductsDiv = function() { let divProductsForm = $("#divProductsForm"); if( divProductsForm.hasClass( "expanded-products" )) { this.reduceCallProductsDiv(); } else { this.expandCallProductsDiv(); } } CallEntryPopup.prototype.expandCallProductsDiv = function() { $("#divDetailForm").addClass( "fse-hidden-element" ); $("#divProductsForm").addClass( "expanded-products" ); $("#prdlist-expand-lnk").text( "reduce" ); } CallEntryPopup.prototype.reduceCallProductsDiv = function() { $("#divProductsForm").removeClass( "expanded-products" ); $("#divDetailForm").removeClass( "fse-hidden-element" ); $("#prdlist-expand-lnk").text( "expand" ); } CallEntryPopup.prototype._helpToolbarItem = function() { let instance = this; return { location : "after", toolbar : "top", template : function() { let helpIcon = $("").addClass( "dx-icon-help" ).css( { cursor : "pointer" } ).attr( "title", "help"); helpIcon.on( "click", function( e ) { let tabItem = instance.tabPanel.option( "selectedItem" ); if( tabItem.helpSubject ) { Fse.Portal.showQuickHelp( tabItem.helpSubject ) } } ); return $("
").append( helpIcon ); } } } CallEntryPopup.prototype.show = function() { let instance = this; let supportToolbarItems = []; supportToolbarItems.push( instance._helpToolbarItem(), { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "<< Call Details", onClick : function( e ) { instance.gotoCallDetailsTab(); } } } ); let popupOptions = { width : "85vw", height : "98vh", title : "Sales Call", hideOnOutsideClick : false, onHidden : function( e ) { e.component.element().remove(); e.component.dispose(); }, contentTemplate : function() { instance.tabPanel = $("
") // moved to htmlTabTemplate .addClass( "sc-dialog" ).addClass( "obj-close-call" ) .dxTabPanel( { items : instance.tabPanelItems, swipeEnabled : false, selectedIndex : instance.CALL_DETAILS_TAB, height : "100%", width : "100%", onSelectionChanged : function( e ) { //console.log( "onSelectionChanged",e ); let idx = e.component.option( "selectedIndex" ); if( idx == instance.CALL_DETAILS_TAB ) { instance.popup.option( "toolbarItems", instance.callDetailsToolbarItems ) if( ! instance.productsUpdated ) { // not continuing the search, so refresh the products instance.refreshProductsDisplayRaw().done( function() { // async requires no follow up }); } } else { let selectedItem = e.component.option( "selectedItem" ); let tabReady = $.Deferred(); if( selectedItem.isContentReady && selectedItem.autoRefresh ) { selectedItem.refresh().done( function() { tabReady.resolve(); }); } else { tabReady.resolve(); } tabReady.done( function() { let toolbarItems = selectedItem.toolbarItems; if( ! toolbarItems ) toolbarItems = supportToolbarItems; instance.popup.option( "toolbarItems", toolbarItems ) }) } } }).dxTabPanel( "instance" ); return instance.tabPanel.element(); }, toolbarItems : [] } instance.loadPromise.done( function() { // console.log( "INSTANCE.DATA", instance.data ); if( instance.data.interactionId ) { let title = `Sales Call : ${instance.data.partnerName}, ${instance.data.salesRepFullName}, ${instance.data.territoryName}, ID ${instance.data.partnerId}`; popupOptions.title = title; } instance._initializeTabPanelItems(); popupOptions.toolbarItems = instance.getCallDetailsToolbarItems(); instance.popup = $("
").attr( "id", "divInteractionDialog" ).dxPopup( popupOptions ).dxPopup( "instance" ); $("body").append( instance.popup.element() ); instance.popup.show(); }) } CallEntryPopup.prototype._bindExportToCalendar = function( content ) { let instance = this; let exportToCalendarLink = content.find( ".export-to-calendar" ); exportToCalendarLink.each( function( i ) { let link = $(this); link.on( "click", function( jqe ) { if( link.hasClass( "export-to-calendar-follow-up" ) ) { instance.exportToCalendar( "followup" ) } else { instance.exportToCalendar( "current" ); } }) }) } CallEntryPopup.prototype._bindConvertPRDtoSKU = function( content ) { let instance = this; let convertCatToSKULink = content.find( "a.convert-prd-to-sku" ); convertCatToSKULink.each( function( i ) { let link = $(this); link.on( "click", function( jqe ) { let interactionDetailId = parseInt( link.attr( "interactionDetailId")); let mfrId = parseInt( link.attr( "mfrId" )); let prodId = parseInt( link.attr( "prodId" )); instance.convertPRDtoSKU( interactionDetailId, mfrId, prodId ); }) }) } CallEntryPopup.prototype._initializeTabPanelItems = function() { let instance = this; instance.tabPanelItems = []; let _addTabPanelItem = function( itemData ) { instance.tabPanelItems.push( itemData ); // return the index return instance.tabPanelItems.length - 1; } instance.CALL_DETAILS_TAB = _addTabPanelItem( { title : "Call Details", id : "divInteractionTab1", view : "interaction-dialog-detail-form", fields : [ "editMode", "highlightSKUId"], helpSubject : "Sales Call Details Tab", template : function( itemData ) { return instance.htmlTabTemplate( itemData, { onContentReady( content ) { let expandLink = content.find( "#prdlist-expand-lnk"); if( expandLink.length ) { expandLink.on( "click", function() { instance.toggleCallProductsDiv(); }) } instance._bindConvertPRDtoSKU( content ); instance._bindExportToCalendar( content ); }} ); } } ); instance.ADD_ITEMS_TAB = _addTabPanelItem( { title : "Add Items", id : "divAddProductsSearch", view : "interaction-dialog-addprod-srchfrm", helpSubject : "Sales Call Add Items Tab", toolbarItems : [ instance._helpToolbarItem(), { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "<< Call Details", onClick : function( e ) { instance.gotoCallDetailsTab(); } } },{ toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Add - Continue", onClick : function( e ) { instance.submitAddProducts( true ) } } }, { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Add - Done", type : "default", onClick : function( e ) { instance.submitAddProducts( false ); } } } ], template : function( itemData ) { // this is not returned from the server so add it //
// let resultsDiv = $("
").attr( { id : "divAddProductsResults", tabindex : 0 }); let resultsDiv = $("
").attr( { id : "divAddProductsResults", tabindex : 0 }); return instance.htmlTabTemplate( itemData, { additionalContent : resultsDiv, onContentReady : function( content ) { let srchTypeFields = content.find("input[name=srchType]"); srchTypeFields.each( function( idx ) { let srchTypeField = $(this); let srchTypeValue = srchTypeField.attr( "value" ); if( srchTypeValue == "misc") { srchTypeField.on( "click", function( jqe ) { document.forms.frmInteractionSrchProds.elements.srchFirstLetterFilter.value='' instance.setLinkedSrchOption( srchTypeValue ); }) } else if ( srchTypeValue == "fav" ) { srchTypeField.on( "click", function( jqe ) { document.forms.frmInteractionSrchProds.elements.srchFavManuf.value='0' instance.setLinkedSrchOption( srchTypeValue ); }) } else { srchTypeField.on( "click", function( jqe ) { instance.setLinkedSrchOption( srchTypeValue ); }) } }) // bind search and clear buttons. instance._bindSearchAndClearButtons( content ); instance.setLinkedSrchOption('prod',false); document.frmInteractionSrchProds.srchType[0].checked = true; } }); } }); instance.OBJECTIVES_TAB = _addTabPanelItem( { title : "Objectives", view : "interaction-dialog-linked-objectives", id : "divLinkedObjectives", fields : "stfID", helpSubject : "Sales Call Objectives Tab", autoRefresh : true, template : function( itemData ) { let scli = new SalesCallLinkedObjectives( { interactionId : instance.interactionID } ); return $("
").css( { "height": "100%", "padding" : "5px" } ).append( scli.element() ); // return instance.htmlTabTemplate( itemData ); } } ); instance.CALL_HISTORY_TAB = _addTabPanelItem( { title : "Call History", id : "divCallHistory", view : "interaction-dialog-call-history", helpSubject : "Sales Call Add Call History Tab", autoRefresh : true, template : function( itemData ) { let sch = new SalesCallHistory( { partnerId : instance.partnerId, partnerType : instance.partnerType, days : 365 }) return $("
").css( { "height": "100%", "padding" : "5px" } ).append( sch.element() ); } } ); // perhaps a tasks tab at somepoint instance.TASKS_TAB = _addTabPanelItem( { title : "Tasks", id : "divTasksTab", helpSubject : "Sales Call Tasks Tab", template : function() { let pt = new PartnerTasks( { partnerType : instance.partnerType, partnerId : instance.partnerId } ) return pt.element(); } }); // instance.EMAIL_TAB = _addTabPanelItem( // { // title : "Email", id : "divIntNotify", view : "interaction-dialog-call-notify", fields : [ "intDate", "contactFirst", "contactLast"], // helpSubject : "Sales Call Notify Tab", // toolbarItems : [ // instance._helpToolbarItem(), // { // toolbar : "bottom", // location : "after", // widget : "dxButton", // options : { // text : "<< Call Details", // onClick : function( e ) { // instance.gotoCallDetailsTab(); // } // } // }, // { // toolbar : "bottom", // location : "after", // widget : "dxButton", // options : { // text : "Send Email", // type : "default", // onClick : function( e ) { // instance.interactionDialogSendEmail(); // } // } // } // ], // autoRefresh : true, // template : function( itemData ) { // instance.emailSender = new EmailSender( { // from : Fse.Portal.appConfiguration.STP.userEmailAddress, // messageFormatter : "BCM.salesCallNotifyFormatMessage", // messageDefaultsURL : Fse.Util.updateURL( $("link#PortalDocRootURL" ).attr( "href" ) + "/apps/BCM/index.cfm", { ajax : "salesCallNotifyDefaults", mode : "direct", "interactionId" : instance.interactionID } ), // trackingCode : "objAddOpr", // subjectType : "CLL", // subjectId : instance.interactionID // } ); // return $("
").css( { "height": "100%", "padding" : "5px" } ).append( instance.emailSender.element() ); // // return instance.htmlTabTemplate( itemData ); // } // }); if( false ) instance.PROFILE_TAB = _addTabPanelItem( { title : "Profile", id : "divInteractionProfileTab", view : "interaction-dialog-profile", helpSubject : "Sales Call Profile Tab", toolbarItems : [ instance._helpToolbarItem(), { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "<< Call Details", onClick : function( e ) { instance.gotoCallDetailsTab(); } } }, { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Update Profile", type : "default", onClick : function( e ) { instance.ineractionDialogSaveProfile(); } } } ], template : function( itemData ) { return instance.htmlTabTemplate( itemData ); } }); instance.AUDIT_TAB = _addTabPanelItem( { title : "Audit", id : "divInteractionAuditTab", view : "interaction-dialog-audit", helpSubject : "Sales Call Audit Tab", toolbarItems : [ instance._helpToolbarItem(), { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "<< Call Details", onClick : function( e ) { instance.gotoCallDetailsTab() } } }, { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "Update Audit", type : "default", onClick : function( e ) { instance.updateAudit(); } } } ], autoRefresh : true, template : function( itemData ) { instance.salesCallAudit = new SalesCallAudit( { interactionId : instance.interactionID } ); return $("
").css( { "height": "100%", "padding" : "5px" } ).append( instance.salesCallAudit.element() ); // return instance.htmlTabTemplate( itemData ); } }); // perhaps a business plan tab at some point if( instance.partnerType == "OPR" || ( instance.partnerType == "CDR" && instance.distributorPurchasingTabEnabled ) ) { instance.PURCHASING_TAB = _addTabPanelItem( { title : "Purchasing", id : "divInteractionPurchasingProfileTab", view : "interaction-dialog-purchasing-profile", helpSubject : "Sales Call Purchasing Tab", toolbarItems : [ instance._helpToolbarItem(), { toolbar : "bottom", location : "after", widget : "dxButton", options : { text : "<< Call Details", onClick : function( e ) { instance.gotoCallDetailsTab() } } }, { toolbar : "bottom", location : "after", widget : "dxButton", visible : instance.partnerType == "OPR" ? true : false, options : { text : "Update Purchasing Profile", type : "default", onClick : function( e ) { instance.savePurchasingProfile(); } } } ], template : function( itemData ) { if( instance.partnerType == "OPR" ) { let operator = { operatorId : instance.partnerId, cho_id : instance.oneFSId } instance.operatorPurchasing = new OperatorPurchasing( operator, { showNewCall : false, showSaveButton : false } ) return instance.operatorPurchasing.element(); } else if ( instance.partnerType == "CDR" ) { let distributor = { distributorId : instance.partnerId, dstcompanytype : instance.companyType } instance.distributorPurchasing = new DistributorPurchasing( distributor ); return instance.distributorPurchasing.element(); } else { return $("
").text( "Invalid Partner Type" ) // return instance.htmlTabTemplate( itemData ); } } } ); } /* // original assets tab instance.ASSETS_TAB_SAVE = _addTabPanelItem( { title : "Assets", view : "interaction-dialog-assets", id : "divInteractionAssetTabOld", helpSubject : "Sales Call Assets Tab", template : function( itemData ) { return instance.htmlTabTemplate( itemData ); } } ); */ instance.ASSETS_TAB = _addTabPanelItem( { title : "Assets", id : "divInteractionAssetTab", view : "interaction-dialog-assets", helpSubject : "Sales Call Assets Tab", autoRefresh : true, isContentReady : true, refresh : function(itemData) { const deferred = $.Deferred(); //console.log('Refreshing assets tab'); setTimeout(() => { const sca = instance._salesCallAssetsInstance; if (sca && typeof sca.refresh === "function") { sca.refresh(); deferred.resolve(); } else { console.warn("SalesCallAssets instance not found or refresh method missing"); deferred.reject("SalesCallAssets instance not ready"); } }, 0); return deferred.promise(); }, template : function( itemData ) { let sca = new SalesCallAssets( { interactionId : instance.interactionID, partnerId : instance.partnerId, partnerType : instance.partnerType }) // store reference for later use (refresh function) instance._salesCallAssetsInstance = sca; return $("
").css( { "height": "100%", "padding" : "5px" } ).append( sca.element() ); } } ); } CallEntryPopup.prototype.refreshTab = function( tabIdx ) { let instance = this; let itemData = instance.tabPanel.option( `items[${tabIdx}]` ); if( itemData && itemData.refresh ) { return itemData.refresh(); } else { let f = $.Deferred(); f.reject(); return f; } } CallEntryPopup.prototype.htmlTabTemplate = function( itemData, options ) { let instance = this; options = options ? options : {}; let wrapper = null; let content = null; if( options.additionalContent ) { wrapper = $("
").attr( "id", itemData.id ); content = $("
"); wrapper.append( content ); wrapper.append( options.additionalContent ); } else { content = $("
").attr( "id", itemData.id ); } content.text( "retrieving data..."); //itemData.scrollView = $(content).dxScrollView( {} ).dxScrollView("instance" ); itemData.refresh = function() { let urlOptions = { view : itemData.view, mode : "direct", interactionID : instance.interactionID } itemData.isContentReady = false; if( itemData.fields ) { let urlFields = Array.isArray( itemData.fields ) ? itemData.fields : itemData.fields.split( "," ); urlFields.forEach( function( uf ) { if( uf == "stfID" ) urlOptions.stfID = instance.stfID; if( uf == "highlightSKUId" ) urlOptions.highlightSKUId = instance.highlightSKUId; if( uf == "editMode" ) urlOptions.editMode = instance.interactionEditable; }) } //console.log( "urlOptions", urlOptions ); let contentURL = Fse.Util.updateURL( instance.baseURL, urlOptions ); content.empty().text( "retrieving data..." ); let refreshPromise = $.ajax( { url : contentURL, method : "GET", headers : { fseAjax : true } }).done( function( data ) { content.parent().addClass( "sc-dialog" ).addClass( "obj-close-call" ); content.empty().append( data ); Fse.DialogManager.initializePopupDateBoxes( content ); itemData.isContentReady = true; if( options.onContentReady ) options.onContentReady( wrapper ? wrapper : content ); }) return refreshPromise; } itemData.refresh(); return wrapper ? wrapper : content; } CallEntryPopup.prototype.exportToCalendar = function(intType) { let instance = this; if (intType == undefined) { intType = 'current' }; let contactFirst = document.forms.frmInteraction.elements.newFirstName.value; let contactLast = document.forms.frmInteraction.elements.newLastName.value; let intDate = null; let oDate = null; if (intType == 'current') { intDate = document.forms.frmInteraction.elements.interactionDate.value; oDate = document.forms.frmInteraction.elements.interactionDate; } else { intDate = document.forms.frmInteraction.elements.followupDate.value; oDate = document.forms.frmInteraction.elements.followupDate; document.getElementById("followupDate").setAttribute("fse:followupDownloaded","TRUE") } let frmInteraction = document.forms.frmInteraction; if ( Fse.FormManager.checkDate(frmInteraction.elements.interactionDate) == false ) { if ( intDate == '' ) { alert('Please enter a date first.'); } else { alert( 'Invalid date format entered: ' + intDate ); } return false; } else { instance.saveBrief().done( function() { let calendarURL = Fse.Util.updateURL( instance.baseURL, { view : "interaction-dialog-calendar-import", mode : "direct", intId : instance.interactionID, intType : intType, intDate : intDate, contactFirst : contactFirst, contactLast : contactLast }) window.location = calendarURL; //window.location = Fse.CLOS.baseURL+'?view=interaction-dialog-calendar-import&mode=direct&intid='+interactionID+'&intType='+intType+'&intDate='+intDate+'&contactFirst='+contactFirst+'&contactLast='+contactLast; }); } } CallEntryPopup.prototype.emailNotify = function() { let instance = this; instance.saveBrief().done( function() { let emailSender = new EmailSender( { from : Fse.Portal.appConfiguration.STP.userEmailAddress, messageFormatter : "BCM.salesCallNotifyFormatMessage", messageDefaultsURL : Fse.Util.updateURL( $("link#PortalDocRootURL" ).attr( "href" ) + "/apps/BCM/index.cfm", { ajax : "salesCallNotifyDefaults", mode : "direct", "interactionId" : instance.interactionID } ), trackingCode : "objAddOpr", subjectType : "CLL", subjectId : instance.interactionID } ); emailSender.show(); }); } CallEntryPopup.prototype.exportToPDF = function() { let instance = this; instance.saveBrief().done( function() { let pdfURL = Fse.Util.updateURL(instance.baseURL, { "view" : "interaction-dialog-pdf-export", "mode" : "direct", "intid" : instance.interactionID } ); window.location = pdfURL; }) // var interactionID = document.frmInteraction.interactionID.value; // Fse.CLOS.saveBrief(); // // window.location = Fse.CLOS.baseURL+'?view=interaction-dialog-pdf-export&mode=direct&intid='+interactionID; // window.location = Fse.Util.updateURL2( Fse.CLOS.baseURL+"?view=interaction-dialog-pdf-export&mode=direct", { "intid" : interactionID } ); } CallEntryPopup.prototype.openInteractionRecapDialog = function() { let instance = this; let cancelRecapButtonText = "Send Recap Later"; let popupVisible = instance.popup.option( "visible" ); if( popupVisible ) { cancelRecapButtonText = "Cancel"; } let scrd = new SalesCallRecapDialog( { interactionID : instance.interactionID, cancelRecapButtonText : cancelRecapButtonText } ); scrd.show().done( function() { if( popupVisible ) instance.popup.hide(); instance.callback(); }).fail( function() { if( ! popupVisible ) instance.callback(); }) } CallEntryPopup.prototype.setLinkedSrchOption = function(srchType,submitForm) { let instance = this; if ( submitForm == undefined ) { submitForm = true }; let oSrchSpace = document.getElementById("td-search-criteria"); if (srchType == 'prod') { if ( getComputedStyle(document.getElementById("search-form-skus")).display == 'block' && getComputedStyle(document.getElementById("td-search-criteria")).opacity == 1 ) { // nothing to do return true; } document.getElementById("search-form-categories").style.display = "none"; document.getElementById("search-form-quick").style.display = "none"; document.getElementById("search-form-1fs").style.display = "none"; document.getElementById("search-form-skus").style.display = "block"; let elements = document.querySelectorAll(".srchFormSku"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = false; } elements = document.querySelectorAll(".srchFormCats"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchFormQuick"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchForm1FS"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } //Fse.CLOS.clearInteractionProdSearch(submitForm); instance.submitInteractionProdSearch(); /* jm 6/2022: trying this approach so that we don't lose criteria each time we try other search methods */ oSrchSpace.style.opacity = 1; } else if (srchType == 'cat') { if ( getComputedStyle(document.getElementById("search-form-categories")).display == 'block' && getComputedStyle(document.getElementById("td-search-criteria")).opacity == 1 ) { // nothing to do return true; } document.getElementById("search-form-skus").style.display = "none"; document.getElementById("search-form-quick").style.display = "none"; document.getElementById("search-form-1fs").style.display = "none"; document.getElementById("search-form-categories").style.display = "block"; let elements = document.querySelectorAll(".srchFormCats"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = false; } elements = document.querySelectorAll(".srchFormSku"); for (var i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchFormQuick"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchForm1FS"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } instance.clearInteractionProdSearch(submitForm); oSrchSpace.style.opacity = 1; } else if (srchType == 'quick') { if ( getComputedStyle(document.getElementById("search-form-quick")).display == 'block' && getComputedStyle(document.getElementById("td-search-criteria")).opacity == 1 ) { // nothing to do return true; } document.getElementById("search-form-skus").style.display = "none"; document.getElementById("search-form-categories").style.display = "none"; document.getElementById("search-form-1fs").style.display = "none"; document.getElementById("search-form-quick").style.display = "block"; let elements = document.querySelectorAll(".srchFormQuick"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = false; } elements = document.querySelectorAll(".srchFormCats"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchFormSku"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchForm1FS"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } if ( document.frmInteractionSrchProds.srchQuickKeyword.value == '' ) { // Spry.Utils.setInnerHTML( "divAddProductsResults", "" ); $("#divAddProductsResults").empty(); } else { instance.clearInteractionProdSearch(submitForm); } setTimeout(function() { document.getElementById('srchQuickKeyword').focus(); }, 10); oSrchSpace.style.opacity = 1; } else if (srchType == '1fs') { if ( getComputedStyle(document.getElementById("search-form-1fs")).display == 'block' && getComputedStyle(document.getElementById("td-search-criteria")).opacity == 1 ) { // nothing to do return true; } document.getElementById("search-form-skus").style.display = "none"; document.getElementById("search-form-quick").style.display = "none"; document.getElementById("search-form-categories").style.display = "none"; document.getElementById("search-form-1fs").style.display = "block"; let elements = document.querySelectorAll(".srchForm1FS"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = false; } elements = document.querySelectorAll(".srchFormCats"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchFormSku"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchFormQuick"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } instance.clearInteractionProdSearch(submitForm); oSrchSpace.style.opacity = 1; } else { let elements = document.querySelectorAll(".srchFormSku"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchFormCats"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } elements = document.querySelectorAll(".srchForm1fs"); for (let i = 0, len = elements.length; i < len; ++i) { elements[i].disabled = true; } if (submitForm == true) { instance.submitInteractionProdSearch(); } oSrchSpace.style.opacity = .3; } } CallEntryPopup.prototype.submitInteractionProdSearch = function() { let instance = this; document.forms.frmInteractionSrchProds.interactionID.value = instance.interactionID; let resultsDiv = $("#divAddProductsResults"); resultsDiv.empty().text( "Searching..."); let searchForm = $(document.forms.frmInteractionSrchProds); // build the url params const urlParams = {}; let formData = new FormData( searchForm[0] ) formData.forEach((value, key) => urlParams[key] = value); const searchURL = Fse.Util.updateURL( searchForm.attr( "action" ), urlParams ); $.ajax( { method : "GET", url : searchURL, headers : { fseAjax : true } }).done( function( resultHTML ) { resultsDiv.empty().append( resultHTML ); instance._bindSearchAndClearButtons( resultsDiv ); if (document.getElementById("srchType-prod").checked) { document.frmInteractionSrchProds.srchKeyword.focus(); document.frmInteractionSrchProds.srchKeyword.select(); } }) .fail( function( x ) { console.log( x ); }) } CallEntryPopup.prototype.clearInteractionProdSearch = function(submitForm) { let instance = this; if ( submitForm == undefined ) { submitForm = true }; if (document.getElementById('srchType-prod').checked) { document.frmInteractionSrchProds.srchManuf.selectedIndex=0; document.frmInteractionSrchProds.srchCategory.selectedIndex=0; document.frmInteractionSrchProds.srchKeyword.value=''; document.frmInteractionSrchProds.srchDistributor.selectedIndex=0; document.frmInteractionSrchProds.srchObjective.selectedIndex=0; if (document.frmInteractionSrchProds.srchKeyword.visibility=="visible") { document.frmInteractionSrchProds.srchKeyword.focus(); } document.frmInteractionSrchProds.srchFocus.checked = false; document.frmInteractionSrchProds.srchFocusCategory.checked = false; if (document.frmInteractionSrchProds.srchBuyingStatus) { document.getElementById('srchBuyingStatus_all').checked = true }; $('#srchConfirmedPurchOnly').prop('checked', false); $('#srchConfirmedPurchOnly').attr('onclick','return false'); $('#srchConfirmedPurchOnly').css('opacity','.3'); if (document.frmInteractionSrchProds.srchAffiliation) {document.frmInteractionSrchProds.srchAffiliation.selectedIndex=0;} if (document.frmInteractionSrchProds.srchProductSet) {document.frmInteractionSrchProds.srchProductSet.selectedIndex=0;} } else if (document.getElementById('srchType-cat').checked) { if (document.frmInteractionSrchProds.srchCatsManuf) {document.frmInteractionSrchProds.srchCatsManuf.selectedIndex=0;} if (document.frmInteractionSrchProds.srchCatsKeyword) {document.frmInteractionSrchProds.srchCatsKeyword.value='';} } else if (document.getElementById('srchType-1fs').checked) { if (document.frmInteractionSrchProds.srch1fsManuf) {document.frmInteractionSrchProds.srch1fsManuf.selectedIndex=0;} if (document.frmInteractionSrchProds.srch1fsKeyword) {document.frmInteractionSrchProds.srch1fsKeyword.value='';} if (document.frmInteractionSrchProds.srch1FSBuyingStatus) { document.getElementById('srch1FSBuyingStatus_all').checked = true; } $('#srch1FSConfirmedPurchOnly').prop('checked', false); $('#srch1FSConfirmedPurchOnly').attr('onclick','return false'); $('#srch1FSConfirmedPurchOnly').css('opacity','.3'); } if (submitForm == true) { instance.submitInteractionProdSearch(); } } CallEntryPopup.prototype._bindSearchAndClearButtons = function( content ) { let instance = this; // the purpose of this method is to find all places where we need to initiate a product search or clear it // and bind the appropriate handlers - i.e. onclick, onchange, onkeydown // with the appropriate logic let clearElements = content.find( ".clear-btn" ); clearElements.each( function( i ) { $(this).on( "click", function( jqe ) { instance.clearInteractionProdSearch(); }) }) let searchElements = content.find( ".search-btn" ); // console.log( "Search Elements", searchElements ); searchElements.each( function( i ) { let element = $(this); if( element.hasClass( "search-btn-misc" )) { if( ! element.hasClass( "first-ltr-disabled" )) { element.on( "click", function( jqe ) { document.forms.frmInteractionSrchProds.elements.srchFirstLetterFilter.value = $(this).attr( "letter"); instance.submitInteractionProdSearch(); }) } } else if ( element.hasClass( "search-btn-fav" )) { if( element.hasClass( "search-btn-mfr")) { element.on( "change", function( jqe ) { document.forms.frmInteractionSrchProds.elements.srchFavManuf.value = this.value; instance.submitInteractionProdSearch(); }) } else if ( element.has( "search-btn-cat" )) { element.on( "change", function( jqe ) { document.forms.frmInteractionSrchProds.elements.srchFavCategory.value = this.value; instance.submitInteractionProdSearch(); }) } } else if ( element.hasClass( "search-btn-enter") ) { element.on( "keydown", function( jqe ){ if(jqe.keyCode==13) instance.submitInteractionProdSearch(); }) } else { element.on( "click", function( jqe ) { instance.submitInteractionProdSearch(); }) } }) } CallEntryPopup.prototype.interactionEditProfile = function() { let instance = this; let editProfilePromise; let profileSaved = function() { alert( "Profile Saved" ); } if( instance.partnerType == "OPR" ) { editProfilePromise = OperatorProfile.openPopupEditor( instance.partnerId ); editProfilePromise.done( function() { profileSaved(); }) } else if ( instance.partnerType == "CDR" ) { editProfilePromise = DistributorProfile.openPopupEditor( instance.partnerId ); editProfilePromise.done( function() { profileSaved(); }) } else { editProfilePromise = $.Deferred(); editProfilePromise.reject( "Unsuppored Partner Type" ); } return editProfilePromise; }