281 lines
11 KiB
PHP
281 lines
11 KiB
PHP
@extends('layouts.main')
|
|
|
|
@section('content')
|
|
<h2>
|
|
<i class="fas fa-users"></i>
|
|
{{ __('Editer le contact') }}
|
|
</h2>
|
|
@if ($errors->any())
|
|
<div class="alert alert-danger">
|
|
<ul>
|
|
@foreach ($errors->all() as $error)
|
|
<li>{{ $error }}</li>
|
|
@endforeach
|
|
</ul>
|
|
</div>
|
|
@endif
|
|
<div class="form-wrapper">
|
|
<form action="{{ route('contact.update', $contact) }}" method="POST">
|
|
@csrf
|
|
@method('PUT')
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
<label>{{ __('Ref') }} *</label>
|
|
<input type="text" name="contact_ref" value="{{ $contact->contact_ref }}" required readonly>
|
|
</div>
|
|
<div class="form-field">
|
|
<label>{{ __('Email') }} *</label>
|
|
<input type="email" name="contact_email" value="{{ $contact->contact_email }}" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
<label>{{ __('Nom') }} *</label>
|
|
<input type="text" name="contact_nom" value="{{ $contact->contact_nom }}" required>
|
|
</div>
|
|
<div class="form-field">
|
|
<label>{{ __('Prénom') }} *</label>
|
|
<input type="text" name="contact_prenom" value="{{ $contact->contact_prenom }}" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
<label>{{ __('Code Postal') }} *</label>
|
|
<input type="text" name="contact_cp" value="{{ $contact->contact_cp }}" required>
|
|
</div>
|
|
<div class="form-field">
|
|
<label>{{ __('Ville') }} *</label>
|
|
<input type="text" name="contact_ville" value="{{ $contact->contact_ville }}" required>
|
|
</div>
|
|
</div>
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
<label for="contact_country">{{ __('Pays') }}</label>
|
|
<select name="contact_country" id="contact_country">
|
|
@foreach (Countries::toArray() as $country)
|
|
<option value="{{ $country->value }}" @if ($contact->contact_country === $country->value) selected @endif>{{ $country->label }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-field submit">
|
|
<span>{{ __('Les champs avec un * sont obligatoires') }}</span>
|
|
<input type="submit" value="{{ __('Mettre à jour') }}">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<h2>
|
|
<i class="fa fa-folder">
|
|
<i class="fas fa-ticket-alt"></i>
|
|
</i>
|
|
{{ __('Campagnes liées') }}
|
|
</h2>
|
|
<div class="contactWidgets">
|
|
<input type="hidden" name="contact_id" id="contact_id" value="{{ $contact->contact_id }}">
|
|
<input type="hidden" name="csrf" id="csrf" value="<?= csrf_token(); ?>">
|
|
@foreach ($campagnes as $campagne)
|
|
<div class="campagne" data-campid="{{ $campagne->camp_id }}" data-campsite = "{{ $campagne->camp_siteId }}">
|
|
<h4>{{$campagne->camp_name}}</h4>
|
|
<p>{{ __('Type') }} : {{ $campagne->camp_type->label }}</p>
|
|
|
|
<div class="loader">
|
|
<div class="lds-ripple">
|
|
<div></div>
|
|
<div></div>
|
|
</div>
|
|
<h4>{{ __('Chargement') }}...</h4>
|
|
</div>
|
|
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
@endsection
|
|
@section('scripts')
|
|
<script>
|
|
$('.loader').show();
|
|
function loadWidget(campagne){
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: '/bo/contact/'+ $('#contact_id').val() +'/load-widget',
|
|
type: 'POST',
|
|
data: {
|
|
camp_id : campagne.attr('data-campid'),
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
if(reponse.success){
|
|
campagne.append(reponse.html);
|
|
$('.loader').hide();
|
|
} else {
|
|
campagne.append("{{ __('Erreur lors du chargement') }}");
|
|
}
|
|
},
|
|
error: function (e) {
|
|
console.log(e.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
$('.campagne').each(function(index){
|
|
var camp = $(this);
|
|
loadWidget(camp);
|
|
});
|
|
|
|
|
|
// ---- widgets : Réinitialiser le mur
|
|
$('.campagne').on('click', '.update-wall', function(event){
|
|
event.preventDefault();
|
|
let campagne = $(this).parent().parent().parent('.campagne');
|
|
let campid = campagne.attr('data-campid');
|
|
let contactRef = $('#contact_ref').val();
|
|
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: '/delctrlcontact',
|
|
type: 'POST',
|
|
data: {
|
|
refcamp: campid,
|
|
refadherent : contactRef,
|
|
admin : 1
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
if(reponse.Statut == "OK"){
|
|
campagne.find('.widget').remove();
|
|
campagne.find('.loader').show();
|
|
loadWidget(campagne);
|
|
$.fancyInfo({
|
|
title : "<i class='fas fa-info-circle'></i> {{ __('Succès') }}",
|
|
message : "{{ __('Le mur a bien été réinitialisé.') }}",
|
|
okButton : "{{ __('Valider') }}",
|
|
noButton : "",
|
|
callback : function (value) {
|
|
}
|
|
});
|
|
} else {
|
|
console.log("{{ __('Erreur') }} : "+reponse.Code+" - "+reponse.Message)
|
|
}
|
|
},
|
|
error: function (e) {
|
|
console.log(e.responseText);
|
|
}
|
|
});
|
|
})
|
|
|
|
// ---- widgets : Ajout dans un panier ou création d'un panier
|
|
$('.campagne').on('click', '.update-basket', function(event){
|
|
let panierId = $(this).attr('data-panier');
|
|
let campagne = $(this).parent().parent().parent('.campagne');
|
|
let campid = campagne.attr('data-campid');
|
|
let campsiteid = campagne.attr('data-campsite');
|
|
let couponsList = $(this).parent('.widgetContent').find('.coupon');
|
|
let couponsTotal = couponsList.length;
|
|
let couponsAdded = 0;
|
|
let coupons = "";
|
|
|
|
|
|
couponsList.each(function(index){
|
|
let couponCode = $(this).find('input').attr('data-couponcode');
|
|
let couponQty = $(this).find('input').val();
|
|
coupons += "("+couponQty+")"+couponCode;
|
|
couponsAdded++;
|
|
if(couponsAdded < couponsTotal){
|
|
coupons += ",";
|
|
}
|
|
})
|
|
|
|
$.ajaxSetup({
|
|
headers: {
|
|
'X-CSRF-TOKEN': $('#csrf').val()
|
|
}
|
|
});
|
|
|
|
if(panierId != ""){
|
|
// ---- BasketId existant - Update du panier
|
|
$.ajax({
|
|
url: '/updatebasket',
|
|
type: 'POST',
|
|
data: {
|
|
basketid: panierId,
|
|
panier : coupons,
|
|
admin:1
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
if(reponse.Statut == "OK"){
|
|
campagne.find('.widget').remove();
|
|
campagne.find('.loader').show();
|
|
loadWidget(campagne);
|
|
$.fancyInfo({
|
|
title : "<i class='fas fa-info-circle'></i> {{ __('Succès') }}",
|
|
message : "{{ __('Le panier a bien été mis à jour.') }}",
|
|
okButton : "{{ __('Valider') }}",
|
|
noButton : "",
|
|
callback : function (value) {
|
|
}
|
|
});
|
|
} else {
|
|
console.log("Erreur : "+reponse.Code+" - "+reponse.Message)
|
|
}
|
|
},
|
|
error: function (e) {
|
|
console.log(e.responseText);
|
|
}
|
|
});
|
|
} else {
|
|
// ---- BasketId non existant - Création du panier
|
|
$.ajax({
|
|
url: '/updatebasket',
|
|
type: 'POST',
|
|
data: {
|
|
refsite: campsiteid,
|
|
refcamp: campid,
|
|
refadherent: $('#contact_ref').val(),
|
|
nom: $('#contact_nom').val(),
|
|
prenom: $('#contact_prenom').val(),
|
|
email: $('#contact_email').val(),
|
|
code_postal: $('#contact_cp').val(),
|
|
commune: $('#contact_ville').val(),
|
|
pays: $('#contact_country').val(),
|
|
panier : coupons,
|
|
admin:1
|
|
},
|
|
dataType: 'JSON',
|
|
success: function (reponse) {
|
|
if(reponse.Statut == "OK"){
|
|
campagne.find('.widget').remove();
|
|
campagne.find('.loader').show();
|
|
loadWidget(campagne);
|
|
$.fancyInfo({
|
|
title : "<i class='fas fa-info-circle'></i> {{ __('Succès') }}",
|
|
message : "{{ __('Le panier a bien été créé.') }}",
|
|
okButton : "{{ __('Valider') }}",
|
|
noButton : "",
|
|
callback : function (value) {
|
|
}
|
|
});
|
|
} else {
|
|
console.log("Erreur : "+reponse.Code+" - "+reponse.Message)
|
|
}
|
|
},
|
|
error: function (e) {
|
|
console.log(e.responseText);
|
|
}
|
|
});
|
|
}
|
|
})
|
|
|
|
|
|
</script>
|
|
@endsection
|