You are about to re-run the query !
Currenly you have ${curImport.data.length} recipients.
After re-running the query, you would have ${tmpResults.nbRows} recipients.
Update the data?
`,
okLabel: 'Yes, rerun the query !',
severity: 'warning',
okPromise: data => this.mailings.refreshImport(this.currentMailing.id, {
sourceType: curImport.sourceType,
refreshOnly: true,
importId: curImport.id,
}, importId).then(
() => btn.loading = false,
() => btn.loading = false
)
})
if(result) this.loadMailingInfo(this.currentMailing.id)
btn.loading = false
}
// async onSourceEditQC(importId, event) {
// event.preventDefault()
// event.stopPropagation()
// const curImport = this.currentMailing.imports.find(i => i.id==importId)
// console.log('=====>onSourceEditQC:', curImport.data.length)
// }
async onImport(){
let result = await this.openDialog(
await this.loadContent(
'comms/mailings/sheet/dialogs/MailingImportDialog',
{ title: `Import recipients from Excel file...` },
{ model: this.mailings,
mid: this.currentMailing.id,
}
)
)
if(result) this.loadMailingInfo(this.currentMailing.id)
}
async onExclusion(){
let result = await this.openDialog(
await this.loadContent(
'comms/mailings/sheet/dialogs/MailingExclusionDialog',
{ title: `Import exclusion list from Excel file...` },
{ model: this.mailings,
mid: this.currentMailing.id,
}
)
)
if(result) this.loadMailingInfo(this.currentMailing.id)
}
async onFetch(){
let result = await this.openDialog(
await this.loadContent(
'comms/mailings/sheet/dialogs/MailingFetchDialog',
{ title: `Fetch recipients from MyEIC applications...` },
{
models: {
contacts: this.contactMgr,
mailings: this.mailings,
},
mid: this.currentMailing.id,
}
)
)
if(result) this.loadMailingInfo(this.currentMailing.id)
}
async onDupsInfo(component, event) {
let result = await this.openDialog(
await this.loadContent(
'comms/mailings/sheet/dialogs/MailingDuplicatesDialog',
{ title: `Duplicate emails...` },
{ dupes: component.dupes,
}
)
)
}
async onMappingChange(component, event) {
let result = await this.openDialog(
await this.loadContent(
'comms/mailings/sheet/dialogs/MailingMappingDialog',
{ title: `Link template variable to a column in the Excel file...` },
{
model: this.mailings,
token: component._el.dataset.token,
sourceId: component._el.dataset.sourceid,
currentMailing: this.currentMailing,
}
)
)
if(result) this.loadMailingInfo(this.currentMailing.id)
}
async onTestSend(){
let result = await this.openDialog(
await this.loadContent(
'comms/mailings/sheet/dialogs/MailingTestDialog',
{ title: `Sending a test mail...` },
{ tokens: this.templates.getTokens(this.currentMailing.template) }
)
)
if(result){
await this.mailings.test(this.currentMailing.id, this.currentMailing.template.id, result.email, result.tokenValues)
}
}
async onReviewRequest(){
let result = await this.confirmDialog({
title: 'Request review ?',
message: `You're about to request for this mailing to be reviewed.
During the review process, the mailing won't be editable anymore.
`,
promptsClass: 'prompts',
okLabel: 'Reject sending',
severity: 'warning',
okSeverity: 'primary',
okPromise: (data) => {
this.currentMailing.status = 'rejected'
this.currentMailing.statusMeta = { reason: data.reason }
return(this.mailings.save(this.currentMailing))
}
})
if(result) { this.loadMailingInfo(this.currentMailing.id) }
}
onScheduleDateChange(){
this.components.scheduleTimeLater.value = ''
this.fillScheduleTime()
this.components.scheduleButton.disabled = true
}
onScheduleTimeChange() { this.components.scheduleButton.disabled = (this.components.scheduleTimeLater.value == '') }
fillScheduleTime(){
const today = new Date().toISOString().split('T')[0]
const thisHour = (new Date()).getHours()
this.components.scheduleTimeLater.el.innerHTML=''
if(this.components.scheduleDateLater.value==today){
if((thisHour+1) < 24) {
for(let h=thisHour+1; h<24; h++) this.components.scheduleTimeLater.el.append(ui.create(``))
}
} else {
for(let h=0; h<24; h++) this.components.scheduleTimeLater.el.append(ui.create(``))
}
}
async onSendingNow(component, event) { await this.sendMailing(this.components.scheduleDateNow.value, this.components.scheduleTimeNow.value) }
async onSendingLater(component, event) { await this.sendMailing(this.components.scheduleDateLater.value, this.components.scheduleTimeLater.value) }
async sendMailing(scheduleDate, scheduleTime) {
const getCETOffset = () => {
const date = new Date()
const options = { timeZone: "Europe/Paris", timeZoneName: "short" }
const formatter = new Intl.DateTimeFormat("en-US", options)
const parts = formatter.formatToParts(date)
const timeZoneOffset = parts.find(part => part.type === "timeZoneName").value
return timeZoneOffset.includes("CEST") ? 2 : 1
}
const today = new Date().toISOString().split('T')[0]
const [year, month, day] = scheduleDate.split("-")
const europeanDate = `${day}/${month}/${year}`
let when
if(scheduleDate==today){
when = scheduleTime=='5min' ? 'in five minutes' : `today at ${scheduleTime.toString().padStart(2, '0')}:00 (${scheduleTime < 12 ? 'AM' : 'PM'})`
} else {
when = `on ${europeanDate} at ${scheduleTime.toString().padStart(2, '0')}:00 (${scheduleTime < 12 ? 'AM' : 'PM'})`
}
let UTCScheduleTime
if(scheduleTime!='5min'){
UTCScheduleTime = (new Date(`${scheduleDate}T${scheduleTime.toString().padStart(2, '0')}:00:00+0${getCETOffset()}:00`)).toISOString()
} else {
UTCScheduleTime = (new Date((new Date).getTime() + 5 * 60 * 1000)).toISOString()
}
let result = await this.confirmDialog({
title: 'Send mailing ?',
message: `You are about to schedule the sending of this mailing ${when}`,
okLabel: 'Schedule sending',
severity: 'secondary',
okSeverity: 'danger',
okPromise: (data) => {
return(this.mailings.schedule(this.currentMailing.id, UTCScheduleTime))
}
})
if(result) { this.loadMailingInfo(this.currentMailing.id); }
}
async onAbortSending(component, event) {
let result = await this.confirmDialog({
title: 'Abort the sending ?',
message: `You are about to abort the sending of this mailing !
If you proceed, it will be editable again,
and it will have to be reviewed again.
Is this really what you want to do ?`,
okLabel: 'Abort',
severity: 'warning',
cancelSeverity: 'primary',
okSeverity: 'secondary',
okPromise: (data) => {
this.currentMailing.status = 'draft'
return(this.mailings.save(this.currentMailing))
}
})
if(result) { this.loadMailingInfo(this.currentMailing.id) }
}
async onUnschedule(component, event) {
let result = await this.confirmDialog({
title: 'Unschedule the sending ?',
message: `You are about to unschedule this mailing !
If you proceed, it will not be sent,
and you will be able to re-schedule or to abort it.
Is this really what you want to do ?`,
okLabel: 'Unschedule',
severity: 'warning',
cancelSeverity: 'primary',
okSeverity: 'secondary',
okPromise: (data) => {
this.currentMailing.status = 'approved'
return(this.mailings.save(this.currentMailing))
}
})
if(result) { this.loadMailingInfo(this.currentMailing.id) }
}
async onMailingDelete(component, event) {
let result = await this.confirmDialog({
title: 'DELETE this mailing ?',
message: `You are about to DELETE this mailing !
If you proceed, it will not be sent,
and everything it contains will be lost.
Is this really what you want to do ?`,
okLabel: 'Delete',
severity: 'danger',
cancelSeverity: 'primary',
okSeverity: 'secondary',
okPromise: (data) => {
return(this.mailings.delete(this.currentMailing.id))
}
})
if(result) { app.Router.route(`/mailings`) }
}
pathChips(path){
const dirs = path.split('/').filter(item=>item)
const markup = (dirs.length>0) ? dirs.map((dir, idx) => {
const path = dirs.slice(0, idx+1).join('/')
return(`${dir}`)
}).join('') : '[Please select it]'
return(markup)
}
}
app.registerClass('MailingSheetView', MailingSheetView)
/*
TODO
-> Delete Draft (add in WF, add method in MT, add here)
*/