2015-03-03 09:25:30 +00:00
|
|
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2014-04-18 10:45:31 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
window.get_product_list = function() {
|
|
|
|
$(".more-btn .btn").click(function() {
|
|
|
|
window.get_product_list()
|
|
|
|
});
|
|
|
|
|
|
|
|
if(window.start==undefined) {
|
|
|
|
throw "product list not initialized (no start)"
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
|
|
|
url: "/",
|
|
|
|
data: {
|
|
|
|
cmd: "erpnext.templates.pages.product_search.get_product_list",
|
|
|
|
start: window.start,
|
|
|
|
search: window.search,
|
|
|
|
product_group: window.product_group
|
|
|
|
},
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
2016-04-09 16:55:21 +00:00
|
|
|
window.render_product_list(data.message || []);
|
2014-04-18 10:45:31 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
window.render_product_list = function(data) {
|
2023-07-15 12:33:16 +00:00
|
|
|
let table = $("#search-list .table");
|
2014-04-18 10:45:31 +00:00
|
|
|
if(data.length) {
|
|
|
|
if(!table.length)
|
2023-07-15 12:33:16 +00:00
|
|
|
table = $("<table class='table'>").appendTo("#search-list");
|
2014-04-18 10:45:31 +00:00
|
|
|
|
|
|
|
$.each(data, function(i, d) {
|
|
|
|
$(d).appendTo(table);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if(data.length < 10) {
|
|
|
|
if(!table) {
|
2023-07-15 12:33:16 +00:00
|
|
|
let message = __("No products found.");
|
2014-04-18 10:45:31 +00:00
|
|
|
$(".more-btn")
|
2023-07-15 12:33:16 +00:00
|
|
|
.replaceWith(`<div class='alert alert-warning'>{{ ${message} }}</div>`);
|
2014-04-18 10:45:31 +00:00
|
|
|
} else {
|
2023-07-15 12:33:16 +00:00
|
|
|
let message = __("Nothing more to show.");
|
2014-04-18 10:45:31 +00:00
|
|
|
$(".more-btn")
|
2023-07-15 12:33:16 +00:00
|
|
|
.replaceWith(`<div class='text-muted'>{{ ${message} }}</div>`);
|
2014-04-18 10:45:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$(".more-btn").toggle(true)
|
|
|
|
}
|
|
|
|
window.start += (data.length || 0);
|
|
|
|
}
|