close #158 Fixed: Don´t validate Customer password field if "Allow login" isn´t checked
This commit is contained in:
parent
e3e6a0862b
commit
968219ad96
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Incomes;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Income\Customer as Request;
|
||||
use Illuminate\Http\Request as FRequest;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Income\Customer;
|
||||
use App\Models\Setting\Currency;
|
||||
@ -241,4 +242,28 @@ class Customers extends Controller
|
||||
|
||||
return response()->json($customer);
|
||||
}
|
||||
|
||||
public function field(FRequest $request)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
if ($request['fields']) {
|
||||
foreach ($request['fields'] as $field) {
|
||||
switch ($field) {
|
||||
case 'password':
|
||||
$html .= \Form::passwordGroup('password', trans('auth.password.current'), 'key', [], null, 'col-md-6 password');
|
||||
break;
|
||||
case 'password_confirmation':
|
||||
$html .= \Form::passwordGroup('password_confirmation', trans('auth.password.current_confirm'), 'key', [], null, 'col-md-6 password');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json = [
|
||||
'html' => $html
|
||||
];
|
||||
|
||||
return response()->json($json);
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,9 @@
|
||||
|
||||
{{ Form::radioGroup('enabled', trans('general.enabled')) }}
|
||||
|
||||
<div class="form-group col-md-12 margin-top">
|
||||
<div id="customer-create-user" class="form-group col-md-12 margin-top">
|
||||
<strong>{{ trans('customers.allow_login') }}</strong> {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }}
|
||||
</div>
|
||||
|
||||
{{ Form::passwordGroup('password', trans('auth.password.current'), 'key', [], null, 'col-md-6 password hidden') }}
|
||||
|
||||
{{ Form::passwordGroup('password_confirmation', trans('auth.password.current_confirm'), 'key', [], null, 'col-md-6 password hidden') }}
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
|
||||
@ -75,7 +71,7 @@
|
||||
$('input[name="user_id"]').remove();
|
||||
|
||||
if ($(this).prop('checked')) {
|
||||
$('.col-md-6.password').addClass('hidden');
|
||||
$('.col-md-6.password').remove();
|
||||
|
||||
$('input[name="email"]').parent().parent().removeClass('has-error');
|
||||
$('input[name="email"]').parent().parent().find('.help-block').remove();
|
||||
@ -83,10 +79,15 @@
|
||||
var email = $('input[name="email"]').val();
|
||||
|
||||
if (!email) {
|
||||
$('input[name="email"]').parent().parent().removeClass('has-error');
|
||||
$('input[name="email"]').parent().parent().find('.help-block').remove();
|
||||
|
||||
$('input[name="email"]').parent().parent().addClass('has-error');
|
||||
$('input[name="email"]').parent().after('<p class="help-block">{{ trans('validation.required', ['attribute' => 'email']) }}</p>');
|
||||
$('input[name="email"]').focus();
|
||||
|
||||
unselect();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -96,14 +97,13 @@
|
||||
dataType: 'JSON',
|
||||
data: {column: 'email', value: email},
|
||||
beforeSend: function() {
|
||||
$('.iCheck-helper').parent().after('<i class="fa fa-spinner fa-pulse fa-fw loading" style="margin-left: 10px;"></i>');
|
||||
|
||||
$('input[name="email"]').parent().parent().removeClass('has-error');
|
||||
$('input[name="email"]').parent().parent().find('.help-block').remove();
|
||||
|
||||
$('.box-footer .btn').attr('disabled', true);
|
||||
},
|
||||
complete: function() {
|
||||
$('.box-footer .btn').attr('disabled', false);
|
||||
},
|
||||
success: function(json) {
|
||||
if (json['errors']) {
|
||||
if (json['data']) {
|
||||
@ -114,7 +114,25 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
$('.col-md-6.password').removeClass('hidden');
|
||||
fields = [];
|
||||
|
||||
fields[0] = 'password';
|
||||
fields[1] = 'password_confirmation';
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("incomes/customers/field") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: {fields: fields},
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
complete: function() {
|
||||
$('.box-footer .btn').attr('disabled', false);
|
||||
$('.loading').remove();
|
||||
},
|
||||
success: function(json) {
|
||||
$('#customer-create-user').after(json['html']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (json['success']) {
|
||||
@ -125,5 +143,11 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function unselect() {
|
||||
setTimeout(function(){
|
||||
$('#create_user').iCheck('uncheck');
|
||||
}, 550);
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -28,17 +28,13 @@
|
||||
|
||||
{{ Form::radioGroup('enabled', trans('general.enabled')) }}
|
||||
|
||||
<div class="form-group col-md-12 margin-top">
|
||||
<div id="customer-create-user" class="form-group col-md-12 margin-top">
|
||||
@if ($customer->user_id)
|
||||
<strong>{{ trans('customers.user_created') }}</strong> {{ Form::checkbox('create_user', '1', 1, ['id' => 'create_user', 'disabled' => 'disabled']) }}
|
||||
@else
|
||||
<strong>{{ trans('customers.allow_login') }}</strong> {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
{{ Form::passwordGroup('password', trans('auth.password.current'), 'key', [], null, 'col-md-6 password hidden') }}
|
||||
|
||||
{{ Form::passwordGroup('password_confirmation', trans('auth.password.current_confirm'), 'key', [], null, 'col-md-6 password hidden') }}
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
|
||||
@ -81,22 +77,68 @@
|
||||
$('input[name="user_id"]').remove();
|
||||
|
||||
if ($(this).prop('checked')) {
|
||||
$('.col-md-6.password').addClass('hidden');
|
||||
$('.col-md-6.password').remove();
|
||||
|
||||
$('input[name="email"]').parent().parent().removeClass('has-error');
|
||||
$('input[name="email"]').parent().parent().find('.help-block').remove();
|
||||
} else {
|
||||
var email = $('input[name="email"]').val();
|
||||
|
||||
if (!email) {
|
||||
$('input[name="email"]').parent().parent().removeClass('has-error');
|
||||
$('input[name="email"]').parent().parent().find('.help-block').remove();
|
||||
|
||||
$('input[name="email"]').parent().parent().addClass('has-error');
|
||||
$('input[name="email"]').parent().after('<p class="help-block">{{ trans('validation.required', ['attribute' => 'email']) }}</p>');
|
||||
$('input[name="email"]').focus();
|
||||
|
||||
unselect();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("auth/users/autocomplete") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {column: 'email', value: $('input[name="email"]').val()},
|
||||
beforeSend: function() {
|
||||
$('.iCheck-helper').parent().after('<i class="fa fa-spinner fa-pulse fa-fw loading" style="margin-left: 10px;"></i>');
|
||||
|
||||
$('input[name="email"]').parent().parent().removeClass('has-error');
|
||||
$('input[name="email"]').parent().parent().find('.help-block').remove();
|
||||
|
||||
$('.box-footer .btn').attr('disabled', true);
|
||||
},
|
||||
complete: function() {
|
||||
$('.box-footer .btn').attr('disabled', false);
|
||||
},
|
||||
success: function(json) {
|
||||
if (json['errors']) {
|
||||
$('.col-md-6.password').removeClass('hidden');
|
||||
if (json['data']) {
|
||||
$('input[name="email"]').parent().parent().addClass('has-error');
|
||||
$('input[name="email"]').parent().after('<p class="help-block">' + json['data'] + '</p>');
|
||||
$('input[name="email"]').focus();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
fields = [];
|
||||
|
||||
fields[0] = 'password';
|
||||
fields[1] = 'password_confirmation';
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("incomes/customers/field") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: {fields: fields},
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
complete: function() {
|
||||
$('.box-footer .btn').attr('disabled', false);
|
||||
$('.loading').remove();
|
||||
},
|
||||
success: function(json) {
|
||||
$('#customer-create-user').after(json['html']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (json['success']) {
|
||||
@ -107,5 +149,11 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function unselect() {
|
||||
setTimeout(function(){
|
||||
$('#create_user').iCheck('uncheck');
|
||||
}, 550);
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -68,6 +68,7 @@ Route::group(['middleware' => 'language'], function () {
|
||||
Route::get('customers/currency', 'Incomes\Customers@currency');
|
||||
Route::get('customers/{customer}/duplicate', 'Incomes\Customers@duplicate');
|
||||
Route::post('customers/customer', 'Incomes\Customers@customer');
|
||||
Route::post('customers/field', 'Incomes\Customers@field');
|
||||
Route::post('customers/import', 'Incomes\Customers@import');
|
||||
Route::resource('customers', 'Incomes\Customers');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user