forked from DGNum/gestioCOF
Optimisation JS K-Psul sélection articles
This commit is contained in:
parent
5569b7d154
commit
e154316eae
1 changed files with 9 additions and 9 deletions
|
@ -504,17 +504,17 @@ $(document).ready(function() {
|
||||||
|
|
||||||
function addArticle(article) {
|
function addArticle(article) {
|
||||||
var article_html = $(article_default_html);
|
var article_html = $(article_default_html);
|
||||||
article_html.attr('data-article', article['id']);
|
article_html.attr('id', 'data-article-'+article['id']);
|
||||||
article_html.attr('data-category', article['category_id']);
|
article_html.addClass('data-category-'+article['category_id']);
|
||||||
for (var elem in article) {
|
for (var elem in article) {
|
||||||
article_html.find('.'+elem).text(article[elem])
|
article_html.find('.'+elem).text(article[elem])
|
||||||
}
|
}
|
||||||
article_html.find('.price').text(amountToUKF(article['price'], false));
|
article_html.find('.price').text(amountToUKF(article['price'], false));
|
||||||
var category_html = articles_container
|
var category_html = articles_container
|
||||||
.find('.category[data-category='+article['category_id']+']');
|
.find('#data-category-'+article['category_id']);
|
||||||
if (category_html.length == 0) {
|
if (category_html.length == 0) {
|
||||||
category_html = $(article_category_default_html);
|
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']);
|
category_html.find('td').text(article['category__name']);
|
||||||
var added = false;
|
var added = false;
|
||||||
articles_container.find('.category').each(function() {
|
articles_container.find('.category').each(function() {
|
||||||
|
@ -528,14 +528,14 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
var added = false;
|
var added = false;
|
||||||
articles_container
|
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()) {
|
if (article['name'].toLowerCase < $('.name', this).text().toLowerCase()) {
|
||||||
$(this).before(article_html);
|
$(this).before(article_html);
|
||||||
added = true;
|
added = true;
|
||||||
return false;
|
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
|
// Pour l'autocomplétion
|
||||||
articlesList.push([article['name'],article['id'],article['category_id'],article['price']]);
|
articlesList.push([article['name'],article['id'],article['category_id'],article['price']]);
|
||||||
}
|
}
|
||||||
|
@ -597,17 +597,17 @@ $(document).ready(function() {
|
||||||
var categories_to_display = [];
|
var categories_to_display = [];
|
||||||
for (var i=0; i<articlesList.length; i++) {
|
for (var i=0; i<articlesList.length; i++) {
|
||||||
if (array.indexOf(articlesList[i]) > -1) {
|
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)
|
if (categories_to_display.indexOf(articlesList[i][2]) == -1)
|
||||||
categories_to_display.push(articlesList[i][2]);
|
categories_to_display.push(articlesList[i][2]);
|
||||||
} else {
|
} else {
|
||||||
articles_container.find('[data-article='+articlesList[i][1]+']').hide();
|
articles_container.find('#data-article-'+articlesList[i][1]).hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
articles_container.find('.category').hide();
|
articles_container.find('.category').hide();
|
||||||
for (var i=0; i<categories_to_display.length; i++) {
|
for (var i=0; i<categories_to_display.length; i++) {
|
||||||
articles_container
|
articles_container
|
||||||
.find('.category[data-category='+categories_to_display[i]+']')
|
.find('#data-category-'+categories_to_display[i])
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue