Optimisation JS K-Psul sélection articles

This commit is contained in:
Aurélien Delobelle 2016-09-06 16:33:04 +02:00
parent 5569b7d154
commit e154316eae

View file

@ -504,17 +504,17 @@ $(document).ready(function() {
function addArticle(article) {
var article_html = $(article_default_html);
article_html.attr('data-article', article['id']);
article_html.attr('data-category', article['category_id']);
article_html.attr('id', 'data-article-'+article['id']);
article_html.addClass('data-category-'+article['category_id']);
for (var elem in article) {
article_html.find('.'+elem).text(article[elem])
}
article_html.find('.price').text(amountToUKF(article['price'], false));
var category_html = articles_container
.find('.category[data-category='+article['category_id']+']');
.find('#data-category-'+article['category_id']);
if (category_html.length == 0) {
category_html = $(article_category_default_html);
category_html.attr('data-category', article['category_id']);
category_html.attr('id', 'data-category-'+article['category_id']);
category_html.find('td').text(article['category__name']);
var added = false;
articles_container.find('.category').each(function() {
@ -528,14 +528,14 @@ $(document).ready(function() {
}
var added = false;
articles_container
.find('.article[data-category='+article['category_id']+']').each(function() {
.find('.article.data-category-'+article['category_id']).each(function() {
if (article['name'].toLowerCase < $('.name', this).text().toLowerCase()) {
$(this).before(article_html);
added = true;
return false;
}
});
if (!added) articles_container.find('.category[data-category='+article['category_id']+']').after(article_html);
if (!added) articles_container.find('#data-category-'+article['category_id']).after(article_html);
// Pour l'autocomplétion
articlesList.push([article['name'],article['id'],article['category_id'],article['price']]);
}
@ -597,17 +597,17 @@ $(document).ready(function() {
var categories_to_display = [];
for (var i=0; i<articlesList.length; i++) {
if (array.indexOf(articlesList[i]) > -1) {
articles_container.find('[data-article='+articlesList[i][1]+']').show();
articles_container.find('#data-article-'+articlesList[i][1]).show();
if (categories_to_display.indexOf(articlesList[i][2]) == -1)
categories_to_display.push(articlesList[i][2]);
} else {
articles_container.find('[data-article='+articlesList[i][1]+']').hide();
articles_container.find('#data-article-'+articlesList[i][1]).hide();
}
}
articles_container.find('.category').hide();
for (var i=0; i<categories_to_display.length; i++) {
articles_container
.find('.category[data-category='+categories_to_display[i]+']')
.find('#data-category-'+categories_to_display[i])
.show();
}
}