symfony2 popup avec iframe fonctionne selon le contexte

Petit nouveau ! | 5 Messages

30 mars 2016, 11:31

Bonjour, j'essaie d'ouvrir une popup dans un projet symfony2
j'y arrive en ajoutant ce code

Code : Tout sélectionner

<a href="javascript:void(0);" class="po-invoice" data-original-title="Facture" data-content=' <iframe src="{{ path('admin_stock_article_list') }}" width="700" height="500"></iframe> '><i class="icon-search"></i></a>
dans cette page

Code : Tout sélectionner

{% extends 'SonataAdminBundle:CRUD:list.html.twig' %} {% set DISPLAY_NONE = constant('tahiti\\BillingBundle\\Entity\\Invoice::DISPLAY_NONE') %} {% set DISPLAY_CHAPTER = constant('tahiti\\BillingBundle\\Entity\\Invoice::DISPLAY_CHAPTER') %} {% set DISPLAY_DETAIL = constant('tahiti\\BillingBundle\\Entity\\Invoice::DISPLAY_DETAIL') %} {% block javascripts %} {{ parent() }} <script> $(function(){ $('.po').popover({ html: true, placement: 'right' }); $('.tt').tooltip({ html: true, placement: 'top' }); $('.po-invoice').popover({ html: true, placement: 'bottom' }).on("click", function(){ $('.popover').addClass('po-invoice-custom'); //Add class .dynamic-class to <div> }); $('.paymentModeBtn').on('click', function(event) { event.preventDefault(); elt = $(this); $.post(elt.attr('href'), function(data) { elt.closest('.btn-group').find('.label-update').html(data); }); }); $('.displayBtn').on('click', function(event) { event.preventDefault(); elt = $(this); $.post(elt.attr('href'), function(data) { elt.closest('.btn-group').find('.label-update').html(data); }); }); $('.validateBtn').on('click', function(event) { event.preventDefault(); elt = $(this); var td = elt.parent(); var tr = elt.closest('tr'); var creationDate = td.find('.date').val(); if (window.confirm(this.title || 'Etes vous sûr de vouloir valider la facture ?\n'+ 'Le numéro de facture va être généré et la facture sera validée à la date saisie' )) { $.post(elt.attr('href'), {creationDate: creationDate}, function(data) { tr.find('.badge').attr('style', 'background: #0086cc;'); tr.find('.badge').html(data.status); tr.find('.ref').html(data.ref); td.html('<a href="'+elt.attr('rel')+'" class="btn btn-info">Modifier</a>'); }, 'json'); } }); $('.chargedBtn').on('click', function(event) { event.preventDefault(); elt = $(this); var td = elt.parent(); var tr = elt.closest('tr'); if (window.confirm(this.title || 'Etes vous sûr de vouloir passer la facture en état PAYÉ ?\n'+ 'Si oui, merci de confirmer' )) { $.post(elt.attr('href'), function(data) { tr.find('.badge').attr('style', 'background: #a800cc;'); tr.find('.badge').html(data.status); td.html('<i class="icon-ok"></i>'); }, 'json'); } }); }); </script> {% endblock %} {% block table_header %} <thead> <tr> <th></th> <th class="txtC">Créé le</th> {% if status.code != 'INVOICE_INPROCESS' %} <th class="txtC">Références</th> {% endif %} <th class="txtC">Aperçu</th> <th class="txtC">Commande</th> <th class="txtC">Devis</th> <th>Client/Station</th> <th class="txtC">Chapitres/Lignes</th> <th class="txtR">Montant</th> {#<th>Status</th>#} <th>Action</th> </tr> </thead> {% endblock %} {% block table_body %} <tbody class="invoice-table"> {% for object in admin.datagrid.results %} <tr> <td><input type="checkbox" name="idx[]" value="{{ object.id }}"/></td> <td class="txtC"> <span>{{ object.createdAt|date('d/m/Y') }}</span><br/> {{ object.createdBy.fullname }} </td> {% if status.code != 'INVOICE_INPROCESS' %} <td class="txtC"> <span>{{ object.ref }}</span> </td> {% endif %} <td class="txtC"> <a href="javascript:void();" class="po-invoice" data-original-title="Facture" data-content=' <iframe src="{{ path('admin_billing_invoice_print', {id : object.id}) }}" width="700" height="500"></iframe> '><i class="icon-search"></i></a> <a href="javascript:void(0);" class="po-invoice" data-original-title="Facture" data-content=' <iframe src="{{ path('admin_stock_article_list') }}" width="700" height="500"></iframe> '><i class="icon-search"></i></a> </td> <td class="txtC"> {% for quotation in object.quotations if quotation.orderRef is not empty %} <span>{{ quotation.orderRef }}</span><br/> {% endfor %} </td> <td class="txtC"> <strong>{{ object.quotations|length }}</strong><br/> {% if object.quotations|length > 0 %} {% for quotation in object.quotations %} <a href="{{ path('admin_billing_quotation_show', { id: quotation.id }) }}"><small>{{ quotation.ref }}</small></a><br/> {% endfor %} <br/> {% endif %} </td> <td> <a href="javascript:void();" class="po link" data-original-title="Client et Destinataire" data-content=' <strong>Client : {{ object.client }}</strong><br/> <i class="icon-home"></i> {{ object.client.address }} - {{ object.client.postcode }} {{ object.client.city }}<br/> <i class="icon-phone"></i>{{ object.client.tel }}<br/> <i class="icon-print"></i>{{ object.client.fax }}<br/> <i class="icon-envelope"></i>{{ object.client.email }}<br/> <br/> <strong>Destinataire : {{ object.contact }}</strong><br/> <i class="icon-home"></i> {{ object.contact.address }} - {{ object.contact.postcode }} {{ object.contact.city }}<br/> <i class="icon-phone"></i>{{ object.contact.tel }}<br/> <i class="icon-print"></i>{{ object.contact.fax }}<br/> <i class="icon-envelope"></i>{{ object.contact.email }}<br/> '>{{ object.client }} <i class="icon-info-sign soft"></i></a><br/> <em class="med">{{ object.station }}</em> </td> <td class="txtC"> <strong>{{ object.chapterCount }}</strong> <span class="med">{{ object.lineCount }}</span> </td> <td class="txtR"><strong>{{ object.totalExcVat|number_format(2,',', ' ') }} €</strong></td> {#<td><span class="badge" style="background: #{{ object.status.color }};">{{ object.status }}</span></td> <td> <div class="btn-group"> <button class="btn btn-mini btn-info label-update">{{ object.paymentMode }}</button> <button class="btn btn-mini btn-info dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> {% for p in paymentModes %} <li><a href="{{ path('admin_billing_invoice_paymentMode', { id: object.id, mode: p.id, ajax: true }) }}" class="paymentModeBtn">{{ p }}</a></li> {% endfor %} </ul> </div> <div class="btn-group" style="margin-left: 0; margin-top: 3px;"> <button class="btn btn-mini btn-info label-update"> {{ (object.display == DISPLAY_NONE) ? 'Aucun détail' }} {{ (object.display == DISPLAY_CHAPTER) ? 'Chapitres' }} {{ (object.display == DISPLAY_DETAIL) ? 'Détaillé' }} </button> <button class="btn btn-mini btn-info dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="{{ path('admin_billing_invoice_displayMode', { id: object.id, mode: DISPLAY_NONE , ajax: true }) }}" class="displayBtn">Aucun détail</a></li> {% if object.hasChapter %} <li><a href="{{ path('admin_billing_invoice_displayMode', { id: object.id, mode: DISPLAY_CHAPTER, ajax: true }) }}" class="displayBtn">Chapitre</a></li> {% endif %} <li><a href="{{ path('admin_billing_invoice_displayMode', { id: object.id, mode: DISPLAY_DETAIL, ajax: true }) }}" class="displayBtn">Détaillé</a></li> </ul> </div> </td> #} <td> {# if object.creationDate is empty %} <input name="date" type="text" class="tt date" style="width: 80px;" title="<strong>Date souhaitée :</strong><br/>{{ object.preferedDate|date('d/m/Y') }}<br/><strong>Commentaire :</strong><br/> {{ object.info }}" value="{{ object.preferedDate|date('d/m/Y') }}" /> <a href="{{ path('admin_billing_invoice_validate', { id: object.id }) }}" class="btn btn-success validateBtn" rel="{{ path('admin_billing_invoice_show', { id: object.id }) }}">Valider</a> {% else %} <a href="{{ path('admin_billing_invoice_show', { id: object.id }) }}" class="btn btn-info">Modifier</a> {% endif #} {% if object.status.code == 'INVOICE_INPROCESS' %} <a href="{{ path('admin_billing_invoice_show', { id: object.id }) }}" class="btn btn-success">Voir</a> {% else %} <a href="{{ path('admin_billing_invoice_show', { id: object.id }) }}" class="btn btn-info">Modifier</a> {% endif %} </td> </tr> {% endfor %} </tbody> {% endblock %} {% block list_filters %} {% if admin.datagrid.filters %} <form class="sonata-filter-form form-stacked {{ admin.isChild and 1 == admin.datagrid.filters|length ? 'hide' : '' }}" action="{{ admin.generateUrl('list') }}" method="GET"> <fieldset class="filter_legend"> <legend class="filter_legend {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">{% trans from 'SonataAdminBundle' %}label_filters{% endtrans %}</legend> <div class="filter_container inactive" style="display: none;"> <table class="table table-bordered"> {% for filter in admin.datagrid.filters %} <tr id="filter_{{ filter.name }}_row" class="filter {{ filter.isActive ? 'active' : 'inactive' }}"> <td class="filter-title">{{ admin.trans(filter.label) }}</td> <td class="filter-type">{{ form_widget(form.getChild(filter.formName).getChild('type')) }}</td> <td class="filter-value">{{ form_widget(form.getChild(filter.formName).getChild('value')) }}</td> </tr> {% endfor %} </table> <input type="hidden" name="filter[_page]" id="filter__page" value="1" /> {% set foo = form.getChild('_page').setRendered() %} {{ form_rest(form) }} <input type="submit" class="btn primary" value="{% trans from 'SonataAdminBundle' %}btn_filter{% endtrans %}" /> <a class="btn" href="{{ admin.generateUrl('list') }}">{% trans from 'SonataAdminBundle' %}link_reset_filter{% endtrans %}</a> </div> </fieldset> </form> {% endif %} <ul class="nav nav-pills"> <li class="{{ (status.code == 'INVOICE_INPROCESS') ? 'active' }}"><a href="{{ path('admin_billing_invoice_filter') }}?status=INVOICE_INPROCESS">Devis à traiter</a></li> <li class="{{ (status.code == 'INVOICED') ? 'active' }}"><a href="{{ path('admin_billing_invoice_filter') }}?status=INVOICED">Factures à comptabiliser</a></li> <li class="{{ (status.code == 'INVOICE_ACCOUNTED') ? 'active' }}"><a href="{{ path('admin_billing_invoice_filter') }}?status=INVOICE_ACCOUNTED">Factures comptabilisées</a></li> <li class="{{ (status.code == 'INVOICE_PAYED') ? 'active' }}"><a href="{{ path('admin_billing_invoice_filter') }}?status=INVOICE_PAYED">Factures payées</a></li> </ul> {% endblock %}
par contre cela ne fonctionne pas en mettant le même code dans cette autre page
je ne comprend pas d'autant plus que je n'ai pas d'erreur JS sur la console ni d'erreurs PHP coté serveur

Code : Tout sélectionner

{% extends 'SonataAdminBundle:CRUD:edit.html.twig' %} {% block form %} {% if action == 'create' %} {% set url = path('admin_billing_order_create') %} {% else %} {% set url = path('admin_billing_order_edit', { 'id': object.id }) %} {% endif %} <form class="order-form" action="{{ url }}" method="post"> {{ form_widget(form._token) }} <fieldset> <legend>Affectation {{ form_errors(form) }}</legend> <div class="row-fluid" style="padding-top: 10px"> <div class="span3"> <div class="control-group"> <label class="control-label">Stock</label> <div class="controls"> {{ form_widget(form.stock) }} </div> </div> </div> <div class="span1"> <span style="font-size: 30px; display: block; padding-top: 20px; text-align: center;">Ou</span> </div> <div class="span3"> <div class="control-group"> <label class="control-label">Intervention</label> <div class="controls"> {{ form_widget(form.interventionSearch) }} </div> </div> </div> </fieldset> <div class="row-fluid"> <div class="span4"> <fieldset> <legend>General</legend> <div class="control-group"> <label class="control-label">Ref devis fournisseur</label> <div class="controls"> {{ form_widget(form.supplierRef) }} </div> </div> <div class="control-group"> <label class="control-label">Nature *</label> <div class="controls"> {{ form_widget(form.nature) }} <div class="errors"> {{ form_errors(form.nature) }} </div> </div> </div> <div class="control-group"> <label class="control-label">Corps d'état *</label> <div class="controls"> {{ form_widget(form.job) }} <div class="errors"> {{ form_errors(form.job) }} </div> </div> </div> </fieldset> </div> <div class="span4"> <fieldset> <legend>Fournisseur</legend> <div class="control-group"> <label class="control-label">Fournisseur *</label> <div class="controls"> {{ form_widget(form.companySearch) }} </div> </div> <div class="control-group"> <label class="control-label">Magasin *</label> <div class="controls"> {{ form_widget(form.supplierSearch) }} <a href="#modal" role="button" class="btn addSupplier" data-toggle="modal" style="{{ (object.supplier is empty) ? "display: none;" }}"><i class="icon-plus-sign"></i></a> </div> </div> </fieldset> </div> <div class="span4"> <fieldset> <legend>Livraison</legend> <div class="control-group delivery-container"> <label class="control-label">Livraison *</label> <div class="controls"> {{ form_errors(form.deliveryType) }} {{ form_widget(form.deliveryType) }} </div> </div> <div class="control-group retreivedBy" {% if object.retrievedBy is empty %}style="display:none;"{% endif %}> <label class="control-label">Enlevé par *</label> <div class="controls"> {{ form_widget(form.userSearch) }} </div> </div> <div class="control-group"> <label class="control-label">Souhaitée le *</label> <div class="controls"> {{ form_widget(form.deliveryDesiredDate) }} <div class="errors"> {{ form_errors(form.deliveryDesiredDate) }} </div> </div> </div> <div class="control-group"> <label class="control-label">Adresse *</label> <div class="controls"> {{ form_widget(form.address) }} </div> </div> <div class="control-group"> <label class="control-label">Code postal *</label> <div class="controls"> {{ form_widget(form.postcode) }} </div> </div> <div class="control-group"> <label class="control-label">Ville *</label> <div class="controls"> {{ form_widget(form.city) }} </div> </div> </fieldset> </div> </div> {% if action == 'edit' %} <fieldset> <legend>Commentaire</legend> <div class="control-group"> <div class="controls"> {{ form_widget(form.comment) }} </div> </div> </fieldset> <fieldset style="margin: 30px 0"> <table class="lines table table-striped"> <thead> <tr> <th>Article</th> <th>Unité</th> <th>Prix Unitaire</th> <th>Eco-contrib.</th> <th>Quantité</th> <th>Réduction</th> <th>Montant</th> <th>&nbsp;</th> <th>Commentaire</th> <th>&nbsp;</th> </tr> </thead> <tbody> {% for key,line in object.lines %} <tr> <td> <input type="hidden" name="id" value="{{ line.id }}" class="line-id" /> {% if line.article is not empty %} <input id="article{{key}}" type="hidden" name="article_id" class="articleSearch" value="{{ line.article.label }}"> {% endif %} </td> <td><input type="text" name="unit" class="unit required callSave" value="{{ line.unit }}" placeholder="U"></td> <td> <div class="input-prepend"> <span class="add-on">&euro;</span> <input type="text" name="price" class="price required callSave tt number" value="{{ line.price }}" {% if line.article is not empty %} title="Prix commandé<br>moyen {{line.article.price }} &euro;<br>min {{ line.article.priceMin }} &euro;<br>max {{ line.article.priceMax }} &euro; {% endif %} "> </div> </td> <td> <div class="input-prepend"> <span class="add-on">&euro;</span> <input type="text" name="eco" class="eco required callSave tt number" value="{{ line.eco }}"> </div> </td> <td><input type="text" name="quantity" class="quantity required callSave number" value="{{ line.quantity }}"></td> <td> <div class="input-append"> <input type="text" name="discount" class="discount callSave number" value="{{ line.discount }}"> <span class="add-on">%</span> </div> </td> <td class="total"></td> <td> <select name="vat" class="callSave" style="width: 65px"> {% for vat in vats %} <option value="{{ vat.id }}" {% if line.vat is not empty and line.vat.id == vat.id %}selected="selected"{% endif %}>{{ vat }}</option> {% endfor %} </select> </td> <td> <input type="text" name="comment" class="comment callSave" value="{{ line.comment }}"> </td> <td><a href="#" class="btn btn-danger remove"><i class="icon-remove"></i></a></td> </tr> {% endfor %} <tr> <td> <input type="hidden" name="id" value="" class="line-id" /> <input type="hidden" name="article_id" class="articleSearch"> <a href="#" class="btn btn-danger out" title="Hors base article"><i class="icon-signout"></i></a> <a href="javascript:alert('1');void(0);alert('2');" class="po-invoice" data-original-title="Facture" data-content=' <iframe src="{{ path('admin_stock_article_list') }}" width="700" height="500"></iframe> '><i class="icon-search"></i></a> </td> <td><input type="text" name="unit" class="unit required callSave" placeholder="U"></td> <td> <div class="input-prepend"> <span class="add-on">&euro;</span> <input type="text" name="price" class="price required callSave tt number"> </div> </td> <td> <div class="input-prepend"> <span class="add-on">&euro;</span> <input type="text" name="eco" class="eco required callSave tt number" value="0"> </div> </td> <td><input type="text" name="quantity" class="quantity required callSave number" value="1"></td> <td> <div class="input-append"> <input type="text" name="discount" class="discount callSave number" value="0"> <span class="add-on">%</span> </div> </td> <td class="total"></td> <td> <select name="vat" class="callSave" style="width: 65px"> {% for vat in vats %} <option value="{{ vat.id }}">{{ vat }}</option> {% endfor %} </select> </td> <td> <input type="text" name="comment" class="comment callSave" value=""> </td> <td><a href="#" class="btn btn-danger remove"><i class="icon-remove"></i></a></td> </tr> </tbody> <tfoot> <tr> <td>Nombre d'article : <span class="counter">XXX</span></td> <td colspan="6" style="text-align: right">Total : <span class="total">XXX</span></td> <td colspan="2"></td> </tr> </tfoot> </table> </fieldset> {% endif %} <div class="well form-actions"> <a href="{{ path('admin_billing_order_list') }}" class="btn">Annuler</a> <input type="submit" class="btn btn-primary save" name="btn_update_and_edit" value="Enregistrer"> </div> </form> <table style="display: none;"> <tr class="clone"> <td> <input type="hidden" name="id" value="" class="line-id" /> <input type="hidden" name="article_id" class="articleSearchTemp"> <a href="#" class="btn btn-danger out" title="Hors base article"><i class="icon-signout"></i></a> </td> <td><input type="text" name="unit" class="unit required callSave" placeholder="U"></td> <td> <div class="input-prepend"> <span class="add-on">&euro;</span> <input type="text" name="price" class="price required callSave tt number"> </div> </td> <td> <div class="input-prepend"> <span class="add-on">&euro;</span> <input type="text" name="eco" class="eco required callSave tt number" value="0"> </div> </td> <td><input type="text" name="quantity" class="quantity required callSave number" value="1"></td> <td> <div class="input-append"> <input type="text" name="discount" class="discount callSave number" value="0"> <span class="add-on">%</span> </div> </td> <td class="total"></td> <td> <select name="vat" class="callSave" style="width: 65px"> {% for vat in vats %} <option value="{{ vat.id }}"@>{{ vat }}</option> {% endfor %} </select> </td> <td><a href="#" class="btn btn-danger remove"><i class="icon-remove"></i></a></td> </tr> </table> <div id="modal" class="modal hide fade"> <div class="modal-header"> <button type="button" class="close" data-dismiss="#modal" aria-hidden="true">&times;</button> <h3>Ajouter un magasin</h3> </div> <div class="modal-body"> <form class="supplierForm" method="post" action="{{ path('supplier_create') }}"> <input type="hidden" name="company" value="{{ (object.supplier is not empty) ? object.supplier.company.id }}"/> {{ form_widget(form_supplier) }} </form> </div> <div class="modal-footer"> <a href="#" class="btn closeModal">Annuler</a> <a href="#" class="btn btn-primary modalSave">Enregistrer</a> </div> </div> <script> $(function(){ $('.tt').tooltip({'html': true}); // Prevent saving form on enter key $('.order-form').bind("keypress", function(e) { if (e.keyCode == 13) { e.preventDefault(); return false; } }); $('.number').keypress(function(event) { if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) { event.preventDefault(); } }); $( ".save" ).click(function(e) { e.preventDefault(); if ($('.interventionSearch').select2("val") != '') { if ($('.deliveryType').val() == 1) { if ($('.userSearch').select2("val") != '') { $( ".order-form" ).submit(); } else { alert('Pour un enlèvement comptoire vous devez choisir un technicien'); } } else { $( ".order-form" ).submit(); } } else { if ($('.stock').val() != '') { $( ".order-form" ).submit(); } else { alert('Veuillez choisir un stock ou une intervention'); } } }); var opts0 = { placeholder: "Choisir un fournisseur", minimumInputLength: 0, allowClear: true, ajax: { url: "{{path('billing_company_search')}}", dataType: 'json', data: function (term, page) { return { q: term, page_limit: 10 }; }, results: function (data, page) { return {results: data.results}; } }, formatResult: companyFormatResult, formatSelection: companyFormatSelection, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return m; } }; $(".companySearch").select2( opts0 ); {% if object.supplier is not empty %} $(".companySearch").select2("data", {id: {{ object.supplier.company.id }}, name: '{{ object.supplier.company.name }}'}); {% endif %} $('.companySearch').on("change", function(e) { $(".supplierSearch").select2('data', null); $('.supplierForm input[name=company]').val($(".companySearch").select2("val")); $('.addSupplier').show(); }); // Configure intervention select2 var opts3 = { placeholder: "Choisir un magasin", minimumInputLength: 0, allowClear: true, ajax: { url: "{{path('billing_supplier_search')}}", dataType: 'json', data: function (term, page) { return { q: term, page_limit: 10, company: $(".companySearch").select2("val") }; }, results: function (data, page) { return {results: data.results}; } }, formatResult: supplierFormatResult, formatSelection: supplierFormatSelection, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return m; } }; $(".supplierSearch").select2( opts3 ); {% if object.supplier is not empty %} $(".supplierSearch").select2("data", {id: {{ object.supplier.id }}, name: '{{ object.supplier.name }}'}); {% endif %} $('.supplierSearch').on("change", function(e) { var data = $(".supplierSearch").select2("data"); $(".companySearch").select2("data", {id: data.company_id, name: data.company_name}); }); // Configure intervention select2 var opts1 = { placeholder: "Choisir une intervention", minimumInputLength: 2, allowClear: true, ajax: { url: "{{path('billing_intervention_search')}}", dataType: 'json', data: function (term, page) { return { q: term, page_limit: 10 }; }, results: function (data, page) { return {results: data.results}; } }, formatResult: interventionFormatResult, formatSelection: interventionFormatSelection, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return m; } }; $(".interventionSearch").select2( opts1 ); {% if object.intervention is not empty %} $(".interventionSearch").select2("data", {id: {{ object.intervention.id }}, ref: '{{ object.intervention.ref }}'}); {% endif %} $('.interventionSearch').on("change", function(e) { $('.stock').val(''); $('.deliveryType').val(''); $('.deliveryType').addClass('error'); $('.delivery-container').show(); }); $('.stock').on("click", function(e) { $('.interventionSearch').select2("data", null); }); $('.stock').on("change", function(e) { $('.deliveryType').val('3'); $('.deliveryType').change(); $('.delivery-container').hide(); }); // Configure article select2 var opts2 = { placeholder: "Ajouter un article", minimumInputLength: 0, ajax: { url: "{{path('billing_article_search')}}", dataType: 'json', data: function (term, page) { return { q: term, page_limit: 10, company: $(".companySearch").select2("val") }; }, results: function (data, page) { return {results: data.results}; } }, formatResult: articleFormatResult, formatSelection: articleFormatSelection, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return m; } }; $(".articleSearch").select2( opts2 ); {% for key,line in object.lines if line.article is not empty %} $("#article{{key}}").select2("data", {id: {{ line.article.id }}, ref: '{{ line.article }}'}); {% endfor %} var opts4 = { placeholder: "Choisir un technicien", minimumInputLength: 0, allowClear: true, ajax: { url: "{{path('billing_user_search')}}", dataType: 'json', data: function (term, page) { return { q: term, page_limit: 10 }; }, results: function (data, page) { return {results: data.results}; } }, formatResult: userFormatResult, formatSelection: userFormatSelection, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return m; } }; $(".userSearch").select2( opts4 ); {% if object.retrievedBy is not empty %} $(".userSearch").select2("data", {id: {{ object.retrievedBy.id }}, ref: '{{ object.retrievedBy.fullname }}'}); {% endif %} $('.deliveryType').on("change", function(e) { $(this).removeClass('error'); var type = $(this).val(); var supplier = $(".supplierSearch").select2("val"); var intervention = $(".interventionSearch").select2("val"); var stock = $(".stock").val(); if (type==1) { $('.retreivedBy').show(); } else { $('.retreivedBy').hide(); } $.post("{{ path('billing_address_search') }}", { 'type': type, 'supplier': supplier, 'intervention': intervention, 'stock': stock }, function(data) { if (data.error) { $('.deliveryType').val(''); $('.address').val(''); $('.city').val(''); $('.postcode').val(''); alert("Un problème est survenu\nVous devez\n- saisir un magasin pour un enlèvement comptoir\n- saisir un intervention pour une livraison chantier"); } else { $('.address').val(data.address); $('.city').val(data.city); $('.postcode').val(data.postcode); } }, 'json'); }).change(); // On article select2 change : save line and create a new one if necessary $(document).on("change", '.articleSearch', function(e) { articleChange($(this)); }); function articleChange(elt) { var line = elt.parent().parent(); var id = line.find('.line-id'); var price = line.find('.price'); var unit = line.find('.unit'); var eco = line.find('.eco'); //console.log('allo'); //console.log($(this).select2('data')); var data = elt.select2('data'); price.val(data.price); price.attr('title', 'Prix commandé<br>moyen '+ data.price +'&euro;<br>min '+ data.priceMin +' &euro;<br>max '+ data.priceMax +' &euro;'); price.tooltip({'html': true}); unit.val(data.unit); eco.val(data.eco); $.post("{{ path('orderline_save', { order: object.id }) }}", line.find(':input').serialize(), function(data) { if (id.val() == '') { // Set price //price.val(data.price); //price.attr('title', 'Prix commandé<br>moyen '+ data.price +'&euro;<br>min '+ data.priceMin +' &euro;<br>max '+ data.priceMax +' &euro;'); //price.tooltip({'html': true}); //unit.val(data.unit); //eco.val(data.eco); // Keep line select2 data and destroy it //var sdata = line.find('.articleSearch').select2("data") //line.find('.articleSearch').select2("destroy"); // Add new line var newline = $('.clone').clone(true); newline.removeClass('clone'); newline.appendTo($('.lines')); // Reinit its inputs newline.find('.ref').val(''); newline.find('.llabel').val(''); newline.find('.unit').val(''); newline.find('.price').val('0'); newline.find('.quantity').val('1'); newline.find('.discount').val('0'); newline.find('.articleSearchTemp').removeClass('articleSearchTemp').addClass('articleSearch'); newline.find('.articleSearch').select2(opts2); //newline.find('.articleSearch').select2("data", {id: '', ref: 'Ajouter un article'}); // Recreate line select2 //line.find('.articleSearch').select2(opts2); //line.find('.articleSearch').select2("data", sdata); //Set the previous line id id.val(data.id); } }, 'json'); } $(document).on("click", '.order-form .out', function(e) { e.preventDefault(); $(this).prev().remove(); $(this).prev().remove(); $(this).parent().append('<input type="hidden" name="article_id"><input type="text" name="ref" class="ref callSave" placeholder="Référence" /><input type="text" name="label" class="llabel callSave" placeholder="Libéllé" /><a href="#" class="btn btn-info in" title="Dans base article"><i class="icon-signin"></i></a>'); $(this).remove(); }); $(document).on("click", '.order-form .in', function(e) { e.preventDefault(); $(this).prev().remove(); $(this).prev().remove(); $(this).parent().append('<input type="hidden" name="article_id" class="articleSearch"><a href="#" class="btn btn-danger out" title="Hors base article"><i class="icon-signout"></i></a>'); $(this).parent().find('.articleSearch').select2(opts2); $(this).parent().find('.articleSearch').select2("data", {id: '', ref: 'Ajouter un article'}); $(this).remove(); }); $(document).on("change", '.callSave', function(event){ var elt = $(this); var line = elt.closest('tr'); var id = line.find('.line-id'); var article = line.find("input[name='article_id']"); //alert(id); if (elt.hasClass('ref')) { //console.log('change1 '+elt); {% if object.supplier is not empty %} $.post("{{ path('orderline_checkArticle', {'company': object.supplier.company.id }) }}", line.find(':input').serialize(), function(data) { if (data.id > 0) { article.val(data.id); line.find('.in').click(); //console.log('1 '+data.id); //console.log(data.ref); line.find('.articleSearch').select2(opts2); line.find(".articleSearch").select2("data", data); articleChange(line.find(".articleSearch")); //line.find(".articleSearch").change(); } }); {% endif %} } else { //console.log('change2 '+elt); $.post("{{ path('orderline_save', { order: object.id }) }}", line.find(':input').serialize(), function(data) { //console.log('2 '+data.id); if (data.id != undefined && data.id > 0 && id.val() != data.id && !data.chapter) { line.find('.articleSearch').select2("destroy"); // Add new line var newline = line.clone(true); newline.appendTo($('.lines')); // Reinit its inputs newline.find('.ref').val(''); newline.find('.llabel').val(''); newline.find('.price').val('0'); newline.find('.quantity').val('1'); newline.find('.discount').val('0'); newline.find('.articleSearch').select2(opts2); newline.find('.articleSearch').select2("data", {id: '', ref: 'Ajouter un article'}); // Recreate line select2 line.find('.articleSearch').select2(opts2); } id.val(data.id); article.val(data.article_id); $('.callSave').prop('readonly', false); }); } updateTotals(); }); $(document).on("click", '.remove', function(event){ event.preventDefault(); var line = $(this).parent().parent(); var id = line.find('.line-id'); $.post("{{ path('orderline_delete') }}", {id: id.val()}, function(data) { line.remove(); }); }); $(document).on("click", '.addSupplier', function(event){ $('#modal input[type=text]').val(''); }); $(document).on("click", '.modalSave', function(event){ event.preventDefault(); $.post("{{ path('supplier_create') }}", $('.supplierForm').serialize(), function(data) { if (data != null) { $(".supplierSearch").select2("data", {id: data.id, name: data.name}); $('#modal').modal('hide'); } }, 'json'); }); $(document).on("click", '.closeModal', function(event){ event.preventDefault(); $('#modal').modal('hide'); }); updateTotals(); }); function updateTotals() { var total = 0; var counter = 0; var totalspan = $('span.total'); var counterspan = $('span.counter'); $('.lines tbody tr').each(function( index ) { var price = parseFloat($(this).find('.price').val()); var quantity = parseFloat($(this).find('.quantity').val()); var eco = parseFloat($(this).find('.eco').val()); var discount = parseFloat($(this).find('.discount').val()); var line_total = $(this).find('.total'); tot = (price + eco) * quantity; if (discount > 0) { tot = tot * (1 - (discount/100)); } if (!isNaN(tot)) { line_total.html(tot.toFixed(2)); total = total + tot; counter++; } }); totalspan.html(total.toFixed(2)); counterspan.html(counter); } </script> {% endblock %}
#-o