Item, Item Group and Partner Web Page generators moved from Shopping Cart to ERPNext

This commit is contained in:
Anand Doshi
2014-04-18 16:15:31 +05:30
parent 603e6e21b5
commit 5d591ebe83
24 changed files with 625 additions and 6 deletions

View File

View File

@@ -0,0 +1,10 @@
{% if parent_groups and (parent_groups|length) > 1 %}
<div class="container">
<ul class="breadcrumb">
{% for ig in parent_groups[:-1] %}
<li><a href="{{ ig.page_name }}.html">{{ ig.name }}</a></li>
{% endfor %}
<li class="active">{{ parent_groups[-1].name }}</li>
</ul>
</div>
{% endif %}

View File

@@ -0,0 +1,14 @@
<div class="col-sm-3">
<div style="height: 120px; overflow: hidden;">
<a href="{{ page_name }}">
{%- if website_image -%}
<img class="product-image" style="width: 80%; margin: auto;" src="{{ website_image }}">
{%- else -%}
{% include 'templates/includes/product_missing_image.html' %}
{%- endif -%}
</a>
</div>
<div style="height: 100px; overflow: hidden; font-size: 80%;">
<h4 style="margin-bottom: 2px;"><a href="{{ page_name }}">{{ item_name }}</a></h4>
</div>
</div>

View File

@@ -0,0 +1,15 @@
<!-- TODO product listing -->
<div class="container content">
<div style="height: 120px; overflow: hidden;">
<a href="{{ page_name }}">
{%- if website_image -%}
<img class="product-image" style="width: 80%; margin: auto;" src="{{ website_image }}">
{%- else -%}
{% include 'templates/includes/product_missing_image.html' %}
{%- endif -%}
</a>
</div>
<div style="height: 100px; overflow: hidden; font-size: 80%;">
<h4 style="margin-bottom: 2px;"><a href="{{ page_name }}">{{ item_name }}</a></h4>
</div>
</div>

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// 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: "/",
dataType: "json",
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) {
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);
}

View File

@@ -0,0 +1 @@
<div class="missing-image"><i class="icon-camera"></i></div>

View File

@@ -0,0 +1,78 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
$(document).ready(function() {
var item_code = $('[itemscope] [itemprop="productID"]').text().trim();
var qty = 0;
frappe.call({
type: "POST",
method: "shopping_cart.shopping_cart.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() {
shopping_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() {
shopping_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);
}

View File

@@ -0,0 +1,28 @@
<div class="container" style="margin-bottom: 7px;">
<form class="form-inline form-search row">
<div class="input-group col-md-4 col-md-offset-8">
<input class="form-control" type="text" id="product-search" placeholder="Product Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="btn-product-search">
<i class="icon-search"></i></button>
</span>
</div>
</form>
<script>
// redirect to product search page
$(document).ready(function() {
$('.dropdown-toggle').dropdown();
$("#btn-product-search").click(function() {
var txt = $("#product-search").val();
if(txt) {
window.location.href="product_search?q=" + txt;
}
return false;
});
$("#product-search").keypress(function(e) {
if(e.which==13) $("#btn-product-search").click();
});
$(".form-search").on("submit", function() { return false; });
});
</script>
</div>