2012-06-27 06:36:45 +00:00
|
|
|
{% extends "product/product_category.js" %}
|
2012-06-26 13:24:10 +00:00
|
|
|
|
|
|
|
{% block javascript %}
|
2012-06-27 06:36:45 +00:00
|
|
|
{{ super() }}
|
2012-06-26 13:24:10 +00:00
|
|
|
// ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-06-27 06:36:45 +00:00
|
|
|
wn.provide('erpnext.products');
|
2012-06-26 13:24:10 +00:00
|
|
|
wn.pages['{{ name }}'].onload = function(wrapper) {
|
|
|
|
wrapper.product_group = "{{ item_group }}";
|
|
|
|
wrapper.product_name = "{{ name }}";
|
2012-06-27 06:36:45 +00:00
|
|
|
erpnext.products.make_product_categories(wrapper);
|
2012-07-09 10:26:12 +00:00
|
|
|
erpnext.products.make_similar_products(wrapper);
|
|
|
|
|
|
|
|
// if website image missing, autogenerate one
|
2012-07-09 14:32:52 +00:00
|
|
|
var $img = $(wrapper).find('.product-page-content .img-area');
|
2012-07-09 10:26:12 +00:00
|
|
|
if ($img && $img.length > 0) {
|
|
|
|
$img.append(wn.dom.placeholder(160, "{{ item_name }}"));
|
|
|
|
}
|
2012-06-27 06:36:45 +00:00
|
|
|
|
2012-07-09 14:32:52 +00:00
|
|
|
erpnext.products.adjust_page_height(wrapper);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.products.adjust_page_height = function(wrapper) {
|
|
|
|
if (!wrapper) { wrapper = erpnext.products.wrapper; }
|
|
|
|
if (!wrapper) { return; }
|
|
|
|
|
2012-07-09 10:26:12 +00:00
|
|
|
// adjust page height based on sidebar height
|
2012-07-09 14:32:52 +00:00
|
|
|
var $main_page = $(wrapper).find('.layout-main-section');
|
|
|
|
var $sidebar = $(wrapper).find('.layout-side-section');
|
2012-07-09 10:26:12 +00:00
|
|
|
if ($sidebar.height() > $main_page.height()) {
|
|
|
|
$main_page.height($sidebar.height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.products.make_similar_products = function(wrapper) {
|
|
|
|
if (!wrapper) { wrapper = erpnext.products.wrapper; }
|
|
|
|
if (!wrapper) { return; }
|
2012-06-26 13:24:10 +00:00
|
|
|
|
|
|
|
// similar products
|
|
|
|
wrapper.similar = new wn.ui.Listing({
|
|
|
|
parent: $(wrapper).find('.similar-products').get(0),
|
|
|
|
hide_refresh: true,
|
|
|
|
page_length: 5,
|
2012-07-09 10:26:12 +00:00
|
|
|
method: 'website.product.get_similar_product_list',
|
|
|
|
get_args: function() {
|
|
|
|
return {
|
|
|
|
product_group: wrapper.product_group,
|
|
|
|
product_name: wrapper.product_name
|
|
|
|
}
|
2012-06-26 13:24:10 +00:00
|
|
|
},
|
|
|
|
render_row: function(parent, data) {
|
2012-07-09 10:26:12 +00:00
|
|
|
if (!data.web_short_description) {
|
|
|
|
data.web_short_description = data.description;
|
|
|
|
}
|
|
|
|
if(data.web_short_description.length > 100) {
|
|
|
|
data.web_short_description =
|
|
|
|
data.web_short_description.substr(0,100) + '...';
|
2012-06-26 13:24:10 +00:00
|
|
|
}
|
2012-06-27 06:36:45 +00:00
|
|
|
parent.innerHTML = repl('\
|
2012-07-09 10:26:12 +00:00
|
|
|
<a href="%(page_name)s.html"><div class="img-area"></div></a>\
|
|
|
|
<div class="similar-product-description">\
|
|
|
|
<h5><a href="%(page_name)s.html">%(item_name)s</a></h5>\
|
|
|
|
<span>%(web_short_description)s</span>\
|
|
|
|
</div>\
|
|
|
|
<div style="clear:both"></div>', data);
|
2012-06-27 06:36:45 +00:00
|
|
|
|
|
|
|
if(data.website_image) {
|
|
|
|
$(parent).find('.img-area').append(repl(
|
2012-07-09 10:26:12 +00:00
|
|
|
'<img src="files/%(website_image)s" />', data))
|
2012-06-27 06:36:45 +00:00
|
|
|
} else {
|
2012-07-09 10:26:12 +00:00
|
|
|
$(parent).find('.img-area').append(wn.dom.placeholder(55,
|
2012-06-27 06:36:45 +00:00
|
|
|
data.item_name));
|
|
|
|
}
|
2012-07-09 14:32:52 +00:00
|
|
|
|
|
|
|
// adjust page height, if sidebar height keeps increasing
|
|
|
|
erpnext.products.adjust_page_height(wrapper);
|
2012-06-26 13:24:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
wrapper.similar.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
{% endblock %}
|