mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
[website] [minor] moving to framework
This commit is contained in:
52
stock/doctype/item/templates/includes/product_list.js
Normal file
52
stock/doctype/item/templates/includes/product_list.js
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
||||
// 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: "server.py",
|
||||
dataType: "json",
|
||||
data: {
|
||||
cmd: "selling.utils.product.get_product_list",
|
||||
start: window.start,
|
||||
search: window.search,
|
||||
product_group: window.product_group
|
||||
},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
window.render_product_list(data.message);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
window.render_product_list = function(data) {
|
||||
if(data.length) {
|
||||
var table = $("#search-list .table");
|
||||
if(!table.length)
|
||||
var table = $("<table class='table'>").appendTo("#search-list");
|
||||
|
||||
$.each(data, function(i, d) {
|
||||
$(d).appendTo(table);
|
||||
});
|
||||
}
|
||||
if(data.length < 10) {
|
||||
if(!table) {
|
||||
$(".more-btn")
|
||||
.replaceWith("<div class='alert alert-warning'>No products found.</div>");
|
||||
} else {
|
||||
$(".more-btn")
|
||||
.replaceWith("<div class='text-muted'>Nothing more to show.</div>");
|
||||
}
|
||||
} else {
|
||||
$(".more-btn").toggle(true)
|
||||
}
|
||||
window.start += (data.length || 0);
|
||||
}
|
||||
13
stock/doctype/item/templates/includes/product_page.css
Normal file
13
stock/doctype/item/templates/includes/product_page.css
Normal file
@@ -0,0 +1,13 @@
|
||||
<style>
|
||||
.item-main-image {
|
||||
max-width: 100%;
|
||||
margin: auto;
|
||||
}
|
||||
.web-long-description {
|
||||
font-size: 18px;
|
||||
line-height: 200%;
|
||||
}
|
||||
.item-stock {
|
||||
margin-bottom: 10px !important;
|
||||
}
|
||||
</style>
|
||||
78
stock/doctype/item/templates/includes/product_page.js
Normal file
78
stock/doctype/item/templates/includes/product_page.js
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
$(document).ready(function() {
|
||||
var item_code = $('[itemscope] [itemprop="name"]').text().trim();
|
||||
var qty = 0;
|
||||
|
||||
wn.call({
|
||||
type: "POST",
|
||||
method: "selling.utils.product.get_product_info",
|
||||
args: {
|
||||
item_code: "{{ name }}"
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.message && r.message.price) {
|
||||
$(".item-price")
|
||||
.html(r.message.price.formatted_price + " per " + r.message.uom);
|
||||
|
||||
if(r.message.stock==0) {
|
||||
$(".item-stock").html("<div class='help'>Not in stock</div>");
|
||||
}
|
||||
else if(r.message.stock==1) {
|
||||
$(".item-stock").html("<div style='color: green'>\
|
||||
<i class='icon-check'></i> Available (in stock)</div>");
|
||||
}
|
||||
|
||||
$(".item-price-info").toggle(true);
|
||||
|
||||
if(r.message.qty) {
|
||||
qty = r.message.qty;
|
||||
toggle_update_cart(qty);
|
||||
$("#item-update-cart input").val(qty);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
$("#item-add-to-cart button").on("click", function() {
|
||||
wn.cart.update_cart({
|
||||
item_code: item_code,
|
||||
qty: 1,
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
toggle_update_cart(1);
|
||||
qty = 1;
|
||||
}
|
||||
},
|
||||
btn: this,
|
||||
});
|
||||
});
|
||||
|
||||
$("#item-update-cart button").on("click", function() {
|
||||
wn.cart.update_cart({
|
||||
item_code: item_code,
|
||||
qty: $("#item-update-cart input").val(),
|
||||
btn: this,
|
||||
callback: function(r) {
|
||||
if(r.exc) {
|
||||
$("#item-update-cart input").val(qty);
|
||||
} else {
|
||||
qty = $("#item-update-cart input").val();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
if(localStorage && localStorage.getItem("pending_add_to_cart") && full_name) {
|
||||
localStorage.removeItem("pending_add_to_cart");
|
||||
$("#item-add-to-cart button").trigger("click");
|
||||
}
|
||||
});
|
||||
|
||||
var toggle_update_cart = function(qty) {
|
||||
$("#item-add-to-cart").toggle(qty ? false : true);
|
||||
$("#item-update-cart")
|
||||
.toggle(qty ? true : false)
|
||||
.find("input").val(qty);
|
||||
}
|
||||
Reference in New Issue
Block a user