BulkActions export issue solved.

This commit is contained in:
Cüneyt Şentürk 2019-12-27 17:18:45 +03:00
parent d9b96a4920
commit c19ffa386a
2 changed files with 63 additions and 49 deletions

View File

@ -31,14 +31,8 @@ BulkActions extends Controller
$result = $bulk_actions->{$request->get('handle')}($request); $result = $bulk_actions->{$request->get('handle')}($request);
if (!empty($result) && isset($result->file)) { if (!empty($result) && ($result instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse)) {
/*return response()->json([ return $result;
'success' => true,
'redirect' => false,
'error' => false,
'data' => [],
'message' => ''
]);*/
} else { } else {
return response()->json([ return response()->json([
'success' => true, 'success' => true,

View File

@ -73,52 +73,72 @@ export default class BulkAction {
this.loading = true; this.loading = true;
axios.post(url +'/common/bulk-actions/' + path, { if (this.value != 'export') {
'handle': this.value, axios.post(url +'/common/bulk-actions/' + path, {
'selected': this.selected 'handle': this.value,
}) 'selected': this.selected
.then(response => { })
//this.loading = false; .then(response => {
//this.modal = false; //this.loading = false;
if (response.data.redirect) { //this.modal = false;
window.location.reload(false); if (response.data.redirect) {
} else { window.location.reload(false);
this.loading = false; } else {
this.modal = false; }
})
.catch(error => {
//this.loading = false;
//this.modal = false;
// It is necessary to create a new blob object with mime-type explicitly set //window.location.reload(false);
// otherwise only Chrome works like it should })
var newBlob = new Blob([response.body], {type: 'application/pdf'}) .finally(function () {
//window.location.reload(false);
});
} else {
axios({
url: url +'/common/bulk-actions/' + path,
method: 'POST',
data:{
'handle': this.value,
'selected': this.selected
},
responseType: 'blob',
}).then((response) => {
console.log(response.data);
const blob = new Blob([response.data], {type: response.data.type});
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
// IE doesn't allow using a blob object directly as link href link.href = url;
// instead it is necessary to use msSaveOrOpenBlob
if (window.navigator && window.navigator.msSaveOrOpenBlob) { const contentDisposition = response.headers['content-disposition'];
window.navigator.msSaveOrOpenBlob(newBlob)
return let fileName = 'unknown';
if (contentDisposition) {
const fileNameMatch = contentDisposition.match(/filename=(.+)/);
if (fileNameMatch.length === 2) {
fileName = fileNameMatch[1];
}
} }
// For other browsers: link.setAttribute('download', fileName);
// Create a link pointing to the ObjectURL containing the blob.
const data = window.URL.createObjectURL(newBlob)
var link = document.createElement('a')
link.href = data
link.download = filename + '.pdf'
link.click()
setTimeout(function () {
// For Firefox it is necessary to delay revoking the ObjectURL
window.URL.revokeObjectURL(data)
}, 100)
}
})
.catch(error => {
//this.loading = false;
//this.modal = false;
//window.location.reload(false); document.body.appendChild(link);
})
.finally(function () { link.click();
//window.location.reload(false); link.remove();
});
window.URL.revokeObjectURL(url);
this.loading = false;
this.modal = false;
this.value = '*';
this.clear();
});
}
} }
// Selected items clear // Selected items clear