From: soufiane Date: Thu, 23 Mar 2023 01:20:03 +0000 (+0100) Subject: wip #5791 @7:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=05f5ed02994fdb5b51001e92c5cedee259766ad3;p=pmi.git wip #5791 @7:00 --- diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index fc7061e..98dc025 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -364,20 +364,88 @@ class AjaxController extends CubistFrontController } public function update(Request $request) { - $validation = [ - 'email' => 'required|email', - 'lastname' => 'required|string|max:255', - 'firstname' => 'required|string|max:255', - 'phone' => 'required|numeric' - ]; + $validation = []; + foreach ($request->all() as $key => $field){ + if($key === "email"){ + $validation[$key] = 'required|email'; + }elseif(in_array($key, ['firstname','lastname','name','company','address','city'])){ + $validation[$key] = 'required|string|max:255'; + }elseif(in_array($key,['phone'])){ + $validation[$key] = 'required|numeric'; + } + + } + + $data = $this->validation_form($request, $validation); + $email = Auth::guard('web-clients')->user()->email; + $client = Client::where('email',$email)->update($data); + } + + public function updateAddress(Request $request){ + $validation = []; + $index = $request->index; + + foreach ($request->all() as $field){ + if (is_array($field)) { + foreach ($field as $keySubfield => $subfield) { + if (in_array($keySubfield, ['firstname', 'lastname', 'name', 'company', 'address', 'city'])) { + $validation['address.' . $keySubfield] = 'required|string|max:255'; + } elseif (in_array($keySubfield, ['zipcode'])) { + $validation['address.' . $keySubfield] = 'required|numeric'; + } + } + } + } + $data = $this->validation_form($request, $validation); $email = Auth::guard('web-clients')->user()->email; - $client = Client::where('email', $email)->update($data); + $address = Auth::guard('web-clients')->user()->address; - $client->save(); + $addressToArray = json_decode($address); - return $data; + $checkBillingAddress = array_filter($addressToArray, function($n) { return $n->billing_address; }); + $checkDeliveryAddress = array_filter($addressToArray, function($n) { return $n->delivery_address; }); + + + if(isset($request->address['billing_address'])){ + foreach ($addressToArray as $key => &$value){ + $value->billing_address = "0"; + } + $data['address']['billing_address'] = "1"; + }else{ + $data['address']['billing_address'] = "0"; + } + + + + if(isset($request->address['delivery_address'])){ + foreach ($addressToArray as $key => &$value){ + $value->delivery_address = "0"; + } + $data['address']['delivery_address'] = "1"; + + }else{ + $data['address']['delivery_address'] = "0"; + } + + foreach ($addressToArray as $key => &$value){ + $value->id = $key; + } + $data['address']['id'] = $index; + $addressToArray[$index] = (object) $data['address']; + + + if(!$checkBillingAddress && !isset($request->address['billing_address'])){ + $addressToArray[0]->billing_address = "1"; + } + if(!$checkDeliveryAddress && !isset($request->address['delivery_address'])){ + $addressToArray[0]->delivery_address = "1"; + } + + // + $addressToString = json_encode($addressToArray); + $client = Client::where('email', $email)->update(['address' => $addressToString]); } public function getaddress() { @@ -385,6 +453,17 @@ class AjaxController extends CubistFrontController return $clientAddress; } + public function deleteaddress(Request $request) { + $index = $request->index; + + $address = Auth::guard('web-clients')->user()->address; + $addressToArray = json_decode($address); + unset($addressToArray[$index]); + $addressToString = json_encode($addressToArray); + $email = Auth::guard('web-clients')->user()->email; + $client = Client::where('email', $email)->update(['address' => $addressToString]); + } + public function getuser() { return Auth::guard('web-clients')->user(); } diff --git a/app/SubForms/Address.php b/app/SubForms/Address.php index 4c7af37..495d3b1 100644 --- a/app/SubForms/Address.php +++ b/app/SubForms/Address.php @@ -8,6 +8,19 @@ class Address extends SubForm { public function init() { parent::init(); + + $this->addField([ + 'name' => 'id', + 'label' => 'Id', + 'type' => 'Integer', + 'attributes' => [ + 'disabled' => 'disabled' + ], + 'options' => [ + 'auto_increment' => true + ] + ]); + $this->addField([ 'name' => 'name', 'label' => "Nom de l'adresse", diff --git a/resources/js/app.js b/resources/js/app.js index 09e307a..ddde1fd 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -67,7 +67,9 @@ const app = new Vue({ validateRegister: false, tab: 'infos', addresses: [{}], - user: '' + user: '', + default_billing_address: null, + default_delivery_address: null }, beforeMount() { @@ -94,6 +96,10 @@ const app = new Vue({ }); }, + updated(){ + console.log(this.selected) + }, + computed: { cartItemCount() { // Todo: See if this should count just number of items or make a sum of all quantities? What is more useful? The sum of quantities can be found using map/reduce functions but this needs to be adapted for the object structure using Object.keys as the source. @@ -241,6 +247,12 @@ const app = new Vue({ // root.user = response.data root.addresses = JSON.parse(response.data.address) + + let indexBillingAddress = root.addresses.filter(address => address.billing_address === "1")[0]['id']; + let indexDeliveryAddress = root.addresses.filter(address => address.delivery_address === "1")[0]['id']; + + root.default_billing_address = 'billing'+indexBillingAddress + root.default_delivery_address = 'delivery'+indexDeliveryAddress }) .catch(function (error) { @@ -268,6 +280,48 @@ const app = new Vue({ .catch(function (error) { }) + }, + updateAddress(id){ + let root = this, + form = document.getElementById(id), + data = new FormData(form) + + axios.post('/ajax/updateAddress', data) + .then(function (response) { + // + root.removeErrors() + root.validateRegister = true + }) + .catch(function (error) { + + }) + }, + deleteAddress(index, form){ + let root = this, + form_ = document.getElementById(form), + data = { + index: index + } + + axios.post('/ajax/deleteaddress', data) + .then(function (response) { + // + form_.animate([ + { opacity: 1 }, + { opacity: 0 } + ], + { + duration: 1000 + } + ); + setTimeout(() => { + form_.parentElement.remove() + }, 1000) + }) + .catch(function (error) { + + }) + } } diff --git a/resources/styles/components/my-account.styl b/resources/styles/components/my-account.styl index bf5b5af..f723dd0 100644 --- a/resources/styles/components/my-account.styl +++ b/resources/styles/components/my-account.styl @@ -26,7 +26,8 @@ &-container-content padding: 46px 96px - &-address + &-address, + &-password .ajax-form:not(:last-child) padding-bottom: 48px border-bottom: 1px solid theme('colors.light-b') @@ -34,6 +35,9 @@ label:first-child padding-top: 0 !important + &-address-header + padding-bottom: 46px + form label padding-top: 24px !important @@ -64,3 +68,12 @@ background-image: url(/images/icon-checked.svg) background-repeat: no-repeat background-position: center + + .btn-show-pwd + position: absolute + top: 50% + transform: translateY(-50%) + right: 2px + height: 94% + svg + margin: auto diff --git a/resources/views/components/address-form.blade.php b/resources/views/components/address-form.blade.php index 900acc7..0eda804 100644 --- a/resources/views/components/address-form.blade.php +++ b/resources/views/components/address-form.blade.php @@ -1,21 +1,21 @@ -
+
+ + - + diff --git a/resources/views/pages/sign_in.blade.php b/resources/views/pages/sign_in.blade.php index 9450f80..df48aaa 100644 --- a/resources/views/pages/sign_in.blade.php +++ b/resources/views/pages/sign_in.blade.php @@ -146,6 +146,8 @@
+ +