Allow checkout of item to things on create page. Need to test validation better and maybe extract code to one place for checkout.blade and edit.blade

This commit is contained in:
Daniel Meltzer 2016-12-29 11:10:52 -05:00
parent 7ccd71978c
commit 13b51bc934
3 changed files with 334 additions and 297 deletions

View file

@ -104,23 +104,26 @@ class AssetsController extends Controller
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v1.0] * @since [v1.0]
* @param integer $model_id * @param Request $request
* @return View * @return View
* @internal param int $model_id
*/ */
public function create(Request $request) public function create(Request $request)
{ {
$this->authorize('create', Asset::class); $this->authorize('create', Asset::class);
$view = View::make('hardware/edit'); $view = View::make('hardware/edit')
$view->with('supplier_list', Helper::suppliersList()); ->with('supplier_list', Helper::suppliersList())
$view->with('company_list', Helper::companyList()); ->with('company_list', Helper::companyList())
$view->with('model_list', Helper::modelList()); ->with('model_list', Helper::modelList())
$view->with('statuslabel_list', Helper::statusLabelList()); ->with('statuslabel_list', Helper::statusLabelList())
$view->with('assigned_to', Helper::usersList()); ->with('location_list', Helper::locationsList())
$view->with('location_list', Helper::locationsList()); ->with('item', new Asset)
$view->with('item', new Asset); ->with('manufacturer', Helper::manufacturerList())
$view->with('manufacturer', Helper::manufacturerList()); ->with('category', Helper::categoryList('asset'))
$view->with('category', Helper::categoryList('asset')); ->with('statuslabel_types', Helper::statusTypeList())
$view->with('statuslabel_types', Helper::statusTypeList()); ->with('users_list', Helper::usersList())
->with('assets_list', Helper::assetsList())
->with('locations_list', Helper::locationsList());
if ($request->has('model_id')) { if ($request->has('model_id')) {
$selected_model = AssetModel::find($request->input('model_id')); $selected_model = AssetModel::find($request->input('model_id'));
@ -217,9 +220,15 @@ class AssetsController extends Controller
// Was the asset created? // Was the asset created?
if ($asset->save()) { if ($asset->save()) {
$asset->logCreate(); $asset->logCreate();
if (Input::get('assigned_to')!='') { if(request('assigned_user')) {
$user = User::find(e(Input::get('assigned_to'))); $target = User::find(request('assigned_user'));
$asset->checkOutToUser($user, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name'))); } elseif(request('assigned_asset')) {
$target = Asset::find(request('assigned_asset'));
} elseif(request('assigned_location')) {
$target = Location::find(request('assigned_location'));
}
if ($target) {
$asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset creation', e(Input::get('name')));
} }
// Redirect to the asset listing page // Redirect to the asset listing page
\Session::flash('success', trans('admin/hardware/message.create.success')); \Session::flash('success', trans('admin/hardware/message.create.success'));
@ -1317,8 +1326,9 @@ class AssetsController extends Controller
public function getDatatable(Request $request, $status = null) public function getDatatable(Request $request, $status = null)
{ {
$this->authorize('index', Asset::class); $this->authorize('index', Asset::class);
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with('model', 'assignedTo', 'assetLoc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'company') $assets = Company::scopeCompanyables(Asset::select('assets.*'))->with(
->Hardware(); 'assetLoc', 'assetstatus', 'defaultLoc', 'assetlog', 'company',
'model.category', 'model.manufacturer', 'model.fieldset');
if ($request->has('search')) { if ($request->has('search')) {
$assets = $assets->TextSearch(e($request->get('search'))); $assets = $assets->TextSearch(e($request->get('search')));
@ -1424,9 +1434,7 @@ class AssetsController extends Controller
$rows = array(); $rows = array();
foreach ($assets as $asset) { foreach ($assets as $asset) {
$row = $asset->present()->forDataTable($all_custom_fields); $row = $asset->present()->forDataTable($all_custom_fields);
if (($request->has('report')) && ($request->get('report')=='true')) { if (($request->has('report')) && ($request->get('report')=='true')) {
$rows[]= Helper::stripTagsFromJSON($row); $rows[]= Helper::stripTagsFromJSON($row);
} else { } else {

View file

@ -38,7 +38,9 @@ class AssetRequest extends Request
'status' => 'integer|nullable', 'status' => 'integer|nullable',
'asset_tag' => 'required', 'asset_tag' => 'required',
'purchase_cost' => 'numeric|nullable', 'purchase_cost' => 'numeric|nullable',
"assigned_user" => 'required_without_all:assigned_asset,assigned_location',
"assigned_asset" => 'required_without_all:assigned_user,assigned_location',
"assigned_location" => 'required_without_all:assigned_user,assigned_asset',
]; ];
$model = AssetModel::find($this->request->get('model_id')); $model = AssetModel::find($this->request->get('model_id'));

View file

@ -64,17 +64,41 @@
@if (!$item->id) @if (!$item->id)
<!-- Assigned To --> <!-- Assigned To -->
<div id="assigned_user" style="display: none;" class="form-group {{ $errors->has('assigned_to') ? ' has-error' : '' }}"> <div id="assigned_user" style="display: none;" class="form-group {{ $errors->has('assigned_user') ? ' has-error' : '' }}">
<label for="parent" class="col-md-3 control-label"> <label for="parent" class="col-md-3 control-label">
{{ trans('admin/hardware/form.checkout_to') }} {{ trans('admin/hardware/form.checkout_to') }}
</label> </label>
<div class="col-md-7 col-sm-12"> <div class="col-md-7 col-sm-12">
{{ Form::select('assigned_to', $assigned_to , Input::old('assigned_to', $item->assigned_to), array('class'=>'select2', 'id'=>'assigned_to', 'style'=>'width:100%')) }} {{ Form::select('assigned_user', $users_list , Input::old('assigned_user', $item->assigned_type == 'App\Models\User' ? $item->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_user', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_user', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
{!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div> </div>
<div class="col-md-1 col-sm-1 text-left" style="margin-left: -20px; padding-top: 3px"> <div class="col-md-1 col-sm-1 text-left" style="margin-left: -20px; padding-top: 3px">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_to' class="btn btn-sm btn-default">New</a> <a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_user' class="btn btn-sm btn-default">New</a>
</div>
</div>
<!-- Assets -->
<div id="assigned_asset" style="display: none;" class="form-group{{ $errors->has('assigned_asset') ? ' has-error' : '' }}">
{{ Form::label('assigned_asset', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7">
{{ Form::select('assigned_asset', $assets_list , Input::old('assigned_asset', $item->assigned_type == 'App\Models\Asset' ? $item->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_asset', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_asset', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_asset' class="btn btn-sm btn-default">New</a>
</div>
</div>
<!-- Locations -->
<div id="assigned_location" style="display: none;" class="form-group{{ $errors->has('assigned_location') ? ' has-error' : '' }}">
{{ Form::label('assigned_location', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7">
{{ Form::select('assigned_location', $locations_list , Input::old('assigned_location', $item->assigned_type == 'App\Models\Asset' ? $item->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_location', 'style'=>'width:100%')) }}
{!! $errors->first('assigned_location', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
<div class="col-md-1 col-sm-1 text-left">
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_location' class="btn btn-sm btn-default">New</a>
</div> </div>
</div> </div>
@endif @endif
@ -170,13 +194,18 @@
if (data == true) { if (data == true) {
$("#assigned_user").css("display", "block"); $("#assigned_user").css("display", "block");
$("#assigned_location").css("display", "block");
$("#assigned_asset").css("display", "block");
} else { } else {
$("#assigned_user").css("display", "none"); $("#assigned_user").css("display", "none");
$("#assigned_location").css("display", "none");
$("#assigned_asset").css("display", "none");
} }
} }
}); });
} }
}; }
;
$(function () { $(function () {
var model, select; var model, select;
@ -194,6 +223,7 @@ $(function () {
//$(selector).show().parent().show(); //$(selector).show().parent().show();
$(selector).parent().parent().show(); $(selector).parent().parent().show();
} }
show_er('#modal-name'); show_er('#modal-name');
switch (model) { switch (model) {
case 'model': case 'model':
@ -235,9 +265,6 @@ $(function () {
}); });
// Resize Files when chosen // Resize Files when chosen
//First check to see if there is a file before doing anything else //First check to see if there is a file before doing anything else
var imageData = ""; var imageData = "";