BulkAction re-factoring for module use core bulk action
This commit is contained in:
137
resources/assets/js/plugins/bulk-action.js
vendored
137
resources/assets/js/plugins/bulk-action.js
vendored
@ -12,6 +12,8 @@ export default class BulkAction {
|
||||
this['value'] = '*';
|
||||
// Select action message
|
||||
this['message'] = '';
|
||||
// Action type
|
||||
this['type'] = '';
|
||||
// Bulk action view status
|
||||
this['show'] = false;
|
||||
// Bulk action modal status
|
||||
@ -63,6 +65,18 @@ export default class BulkAction {
|
||||
this.message = '';
|
||||
}
|
||||
|
||||
this.path = document.getElementsByName("bulk_action_path")[0].getAttribute('value');
|
||||
|
||||
if (event.target.options[event.target.options.selectedIndex].dataset.path) {
|
||||
this.path = event.target.options[event.target.options.selectedIndex].dataset.path;
|
||||
}
|
||||
|
||||
this.type = '*';
|
||||
|
||||
if (event.target.options[event.target.options.selectedIndex].dataset.type) {
|
||||
this.type = event.target.options[event.target.options.selectedIndex].dataset.type;
|
||||
}
|
||||
|
||||
return this.message;
|
||||
}
|
||||
|
||||
@ -72,72 +86,79 @@ export default class BulkAction {
|
||||
return;
|
||||
}
|
||||
|
||||
var path = document.getElementsByName("bulk_action_path")[0].getAttribute('value');
|
||||
|
||||
this.loading = true;
|
||||
|
||||
if (this.value != 'export') {
|
||||
window.axios.post(path, {
|
||||
'handle': this.value,
|
||||
'selected': this.selected
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.redirect) {
|
||||
window.location.reload(false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
//this.loading = false;
|
||||
//this.modal = false;
|
||||
// bwfore version 2.0.23
|
||||
if (this.value == 'export') {
|
||||
this.type = 'download';
|
||||
}
|
||||
|
||||
//window.location.reload(false);
|
||||
})
|
||||
.finally(function () {
|
||||
//window.location.reload(false);
|
||||
});
|
||||
} else {
|
||||
window.axios({
|
||||
url: path,
|
||||
method: 'POST',
|
||||
data:{
|
||||
switch (this.type) {
|
||||
case 'download':
|
||||
let download_promise = Promise.resolve(window.axios({
|
||||
url: this.path,
|
||||
method: 'POST',
|
||||
data:{
|
||||
'handle': this.value,
|
||||
'selected': this.selected
|
||||
},
|
||||
responseType: 'blob',
|
||||
}));
|
||||
|
||||
download_promise.then((response) => {
|
||||
const blob = new Blob([response.data], {type: response.data.type});
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
|
||||
link.href = url;
|
||||
|
||||
const contentDisposition = response.headers['content-disposition'];
|
||||
|
||||
let fileName = 'unknown';
|
||||
|
||||
if (contentDisposition) {
|
||||
const fileNameMatch = contentDisposition.match(/filename=(.+)/);
|
||||
|
||||
if (fileNameMatch.length === 2) {
|
||||
fileName = fileNameMatch[1];
|
||||
}
|
||||
}
|
||||
|
||||
link.setAttribute('download', fileName);
|
||||
|
||||
document.body.appendChild(link);
|
||||
|
||||
link.click();
|
||||
link.remove();
|
||||
|
||||
window.URL.revokeObjectURL(url);
|
||||
|
||||
this.loading = false;
|
||||
this.modal = false;
|
||||
this.value = '*';
|
||||
this.clear();
|
||||
});
|
||||
break;
|
||||
default:
|
||||
let type_promise = Promise.resolve(window.axios.post(this.path, {
|
||||
'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');
|
||||
}));
|
||||
|
||||
link.href = url;
|
||||
|
||||
const contentDisposition = response.headers['content-disposition'];
|
||||
|
||||
let fileName = 'unknown';
|
||||
|
||||
if (contentDisposition) {
|
||||
const fileNameMatch = contentDisposition.match(/filename=(.+)/);
|
||||
|
||||
if (fileNameMatch.length === 2) {
|
||||
fileName = fileNameMatch[1];
|
||||
type_promise.then(response => {
|
||||
if (response.data.redirect) {
|
||||
window.location.reload(false);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
//this.loading = false;
|
||||
//this.modal = false;
|
||||
|
||||
link.setAttribute('download', fileName);
|
||||
|
||||
document.body.appendChild(link);
|
||||
|
||||
link.click();
|
||||
link.remove();
|
||||
|
||||
window.URL.revokeObjectURL(url);
|
||||
|
||||
this.loading = false;
|
||||
this.modal = false;
|
||||
this.value = '*';
|
||||
this.clear();
|
||||
});
|
||||
//window.location.reload(false);
|
||||
})
|
||||
.finally(function () {
|
||||
//window.location.reload(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user