Fixes #4491 and #4483 - handle pre-selected asset on checkout, better checkout-to selection UI (#4501)

* Added form checkout selector partial

* Stupid stash

* Added radio button checkout selector javascript

* New compiled production assets

* Added $style override in form partials for select2 ajax lists

* Added checkout-to radio button selector

TODO: Fix for accessibility - currently cannot tab-select this radio button

* Added new checkout-to selector to hardware edit

* Added new checkout-to selector to asset checkout form

* Refactored postCheckout to use radio button submission

This defaults to user checkout if nothing is passed for some reason

* Better visual feedback on whether or not an asset is deployable in edit screen
This commit is contained in:
snipe 2017-11-21 15:58:31 -08:00 committed by GitHub
parent 4fd35573ad
commit 4696e799ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 95 additions and 44 deletions

View file

@ -453,34 +453,31 @@ class AssetsController extends Controller
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));
}
$this->authorize('checkout', $asset);
// Fetch the target and set the asset's new location_id
if (request('assigned_user')) {
$target = User::find(request('assigned_user'));
$asset->location_id = ($target) ? $target->location_id : '';
} elseif (request('assigned_asset')) {
$admin = Auth::user();
// This item is checked out to a location
if (request('checkout_to_type')=='location') {
$target = Location::find(request('assigned_location'));
$asset->location_id = ($target) ? $target->id : '';
} elseif (request('checkout_to_type')=='asset') {
$target = Asset::where('id','!=',$assetId)->find(request('assigned_asset'));
$asset->location_id = $target->rtd_location_id;
// Override with the asset's location_id if it has one
if ($target->location_id!='') {
$asset->location_id = ($target) ? $target->location_id : '';
}
} elseif (request('assigned_location')) {
$target = Location::find(request('assigned_location'));
$asset->location_id = ($target) ? $target->id : '';
} else {
// Fetch the target and set the asset's new location_id
$target = User::find(request('assigned_user'));
$asset->location_id = ($target) ? $target->location_id : '';
}
// No valid target was found - error out
if (!$target) {
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors());
}
$admin = Auth::user();
if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) {
$checkout_at = Input::get('checkout_at');
@ -496,7 +493,6 @@ class AssetsController extends Controller
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), Input::get('name'))) {
// Redirect to the new asset page
return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.checkout.success'));
}

Binary file not shown.

BIN
public/js/dist/all.js vendored

Binary file not shown.

View file

@ -8,7 +8,7 @@
"/css/app.css.map": "/css/app.css.map?id=bdbe05e6ecd70ccfac72",
"/css/overrides.css.map": "/css/overrides.css.map?id=898c91d4a425b01b589b",
"/css/dist/all.css": "/css/dist/all.css?id=7c3842d2639193ac7e88",
"/js/dist/all.js": "/js/dist/all.js?id=0d558c3ed637f4c81a77",
"/js/dist/all.js": "/js/dist/all.js?id=c25f257f81287cafe6a3",
"/css/build/all.css": "/css/build/all.css?id=7c3842d2639193ac7e88",
"/js/build/all.js": "/js/build/all.js?id=0d558c3ed637f4c81a77"
"/js/build/all.js": "/js/build/all.js?id=c25f257f81287cafe6a3"
}

View file

@ -255,8 +255,37 @@ $(document).ready(function () {
return datalist.text;
}
$(function() {
$('input[name=checkout_to_type]').on("change",function () {
var assignto_type = $('input[name=checkout_to_type]:checked').val();
var userid = $('#assigned_user option:selected').val();
if (assignto_type == 'asset') {
$('#current_assets_box').fadeOut();
$('#assigned_asset').show();
$('#assigned_user').hide();
$('#assigned_location').hide();
$('.notification-callout').fadeOut();
} else if (assignto_type == 'location') {
$('#current_assets_box').fadeOut();
$('#assigned_asset').hide();
$('#assigned_user').hide();
$('#assigned_location').show();
$('.notification-callout').fadeOut();
} else {
$('#assigned_asset').hide();
$('#assigned_user').show();
$('#assigned_location').hide();
if (userid) {
$('#current_assets_box').fadeIn();
}
$('.notification-callout').fadeIn();
}
});
});
});

View file

@ -40,12 +40,13 @@
<div class="form-group {{ $errors->has('name') ? 'error' : '' }}">
{{ Form::label('name', trans('admin/hardware/form.name'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8">
<input class="form-control" type="text" name="name" id="name" value="{{ Input::old('name', $asset->name) }}" />
<input class="form-control" type="text" name="name" id="name" value="{{ Input::old('name', $asset->name) }}" tabindex="1">
{!! $errors->first('name', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
@include ('partials.forms.checkout-selector')
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user'])
@include ('partials.forms.edit.user-select', ['translated_name' => trans('general.user'), 'fieldname' => 'assigned_user', 'required'=>'true'])
@if ($asset->requireAcceptance())
<div class="form-group">
@ -57,11 +58,10 @@
</div>
</div>
@else
<!-- We have to pass unselect here so that we don't default to the asset that's being checked out. We want that asset to be pre-selected everywhere else. -->
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('general.asset'), 'fieldname' => 'assigned_asset', 'unselect' => 'true', 'style' => 'display:none;', 'required'=>'true'])
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required'=>'true'])
@endif
@ -99,7 +99,7 @@
</div>
@if ($asset->requireAcceptance() || $asset->getEula())
<div class="form-group">
<div class="form-group notification-callout">
<div class="col-md-8 col-md-offset-3">
<div class="callout callout-info">

View file

@ -47,11 +47,13 @@
@include ('partials.forms.edit.status')
@if (!$item->id)
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user'])
@include ('partials.forms.checkout-selector', ['style' => 'display:none;'])
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset'])
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user', 'style' => 'display:none;'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location'])
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset', 'style' => 'display:none;'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location', 'style' => 'display:none;'])
@endif
@include ('partials.forms.edit.serial', ['translated_serial' => trans('admin/hardware/form.serial')])
@ -140,15 +142,21 @@
},
success: function (data) {
$(".status_spinner").css("display", "none");
$("#selected_status_status").fadeIn();
if (data == true) {
$("#assigned_user").css("display", "block");
$("#assigned_location").css("display", "block");
$("#assigned_asset").css("display", "block");
$("#assignto_selector").show();
$("#selected_status_status").removeClass('text-danger');
$("#selected_status_status").addClass('text-success');
$("#selected_status_status").html('<i class="fa fa-check"></i> That status is deployable. This asset can be checked out.');
} else {
$("#assigned_user").css("display", "none");
$("#assigned_location").css("display", "none");
$("#assigned_asset").css("display", "none");
$("#assignto_selector").hide();
$("#selected_status_status").removeClass('text-success');
$("#selected_status_status").addClass('text-danger');
$("#selected_status_status").html('<i class="fa fa-times"></i> That asset status is not deployable. This asset cannot be checked out. ');
}
}
});

View file

@ -0,0 +1,16 @@
<div class="form-group" id="assignto_selector"{!! (isset($style)) ? ' style="'.e($style).'"' : '' !!}>
{{ Form::label('name', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-8">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input name="checkout_to_type" value="user" type="radio" selected><i class="fa fa-user"></i> {{ trans('general.user') }}
</label>
<label class="btn btn-default">
<input name="checkout_to_type" value="asset" type="radio"><i class="fa fa-barcode"></i> {{ trans('general.asset') }}
</label>
<label class="btn btn-default">
<input name="checkout_to_type" value="location" class="active" type="radio"><i class="fa fa-map-marker"></i> {{ trans('general.location') }}
</label>
</div>
</div>
</div>

View file

@ -1,10 +1,10 @@
<!-- Asset -->
<div id="{{ $fieldname }}" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
<div id="{{ $fieldname }}" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}"{!! (isset($style)) ? ' style="'.e($style).'"' : '' !!}>
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required">
<div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}">
<select class="js-data-ajax select2" data-endpoint="hardware" name="{{ $fieldname }}" style="width: 100%" id="assigned_asset_select"{{ (isset($multiple)) ? ' multiple="multiple"' : '' }}>
@if ($asset_id = Input::old($fieldname, (isset($asset) ? $asset->id : (isset($item) ? $item->{$fieldname} : ''))))
@if ((!isset($unselect)) && ($asset_id = Input::old($fieldname, (isset($asset) ? $asset->id : (isset($item) ? $item->{$fieldname} : '')))))
<option value="{{ $asset_id }}" selected="selected">
{{ (\App\Models\Asset::find($asset_id)) ? \App\Models\Asset::find($asset_id)->present()->fullName : '' }}
</option>

View file

@ -1,5 +1,5 @@
<!-- Location -->
<div id="{{ $fieldname }}" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
<div id="{{ $fieldname }}" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}"{!! (isset($style)) ? ' style="'.e($style).'"' : '' !!}>
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}">

View file

@ -5,11 +5,13 @@
{{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $item->status_id), array('class'=>'select2 status_id', 'style'=>'width:100%','id'=>'status_select_id')) }}
{!! $errors->first('status_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<div class="col-md-2 col-sm-2 text-left">
<a href='{{ route('modal.statuslabel') }}' data-toggle="modal" data-target="#createModal" data-dependency='statuslabel' data-select='status_select_id' class="btn btn-sm btn-default">New</a>
<span class="status_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
</div>
<div class="col-md-7 col-sm-11 col-md-offset-3">
<p class="help-block">{{ trans('admin/hardware/form.help_checkout') }}</p>
<div class="col-md-7 col-sm-11 col-md-offset-3" id="status_helptext">
<p id="selected_status_status" style="display:none;"></p>
</div>
</div>
</div>

View file

@ -1,4 +1,4 @@
<div id="assigned_user" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
<div id="assigned_user" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}"{!! (isset($style)) ? ' style="'.e($style).'"' : '' !!}>
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}