Merge pull request #1612 from cuneytsenturk/master
BulkAction re-factoring for module use core bulk action
This commit is contained in:
commit
0701b129af
@ -34,6 +34,7 @@ abstract class BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download'
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -15,11 +15,15 @@ class Items extends BulkAction
|
||||
'enable' => [
|
||||
'name' => 'general.enable',
|
||||
'message' => 'bulk_actions.message.enable',
|
||||
'path' => ['group' => 'common', 'type' => 'items'],
|
||||
'type' => '*',
|
||||
'permission' => 'update-common-items',
|
||||
],
|
||||
'disable' => [
|
||||
'name' => 'general.disable',
|
||||
'message' => 'bulk_actions.message.disable',
|
||||
'path' => ['group' => 'common', 'type' => 'items'],
|
||||
'type' => '*',
|
||||
'permission' => 'update-common-items',
|
||||
],
|
||||
'delete' => [
|
||||
@ -30,6 +34,7 @@ class Items extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -33,6 +33,7 @@ class Bills extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -14,6 +14,7 @@ class Payments extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
'delete' => [
|
||||
'name' => 'general.delete',
|
||||
|
@ -29,6 +29,7 @@ class Vendors extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -29,6 +29,7 @@ class Customers extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -39,6 +39,7 @@ class Invoices extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -19,6 +19,7 @@ class Revenues extends BulkAction
|
||||
'export' => [
|
||||
'name' => 'general.export',
|
||||
'message' => 'bulk_actions.message.export',
|
||||
'type' => 'download',
|
||||
],
|
||||
];
|
||||
|
||||
|
22
app/Events/Common/BulkActionsAdding.php
Normal file
22
app/Events/Common/BulkActionsAdding.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BulkActionsAdding
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $bulk_action;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $bulk_action
|
||||
*/
|
||||
public function __construct($bulk_action)
|
||||
{
|
||||
$this->bulk_action = $bulk_action;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\ViewComposers;
|
||||
|
||||
use Akaunting\Module\Module;
|
||||
use App\Events\Common\BulkActionsAdding;
|
||||
use Date;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
@ -67,10 +68,19 @@ class Index
|
||||
$class_name = 'App\BulkActions\\' . $file_name;
|
||||
}
|
||||
|
||||
if (!class_exists($class_name)) {
|
||||
return;
|
||||
if (class_exists($class_name)) {
|
||||
event(new BulkActionsAdding(app($class_name)));
|
||||
|
||||
$bulk_actions = app($class_name)->actions;
|
||||
} else {
|
||||
$b = new \stdClass();
|
||||
$b->actions = [];
|
||||
|
||||
event(new BulkActionsAdding($b));
|
||||
|
||||
$bulk_actions = $b->actions;
|
||||
}
|
||||
|
||||
$view->with(['bulk_actions' => app($class_name)->actions]);
|
||||
$view->with(['bulk_actions' => $bulk_actions]);
|
||||
}
|
||||
}
|
||||
|
69
resources/assets/js/plugins/bulk-action.js
vendored
69
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,40 +86,26 @@ 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);
|
||||
// bwfore version 2.0.23
|
||||
if (this.value == 'export') {
|
||||
this.type = 'download';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
//this.loading = false;
|
||||
//this.modal = false;
|
||||
|
||||
//window.location.reload(false);
|
||||
})
|
||||
.finally(function () {
|
||||
//window.location.reload(false);
|
||||
});
|
||||
} else {
|
||||
window.axios({
|
||||
url: path,
|
||||
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',
|
||||
}).then((response) => {
|
||||
console.log(response.data);
|
||||
}));
|
||||
|
||||
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');
|
||||
@ -138,6 +138,27 @@ export default class BulkAction {
|
||||
this.value = '*';
|
||||
this.clear();
|
||||
});
|
||||
break;
|
||||
default:
|
||||
let type_promise = Promise.resolve(window.axios.post(this.path, {
|
||||
'handle': this.value,
|
||||
'selected': this.selected
|
||||
}));
|
||||
|
||||
type_promise.then(response => {
|
||||
if (response.data.redirect) {
|
||||
window.location.reload(false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
//this.loading = false;
|
||||
//this.modal = false;
|
||||
|
||||
//window.location.reload(false);
|
||||
})
|
||||
.finally(function () {
|
||||
//window.location.reload(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,16 @@
|
||||
@if(!empty($action['message']))
|
||||
data-message="{{ trans_choice($action['message'], 2, ['type' => $text]) }}"
|
||||
@endif
|
||||
@if(isset($action['path']) && !empty($action['path']))
|
||||
data-path="{{ route('bulk-actions.action', $action['path']) }}"
|
||||
@else
|
||||
data-path=""
|
||||
@endif
|
||||
@if(isset($action['type']) && !empty($action['type']))
|
||||
data-type="{{ $action['type'] }}"
|
||||
@else
|
||||
data-type=""
|
||||
@endif
|
||||
>{{ trans($action['name']) }}</option>
|
||||
@endif
|
||||
@endforeach
|
||||
|
Loading…
x
Reference in New Issue
Block a user