8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00

Fix bug id avec JS et paiement + utilisation bootstrap

This commit is contained in:
Maël Kervella 2017-10-15 00:18:08 +00:00
parent 25128b600e
commit f696f8289f

View file

@ -38,18 +38,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{{ venteform.management_form }} {{ venteform.management_form }}
<!-- TODO: FIXME to include data-type="check" for right option in id_cheque select --> <!-- TODO: FIXME to include data-type="check" for right option in id_cheque select -->
<h3>Articles de la facture</h3> <h3>Articles de la facture</h3>
<div id="form_set"> <div id="form_set" class="form-group">
{% for form in venteform.forms %} {% for form in venteform.forms %}
<div class='product_to_sell'> <div class='product_to_sell form-inline'>
<p> Article : &nbsp;
{{ form.as_table }} {% bootstrap_form form label_class='sr-only' %}
</p> &nbsp;
<button class="btn btn-danger btn-sm"
id="id_form-0-article-remove" type="button">
<span class="glyphicon glyphicon-remove"></span>
</button>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<p>
<input class="btn btn-primary btn-sm" role="button" value="Ajouter un article" id="add_one"> <input class="btn btn-primary btn-sm" role="button" value="Ajouter un article" id="add_one">
</p>
<p> <p>
Prix total : <span id="total_price">0,00</span> Prix total : <span id="total_price">0,00</span>
</p> </p>
@ -63,19 +65,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
prices[{{ article.id|escapejs }}] = {{ article.prix }}; prices[{{ article.id|escapejs }}] = {{ article.prix }};
{% endfor %} {% endfor %}
var template = `<p>{{ venteform.empty_form.as_table }}</p>`; var template = `Article : &nbsp;
{% bootstrap_form venteform.empty_form label_class='sr-only' %}
&nbsp;
<button class="btn btn-danger btn-sm"
id="id_form-__prefix__-article-remove" type="button">
<span class="glyphicon glyphicon-remove"></span>
</button>`
function add_article(){ function add_article(){
// Index start at 0 => new_index = number of items // Index start at 0 => new_index = number of items
var new_index = var new_index =
document.getElementsByClassName('product_to_sell').length; document.getElementsByClassName('product_to_sell').length;
document.getElementById('id_form-TOTAL_FORMS').value = document.getElementById('id_form-TOTAL_FORMS').value ++;
parseInt(document.getElementById('id_form-TOTAL_FORMS').value) + 1;
var new_article = document.createElement('div'); var new_article = document.createElement('div');
new_article.className = 'product_to_sell'; new_article.className = 'product_to_sell form-inline';
new_article.innerHTML = template.replace(/__prefix__/g, new_index); new_article.innerHTML = template.replace(/__prefix__/g, new_index);
document.getElementById('form_set') document.getElementById('form_set').appendChild(new_article);
.appendChild(new_article);
add_listenner_for_id(new_index); add_listenner_for_id(new_index);
} }
@ -106,18 +112,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
.addEventListener("onkeypress", update_price, true); .addEventListener("onkeypress", update_price, true);
document.getElementById('id_form-' + i.toString() + '-quantity') document.getElementById('id_form-' + i.toString() + '-quantity')
.addEventListener("change", update_price, true); .addEventListener("change", update_price, true);
document.getElementById('id_form-' + i.toString() + '-article-remove')
.addEventListener("click", function(event) {
var article = event.target.parentNode;
article.parentNode.removeChild(article);
document.getElementById('id_form-TOTAL_FORMS').value --;
update_price();
}
)
} }
function set_cheque_info_visibility(){ function set_cheque_info_visibility() {
var visible = document.getElementById("id_paiement").value == document.getElementById("id_paiement").getAttribute('data-cheque'); var paiement = document.getElementById("id_Facture-paiement");
p = document.getElementById("id_paiement") var visible = paiement.value == paiement.getAttribute('data-cheque');
console.log(p); p = document.getElementById("id_Facture-paiement");
var display = 'none'; var display = 'none';
if (visible) { if (visible) {
display = 'block'; display = 'block';
} }
document.getElementById("id_cheque").parentNode.style.display = display; document.getElementById("id_Facture-cheque")
document.getElementById("id_banque").parentNode.style.display = display; .parentNode.style.display = display;
document.getElementById("id_Facture-banque")
.parentNode.style.display = display;
} }
// Add events manager when DOM is fully loaded // Add events manager when DOM is fully loaded
@ -129,7 +145,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
for (i = 0; i < product_count; ++i){ for (i = 0; i < product_count; ++i){
add_listenner_for_id(i); add_listenner_for_id(i);
} }
document.getElementById("id_paiement") document.getElementById("id_Facture-paiement")
.addEventListener("change", set_cheque_info_visibility, true); .addEventListener("change", set_cheque_info_visibility, true);
set_cheque_info_visibility(); set_cheque_info_visibility();
update_price(); update_price();