Download attachments
This commit is contained in:
@ -2,9 +2,12 @@
|
||||
use ProVM\Common\Controller\Emails;
|
||||
|
||||
$app->group('/emails', function($app) {
|
||||
$app->group('/mailbox/{mailbox}', function ($app) {
|
||||
$app->group('/mailbox/{mailbox_id}', function($app) {
|
||||
$app->get('[/]', [Emails::class, 'messages']);
|
||||
});
|
||||
$app->group('/message/{message_id}', function($app) {
|
||||
$app->get('[/]', [Emails::class, 'show']);
|
||||
});
|
||||
$app->get('/mailboxes', Emails::class);
|
||||
$app->get('[/]', Emails::class);
|
||||
});
|
||||
|
6
ui/resources/routes/02_attachments.php
Normal file
6
ui/resources/routes/02_attachments.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
use ProVM\Common\Controller\Attachments;
|
||||
|
||||
$app->group('/attachment/{attachment_id}', function($app) {
|
||||
$app->get('[/]', [Attachments::class, 'get']);
|
||||
});
|
@ -141,7 +141,7 @@
|
||||
$('<div></div>').addClass('ui popup').append(list)
|
||||
)
|
||||
}
|
||||
return $('<tr></tr>').append(
|
||||
const tr = $('<tr></tr>').append(
|
||||
$('<td></td>').html(this.get().subject())
|
||||
).append(
|
||||
$('<td></td>').html(format.format(date))
|
||||
@ -163,6 +163,19 @@
|
||||
}) : ''
|
||||
)
|
||||
)
|
||||
if (this.has().downloaded()) {
|
||||
tr.find('td').each((i, td) => {
|
||||
const content = $(td).html()
|
||||
if (content.indexOf('icon') > -1) {
|
||||
return
|
||||
}
|
||||
$(td).html('')
|
||||
$(td).append(
|
||||
$('<a></a>').attr('href', '{{$urls->base}}/emails/message/' + this.id).html(content)
|
||||
)
|
||||
})
|
||||
}
|
||||
return tr
|
||||
}
|
||||
|
||||
download() {
|
||||
|
103
ui/resources/views/emails/show.blade.php
Normal file
103
ui/resources/views/emails/show.blade.php
Normal file
@ -0,0 +1,103 @@
|
||||
@extends('emails.base')
|
||||
|
||||
@section('emails_content')
|
||||
<h3>Message - <span id="subject"></span> - <span id="from"></span></h3>
|
||||
<h4 id="date_time"></h4>
|
||||
<div class="ui list" id="attachments"></div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
const message = {
|
||||
ids: {
|
||||
subject: '',
|
||||
from: '',
|
||||
date_time: '',
|
||||
attachments: ''
|
||||
},
|
||||
data: {
|
||||
subject: '',
|
||||
from: '',
|
||||
date_time: '',
|
||||
attachments: []
|
||||
},
|
||||
get: function() {
|
||||
return {
|
||||
message: message_id => {
|
||||
return Send.get('/message/' + message_id).then(response => {
|
||||
this.set().subject(response.message.subject)
|
||||
.set().from(response.message.from)
|
||||
.set().date_time(response.message.date_time)
|
||||
.set().attachments(response.message.attachments)
|
||||
}).then(() => {
|
||||
this.draw().data()
|
||||
})
|
||||
},
|
||||
subject: () => {
|
||||
return this.data.subject
|
||||
},
|
||||
from: () => {
|
||||
return this.data.from
|
||||
},
|
||||
date_time: () => {
|
||||
return this.data.date_time
|
||||
},
|
||||
attachments: () => {
|
||||
return this.data.attachments
|
||||
}
|
||||
}
|
||||
},
|
||||
set: function() {
|
||||
return {
|
||||
subject: subject => {
|
||||
this.data.subject = subject
|
||||
return this
|
||||
},
|
||||
from: from => {
|
||||
this.data.from = from
|
||||
return this
|
||||
},
|
||||
date_time: date => {
|
||||
this.data.date_time = date
|
||||
return this
|
||||
},
|
||||
attachments: attachments => {
|
||||
attachments.forEach(attachment => {
|
||||
this.data.attachments.push(attachment)
|
||||
})
|
||||
return this
|
||||
}
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
return {
|
||||
data: () => {
|
||||
$(this.ids.subject).html(this.get().subject())
|
||||
$(this.ids.from).html(this.get().from())
|
||||
$(this.ids.date_time).html(this.get().date_time())
|
||||
|
||||
this.draw().attachments($(this.ids.attachments))
|
||||
|
||||
},
|
||||
attachments: parent => {
|
||||
this.get().attachments().forEach(attachment => {
|
||||
parent.append(
|
||||
$('<a></a>').attr('href', _urls.base + '/attachment/' + attachment.id).attr('download', attachment.fullname).html(attachment.fullname)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
setup: function(message_id) {
|
||||
this.get().message(message_id)
|
||||
}
|
||||
}
|
||||
$(document).ready(() => {
|
||||
message.ids.subject = '#subject'
|
||||
message.ids.from = '#from'
|
||||
message.ids.date_time = '#date_time'
|
||||
message.ids.attachments = '#attachments'
|
||||
message.setup('{{$message_id}}')
|
||||
})
|
||||
</script>
|
||||
@endpush
|
@ -35,4 +35,5 @@
|
||||
return this.base({method: 'delete', uri, data, dataType, contentType})
|
||||
}
|
||||
}
|
||||
const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
|
||||
</script>
|
Reference in New Issue
Block a user