/** Copyright La boîte à pain (2018) contact@laboiteapain.net Ce logiciel est un programme informatique servant à aider les producteurs à distribuer leur production en circuits courts. Ce logiciel est régi par la licence CeCILL soumise au droit français et respectant les principes de diffusion des logiciels libres. Vous pouvez utiliser, modifier et/ou redistribuer ce programme sous les conditions de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA sur le site "http://www.cecill.info". En contrepartie de l'accessibilité au code source et des droits de copie, de modification et de redistribution accordés par cette licence, il n'est offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, seule une responsabilité restreinte pèse sur l'auteur du programme, le titulaire des droits patrimoniaux et les concédants successifs. A cet égard l'attention de l'utilisateur est attirée sur les risques associés au chargement, à l'utilisation, à la modification et/ou au développement et à la reproduction du logiciel par l'utilisateur étant donné sa spécificité de logiciel libre, qui peut le rendre complexe à manipuler et qui le réserve donc à des développeurs et des professionnels avertis possédant des connaissances informatiques approfondies. Les utilisateurs sont donc invités à charger et tester l'adéquation du logiciel à leurs besoins dans des conditions permettant d'assurer la sécurité de leurs systèmes et ou de leurs données et, plus généralement, à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la licence CeCILL, et que vous en avez accepté les termes. */ /* French initialisation for the jQuery UI date picker plugin. */ /* Written by Keith Wood (kbwood{at}iinet.com.au), Stéphane Nahmani (sholby@sholby.net), Stéphane Raimbault */ (function( factory ) { if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. define([ "../jquery.ui.datepicker" ], factory ); } else { // Browser globals factory( jQuery.datepicker ); } }(function( datepicker ) { datepicker.regional['fr'] = { closeText: 'Fermer', prevText: 'Précédent', nextText: 'Suivant', currentText: 'Aujourd\'hui', monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'], monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'], dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'], dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'], dayNamesMin: ['D','L','M','M','J','V','S'], weekHeader: 'Sem.', dateFormat: 'dd/mm/yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; datepicker.setDefaults(datepicker.regional['fr']); return datepicker.regional['fr']; })); $(document).ready(function() { //chat_scroll() ; chat_tabs_gamme_saison() ; //chat_slideshow() ; $('[data-toggle="tooltip"]').tooltip() ; chat_systeme_commande() ; chat_profil_user() ; $('.dropdown-toggle').dropdown() ; }) ; function chat_profil_user() { if($('#profil-user').size()) { if($('#user-no_mail').is(':checked')) { $('#mails-jours-prod').hide() ; } $('#user-no_mail').change(function() { if($('#user-no_mail').is(':checked')) { $('#mails-jours-prod').hide() ; } else { $('#mails-jours-prod').fadeIn() ; } }) ; } } function chat_event_click_point_vente(id, force) { if($('.point-vente-'+id).data('code') == 1) { $('#modal-code #id-point-vente').val(id) ; $('#modal-code').modal('show') ; } else { $('#commande-id_point_vente').val(id) ; $('#points-vente .point-vente').removeClass('selected') ; $('.point-vente-'+id).addClass('selected') ; $('.point-vente-'+id).hide().fadeIn('fast') ; var pain = parseInt($('.point-vente-'+id).data('pain')) ; var vrac = parseInt($('.point-vente-'+id).data('vrac')) ; if(pain) { $('#pain .table').show() ; $('#pain .indisponible').hide() ; } else { $('#pain .table').hide() ; $('#pain .indisponible').show() ; } if(vrac) { $('#vrac .table').show() ; $('#vrac .indisponible').hide() ; } else { $('#vrac .table').hide() ; $('#vrac .indisponible').show() ; } $('#produits, .valider-commande, .btn-commentaire, #bar-fixed').fadeIn() ; // credit pain chat_systeme_commande_credit_pain_event(chat_systeme_commande_maj_table_prix()) ; // scroll if(!force) { boulange_scroll('step-infos-pv') ; } // infos point de vente $('.infos-pv').hide() ; $('.infos-pv-'+id).fadeIn() ; } } function chat_init_horaire_point_vente(date) { $('.infos-pv .jour').hide() ; var selector_jour = '.infos-pv .jour-'+date.getDay() ; $(selector_jour).show() ; $('.select-previous-day').unbind('click').click(function() { $('.ui-datepicker-current-day').prev().find('a').click() ; }) ; } function chat_base_url(with_slug) { var base_url = $('meta[name=base-url]').attr('content')+'/' ; if(with_slug) { base_url += $('meta[name=slug-producer]').attr('content')+'/' ; } return base_url ; } function chat_systeme_commande() { if($('.commande-form').size()) { // scroll initial if($('.boulangerie.selected').size()) { boulange_scroll('step-choix-date') ; } // affichage des différentes parties du formulaire if(!$('#commande-id_production').val()) { $('#depots, #points-vente, #produits, .valider-commande, #info-horaire-retrait-commande, .btn-commentaire, #bar-fixed').hide() ; } else if(!$('#commande-id_point_vente').val()) { $('#produits, .valider-commande, .btn-commentaire, #bar-fixed').hide() ; } // points de vente if($('#commande-id_point_vente').val()) chat_event_click_point_vente($('#commande-id_point_vente').val(), true) ; $('#modal-code form').submit(function() { var id_pv = $('#modal-code #id-point-vente').val() ; var code = $('#modal-code #code').val() ; $.get(chat_base_url(true)+'commande/verif-code-point-vente',{ id_point_vente: id_pv, code: code }, function(ok) { if(ok) { $('.point-vente-'+id_pv).data('code',0) ; $('.point-vente-'+id_pv+' .glyphicon').remove() ; $('input[name="code_point_vente_'+id_pv+'"]').val(code) ; $('#modal-code').modal('hide') ; chat_event_click_point_vente($('#modal-code #id-point-vente').val()) ; } else { $('#modal-code .field-code').addClass('has-error') ; $('#modal-code .help-block-error').hide().fadeIn() ; } }) ; return false ; }) ; $('#points-vente .point-vente').click(function() { var id = parseInt($(this).find('.id').html()) ; chat_event_click_point_vente(id) ; }) ; // datepicker var dates_production = [] ; $('#dates div').each(function() { dates_production.push($(this).find('.date').html()) ; }) ; //var var_datepicker = $.datepicker ; $('#datepicker-production').datepicker({ beforeShowDay: function(date){ var string = $.datepicker.formatDate('dd/mm/yy', date); for(var i=0; i 0 || no_limit) { quantite ++ ; quantite_restante -- ; } } $(this).parent().parent().parent().find('.quantite-restante .nb').html(quantite_restante) ; if(quantite_restante <= 5 && quantite_restante > 0) { $(this).parent().parent().parent().find('.quantite-restante').fadeIn() ; } else { $(this).parent().parent().parent().find('.quantite-restante').hide() ; } if(quantite_restante == 0 && !no_limit) { $(this).parent().parent().parent().find('.epuise').fadeIn() ; } else { $(this).parent().parent().parent().find('.epuise').hide() ; } $(this).parent().parent().find('input.quantity').val(quantite) ; chat_systeme_commande_maj_table_prix(); } }) ; chat_systeme_commande_maj_table_prix() ; chat_systeme_commande_credit_pain(); } // commentaire commande $('.commande-form .btn-commentaire').click(function() { if($('.field-commande-commentaire').css('display') == 'none') { $('.field-commande-commentaire').slideDown() ; } else { $('.field-commande-commentaire').slideUp() ; } return false ; }) ; // bar fixed if($('#bar-fixed').size()) { $(window).scroll(function (event) { var scroll = $(window).scrollTop() + $(window).height(); var pos_bottom_produits = $('#table-produits').offset().top + $('#table-produits').height() + 100 ; if($(window).height() < 1000) { if(!$('#bar-fixed').hasClass('not-fixed')) { $('#bar-fixed').addClass('not-fixed') ; } } else { if(scroll > pos_bottom_produits) { if(!$('#bar-fixed').hasClass('not-fixed')) { $('#bar-fixed').addClass('not-fixed') ; } } else { $('#bar-fixed').removeClass('not-fixed') ; } } }); } } function chat_systeme_commande_produits_dispos(str_date, date) { // produits dispos à la vente à cette date $.get(chat_base_url(true)+'commande/infos-production',{ id_production: $('#commande-id_production').val() }, function(data) { if(data.produits_dispos) { $.each(data.produits_dispos, function( id_produit, produit ) { if(produit.actif) $('.produit-'+id_produit).show() ; else $('.produit-'+id_produit).hide() ; var quantite_restante = produit.quantite_max - produit.quantite_commandee ; var no_limit = 0 ; if(!produit.quantite_max) no_limit = 1 ; $('.produit-'+id_produit).attr('data-no-limit',no_limit) ; $('.produit-'+id_produit).attr('data-quantite-max',produit.quantite_max) ; $('.produit-'+id_produit+' .quantite-restante .nb').html(quantite_restante) ; if(produit.quantite_max && (!quantite_restante || quantite_restante < 0 || produit.epuise)) { $('.produit-'+id_produit+' .epuise').show() ; if(!$('#id-commande').val() && $('.produit-'+id_produit+' .quantity').val() == 0) { $('.produit-'+id_produit+' .quantite-restante').hide() ; $('.produit-'+id_produit+' .input-group').hide() ; } } else { $('.produit-'+id_produit+' .epuise').hide() ; $('.produit-'+id_produit+' .input-group').show() ; $('.produit-'+id_produit+' .quantite-restante .nb').html(quantite_restante) ; } if($('.produit-'+id_produit+' .quantite-restante').size()) { if(parseInt($('.produit-'+id_produit+' .quantite-restante .nb').html()) > 5 || parseInt($('.produit-'+id_produit+' .quantite-restante .nb').html()) <= 0) { $('.produit-'+id_produit+' .quantite-restante').hide() ; } else { $('.produit-'+id_produit+' .quantite-restante').show() ; } } }); } $('#points-vente .point-vente').hide() ; // init affichage points de vente $.each(data.points_vente, function(key, livraison) { console.log(key+' | '+livraison) ; if(livraison) { $('.point-vente-'+key).fadeIn() ; } else { $('.point-vente-'+key).hide() ; } }) ; chat_init_horaire_point_vente(date) ; }, 'json') ; } function chat_systeme_commande_reset_table_prix() { $('#table-produits tr .colonne-quantite .quantity').each(function() { $(this).val(0) ; }) ; chat_systeme_commande_maj_table_prix() ; } function chat_systeme_commande_maj_table_prix() { // produits pain var prix = 0 ; $('.commande-form #table-produits tbody tr').each(function() { var quantite = parseInt($(this).find('.quantity').val()) ; var prix_produit = parseFloat($(this).find('.prix').html()) ; var prix_total_produit = quantite * prix_produit ; if(prix_total_produit) $(this).find('.total').html(formate_prix(prix_total_produit)+' €') ; else $(this).find('.total').html('--') ; if(quantite > 0) prix += prix_total_produit ; }) ; $('#total-commande strong').html(formate_prix(prix)+' €') ; var prix_global = prix ; // produits vrac var prix = 0 ; $('.commande-form #table-produits-vrac tbody tr').each(function() { var quantite = parseInt($(this).find('.quantity').val()) ; var prix_produit = parseFloat($(this).find('.prix').html()) ; var prix_total_produit = quantite/1000 * prix_produit ; if(prix_total_produit) $(this).find('.total').html(formate_prix(prix_total_produit)+' €') ; else $(this).find('.total').html('--') ; if(quantite > 0) prix += prix_total_produit ; }) ; $('#total-commande-vrac strong').html(formate_prix(prix)+' €') ; prix_global += prix ; $('#total-commande-bottom span').html(formate_prix(prix_global)) ; if(prix_global) $('#total-commande-bottom').fadeIn() ; else $('#total-commande-bottom').hide() ; // maj credit pain chat_systeme_commande_credit_pain_event(prix_global) ; return prix_global ; } function chat_systeme_commande_credit_pain() { $('input[name=credit_pain]').change(function() { var prix_global = chat_systeme_commande_maj_table_prix() ; chat_systeme_commande_credit_pain_event(prix_global) ; }) ; } function chat_systeme_commande_credit_pain_event(prix_global) { var html = '' ; var use_credit_pain = $('input[name=credit_pain]').prop('checked') ; var credit_pain = parseFloat($('#montant-credit-pain').val()) ; var credit_pain_dispo = credit_pain ; var montant_paye = 0 if($('#montant-paye').size() && $('#montant-paye').val()) montant_paye = parseFloat($('#montant-paye').val()) ; if($('#id-commande').size() && $('#id-commande').val()) { credit_pain_dispo = credit_pain + montant_paye ; } var credit_pain_active = $('.point-vente.selected').data('credit-pain') ; if(credit_pain_active || montant_paye) { $('#checkbox-credit-pain #info-credit-vide').show() ; $('#checkbox-credit-pain label').show() ; $('#checkbox-credit-pain #credit-pain-disabled').hide() ; if(prix_global > credit_pain_dispo) { var reste_payer = prix_global - credit_pain_dispo ; if(use_credit_pain) { if(montant_paye) { html += ''+montant_paye+' € déjà payé
' ; } html += ''+credit_pain+' € seront débités
' ; html += 'Restera '+reste_payer+' € à payer à la boulangerie' ; $('#checkbox-credit-pain .info').html(html) ; } else { $('#checkbox-credit-pain .info').html('') ; } } else { $('#checkbox-credit-pain').removeClass('paiement-impossible') ; $('input[name=credit_pain]').removeAttr('disabled') ; if(use_credit_pain) { var html = '' ; // à payer if(prix_global > montant_paye) { montant = prix_global - montant_paye ; if(montant_paye) { html += ''+montant_paye+' € déjà payé
' ; } html += ''+montant+' € seront débités' ; $('#checkbox-credit-pain .info').html(html) ; } // remboursé else if(prix_global < montant_paye) { montant = montant_paye - prix_global ; if(montant_paye) { html += ''+montant_paye+' € déjà payé
' ; } html += ''+montant+' € seront remboursés' ; $('#checkbox-credit-pain .info').html(html) ; } else { if(montant_paye > 0) $('#checkbox-credit-pain .info').html(''+montant_paye+' € déjà payé') ; else $('#checkbox-credit-pain .info').html('') ; } } else { $('#checkbox-credit-pain .info').html('') } } } else { $('#checkbox-credit-pain #info-credit-vide').hide() ; $('#checkbox-credit-pain label').hide() ; $('#checkbox-credit-pain #credit-pain-disabled').show() ; } } function formate_prix(prix) { return prix.toFixed(2).replace( ".", "," ) ; } function chat_slideshow() { if($('body').hasClass('home')) { var base_url = $('#base_url').val() ; $.vegas('slideshow', { backgrounds:[ //{ src:'./img/background/back2.jpg' }, { src:base_url+'/img/background/four.jpg' }, { src:base_url+'/img/background/gueulard.jpg' } ], walk: function() { $('.vegas-loading').css('display','none') ; $('.vegas-background').css('position','absolute') ; } })('overlay'); } } function chat_scroll() { if($('body').hasClass('home')) { $('#header nav ul a[href^="#"]').click(function(){ var the_id = $(this).attr("href"); $('html, body').animate({ scrollTop: $(the_id).offset().top - 100 }, 'normal'); return false; }); $(window).scroll(function() { chat_event_scroll() ; }) ; chat_event_scroll() ; } } function chat_event_scroll() { var scroll_top = $(window).scrollTop() ; //console.log(scroll_top + ' '+ ($('#horaires').offset().top-100)) ; $('#header nav ul a').each(function() { var top = $($(this).attr('href')).offset().top ; var test = top + $($(this).attr('href')).height() - 150 ; //console.log($(this).attr('href')+' : '+scroll_top+ ' | '+ test) ; if(scroll_top <= top + $($(this).attr('href')).height() - 150) { $('#header a').removeClass('selec') ; $(this).addClass('selec') ; } }) ; } function chat_tabs_gamme_saison() { $('#tab-gamme-saison a').click(function (e) { e.preventDefault(); $(this).tab('show'); }); }