close #158 Fixed: Don´t validate Customer password field if "Allow login" isn´t checked

This commit is contained in:
cuneytsenturk 2018-02-08 16:01:22 +03:00
parent e3e6a0862b
commit 968219ad96
4 changed files with 118 additions and 20 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Incomes;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\Income\Customer as Request; use App\Http\Requests\Income\Customer as Request;
use Illuminate\Http\Request as FRequest;
use App\Models\Auth\User; use App\Models\Auth\User;
use App\Models\Income\Customer; use App\Models\Income\Customer;
use App\Models\Setting\Currency; use App\Models\Setting\Currency;
@ -241,4 +242,28 @@ class Customers extends Controller
return response()->json($customer); 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);
}
} }

View File

@ -24,13 +24,9 @@
{{ Form::radioGroup('enabled', trans('general.enabled')) }} {{ 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> &nbsp; {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }} <strong>{{ trans('customers.allow_login') }}</strong> &nbsp; {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }}
</div> </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> </div>
<!-- /.box-body --> <!-- /.box-body -->
@ -75,7 +71,7 @@
$('input[name="user_id"]').remove(); $('input[name="user_id"]').remove();
if ($(this).prop('checked')) { 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().removeClass('has-error');
$('input[name="email"]').parent().parent().find('.help-block').remove(); $('input[name="email"]').parent().parent().find('.help-block').remove();
@ -83,10 +79,15 @@
var email = $('input[name="email"]').val(); var email = $('input[name="email"]').val();
if (!email) { 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().parent().addClass('has-error');
$('input[name="email"]').parent().after('<p class="help-block">{{ trans('validation.required', ['attribute' => 'email']) }}</p>'); $('input[name="email"]').parent().after('<p class="help-block">{{ trans('validation.required', ['attribute' => 'email']) }}</p>');
$('input[name="email"]').focus(); $('input[name="email"]').focus();
unselect();
return false; return false;
} }
@ -96,14 +97,13 @@
dataType: 'JSON', dataType: 'JSON',
data: {column: 'email', value: email}, data: {column: 'email', value: email},
beforeSend: function() { 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().removeClass('has-error');
$('input[name="email"]').parent().parent().find('.help-block').remove(); $('input[name="email"]').parent().parent().find('.help-block').remove();
$('.box-footer .btn').attr('disabled', true); $('.box-footer .btn').attr('disabled', true);
}, },
complete: function() {
$('.box-footer .btn').attr('disabled', false);
},
success: function(json) { success: function(json) {
if (json['errors']) { if (json['errors']) {
if (json['data']) { if (json['data']) {
@ -114,7 +114,25 @@
return false; 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']) { if (json['success']) {
@ -125,5 +143,11 @@
} }
}); });
}); });
function unselect() {
setTimeout(function(){
$('#create_user').iCheck('uncheck');
}, 550);
}
</script> </script>
@endpush @endpush

View File

@ -28,17 +28,13 @@
{{ Form::radioGroup('enabled', trans('general.enabled')) }} {{ 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) @if ($customer->user_id)
<strong>{{ trans('customers.user_created') }}</strong> &nbsp; {{ Form::checkbox('create_user', '1', 1, ['id' => 'create_user', 'disabled' => 'disabled']) }} <strong>{{ trans('customers.user_created') }}</strong> &nbsp; {{ Form::checkbox('create_user', '1', 1, ['id' => 'create_user', 'disabled' => 'disabled']) }}
@else @else
<strong>{{ trans('customers.allow_login') }}</strong> &nbsp; {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }} <strong>{{ trans('customers.allow_login') }}</strong> &nbsp; {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }}
@endif @endif
</div> </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> </div>
<!-- /.box-body --> <!-- /.box-body -->
@ -81,22 +77,68 @@
$('input[name="user_id"]').remove(); $('input[name="user_id"]').remove();
if ($(this).prop('checked')) { 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 { } 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({ $.ajax({
url: '{{ url("auth/users/autocomplete") }}', url: '{{ url("auth/users/autocomplete") }}',
type: 'GET', type: 'GET',
dataType: 'JSON', dataType: 'JSON',
data: {column: 'email', value: $('input[name="email"]').val()}, data: {column: 'email', value: $('input[name="email"]').val()},
beforeSend: function() { 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); $('.box-footer .btn').attr('disabled', true);
}, },
complete: function() {
$('.box-footer .btn').attr('disabled', false);
},
success: function(json) { success: function(json) {
if (json['errors']) { 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']) { if (json['success']) {
@ -107,5 +149,11 @@
} }
}); });
}); });
function unselect() {
setTimeout(function(){
$('#create_user').iCheck('uncheck');
}, 550);
}
</script> </script>
@endpush @endpush

View File

@ -68,6 +68,7 @@ Route::group(['middleware' => 'language'], function () {
Route::get('customers/currency', 'Incomes\Customers@currency'); Route::get('customers/currency', 'Incomes\Customers@currency');
Route::get('customers/{customer}/duplicate', 'Incomes\Customers@duplicate'); Route::get('customers/{customer}/duplicate', 'Incomes\Customers@duplicate');
Route::post('customers/customer', 'Incomes\Customers@customer'); Route::post('customers/customer', 'Incomes\Customers@customer');
Route::post('customers/field', 'Incomes\Customers@field');
Route::post('customers/import', 'Incomes\Customers@import'); Route::post('customers/import', 'Incomes\Customers@import');
Route::resource('customers', 'Incomes\Customers'); Route::resource('customers', 'Incomes\Customers');
}); });