{% extends 'base.html.twig' %}
{% block title %}Nouveau Client{% endblock %}
{% block body %}
<ol class="breadcrumb">
<li>
<i class="clip-grid-6"></i>
<a href="#">
Client
</a>
</li>
<li class="active">
Liste
</li>
<li class="search-box">
<form class="sidebar-search">
<div class="form-group">
<input type="text" placeholder="Start Searching..." data-default="130">
<button class="submit">
<i class="clip-search-3"></i>
</button>
</div>
</form>
</li>
</ol>
<div class="page-header">
<h1>Ajout d'un client</h1>
</div>
<div class="row">
<div class="col-md-12">
{{ include('client/_form.html.twig') }}
</div>
</div>
<a href="{{ path('client_index') }}" class="btn btn-outline-info back-button">Revenir à la liste</a>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="application/javascript">
$('#filter_status').select2( {width: '250px' });
function addTagForm($collectionHolder) {
// Get the data-prototype explained earlier
var prototype = $collectionHolder.data('prototype');
// get the new index
var index = $collectionHolder.data('index');
var newForm = prototype;
// You need this only if you didn't set 'label' => false in your tags field in TaskType
// Replace '__name__label__' in the prototype's HTML to
// instead be a number based on how many items we have
// newForm = newForm.replace(/__name__label__/g, index);
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
newForm = newForm.replace(/__name__/g, index);
// increase the index with one for the next item
$collectionHolder.data('index', index + 1);
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLi = $('<div></div>').append(newForm);
//$newLinkLi.before($newFormLi);
$collectionHolder.after($newFormLi);
$newFormLi.find(".flatpicker").flatpickr({
'dateFormat' : 'd-m-Y',
"locale": "fr"
});
$('.hourPicker:not(.flatpickr-input):not(.input)').flatpickr({
enableTime: true,
noCalendar: true,
dateFormat: "H:i",
time_24hr: true,
locale: "fr"
});
}
jQuery(document).ready(function() {
$('#client_site').select2({ width: '100%' });
var $collectionHolder;
const $addTagButton = jQuery('.btnAddContrat');
const $addFamilyButton = jQuery('.btnAddFamily');
const $familyList = jQuery('.familyList');
// Get the ul that holds the collection of tags
$collectionHolder = jQuery('ul.contratList');
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.find(':input').length);
$familyList.data('index', $collectionHolder.find(':input').length);
$addTagButton.on('click', function(e) {
// add a new tag form (see next code block)
addTagForm($collectionHolder);
$('.select-product').select2({ width: '100%' });
});
$addFamilyButton.on('click', function(e) {
// add a new tag form (see next code block)
addTagForm($familyList);
});
// DELETE CONTRACT
$(document).on('click','.btnDeleteContract', function(e) {
// add a new tag form (see next code block)
$(e.target).parents('.contract-item').remove();
var index = $collectionHolder.data('index');
$collectionHolder.data('index', index - 1);
});
// DELETE FAMILY
$(document).on('click','.btnDeleteFamily', function(e) {
// add a new tag form (see next code block)
console.log($(e.target).parents('.family-item'));
$(e.target).parents('.family-item').remove();
var index = $familyList.data('index');
$familyList.data('index', index - 1);
});
// filter products
$(document).on('change', '.tag', function (e) {
console.log('tag changed');
const val = $(e.target).val();
var url = '{{ path("app_client_ajaxgetproducts", {'id': 'salon_id'}) }}';
url = url.replace("salon_id", val);
$.ajax({
url: url,
type: 'get',
success: function(data) {
$(e.target).parents('.contract-item').find('.select-product').empty();
console.log(data);
for(var i = 0; i < data.length; i++) {
var item = data[i];
$(e.target).parents('.contract-item').find('.select-product').append('<option value="' + item.id + '">'+ item.name + '</option>');
}
}
});
});
// Change payMonde
$('#client_billingInfos_payMode').on('change', function () {
const val = $('#client_billingInfos_payMode').val();
if(val === 'sepa') {
$('.hide').each(function (e) {
$( this ).removeClass('hide');
})
}
else {
$('.hiddenFields').each(function (e) {
$( this ).addClass('hide');
});
}
});
$('#form_client').submit( function(e) {
e.preventDefault();
// if(($('#client_billingInfos_sendMode').val() === '' || $('#client_billingInfos_sendMode').val() === 'email') && $('#client_billingInfos_email').val() === ''){
// notie.alert({
// text: 'Veuillez entrer un email de facturation',
//
// });
// return false;
// }
if($('#client_deathday').val()) {
notie.confirm({
text: 'Vous avez entré une date de décès êtes vous sur de continuer ?',
submitText: 'Confirmer', // optional, default = 'Yes'
cancelText: 'Annuler', // optional, default = 'Cancel'
submitCallback: function () {
$(this).unbind();
$(this).submit();
}, // optional
cancelCallback: function () {
return false;
} // optional
});
}
$(this).unbind();
$(this).submit();
});
});
$('#dateDebut').flatpickr({
'dateFormat': 'Y-m-d',
"locale": "fr"
});
</script>
{% endblock %}