mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
52bd7d0d68
|
@ -8,6 +8,7 @@ use App\Models\AssetModel;
|
|||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Redirect;
|
||||
use Request;
|
||||
use Storage;
|
||||
|
@ -90,7 +91,9 @@ class AssetModelsController extends Controller
|
|||
// Was it created?
|
||||
if ($model->save()) {
|
||||
if ($this->shouldAddDefaultValues($request->input())) {
|
||||
$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'));
|
||||
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){
|
||||
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to the new model page
|
||||
|
@ -163,7 +166,9 @@ class AssetModelsController extends Controller
|
|||
$model->fieldset_id = $request->input('custom_fieldset');
|
||||
|
||||
if ($this->shouldAddDefaultValues($request->input())) {
|
||||
$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'));
|
||||
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){
|
||||
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,6 +456,21 @@ class AssetModelsController extends Controller
|
|||
*/
|
||||
private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues)
|
||||
{
|
||||
$data = array();
|
||||
foreach ($defaultValues as $customFieldId => $defaultValue) {
|
||||
$customField = \App\Models\CustomField::find($customFieldId);
|
||||
|
||||
$data[$customField->db_column] = $defaultValue;
|
||||
}
|
||||
|
||||
$rules = $model->fieldset->validation_rules();
|
||||
|
||||
$validator = Validator::make($data, $rules);
|
||||
|
||||
if($validator->fails()){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($defaultValues as $customFieldId => $defaultValue) {
|
||||
if(is_array($defaultValue)){
|
||||
$model->defaultValues()->attach($customFieldId, ['default_value' => implode(', ', $defaultValue)]);
|
||||
|
@ -458,6 +478,7 @@ class AssetModelsController extends Controller
|
|||
$model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,6 +20,7 @@ use Gate;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Input;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use League\Csv\Reader;
|
||||
|
@ -201,18 +202,36 @@ class AssetsController extends Controller
|
|||
}
|
||||
|
||||
$success = true;
|
||||
|
||||
// $cookie = Cookie::queue(Cookie::make('optional_info', $_POST['options'],$minutes));
|
||||
// $data = $request->session()->all();
|
||||
|
||||
// dd($_POST['options']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
// Redirect to the asset listing page
|
||||
$minutes = 518400;
|
||||
// dd( $_POST['options']);
|
||||
// Cookie::queue(Cookie::make('optional_info', json_decode($_POST['options']), $minutes));
|
||||
return redirect()->route('hardware.index')
|
||||
->with('success', trans('admin/hardware/message.create.success'));
|
||||
->with('success', trans('admin/hardware/message.create.success'))
|
||||
->withCookie(cookie('optional_info',json_encode($_POST['options']),$minutes,null,null,null,false));
|
||||
|
||||
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($asset->getErrors());
|
||||
}
|
||||
|
||||
public function getOptionCookie(Request $request){
|
||||
$value = $request->cookie('optional_info');
|
||||
echo $value;
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a view that presents a form to edit an existing asset.
|
||||
*
|
||||
|
|
|
@ -41,7 +41,7 @@ return [
|
|||
'make_required' => 'Optional - click to make required',
|
||||
'reorder' => 'Reorder',
|
||||
'db_field' => 'DB Field',
|
||||
'db_convert_warning' => 'WARNING. This field is in the custom fields table as <code> :db_column </code> but should be :expected </code>.',
|
||||
'db_convert_warning' => 'WARNING. This field is in the custom fields table as <code>:db_column</code> but should be <code>:expected</code>.',
|
||||
'is_unique' => 'This value must be unique across all assets',
|
||||
'unique' => 'Unique',
|
||||
];
|
||||
|
|
|
@ -49,6 +49,12 @@ return array(
|
|||
|
||||
),
|
||||
|
||||
'fieldset_default_value' => array(
|
||||
|
||||
'error' => 'Error validating default fieldset values.',
|
||||
|
||||
),
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -46,4 +46,6 @@ return [
|
|||
'asset_not_deployable' => 'That asset status is not deployable. This asset cannot be checked out.',
|
||||
'asset_deployable' => 'That status is deployable. This asset can be checked out.',
|
||||
'processing_spinner' => 'Processing...',
|
||||
'optional_infos' => 'Optional Information',
|
||||
'order_details' => 'Order Related Information'
|
||||
];
|
||||
|
|
|
@ -150,7 +150,8 @@
|
|||
<td>
|
||||
<code>{{ $field->convertUnicodeDbSlug() }}</code>
|
||||
@if ($field->convertUnicodeDbSlug()!=$field->db_column)
|
||||
<br><i class="fas fa-exclamation-triangle text-danger"></i>{{!! trans('admin/custom_fields/general.db_convert_warning', array('db_column' => $field->db_column, 'expected' => $field->convertUnicodeDbSlug())) !!}}
|
||||
<br><i class="fas fa-exclamation-triangle text-danger"></i>
|
||||
{!! trans('admin/custom_fields/general.db_convert_warning',['db_column' => $field->db_column, 'expected' => $field->convertUnicodeDbSlug()]) !!}
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $field->format }}</td>
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
|
||||
|
||||
{{-- Page content --}}
|
||||
|
||||
@section('inputFields')
|
||||
|
||||
|
||||
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
|
||||
|
||||
|
||||
<!-- {{Request::cookie('optional_info');}} -->
|
||||
<!-- Asset Tag -->
|
||||
<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>
|
||||
|
||||
|
||||
<!-- we are editing an existing asset -->
|
||||
@if ($item->id)
|
||||
<div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}">
|
||||
|
@ -41,78 +41,116 @@
|
|||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
@include ('partials.forms.edit.serial', ['fieldname'=> 'serials[1]', 'translated_serial' => trans('admin/hardware/form.serial')])
|
||||
|
||||
<div class="input_fields_wrap">
|
||||
</div>
|
||||
|
||||
|
||||
@include ('partials.forms.edit.model-select', ['translated_name' => trans('admin/hardware/form.model'), 'fieldname' => 'model_id', 'field_req' => true])
|
||||
|
||||
|
||||
<div id='custom_fields_content'>
|
||||
<!-- Custom Fields -->
|
||||
@if ($item->model && $item->model->fieldset)
|
||||
<?php $model=$item->model; ?>
|
||||
@endif
|
||||
@if (Request::old('model_id'))
|
||||
<?php $model=\App\Models\AssetModel::find(Request::old('model_id')); ?>
|
||||
@elseif (isset($selected_model))
|
||||
<?php $model=$selected_model; ?>
|
||||
@endif
|
||||
@if (isset($model) && $model)
|
||||
@include("models/custom_fields_form",["model" => $model])
|
||||
@endif
|
||||
</div>
|
||||
@include ('partials.forms.edit.status', [ 'required' => 'true'])
|
||||
@if (!$item->id)
|
||||
@include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true', 'style' => 'display:none;'])
|
||||
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user', 'style' => 'display:none;', 'required' => 'false'])
|
||||
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset', 'style' => 'display:none;', 'required' => 'false'])
|
||||
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required' => 'false'])
|
||||
@elseif (($item->assignedTo) && ($item->deleted_at == ''))
|
||||
<!-- This is an asset and it's currently deployed, so let them edit the expected checkin date -->
|
||||
@include ('partials.forms.edit.datepicker', ['translated_name' => trans('admin/hardware/form.expected_checkin'),'fieldname' => 'expected_checkin'])
|
||||
@endif
|
||||
|
||||
@include ('partials.forms.edit.status', [ 'required' => 'true'])
|
||||
@if (!$item->id)
|
||||
@include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true', 'style' => 'display:none;'])
|
||||
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user', 'style' => 'display:none;', 'required' => 'false'])
|
||||
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset', 'style' => 'display:none;', 'required' => 'false'])
|
||||
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required' => 'false'])
|
||||
@elseif (($item->assignedTo) && ($item->deleted_at==''))
|
||||
<!-- This is an asset and it's currently deployed, so let them edit the expected checkin date -->
|
||||
@include ('partials.forms.edit.datepicker', ['translated_name' => trans('admin/hardware/form.expected_checkin'),'fieldname' => 'expected_checkin'])
|
||||
@endif
|
||||
@include ('partials.forms.edit.notes')
|
||||
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'fieldname' => 'rtd_location_id'])
|
||||
@include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/hardware/general.requestable')])
|
||||
|
||||
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')])
|
||||
@include ('partials.forms.edit.purchase_date')
|
||||
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
|
||||
@include ('partials.forms.edit.order_number')
|
||||
<?php
|
||||
$currency_type=null;
|
||||
if ($item->id && $item->location) {
|
||||
$currency_type = $item->location->currency;
|
||||
}
|
||||
?>
|
||||
@include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type])
|
||||
@include ('partials.forms.edit.warranty')
|
||||
@include ('partials.forms.edit.notes')
|
||||
<!-- Image -->
|
||||
@if ($item->image)
|
||||
<div class="form-group {{ $errors->has('image_delete') ? 'has-error' : '' }}">
|
||||
<label class="col-md-3 control-label" for="image_delete">{{ trans('general.image_delete') }}</label>
|
||||
<div class="col-md-5">
|
||||
<label class="control-label" for="image_delete">
|
||||
<input type="checkbox" value="1" name="image_delete" id="image_delete" class="minimal" {{ Request::old('image_delete') == '1' ? ' checked="checked"' : '' }}>
|
||||
{!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
|
||||
</label>
|
||||
<div style="margin-top: 0.5em">
|
||||
<img src="{{ Storage::disk('public')->url(app('assets_upload_path').e($item->image)) }}" class="img-responsive" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'fieldname' => 'rtd_location_id'])
|
||||
@include ('partials.forms.edit.image-upload')
|
||||
|
||||
<div id='custom_fields_content'>
|
||||
<!-- Custom Fields -->
|
||||
@if ($item->model && $item->model->fieldset)
|
||||
<?php $model = $item->model; ?>
|
||||
@endif
|
||||
@if (Request::old('model_id'))
|
||||
@php
|
||||
$model = \App\Models\AssetModel::find(Request::old('model_id'));
|
||||
@endphp
|
||||
@elseif (isset($selected_model))
|
||||
@php
|
||||
$model = $selected_model;
|
||||
@endphp
|
||||
@endif
|
||||
@if (isset($model) && $model)
|
||||
@include("models/custom_fields_form",["model" => $model])
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/hardware/general.requestable')])
|
||||
<div class="form-group">
|
||||
<label class="col-md-3 control-label"></label>
|
||||
|
||||
<!-- Image -->
|
||||
@if ($item->image)
|
||||
<div class="form-group {{ $errors->has('image_delete') ? 'has-error' : '' }}">
|
||||
<label class="col-md-3 control-label" for="image_delete">{{ trans('general.image_delete') }}</label>
|
||||
<div class="col-md-5">
|
||||
<label class="control-label" for="image_delete">
|
||||
<input type="checkbox" value="1" name="image_delete" id="image_delete" class="minimal" {{ Request::old('image_delete') == '1' ? ' checked="checked"' : '' }}>
|
||||
{!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
|
||||
</label>
|
||||
<div style="margin-top: 0.5em">
|
||||
<img src="{{ Storage::disk('public')->url(app('assets_upload_path').e($item->image)) }}" class="img-responsive" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<div class="col-md-9 col-sm-9 col-md-offset-3">
|
||||
|
||||
@include ('partials.forms.edit.image-upload')
|
||||
<a id="optional_info" class="text-primary">
|
||||
<i class="fa fa-caret-right fa-2x" id="optional_info_icon"></i>
|
||||
<strong>{{ trans('admin/hardware/form.optional_infos') }}</strong>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="optional_details" class="col-md-12" style="display:none">
|
||||
<br>
|
||||
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')])
|
||||
@include ('partials.forms.edit.warranty')
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-9 col-sm-9 col-md-offset-3">
|
||||
<a id="order_info" class="text-primary">
|
||||
<i class="fa fa-caret-right fa-2x" id="order_info_icon"></i>
|
||||
<strong>{{ trans('admin/hardware/form.order_details') }}</strong>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div id='order_details' class="col-md-12" style="display:none">
|
||||
<br>
|
||||
@include ('partials.forms.edit.order_number')
|
||||
@include ('partials.forms.edit.purchase_date')
|
||||
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
|
||||
|
||||
@php
|
||||
$currency_type = null;
|
||||
if ($item->id && $item->location) {
|
||||
$currency_type = $item->location->currency;
|
||||
}
|
||||
@endphp
|
||||
|
||||
@include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type])
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@stop
|
||||
|
||||
@section('moar_scripts')
|
||||
|
@ -121,7 +159,6 @@
|
|||
|
||||
<script nonce="{{ csrf_token() }}">
|
||||
|
||||
|
||||
var transformed_oldvals={};
|
||||
|
||||
function fetchCustomFields() {
|
||||
|
@ -138,7 +175,7 @@
|
|||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: "{{url('/') }}/models/" + modelid + "/custom_fields",
|
||||
url: "{{ url('/') }}/models/" + modelid + "/custom_fields",
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
|
@ -276,13 +313,62 @@
|
|||
$(".add_field_button").removeAttr('disabled');
|
||||
$(".add_field_button").removeClass('disabled');
|
||||
e.preventDefault();
|
||||
console.log(x);
|
||||
//console.log(x);
|
||||
|
||||
$(this).parent('div').parent('div').parent('span').remove();
|
||||
x--;
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
$('.expand').click(function(){
|
||||
id = $(this).attr('id');
|
||||
fields = $(this).text();
|
||||
if (txt == '+'){
|
||||
$(this).text('-');
|
||||
}
|
||||
else{
|
||||
$(this).text('+');
|
||||
}
|
||||
$("#"+id).toggle();
|
||||
|
||||
});
|
||||
|
||||
{{-- TODO: Clean up some of the duplication in here. Not too high of a priority since we only copied it once. --}}
|
||||
$("#optional_info").on("click",function(){
|
||||
$('#optional_details').fadeToggle(100);
|
||||
$('#optional_info_icon').toggleClass('fa-caret-right fa-caret-down');
|
||||
var optional_info_open = $('#optional_info_icon').hasClass('fa-caret-down');
|
||||
document.cookie = "optional_info_open="+optional_info_open+'; path=/';
|
||||
});
|
||||
|
||||
$("#order_info").on("click",function(){
|
||||
$('#order_details').fadeToggle(100);
|
||||
$("#order_info_icon").toggleClass('fa-caret-right fa-caret-down');
|
||||
var order_info_open = $('#order_info_icon').hasClass('fa-caret-down');
|
||||
document.cookie = "order_info_open="+order_info_open+'; path=/';
|
||||
});
|
||||
|
||||
var all_cookies = document.cookie.split(';')
|
||||
for(var i in all_cookies) {
|
||||
var trimmed_cookie = all_cookies[i].trim(' ')
|
||||
if (trimmed_cookie.startsWith('optional_info_open=')) {
|
||||
elems = all_cookies[i].split('=', 2)
|
||||
if (elems[1] == 'true') {
|
||||
$('#optional_info').trigger('click')
|
||||
}
|
||||
}
|
||||
if (trimmed_cookie.startsWith('order_info_open=')) {
|
||||
elems = all_cookies[i].split('=', 2)
|
||||
if (elems[1] == 'true') {
|
||||
$('#order_info').trigger('click')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
@stop
|
||||
|
|
|
@ -22,8 +22,14 @@
|
|||
<label class="col-md-3 control-label{{ $errors->has($field->name) ? ' has-error' : '' }}" for="default-value{{ $field->id }}">{{ $field->name }}</label>
|
||||
|
||||
<div class="col-md-7">
|
||||
|
||||
@if ($field->element == "text")
|
||||
@if ($field->format == "DATE")
|
||||
<div class="input-group col-md-4" style="padding-left: 0px;">
|
||||
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true">
|
||||
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="default_values[{{ $field->id }}]" id="default-value{{ $field->id }}" value="{{ $field->defaultValue($model_id) }}">
|
||||
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
@elseif ($field->element == "text")
|
||||
<input class="form-control m-b-xs" type="text" value="{{ $field->defaultValue($model_id) }}" id="default-value{{ $field->id }}" name="default_values[{{ $field->id }}]">
|
||||
@elseif($field->element == "textarea")
|
||||
<textarea class="form-control" id="default-value{{ $field->id }}" name="default_values[{{ $field->id }}]">{{ $field->defaultValue($model_id) }}</textarea><br>
|
||||
|
|
Loading…
Reference in a new issue