class MailingFetchDialog extends EICDialogContent {
actions = [
{
label: 'Cancel',
onclick: this.cancel.bind(this),
severity: 'secondary',
role: 'cancel'
},
{
label: 'Use these recipients',
onclick: this.add.bind(this),
severity: 'primary',
role: 'add',
disabled: true
}
]
constructor(...args) {
super(...args)
Object.assign(this, app.helpers.activeAttributes)
this.currentFilters = []
this.currentQCId = null
this.currentNbResults = 0
this.baseColors = ['success','primary','danger','warning','accent','secondary']
}
DOMContentLoaded(options) {
this.contactsModel = options.models.contacts
this.mailingsModel = options.models.mailings
this.mid = options.mid
const components = ui.eicfy(this.el)
this.setupTriggers(components)
this.setupRefs(components)
this.components.searchType.disabled = true
this.setAsyncLoading(true, ['searchType'])
this.contactsModel.list().then(this.fillQCSelector.bind(this))
}
fillQCSelector(qcList){
for(let query of qcList){
this.components.searchType.el.append(ui.create(
``
))
}
this.components.searchType.disabled = false
this.setAsyncLoading(false, ['searchType'])
}
onsearchType(component, event){
this.setAsyncLoading(true, ['searchCriteria'])
this.components.searchBtn.disabled = true
this.contactsModel.get(component.value).then(this.buildForm.bind(this))
}
onSourceName(component, event){ this.changeAddBtnState() }
buildForm(query){
this.fieldNames = {}
this.fieldColors = {}
this.output('searchCriteria','')
const tabsMenu = ui.create(`
`)
const tabsDiv = ui.create(``)
this.outputs.searchCriteria.append(tabsDiv)
for(let queryGroup of query.group){
const groupEl = ui.create(`
${queryGroup.title}
${queryGroup.description ? ``: ''}
`)
const sectionEl = groupEl.querySelector('section')
let colIdx = 0
for(let field of queryGroup.field){
this.fieldNames[field.id] = field.title
this.fieldColors[field.id] = {
severity: this.baseColors[colIdx % this.baseColors.length],
brightness: 100+(20*Math.floor(colIdx/this.baseColors.length))
}
colIdx++
const el = ui.create(`
${field.description ? `` : ''}
`)
if(!field.type) field.type='text'
switch(field.type){
case 'list':
const selector = ui.create(``)
for(let value of field.value){
selector.append(ui.create(
``
))
}
el.append(selector)
break
case 'date':
el.append(ui.create(``))
break
default:
el.append(ui.create(`