Adds a check to know if the asset is checked out to the logged in user to allow check the state int the view

This commit is contained in:
Ivan Nieto Vivanco 2021-07-20 18:56:22 -05:00
parent 5e76d50f2d
commit 35ffe8b902
2 changed files with 4 additions and 2 deletions

View file

@ -185,12 +185,12 @@ class AssetsTransformer
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'), 'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
'location' => ($asset->location) ? e($asset->location->name) : null, 'location' => ($asset->location) ? e($asset->location->name) : null,
'status'=> ($asset->assetstatus) ? $asset->present()->statusMeta : null, 'status'=> ($asset->assetstatus) ? $asset->present()->statusMeta : null,
'assigned_to_self' => ($asset->assigned_to == \Auth::user()->id),
]; ];
$permissions_array['available_actions'] = [ $permissions_array['available_actions'] = [
'cancel' => ($asset->isRequestedBy(\Auth::user())) ? true : false, 'cancel' => ($asset->isRequestedBy(\Auth::user())) ? true : false,
'request' => ($asset->isRequestedBy(\Auth::user())) ? false : true, 'request' => ($asset->isRequestedBy(\Auth::user())) ? false : true,
]; ];
$array += $permissions_array; $array += $permissions_array;

View file

@ -333,7 +333,9 @@
// This is only used by the requestable assets section // This is only used by the requestable assets section
function assetRequestActionsFormatter (row, value) { function assetRequestActionsFormatter (row, value) {
if (value.available_actions.cancel == true) { if (value.assigned_to_self == true){
return '<button class="btn btn-danger btn-sm disabled" data-toggle="tooltip" title="Cancel this item request">{{ trans('button.cancel') }}</button>';
} else if (value.available_actions.cancel == true) {
return '<form action="{{ url('/') }}/account/request-asset/'+ value.id + '" method="GET"><button class="btn btn-danger btn-sm" data-toggle="tooltip" title="Cancel this item request">{{ trans('button.cancel') }}</button></form>'; return '<form action="{{ url('/') }}/account/request-asset/'+ value.id + '" method="GET"><button class="btn btn-danger btn-sm" data-toggle="tooltip" title="Cancel this item request">{{ trans('button.cancel') }}</button></form>';
} else if (value.available_actions.request == true) { } else if (value.available_actions.request == true) {
return '<form action="{{ url('/') }}/account/request-asset/'+ value.id + '" method="GET"><button class="btn btn-primary btn-sm" data-toggle="tooltip" title="Request this item">{{ trans('button.request') }}</button></form>'; return '<form action="{{ url('/') }}/account/request-asset/'+ value.id + '" method="GET"><button class="btn btn-primary btn-sm" data-toggle="tooltip" title="Request this item">{{ trans('button.request') }}</button></form>';