Add 'bulk checkout' as one of the bulk actions in the bulk actions toolbar
This commit is contained in:
parent
2500375400
commit
6b7af802af
4 changed files with 31 additions and 14 deletions
|
@ -52,6 +52,10 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset_ids = $request->input('ids');
|
$asset_ids = $request->input('ids');
|
||||||
|
if ($request->input('bulk_actions') === 'checkout') {
|
||||||
|
$request->session()->flashInput(['selected_assets' => $asset_ids]);
|
||||||
|
return redirect()->route('hardware.bulkcheckout.show');
|
||||||
|
}
|
||||||
|
|
||||||
// Figure out where we need to send the user after the update is complete, and store that in the session
|
// Figure out where we need to send the user after the update is complete, and store that in the session
|
||||||
$bulk_back_url = request()->headers->get('referer');
|
$bulk_back_url = request()->headers->get('referer');
|
||||||
|
@ -580,8 +584,9 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
if ($target->location_id != '') {
|
if ($target->location_id != '') {
|
||||||
$asset->location_id = $target->location_id;
|
$asset->location_id = $target->location_id;
|
||||||
$asset->unsetEventDispatcher();
|
$asset::withoutEvents(function () use ($asset) { // TODO - I don't know why this is being saved without events
|
||||||
$asset->save();
|
$asset->save();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error) {
|
if ($error) {
|
||||||
|
@ -592,10 +597,10 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
if (! $errors) {
|
if (! $errors) {
|
||||||
// Redirect to the new asset page
|
// Redirect to the new asset page
|
||||||
return redirect()->to('hardware')->with('success', trans('admin/hardware/message.checkout.success'));
|
return redirect()->to('hardware')->with('success', trans_choice('admin/hardware/message.multi-checkout.success', $asset_ids));
|
||||||
}
|
}
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->route('hardware.bulkcheckout.show')->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors);
|
return redirect()->route('hardware.bulkcheckout.show')->with('error', trans_choice('admin/hardware/message.multi-checkout.error', $asset_ids))->withErrors($errors);
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors());
|
return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Watson\Validating\ValidationException;
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Exceptions\CheckoutNotAllowed;
|
use App\Exceptions\CheckoutNotAllowed;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -379,6 +380,9 @@ class Asset extends Depreciable
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
$validator = $this->makeValidator($this->getRules());
|
||||||
|
|
||||||
|
throw new ValidationException($validator, $this);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,11 @@ return [
|
||||||
'no_assets_selected' => 'You must select at least one asset from the list',
|
'no_assets_selected' => 'You must select at least one asset from the list',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'multi-checkout' => [
|
||||||
|
'error' => 'Asset was not checked out, please try again|Assets were not checked out, please try again',
|
||||||
|
'success' => 'Asset checked out successfully.|Assets checked out successfully.',
|
||||||
|
],
|
||||||
|
|
||||||
'checkin' => [
|
'checkin' => [
|
||||||
'error' => 'Asset was not checked in, please try again',
|
'error' => 'Asset was not checked in, please try again',
|
||||||
'success' => 'Asset checked in successfully.',
|
'success' => 'Asset checked in successfully.',
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
@can('update', \App\Models\Asset::class)
|
@can('update', \App\Models\Asset::class)
|
||||||
<option value="edit">{{ trans('button.edit') }}</option>
|
<option value="edit">{{ trans('button.edit') }}</option>
|
||||||
@endcan
|
@endcan
|
||||||
|
@can('checkout', \App\Models\Asset::class)
|
||||||
|
<option value="checkout">{{ trans('general.bulk_checkout') }}</option>
|
||||||
|
@endcan
|
||||||
@can('delete', \App\Models\Asset::class)
|
@can('delete', \App\Models\Asset::class)
|
||||||
<option value="delete">{{ trans('button.delete') }}</option>
|
<option value="delete">{{ trans('button.delete') }}</option>
|
||||||
@endcan
|
@endcan
|
||||||
|
|
Loading…
Add table
Reference in a new issue