mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-12 16:44:08 -08:00
Helper method to introspect into the model level validation to see if the field is required
(This does not yet handle form request validation)
This commit is contained in:
parent
3a04686ade
commit
78fda31379
|
@ -403,4 +403,30 @@ class Helper
|
||||||
return $permissions_arr;
|
return $permissions_arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Introspects into the model validation to see if the field passed is required.
|
||||||
|
* This is used by the blades to add a required class onto the HTML element.
|
||||||
|
* This isn't critical, but is helpful to keep form fields in sync with the actual
|
||||||
|
* model level validation.
|
||||||
|
*
|
||||||
|
* This does not currently handle form request validation requiredness :(
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v3.0]
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function checkIfRequired($class, $field) {
|
||||||
|
$rules = $class::rules();
|
||||||
|
foreach ($rules as $rule_name => $rule) {
|
||||||
|
if ($rule_name == $field) {
|
||||||
|
if (strpos($rule, 'required') === false) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
return array (
|
return array (
|
||||||
'app_version' => 'v3.0',
|
'app_version' => 'v3.0',
|
||||||
'hash_version' => 'v3.0-15-gf0c0089',
|
'hash_version' => 'v3.0-17-gca5d3e3',
|
||||||
);
|
);
|
|
@ -47,26 +47,24 @@
|
||||||
|
|
||||||
<!-- Asset Tag -->
|
<!-- Asset Tag -->
|
||||||
<div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}">
|
||||||
<label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}
|
<label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}</label>
|
||||||
*</label>
|
|
||||||
</label>
|
</label>
|
||||||
<div class="col-md-7 col-sm-12">
|
<div class="col-md-7 col-sm-12{{ (\App\Helpers\Helper::checkIfRequired($asset, 'asset_tag')) ? ' required' : '' }}">
|
||||||
@if ($asset->id)
|
@if ($asset->id)
|
||||||
<input class="form-control" type="text" name="asset_tag" id="asset_tag" value="{{ Input::old('asset_tag', $asset->asset_tag) }}" />
|
<input class="form-control" type="text" name="asset_tag" id="asset_tag" value="{{ Input::old('asset_tag', $asset->asset_tag) }}" />
|
||||||
@else
|
@else
|
||||||
<input class="form-control" type="text" name="asset_tag" id="asset_tag" value="{{ Input::old('asset_tag', \App\Models\Asset::autoincrement_asset()) }}" />
|
<input class="form-control" type="text" name="asset_tag" id="asset_tag" value="{{ Input::old('asset_tag', \App\Models\Asset::autoincrement_asset()) }}">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
{!! $errors->first('asset_tag', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('asset_tag', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Model -->
|
<!-- Model -->
|
||||||
<div class="form-group {{ $errors->has('model_id') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('model_id') ? ' has-error' : '' }}">
|
||||||
<label for="parent" class="col-md-3 control-label">{{ trans('admin/hardware/form.model') }}
|
<label for="parent" class="col-md-3 control-label">{{ trans('admin/hardware/form.model') }}</label>
|
||||||
*</label>
|
|
||||||
</label>
|
</label>
|
||||||
<div class="col-md-7 col-sm-10">
|
<div class="col-md-7 col-sm-10{{ (\App\Helpers\Helper::checkIfRequired($asset, 'model_id')) ? ' required' : '' }}">
|
||||||
@if (isset($selected_model))
|
@if (isset($selected_model))
|
||||||
{{ Form::select('model_id', $model_list , $selected_model->id, array('class'=>'select2 model', 'style'=>'width:100%','id' =>'model_select_id')) }}
|
{{ Form::select('model_id', $model_list , $selected_model->id, array('class'=>'select2 model', 'style'=>'width:100%','id' =>'model_select_id')) }}
|
||||||
|
|
||||||
|
@ -78,8 +76,8 @@
|
||||||
{!! $errors->first('model_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('model_id', '<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">
|
||||||
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="model" data-select="model_select_id"><i class="verticon fa fa-plus-square-o fa-2x"></i></a>
|
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="model" data-select="model_select_id" class="btn btn-sm btn-default">New</a>
|
||||||
<span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
|
<span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -102,18 +100,21 @@
|
||||||
|
|
||||||
<!-- Status -->
|
<!-- Status -->
|
||||||
<div class="form-group {{ $errors->has('status_id') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('status_id') ? ' has-error' : '' }}">
|
||||||
<label for="status_id" class="col-md-3 control-label">{{ trans('admin/hardware/form.status') }} *</label>
|
<label for="status_id" class="col-md-3 control-label">{{ trans('admin/hardware/form.status') }}</label>
|
||||||
<div class="col-md-7 col-sm-11">
|
<div class="col-md-7 col-sm-11{{ (\App\Helpers\Helper::checkIfRequired($asset, 'status_id')) ? ' required' : '' }}">
|
||||||
{{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $asset->status_id), array('class'=>'select2 status_id', 'style'=>'width:100%','id'=>'status_select_id')) }}
|
{{ Form::select('status_id', $statuslabel_list , Input::old('status_id', $asset->status_id), array('class'=>'select2 status_id', 'style'=>'width:100%','id'=>'status_select_id')) }}
|
||||||
|
|
||||||
|
|
||||||
<p class="help-block">{{ trans('admin/hardware/form.help_checkout') }}</p>
|
|
||||||
{!! $errors->first('status_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('status_id', '<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">
|
||||||
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency='statuslabel' data-select='status_select_id'><i class="verticon fa fa-plus-square-o fa-2x"></i></a>
|
<a href='#' 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>
|
<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>
|
||||||
|
<div class="col-md-7 col-sm-11 col-md-offset-3">
|
||||||
|
<p class="help-block">{{ trans('admin/hardware/form.help_checkout') }}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (!$asset->id)
|
@if (!$asset->id)
|
||||||
|
@ -127,7 +128,7 @@
|
||||||
{!! $errors->first('assigned_to', '<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'><i class="verticon fa fa-plus-square-o fa-2x"></i></a>
|
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="user" data-select='assigned_to' class="btn btn-sm btn-default">New</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@ -136,7 +137,7 @@
|
||||||
<!-- Serial -->
|
<!-- Serial -->
|
||||||
<div class="form-group {{ $errors->has('serial') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('serial') ? ' has-error' : '' }}">
|
||||||
<label for="serial" class="col-md-3 control-label">{{ trans('admin/hardware/form.serial') }} </label>
|
<label for="serial" class="col-md-3 control-label">{{ trans('admin/hardware/form.serial') }} </label>
|
||||||
<div class="col-md-7 col-sm-12">
|
<div class="col-md-7 col-sm-12{{ (\App\Helpers\Helper::checkIfRequired($asset, 'serial')) ? ' required' : '' }}">
|
||||||
<input class="form-control" type="text" name="serial" id="serial" value="{{ Input::old('serial', $asset->serial) }}" />
|
<input class="form-control" type="text" name="serial" id="serial" value="{{ Input::old('serial', $asset->serial) }}" />
|
||||||
{!! $errors->first('serial', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('serial', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
|
@ -145,7 +146,7 @@
|
||||||
<!-- Asset Name -->
|
<!-- Asset Name -->
|
||||||
<div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
|
||||||
<label for="name" class="col-md-3 control-label">{{ trans('admin/hardware/form.name') }}</label>
|
<label for="name" class="col-md-3 control-label">{{ trans('admin/hardware/form.name') }}</label>
|
||||||
<div class="col-md-7 col-sm-12">
|
<div class="col-md-7 col-sm-12{{ (\App\Helpers\Helper::checkIfRequired($asset, 'name')) ? ' required' : '' }}">
|
||||||
<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) }}" />
|
||||||
{!! $errors->first('name', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('name', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
|
@ -156,7 +157,7 @@
|
||||||
@if (\App\Models\Company::isCurrentUserAuthorized())
|
@if (\App\Models\Company::isCurrentUserAuthorized())
|
||||||
<div class="form-group {{ $errors->has('company_id') ? ' has-error' : '' }}">
|
<div class="form-group {{ $errors->has('company_id') ? ' has-error' : '' }}">
|
||||||
<div class="col-md-3 control-label">{{ Form::label('company_id', trans('general.company')) }}</div>
|
<div class="col-md-3 control-label">{{ Form::label('company_id', trans('general.company')) }}</div>
|
||||||
<div class="col-md-7 col-sm-12">
|
<div class="col-md-7 col-sm-12{{ (\App\Helpers\Helper::checkIfRequired($asset, 'company_id')) ? ' required' : '' }}">
|
||||||
{{ Form::select('company_id', $company_list , Input::old('company_id', $asset->company_id),
|
{{ Form::select('company_id', $company_list , Input::old('company_id', $asset->company_id),
|
||||||
['class'=>'select2', 'style'=>'width:100%']) }}
|
['class'=>'select2', 'style'=>'width:100%']) }}
|
||||||
{!! $errors->first('company_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('company_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||||
|
@ -171,9 +172,10 @@
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
|
|
||||||
<input type="text" class="datepicker form-control" data-date-format="yyyy-mm-dd" placeholder="yyyy-mm-dd" name="purchase_date" id="purchase_date" value="{{ Input::old('purchase_date', $asset->purchase_date) }}">
|
<input type="text" class="datepicker form-control" data-date-format="yyyy-mm-dd" placeholder="yyyy-mm-dd" name="purchase_date" id="purchase_date" value="{{ Input::old('purchase_date', $asset->purchase_date) }}">
|
||||||
|
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
||||||
</div><!-- /.input group -->
|
</div><!-- /.input group -->
|
||||||
|
|
||||||
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
||||||
{!! $errors->first('purchase_date', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('purchase_date', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -185,8 +187,8 @@
|
||||||
|
|
||||||
{!! $errors->first('supplier_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('supplier_id', '<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">
|
||||||
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select_id'><i class="verticon fa fa-plus-square-o fa-2x"></i></a>
|
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select_id' class="btn btn-sm btn-default">New</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -255,8 +257,8 @@
|
||||||
|
|
||||||
{!! $errors->first('rtd_location_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
{!! $errors->first('rtd_location_id', '<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">
|
||||||
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency='location' data-select='rtd_location_select'><i class="verticon fa fa-plus-square-o fa-2x"></i></a>
|
<a href='#' data-toggle="modal" data-target="#createModal" data-dependency='location' data-select='rtd_location_select' class="btn btn-sm btn-default">New</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue