297 lines
11 KiB
PHP
297 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::model($contact, ['route' => ['contact.update', $contact], 'enctype' => 'multipart/form-data']) !!}
|
|
@method('PUT')
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
{!! Form::label('contact_ref', 'Ref *') !!}
|
|
{!! Form::input('text', 'contact_ref', null, ['required', 'readonly']) !!}
|
|
</div>
|
|
<div class="form-field">
|
|
{!! Form::label('contact_email', 'Email *') !!}
|
|
{!! Form::email('contact_email', null, ['required']) !!}
|
|
</div>
|
|
</div>
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
{!! Form::label('contact_nom', 'Nom *') !!}
|
|
{!! Form::input('text','contact_nom', null, ['required']) !!}
|
|
</div>
|
|
<div class="form-field">
|
|
{!! Form::label('contact_prenom', 'Prénom *') !!}
|
|
{!! Form::input('text','contact_prenom', null, ['required']) !!}
|
|
</div>
|
|
</div>
|
|
<div class="form-split">
|
|
<div class="form-field">
|
|
{!! Form::label('contact_cp', 'Code Postal *') !!}
|
|
{!! Form::input('text','contact_cp', null, ['required']) !!}
|
|
</div>
|
|
<div class="form-field">
|
|
{!! Form::label('contact_ville', 'Ville *') !!}
|
|
{!! Form::input('text','contact_ville', null, ['required']) !!}
|
|
</div>
|
|
</div>
|
|
<div class="form-split">
|
|
|
|
<div class="form-field">
|
|
<label for="contact_country">Pays *</label>
|
|
<select name="contact_country" id="contact_country">
|
|
<option value="" >Tous</option>
|
|
<option value="250" @if ($contact->contact_country == 250) selected="selected" @endif>France</option>
|
|
<option value="56" @if ($contact->contact_country == 56) selected="selected" @endif>Belgique</option>
|
|
<option value="442" @if ($contact->contact_country == 442) selected="selected" @endif>Luxembourg</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-field submit">
|
|
<span>Les champs avec un * sont obligatoires</span>
|
|
{!! Form::submit('Mettre à jour') !!}
|
|
</div>
|
|
{!! Form::close() !!}
|
|
</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="hash" id="hash" value="{{ $contact->contact_hash }}">
|
|
<input type="hidden" name="csrf" id="csrf" value="<?php echo csrf_token(); ?>">
|
|
@foreach ($campagnes as $campagne)
|
|
<div class="campagne" data-campid="{{ $campagne->camp_id }}" data-campsite = "{{ $campagne->camp_siteId }}">
|
|
<h4>{{$campagne->camp_name}}</h4>
|
|
@switch($campagne->camp_type)
|
|
@case(0)
|
|
<p>Type : Mur</p>
|
|
@break
|
|
@case(1)
|
|
<p>Type : Panier</p>
|
|
@break
|
|
@case(2)
|
|
<p>Type : Mur non sélectionnable</p>
|
|
@break
|
|
@case(3)
|
|
<p>Type : Panier sélectionnable</p>
|
|
@break
|
|
@endswitch
|
|
<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: '/loadWidget',
|
|
type: 'POST',
|
|
data: {
|
|
contact_hash: $('#hash').val(),
|
|
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
|
|
@if(isset($created) && $created)
|
|
@section('scripts')
|
|
<script defer>
|
|
$.fancyInfo({
|
|
title : "<i class='fas fa-info-circle'></i> Parfait",
|
|
message : "Le contact a bien été créé.",
|
|
okButton : 'Valider',
|
|
callback : function (value) {
|
|
}
|
|
});
|
|
</script>
|
|
@endsection
|
|
@endif
|