function showRecipientModal(view, event, composeView, draftId){
const el = document.createElement('div');
el.style.width = '250px';
el.style.height = '100px';
el.innerHTML = 'Blah blah...';
const modal= view.showModalView({
el,
title: 'blah',
buttons: [
{
text: "Send Anyway",
title: "Send Anyway",
onClick: function(click){
console.log("OK button clicked");
sendEmail(composeView, event, draftId);
modal.close();
},
type: 'PRIMARY_ACTION',
color: 'green'
},
{
text: "Edit",
title: "Edit",
onClick: function(click){
//Here, I want to return to the ComposeView and edit my email
console.log("Edit button clicked");
modal.close();
event.cancel();
},
type: 'SECONDARY',
color: 'grey'
}
]
});
}
function sendEmail(composeView, event, draftId){
var params = {
tracking: computeTrackingChoice(),
threadId: draftId
};
// Call My API to send the email using the gmail API
.done(function(data) {
console.log('sendEmail API call success, data: ', data);
event.cancel();
})
.fail(function(e) {
console.log('failed to sendEmail to API', e);
//Server is down/ service is unavailable -> Send the email anyway!
});
composeView.close();
}
InboxSDK.load(2, 'sdk_Saleswings_c25da028c8').then(function(sdk){
console.log('SDK loaded');
checkIfLinkedWithGmail();
console.log("gmaiAddress", gmailAddress);
// the SDK has been loaded, now do something with it!
sdk.Compose.registerComposeViewHandler(function(composeView){
composeView.addButton({
title: 'SalesWings tracking',
iconUrl: chrome.extension.getURL(SMALL_WING),
iconClass: 'sw-tracking-button',
hasDropdown: true,
onClick: function(event){
event.dropdown.el.innerHTML = showPopup(gmailAddress);
if(readyToSend){addCheckBoxListeners(event.dropdown.el)};
}
});
var draftId = '';
composeView.getDraftID().then(function(id){
console.log('DraftID: ',id);
draftId = id;
});
composeView.on('presending', event =>{
console.log('Cancel sending message '+draftId);
console.log("event", event);
var recipients = composeView.getToRecipients();
if(recipients.length != 1){
showRecipientModal(sdk.Widgets, event, composeView, draftId);
}else{
sendEmail(composeView, event, draftId);
}
});
});
});