SalesCallRecapDialog = function( options ) {
let instance = this;
instance.interactionID = options.interactionID;
instance.baseURL = $("link#bcmHandlerLink").attr( "href" );
instance.cancelRecapButtonText = "Cancel";
if( options.cancelRecapButtonText ) {
instance.cancelRecapButtonText = options.cancelRecapButtonText;
}
}
SalesCallRecapDialog.prototype.constructor = SalesCallRecapDialog
SalesCallRecapDialog.prototype.show = function() {
let instance = this;
let showPromise = $.Deferred();
let recapSubmitted = false;
let recapPopup = $("
").dxPopup( {
title : "Sales Call Recap",
width : 800,
height : "auto",
hideOnOutsideClick : false,
onHiding : function( e ) {
if( ! recapSubmitted ) {
showPromise.reject();
}
},
toolbarItems : [
{
toolbar : "bottom", location : "after",
widget : "dxButton", options : {
text : instance.cancelRecapButtonText,
onClick : function( e ) {
recapPopup.hide();
}
}
},
{
toolbar : "bottom", location : "after",
widget : "dxButton", options : {
text : "Send Recap NOW",
onClick : function( e ) {
instance.sendInteractionRecap().done( function( ) {
recapSubmitted = true;
recapPopup.hide();
showPromise.resolve();
});
}
}
}
],
contentTemplate : function() {
let content = $("
").text( "Loading...").attr( "id", "divInteractionRecapDialog_bodySocket" ).css( "height", "440px" );
let recapBodyURL = Fse.Util.updateURL( instance.baseURL, {
view : "interaction-dialog-recap-init",
mode : "direct",
interactionID : instance.interactionID
})
$.ajax( {
url : recapBodyURL,
method : "GET",
headers : { fseAjax : true }
}).done( function( responseHTML ) {
content.empty().append( responseHTML );
})
return content;
},
onHidden : function( e ) {
e.component.element().remove();
e.component.dispose();
}
}).dxPopup("instance");
recapPopup.element().appendTo( $("body") );
recapPopup.show();
return showPromise;
}
SalesCallRecapDialog.prototype.sendInteractionRecap = function() {
let sendRecapPromise = $.Deferred();
let frmEmailSalesCallRecap = $( document.forms.frmEmailSalesCallRecap );
if( Fse.FormManager.submit( frmEmailSalesCallRecap[0], false ) ) {
let ajaxOptions = {
url : frmEmailSalesCallRecap.attr( "action" ),
method : frmEmailSalesCallRecap.attr( "method" ),
data : frmEmailSalesCallRecap.serialize(),
headers : { fseAjax : true }
}
$.ajax( ajaxOptions )
.done( function( result ) {
sendRecapPromise.resolve();
})
.fail( function( jqXHR ) {
sendRecapPromise.reject();
})
} else {
sendRecapPromise.reject();
}
return sendRecapPromise;
}