From 968219ad9655a418d2bfbde6da9051c6c2294c97 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Thu, 8 Feb 2018 16:01:22 +0300 Subject: [PATCH] =?UTF-8?q?close=20#158=20Fixed:=20Don=C2=B4t=20validate?= =?UTF-8?q?=20Customer=20password=20field=20if=20"Allow=20login"=20isn?= =?UTF-8?q?=C2=B4t=20checked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Incomes/Customers.php | 25 +++++++ .../views/incomes/customers/create.blade.php | 44 +++++++++--- .../views/incomes/customers/edit.blade.php | 68 ++++++++++++++++--- routes/web.php | 1 + 4 files changed, 118 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Incomes/Customers.php b/app/Http/Controllers/Incomes/Customers.php index ebf317aef..5fc0f692b 100644 --- a/app/Http/Controllers/Incomes/Customers.php +++ b/app/Http/Controllers/Incomes/Customers.php @@ -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); + } } diff --git a/resources/views/incomes/customers/create.blade.php b/resources/views/incomes/customers/create.blade.php index 264da5a3f..0335199f4 100644 --- a/resources/views/incomes/customers/create.blade.php +++ b/resources/views/incomes/customers/create.blade.php @@ -24,13 +24,9 @@ {{ Form::radioGroup('enabled', trans('general.enabled')) }} -
+
{{ trans('customers.allow_login') }}   {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }}
- - {{ 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') }}
@@ -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('

{{ trans('validation.required', ['attribute' => 'email']) }}

'); $('input[name="email"]').focus(); + unselect(); + return false; } @@ -96,14 +97,13 @@ dataType: 'JSON', data: {column: 'email', value: email}, beforeSend: function() { + $('.iCheck-helper').parent().after(''); + $('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); + } @endpush diff --git a/resources/views/incomes/customers/edit.blade.php b/resources/views/incomes/customers/edit.blade.php index 8d7ed7429..c7b4b9643 100644 --- a/resources/views/incomes/customers/edit.blade.php +++ b/resources/views/incomes/customers/edit.blade.php @@ -28,17 +28,13 @@ {{ Form::radioGroup('enabled', trans('general.enabled')) }} -
+
@if ($customer->user_id) {{ trans('customers.user_created') }}   {{ Form::checkbox('create_user', '1', 1, ['id' => 'create_user', 'disabled' => 'disabled']) }} @else {{ trans('customers.allow_login') }}   {{ Form::checkbox('create_user', '1', null, ['id' => 'create_user']) }} @endif
- - {{ 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') }}
@@ -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('

{{ trans('validation.required', ['attribute' => 'email']) }}

'); + $('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(''); + + $('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('

' + json['data'] + '

'); + $('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); + } @endpush diff --git a/routes/web.php b/routes/web.php index 13d2b4002..f6963781e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); });