Fixes models on create asset

This commit is contained in:
snipe 2017-08-23 13:08:42 -07:00
parent 2d2cae10b9
commit ca78b3ed7c
4 changed files with 18 additions and 13 deletions

View file

@ -31,9 +31,9 @@
<label for="parent" class="col-md-3 control-label">{{ trans('admin/hardware/form.model') }}</label> <label for="parent" class="col-md-3 control-label">{{ trans('admin/hardware/form.model') }}</label>
<div class="col-md-7 col-sm-10{{ (\App\Helpers\Helper::checkIfRequired($item, 'model_id')) ? ' required' : '' }}"> <div class="col-md-7 col-sm-10{{ (\App\Helpers\Helper::checkIfRequired($item, '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', 'id' =>'model_select_id')) }}
@else @else
{{ Form::select('model_id', $model_list , Input::old('model_id', $item->model_id), array('class'=>'select2 model', 'style'=>'width:100%','id' =>'model_select_id')) }} {{ Form::select('model_id', $model_list , Input::old('model_id', $item->model_id), array('class'=>'select2 model', 'id' => 'model_select_id', 'style'=>'width:100%','id' =>'model_select_id')) }}
@endif @endif
<!-- onclick="return dependency('model')" --> <!-- onclick="return dependency('model')" -->
{!! $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>') !!}
@ -86,9 +86,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%')) }} {{ 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>') !!} {!! $errors->first('assigned_asset', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div> </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> </div>
<!-- Locations --> <!-- Locations -->
@ -100,7 +98,7 @@
{!! $errors->first('assigned_location', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!} {!! $errors->first('assigned_location', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div> </div>
<div class="col-md-1 col-sm-1 text-left"> <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> <a href='#' data-toggle="modal" data-target="#createModal" data-dependency="location" data-select='assigned_location' class="btn btn-sm btn-default">New</a>
</div> </div>
</div> </div>
@endif @endif
@ -271,7 +269,7 @@
break; break;
case 'statuslabel': case 'statuslabel':
show_er("#modal-statuslabel_types"); show_er("#modal-type");
break; break;
case 'supplier': case 'supplier':
@ -436,10 +434,16 @@
success: function (result) { success: function (result) {
var id = result.id; var id = result.id;
var name = result.name || (result.first_name + " " + result.last_name); var name = result.payload.name || (result.payload.first_name + " " + result.payload.last_name);
console.log(name);
$('.modal-body input:visible').val(""); $('.modal-body input:visible').val("");
$('#createModal').modal('hide'); $('#createModal').modal('hide');
// "select" is the original drop-down menu that someone
// clicked 'add' on to add a new 'thing'
// this code adds the newly created object to that select
var selector = document.getElementById(select); var selector = document.getElementById(select);
//console.log(document.getElementById(select));
selector.options[selector.length] = new Option(name, id); selector.options[selector.length] = new Option(name, id);
selector.selectedIndex = selector.length - 1; selector.selectedIndex = selector.length - 1;
$(selector).trigger("change"); $(selector).trigger("change");
@ -447,7 +451,8 @@
}, },
error: function (result) { error: function (result) {
msg = result.responseJSON.error.message || result.responseJSON.error; // console.log('Error: ' + result.responseJSON.error.message );
msg = result.responseJSON.messages || result.responseJSON.error;
window.alert("Unable to add new " + model + " - error: " + msg); window.alert("Unable to add new " + model + " - error: " + msg);
} }

View file

@ -1,4 +1,4 @@
@if($model->fieldset) @if (($model) && ($model->fieldset))
@foreach($model->fieldset->fields AS $field) @foreach($model->fieldset->fields AS $field)
<div class="form-group{{ $errors->has($field->db_column_name()) ? ' has-error' : '' }}"> <div class="form-group{{ $errors->has($field->db_column_name()) ? ' has-error' : '' }}">
<label for="{{ $field->db_column_name() }}" class="col-md-3 control-label">{{ $field->name }} </label> <label for="{{ $field->db_column_name() }}" class="col-md-3 control-label">{{ $field->name }} </label>

View file

@ -2,7 +2,7 @@
<div class="form-group {{ $errors->has('supplier_id') ? ' has-error' : '' }}"> <div class="form-group {{ $errors->has('supplier_id') ? ' has-error' : '' }}">
<label for="supplier_id" class="col-md-3 control-label">{{ trans('general.supplier') }}</label> <label for="supplier_id" class="col-md-3 control-label">{{ trans('general.supplier') }}</label>
<div class="col-md-7{{ (\App\Helpers\Helper::checkIfRequired($item, 'supplier_id')) ? ' required' : '' }}"> <div class="col-md-7{{ (\App\Helpers\Helper::checkIfRequired($item, 'supplier_id')) ? ' required' : '' }}">
{{ Form::select('supplier_id', $supplier_list , Input::old('supplier_id', $item->supplier_id), ['class'=>'select2', 'style'=>'min-width:350px']) }} {{ Form::select('supplier_id', $supplier_list , Input::old('supplier_id', $item->supplier_id), ['class'=>'select2', 'style'=>'min-width:350px', 'id' => 'supplier_select_id']) }}
{!! $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"> <div class="col-md-1 col-sm-1 text-left">

View file

@ -31,9 +31,9 @@
</div> </div>
<div class="dynamic-form-row"> <div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-statuslabel_types">{{ trans('admin/statuslabels/table.status_type') }}: <div class="col-md-4 col-xs-12"><label for="modal-type">{{ trans('admin/statuslabels/table.status_type') }}:
</label></div> </label></div>
<div class="col-md-8 col-xs-12 required">{{ Form::select('modal-statuslabel_types', $statuslabel_types, '', array('class'=>'select2', 'style'=>'width:90%','id' =>'modal-statuslabel_types')) }}</div> <div class="col-md-8 col-xs-12 required">{{ Form::select('modal-type', $statuslabel_types, '', array('class'=>'select2', 'style'=>'width:90%','id' =>'modal-type')) }}</div>
</div> </div>
<div class="dynamic-form-row"> <div class="dynamic-form-row">