Full implemantation
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
this.id = props.id
|
||||
}
|
||||
}
|
||||
draw() {
|
||||
draw(tr) {
|
||||
const name = $('<td></td>')
|
||||
const register = $('<td></td>')
|
||||
if (this.registered) {
|
||||
@ -42,27 +42,32 @@
|
||||
register.append(
|
||||
$('<button></button>').addClass('ui mini circular icon button').append(
|
||||
$('<i></i>').addClass('save icon')
|
||||
).click(() => {
|
||||
this.register()
|
||||
).click((e) => {
|
||||
this.register($(e.currentTarget))
|
||||
})
|
||||
)
|
||||
}
|
||||
return $('<tr></tr>').append(name).append(register)
|
||||
return tr.append(name).append(register)
|
||||
}
|
||||
register() {
|
||||
register(button) {
|
||||
const uri = '/mailboxes/register'
|
||||
const data = {
|
||||
mailboxes: [this.name]
|
||||
}
|
||||
button.html('').append(
|
||||
$('<i></i>').addClass('redo loading icon')
|
||||
)
|
||||
return Send.post({
|
||||
uri,
|
||||
data
|
||||
}).then(response => {
|
||||
response.mailboxes.forEach(mb => {
|
||||
if (mb.name === this.name && mb.created) {
|
||||
response.registered.mailboxes.forEach(mb => {
|
||||
if (mb.name === this.name && mb.registered) {
|
||||
this.id = mb.id
|
||||
this.registered = true
|
||||
mailboxes.draw().table()
|
||||
const tr = button.parent().parent()
|
||||
tr.html('')
|
||||
this.draw(tr)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -91,7 +96,7 @@
|
||||
mailboxes: [],
|
||||
get: function() {
|
||||
this.draw().loading()
|
||||
return Send.get('/mailboxes').then(response => {
|
||||
return Send.get('/mailboxes').then((response, status, jqXHR) => {
|
||||
response.mailboxes.forEach(mb => {
|
||||
this.mailboxes.push(new Mailbox(mb))
|
||||
})
|
||||
@ -138,7 +143,7 @@
|
||||
body: () => {
|
||||
const body = $('<tbody></tbody>')
|
||||
this.mailboxes.forEach(mb => {
|
||||
body.append(mb.draw())
|
||||
body.append(mb.draw($('<tr></tr>')))
|
||||
})
|
||||
return body
|
||||
}
|
||||
|
@ -19,14 +19,16 @@
|
||||
valid: false,
|
||||
downloaded: false
|
||||
}
|
||||
attachments
|
||||
|
||||
constructor({id, uid, subject, date_time, from, states}) {
|
||||
constructor({id, uid, subject, date_time, from, states, attachments}) {
|
||||
this.set().id(id)
|
||||
.set().uid(uid)
|
||||
.set().subject(subject)
|
||||
.set().date(date_time)
|
||||
.set().from(from)
|
||||
.set().states(states)
|
||||
.set().attachments(attachments)
|
||||
}
|
||||
get() {
|
||||
return {
|
||||
@ -47,6 +49,9 @@
|
||||
},
|
||||
states: () => {
|
||||
return this.states
|
||||
},
|
||||
attachments: () => {
|
||||
return this.attachments
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,6 +87,9 @@
|
||||
this.states[map_keys[k]] = states[k]
|
||||
})
|
||||
return this
|
||||
},
|
||||
attachments: attachments => {
|
||||
this.attachments = attachments
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,25 +131,35 @@
|
||||
} catch (e) {
|
||||
console.debug(e)
|
||||
}
|
||||
const valid = $('<td></td>').html($('<i></i>').addClass(this.has().valid() ? 'green check circle icon' : 'red times circle icon'))
|
||||
if (this.has().valid() && this.get().attachments().length > 0) {
|
||||
const list = $('<div></div>').addClass('ui list')
|
||||
this.get().attachments().forEach(attachment => {
|
||||
list.append($('<div></div>').addClass('item').html(attachment.filename))
|
||||
})
|
||||
valid.append(
|
||||
$('<div></div>').addClass('ui popup').append(list)
|
||||
)
|
||||
}
|
||||
return $('<tr></tr>').append(
|
||||
$('<td></td>').html(this.get().subject())
|
||||
).append(
|
||||
$('<td></td>').html(format.format(date))
|
||||
).append(
|
||||
$('<td></td>').html(this.get().from())
|
||||
$('<td></td>').html(this.get().from().full)
|
||||
).append(
|
||||
$('<td></td>').html($('<i></i>').addClass(this.has().attachments() ? 'green check circle icon' : 'red times circle icon'))
|
||||
).append(
|
||||
$('<td></td>').html($('<i></i>').addClass(this.has().valid() ? 'green check circle icon' : 'red times circle icon'))
|
||||
valid
|
||||
).append(
|
||||
$('<td></td>').html($('<i></i>').addClass(this.has().downloaded() ? 'green check circle icon' : 'red times circle icon'))
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
(this.has().attachments() && this.has().valid() && !this.has().downloaded()) ?
|
||||
$('<button></button>').addClass('ui mini green circular icon button').append(
|
||||
$('<i></i>').addClass('paperclip icon')
|
||||
$('<i></i>').addClass('clock icon')
|
||||
).click(() => {
|
||||
this.download().attachments(this.get().uid())
|
||||
this.download().attachments(this.get().id())
|
||||
}) : ''
|
||||
)
|
||||
)
|
||||
@ -149,21 +167,19 @@
|
||||
|
||||
download() {
|
||||
return {
|
||||
attachments: uid => {
|
||||
const uri = '/emails/attachment'
|
||||
attachments: id => {
|
||||
const uri = '/messages/schedule'
|
||||
const data = {
|
||||
mailbox: '{{$mailbox_id}}',
|
||||
messages: [
|
||||
uid
|
||||
],
|
||||
extension: 'pdf'
|
||||
id
|
||||
]
|
||||
}
|
||||
return Send.post({
|
||||
return Send.put({
|
||||
uri,
|
||||
data
|
||||
}).then(response => {
|
||||
if (response.attachments_count > 0) {
|
||||
alert('Grabbed Attachments')
|
||||
if (response.scheduled > 0) {
|
||||
alert('Scheduled Attachments Job')
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -191,14 +207,8 @@
|
||||
})
|
||||
},
|
||||
messages: () => {
|
||||
const uri = '/messages/valid'
|
||||
const data = {
|
||||
mailboxes: ['{{$mailbox_id}}']
|
||||
}
|
||||
return Send.post({
|
||||
uri,
|
||||
data
|
||||
}).then(response => {
|
||||
const uri = '/mailbox/{{$mailbox_id}}/messages/valid'
|
||||
return Send.get(uri).then(response => {
|
||||
if (this.total === null) {
|
||||
$(this.id.count).html(' (' + response.total + ')')
|
||||
this.total = response.total
|
||||
|
@ -13,8 +13,13 @@
|
||||
get: function() {
|
||||
const uri = '/mailboxes/registered'
|
||||
this.draw().loading()
|
||||
return Send.get(uri).then(response => {
|
||||
this.mailboxes = response.mailboxes
|
||||
return Send.get(uri).then((response, status, jqXHR) => {
|
||||
if (parseInt(jqXHR.status / 100) !== 2) {
|
||||
return
|
||||
}
|
||||
if (jqXHR.status === 200) {
|
||||
this.mailboxes = response.mailboxes
|
||||
}
|
||||
this.draw().list()
|
||||
})
|
||||
},
|
||||
@ -38,6 +43,10 @@
|
||||
list: () => {
|
||||
const parent = $(this.div_id)
|
||||
parent.html('')
|
||||
if (this.mailboxes.length === 0) {
|
||||
parent.html('No mailboxes registered.')
|
||||
return
|
||||
}
|
||||
const list = $('<div></div>').addClass('ui list')
|
||||
this.mailboxes.forEach(mb => {
|
||||
list.append(
|
||||
|
Reference in New Issue
Block a user