mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
better file download handling
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import repository from './repository'
|
||||
|
||||
export default {
|
||||
getCredentials (id) {
|
||||
return repository.get(`credentials/${id}/`)
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,7 @@ import { bus } from '@/main'
|
||||
import identities from '@/api/identities'
|
||||
import accounts from '@/api/accounts'
|
||||
import aliases from '@/api/aliases'
|
||||
import credentials from '@/api/credentials'
|
||||
import ConfirmDialog from '@/components/layout/ConfirmDialog'
|
||||
import MenuItems from '@/components/tools/MenuItems'
|
||||
|
||||
@@ -211,10 +212,20 @@ export default {
|
||||
result.push({
|
||||
label: this.$gettext(element.label),
|
||||
icon: element.icon,
|
||||
link: element.url,
|
||||
onClick: () => {
|
||||
window.open(element.url)
|
||||
this.fetchIdentities()
|
||||
if (element.body.type === 'pdfcredentials') {
|
||||
credentials.getCredentials(item.pk)
|
||||
.then((response) => {
|
||||
const blob = new Blob([response.data], {
|
||||
type: 'application/pdf'
|
||||
})
|
||||
const _url = window.URL.createObjectURL(blob)
|
||||
window.open(_url, '_blank').focus()
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
this.fetchIdentities()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -228,7 +239,9 @@ export default {
|
||||
},
|
||||
getActionMenuItems () {
|
||||
const result = []
|
||||
result.push({ label: this.$gettext('Delete'), icon: 'mdi-delete-outline', onClick: this.deleteIdentities, color: 'red' })
|
||||
if (this.selected.length > 0) {
|
||||
result.push({ label: this.$gettext('Delete'), icon: 'mdi-delete-outline', onClick: this.deleteIdentities, color: 'red' })
|
||||
}
|
||||
result.push({ label: 'Reload', icon: 'mdi-reload', onClick: this.fetchIdentities })
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ class IdPossibleActionsSerializer(serializers.Serializer):
|
||||
name = serializers.CharField()
|
||||
icon = serializers.CharField()
|
||||
label = serializers.CharField()
|
||||
url = serializers.URLField()
|
||||
body = serializers.DictField()
|
||||
|
||||
|
||||
class IdentitySerializer(serializers.Serializer):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""PDF Credentials API v2 views."""
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse
|
||||
|
||||
from rest_framework import permissions
|
||||
from rest_framework.views import APIView
|
||||
@@ -33,7 +33,7 @@ class PDFCredentialView(APIView):
|
||||
content = serializer.context["content"]
|
||||
fname = serializer.context["fname"]
|
||||
resp = HttpResponse(content)
|
||||
resp["Content-Type"] = "application/pdf"
|
||||
resp["Content-Type"] = "application/pdf;base64"
|
||||
resp["Content-Length"] = len(content)
|
||||
resp["Content-Disposition"] = f"attachment; filename={fname};"
|
||||
return resp
|
||||
|
||||
@@ -65,8 +65,7 @@ def extra_identities_actions(sender, account, **kwargs):
|
||||
return []
|
||||
return {
|
||||
"name": "get_credentials",
|
||||
"url": reverse("v2:get-credentials",
|
||||
args=[account.id]),
|
||||
"body": {"type": "pdfcredentials"},
|
||||
"icon": "mdi-file-download-outline",
|
||||
"label": _("Download PDF credentials")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user