mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Allow admin to add user on checkout screen
This commit is contained in:
parent
bb758d618b
commit
2b5fb04ba9
|
@ -148,17 +148,30 @@ class UsersController extends Controller
|
|||
/**
|
||||
* JSON handler for creating a user through a modal popup
|
||||
*
|
||||
* @todo Handle validation more graciously
|
||||
* @author [B. Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v1.8]
|
||||
* @return string JSON
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$user = new User;
|
||||
|
||||
$user = new User;
|
||||
$inputs = Input::except('csrf_token', 'password_confirm', 'groups', 'email_user');
|
||||
$inputs['activated'] = true;
|
||||
|
||||
$user->first_name = e(Input::get('first_name'));
|
||||
$user->last_name = e(Input::get('last_name'));
|
||||
$user->username = e(Input::get('username'));
|
||||
$user->email = e(Input::get('email'));
|
||||
if (Input::has('password')) {
|
||||
$user->password = bcrypt(Input::get('password'));
|
||||
}
|
||||
|
||||
$user->activated = true;
|
||||
|
||||
|
||||
|
||||
// Was the user created?
|
||||
if ($user->save()) {
|
||||
|
||||
|
@ -167,6 +180,7 @@ class UsersController extends Controller
|
|||
$data = array();
|
||||
$data['email'] = e(Input::get('email'));
|
||||
$data['first_name'] = e(Input::get('first_name'));
|
||||
$data['last_name'] = e(Input::get('last_name'));
|
||||
$data['password'] = e(Input::get('password'));
|
||||
|
||||
Mail::send('emails.send-login', $data, function ($m) use ($user) {
|
||||
|
@ -180,7 +194,6 @@ class UsersController extends Controller
|
|||
} else {
|
||||
return JsonResponse::create(["error" => "Failed validation: " . print_r($user->getErrors(), true)], 500);
|
||||
}
|
||||
return JsonResponse::create(["error" => "Couldn't save User"], 500);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -57,16 +57,22 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User -->
|
||||
<div class="form-group {{ $errors->has('assigned_to') ? 'error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('assigned_to', trans('admin/hardware/form.checkout_to')) }}
|
||||
<!-- User -->
|
||||
<div id="assigned_user" class="form-group{{ $errors->has('assigned_to') ? ' has-error' : '' }}">
|
||||
<div class="col-md-3">
|
||||
{{ Form::label('assigned_to', trans('admin/hardware/form.checkout_to')) }}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
{{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $asset->assigned_to), array('class'=>'select2', 'id'=>'assigned_to', 'style'=>'width:100%')) }}
|
||||
|
||||
{!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{{ Form::select('assigned_to', $users_list , Input::old('assigned_to', $asset->assigned_to), array('id'=>'checkout_to_user','class'=>'select2', 'style'=>'min-width:350px')) }}
|
||||
{!! $errors->first('assigned_to', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Checkout/Checkin Date -->
|
||||
<div class="form-group {{ $errors->has('checkout_at') ? 'error' : '' }}">
|
||||
|
@ -153,9 +159,144 @@
|
|||
|
||||
</div>
|
||||
|
||||
|
||||
@section('moar_scripts')
|
||||
|
||||
<!-- Ajax call to retrieve user assets -->
|
||||
{{-- Some room for the modals --}}
|
||||
<div class="modal fade" id="createModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Modal title</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-first_name">{{ trans('general.first_name') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-first_name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-last_name">{{ trans('general.last_name') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-last_name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-username">{{ trans('admin/users/table.username') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-username' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-email">{{ trans('admin/users/table.email') }}:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='email' id='modal-email' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-password">{{ trans('admin/users/table.password') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='password' id='modal-password' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
|
||||
<button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Ajax call to retrieve user assets -->
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
$(function () {
|
||||
var model,select;
|
||||
|
||||
|
||||
$('#createModal').on("show.bs.modal",function (event) {
|
||||
console.warn('modal ran');
|
||||
var link = $(event.relatedTarget);
|
||||
model=link.data("dependency");
|
||||
select=link.data("select");
|
||||
|
||||
var modal = $(this);
|
||||
modal.find('.modal-title').text('Add a new ' + model);
|
||||
|
||||
$('.dynamic-form-row').hide();
|
||||
function show_er(selector) {
|
||||
$(selector).parent().parent().show();
|
||||
}
|
||||
show_er('#modal-name');
|
||||
switch(model) {
|
||||
|
||||
case 'user':
|
||||
$('.dynamic-form-row').hide(); //we don't want a generic "name"
|
||||
show_er("#modal-first_name");
|
||||
show_er("#modal-last_name");
|
||||
show_er("#modal-username");
|
||||
show_er("#modal-email");
|
||||
show_er("#modal-password");
|
||||
show_er("#modal-password_confirm");
|
||||
break;
|
||||
|
||||
|
||||
//do nothing, they just need 'name'
|
||||
}
|
||||
|
||||
//console.warn("The Model is: "+model+" and the select is: "+select);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$('#modal-save').on('click',function () {
|
||||
var data={};
|
||||
//console.warn("We are about to SAVE!!! for model: "+model+" and select ID: "+select);
|
||||
$('.modal-body input:visible').each(function (index,elem) {
|
||||
//console.warn("["+index+"]: "+elem.id+" = "+$(elem).val());
|
||||
var bits=elem.id.split("-");
|
||||
if(bits[0]==="modal") {
|
||||
data[bits[1]]=$(elem).val();
|
||||
}
|
||||
});
|
||||
$('.modal-body select:visible').each(function (index,elem) {
|
||||
var bits=elem.id.split("-");
|
||||
data[bits[1]]=$(elem).val();
|
||||
});
|
||||
|
||||
data._token = '{{ csrf_token() }}',
|
||||
// console.dir(data);
|
||||
|
||||
$.post("{{config('app.url') }}/api/"+model+"s",data,function (result) {
|
||||
var id=result.id;
|
||||
var name=result.name || (result.first_name+" "+result.last_name);
|
||||
$('.modal-body input:visible').val("");
|
||||
$('#createModal').modal('hide');
|
||||
|
||||
//console.warn("The select ID thing we're going for is: "+select);
|
||||
var selector=document.getElementById(select);
|
||||
selector.options[selector.length] = new Option(name,id);
|
||||
selector.selectedIndex=selector.length-1;
|
||||
$(selector).trigger("change");
|
||||
|
||||
|
||||
}).fail(function (result) {
|
||||
//console.dir(result.responseJSON);
|
||||
msg=result.responseJSON.error.message || result.responseJSON.error;
|
||||
window.alert("Unable to add new "+model+" - error: "+msg);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
$(function() {
|
||||
|
|
|
@ -15,92 +15,7 @@
|
|||
{{ trans('general.back') }}</a>
|
||||
@stop
|
||||
|
||||
{{-- Some room for the modals --}}
|
||||
<div class="modal fade" id="createModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Modal title</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-name">{{ trans('general.name') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-manufacturer_id">{{ trans('general.manufacturer') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('modal-manufacturer', $manufacturer , '', array('class'=>'select2 parent', 'style'=>'width:100%','id' =>'modal-manufacturer_id')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-category_id">{{ trans('general.category') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('modal-category', $category ,'', array('class'=>'select2 parent', 'style'=>'width:100%','id' => 'modal-category_id')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-modelno">{{ trans('general.model_no') }}:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-modelno' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-statuslabel_types">{{ trans('admin/statuslabels/table.status_type') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('modal-statuslabel_types', $statuslabel_types, '', array('class'=>'select2', 'style'=>'width:90%','id' =>'modal-statuslabel_types')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-city">{{ trans('general.city') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-city' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-country">{{ trans('general.country') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12">{!! Form::countries('country', Input::old('country'), 'select2 country',"modal-country") !!}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-fieldset_id">{{ trans('admin/models/general.fieldset') }}:</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('custom_fieldset', \App\Helpers\Helper::customFieldsetList(),Input::old('custom_fieldset'), array('class'=>'select2', 'id'=>'modal-fieldset_id', 'style'=>'width:350px')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-first_name">{{ trans('general.first_name') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-first_name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-last_name">{{ trans('general.last_name') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-last_name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-username">{{ trans('admin/users/table.username') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-username' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-password">{{ trans('admin/users/table.password') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='password' id='modal-password' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-password_confirm">{{ trans('admin/users/table.password_confirm') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='password' id='modal-password_confirm' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
|
||||
<button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
@include('partials/modals')
|
||||
|
||||
{{-- Page content --}}
|
||||
|
||||
|
|
86
resources/views/partials/modals.blade.php
Normal file
86
resources/views/partials/modals.blade.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
{{-- Some room for the modals --}}
|
||||
<div class="modal fade" id="createModal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Modal title</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-name">{{ trans('general.name') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-manufacturer_id">{{ trans('general.manufacturer') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('modal-manufacturer', $manufacturer , '', array('class'=>'select2 parent', 'style'=>'width:100%','id' =>'modal-manufacturer_id')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-category_id">{{ trans('general.category') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('modal-category', $category ,'', array('class'=>'select2 parent', 'style'=>'width:100%','id' => 'modal-category_id')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-modelno">{{ trans('general.model_no') }}:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-modelno' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-statuslabel_types">{{ trans('admin/statuslabels/table.status_type') }}*:
|
||||
</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('modal-statuslabel_types', $statuslabel_types, '', array('class'=>'select2', 'style'=>'width:90%','id' =>'modal-statuslabel_types')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-city">{{ trans('general.city') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-city' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-country">{{ trans('general.country') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12">{!! Form::countries('country', Input::old('country'), 'select2 country',"modal-country") !!}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-fieldset_id">{{ trans('admin/models/general.fieldset') }}:</label></div>
|
||||
<div class="col-md-8 col-xs-12">{{ Form::select('custom_fieldset', \App\Helpers\Helper::customFieldsetList(),Input::old('custom_fieldset'), array('class'=>'select2', 'id'=>'modal-fieldset_id', 'style'=>'width:350px')) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-first_name">{{ trans('general.first_name') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-first_name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-last_name">{{ trans('general.last_name') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-last_name' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-username">{{ trans('admin/users/table.username') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='text' id='modal-username' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-password">{{ trans('admin/users/table.password') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='password' id='modal-password' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-password_confirm">{{ trans('admin/users/table.password_confirm') }}*:</label></div>
|
||||
<div class="col-md-8 col-xs-12"><input type='password' id='modal-password_confirm' class="form-control"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
|
||||
<button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
Loading…
Reference in a new issue