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' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -15,11 +15,15 @@ class Items extends BulkAction
|
|||||||
'enable' => [
|
'enable' => [
|
||||||
'name' => 'general.enable',
|
'name' => 'general.enable',
|
||||||
'message' => 'bulk_actions.message.enable',
|
'message' => 'bulk_actions.message.enable',
|
||||||
|
'path' => ['group' => 'common', 'type' => 'items'],
|
||||||
|
'type' => '*',
|
||||||
'permission' => 'update-common-items',
|
'permission' => 'update-common-items',
|
||||||
],
|
],
|
||||||
'disable' => [
|
'disable' => [
|
||||||
'name' => 'general.disable',
|
'name' => 'general.disable',
|
||||||
'message' => 'bulk_actions.message.disable',
|
'message' => 'bulk_actions.message.disable',
|
||||||
|
'path' => ['group' => 'common', 'type' => 'items'],
|
||||||
|
'type' => '*',
|
||||||
'permission' => 'update-common-items',
|
'permission' => 'update-common-items',
|
||||||
],
|
],
|
||||||
'delete' => [
|
'delete' => [
|
||||||
@ -30,6 +34,7 @@ class Items extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class Bills extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ class Payments extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download',
|
||||||
],
|
],
|
||||||
'delete' => [
|
'delete' => [
|
||||||
'name' => 'general.delete',
|
'name' => 'general.delete',
|
||||||
|
@ -29,6 +29,7 @@ class Vendors extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ class Customers extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ class Invoices extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.export',
|
'message' => 'bulk_actions.message.export',
|
||||||
|
'type' => 'download',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ class Revenues extends BulkAction
|
|||||||
'export' => [
|
'export' => [
|
||||||
'name' => 'general.export',
|
'name' => 'general.export',
|
||||||
'message' => 'bulk_actions.message.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;
|
namespace App\Http\ViewComposers;
|
||||||
|
|
||||||
use Akaunting\Module\Module;
|
use Akaunting\Module\Module;
|
||||||
|
use App\Events\Common\BulkActionsAdding;
|
||||||
use Date;
|
use Date;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
@ -67,10 +68,19 @@ class Index
|
|||||||
$class_name = 'App\BulkActions\\' . $file_name;
|
$class_name = 'App\BulkActions\\' . $file_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($class_name)) {
|
if (class_exists($class_name)) {
|
||||||
return;
|
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'] = '*';
|
this['value'] = '*';
|
||||||
// Select action message
|
// Select action message
|
||||||
this['message'] = '';
|
this['message'] = '';
|
||||||
|
// Action type
|
||||||
|
this['type'] = '';
|
||||||
// Bulk action view status
|
// Bulk action view status
|
||||||
this['show'] = false;
|
this['show'] = false;
|
||||||
// Bulk action modal status
|
// Bulk action modal status
|
||||||
@ -63,6 +65,18 @@ export default class BulkAction {
|
|||||||
this.message = '';
|
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;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,40 +86,26 @@ export default class BulkAction {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = document.getElementsByName("bulk_action_path")[0].getAttribute('value');
|
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
if (this.value != 'export') {
|
// bwfore version 2.0.23
|
||||||
window.axios.post(path, {
|
if (this.value == 'export') {
|
||||||
'handle': this.value,
|
this.type = 'download';
|
||||||
'selected': this.selected
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.redirect) {
|
|
||||||
window.location.reload(false);
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
//this.loading = false;
|
|
||||||
//this.modal = false;
|
|
||||||
|
|
||||||
//window.location.reload(false);
|
switch (this.type) {
|
||||||
})
|
case 'download':
|
||||||
.finally(function () {
|
let download_promise = Promise.resolve(window.axios({
|
||||||
//window.location.reload(false);
|
url: this.path,
|
||||||
});
|
|
||||||
} else {
|
|
||||||
window.axios({
|
|
||||||
url: path,
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data:{
|
data:{
|
||||||
'handle': this.value,
|
'handle': this.value,
|
||||||
'selected': this.selected
|
'selected': this.selected
|
||||||
},
|
},
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
}).then((response) => {
|
}));
|
||||||
console.log(response.data);
|
|
||||||
|
download_promise.then((response) => {
|
||||||
const blob = new Blob([response.data], {type: response.data.type});
|
const blob = new Blob([response.data], {type: response.data.type});
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
@ -138,6 +138,27 @@ export default class BulkAction {
|
|||||||
this.value = '*';
|
this.value = '*';
|
||||||
this.clear();
|
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']))
|
@if(!empty($action['message']))
|
||||||
data-message="{{ trans_choice($action['message'], 2, ['type' => $text]) }}"
|
data-message="{{ trans_choice($action['message'], 2, ['type' => $text]) }}"
|
||||||
@endif
|
@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>
|
>{{ trans($action['name']) }}</option>
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
|
Loading…
x
Reference in New Issue
Block a user