diff --git a/erpnext/website/js/product_category.js b/erpnext/website/js/product_category.js index 8d3f8988838..bed4d2457a2 100644 --- a/erpnext/website/js/product_category.js +++ b/erpnext/website/js/product_category.js @@ -18,7 +18,10 @@ erpnext.make_product_categories = function(wrapper) { wrapper.category_list = new wn.ui.Listing({ parent: $(wrapper).find('.more-categories').get(0), query: 'select count(name) as items, item_group \ - from tabItem where is_sales_item="Yes" \ + from tabItem \ + where is_sales_item="Yes" and \ + ifnull(show_in_website, "No")="Yes" and \ + docstatus = 0 \ group by item_group order by items desc', hide_refresh: true, render_row: function(parent, data) { @@ -26,5 +29,6 @@ erpnext.make_product_categories = function(wrapper) { data); } }); - wrapper.category_list.run(); + wrapper.category_list.run(); + console.log('product categories made'); } diff --git a/erpnext/website/templates/product/product.html b/erpnext/website/templates/product/product.html index 5a04e79d6bb..5d3c3da980d 100644 --- a/erpnext/website/templates/product/product.html +++ b/erpnext/website/templates/product/product.html @@ -9,9 +9,11 @@

{{ item_name }}



+ {% if website_image %}

+ {% endif %} {{ web_description_html }} +
+
-

Categories

+

Categories

diff --git a/erpnext/website/templates/product/product_list.js b/erpnext/website/templates/product/product_list.js index 82c788687d6..5166fed6393 100644 --- a/erpnext/website/templates/product/product_list.js +++ b/erpnext/website/templates/product/product_list.js @@ -1,6 +1,8 @@ -{% extends "page.html" %} +{% extends "product/product_category.js" %} {% block javascript %} +{{ super() }} + // ERPNext - web based ERP (http://erpnext.com) // Copyright (C) 2012 Web Notes Technologies Pvt Ltd // @@ -18,23 +20,103 @@ // along with this program. If not, see . // js inside blog page +wn.provide('erpnext.products'); + wn.pages['{{ name }}'].onload = function(wrapper) { - erpnext.product_list = new wn.ui.Listing({ - parent: $(wrapper).find('#product-list').get(0), - query: "select name, item_code, item_name, description, page_name \ - from `tabItem` \ - where docstatus = 0 and ifnull(show_in_website, 'No')='Yes'\ - order by item_name asc", - hide_refresh: true, - no_toolbar: true, - render_row: function(parent, data) { - if(data.description && data.description.length==1000) data.description += '... (read on)'; - parent.innerHTML = repl('

%(item_name)s

\ -

%(description)s

', data); - }, - page_length: 10 + erpnext.products.wrapper = wrapper; + + // make product categories in the sidebar + erpnext.products.make_product_categories(wrapper); + + // make lists + erpnext.products.make_product_list(wrapper); + + // erpnext.products.product_list.run(); + + // bind search button or enter key + $(wrapper).find('.products-search .btn').click(function() { + erpnext.products.product_list.run(); }); - erpnext.product_list.run(); + + $(wrapper).find('.products-search input').keypress(function(ev) { + if(ev.which==13) $(wrapper).find('.products-search .btn').click(); + }); +} + +erpnext.products.make_product_list = function(wrapper) { + if (!wrapper) { wrapper = erpnext.products.wrapper; } + if (!wrapper) { return; } + + erpnext.products.product_list = new wn.ui.Listing({ + parent: $(wrapper).find('#products-list').get(0), + run_btn: $(wrapper).find('.products-search .btn').get(0), + no_toolbar: true, + get_query: function() { + var srch = $('input[name="products-search"]').val() + var search_cond = 'and (description like "%%(srch)s%"\ + or item_name like "%%(srch)s%")'; + var product_group_cond = 'and item_group="%(group)s"'; + var cur_group = erpnext.products.cur_group + args = { + search_cond: srch ? repl(search_cond, {srch:srch}) : '', + cat: cur_group ? repl(product_group_cond, {group: cur_group}) : '', + }; + return repl('select name, item_name, website_image, \ + description, page_name \ + from tabItem \ + where is_sales_item="Yes" \ + %(cat)s \ + and docstatus = 0 and ifnull(show_in_website, "No")="Yes"\ + %(search_cond)s', args) + }, + render_row: function(parent, data) { + parent.innerHTML = repl('\ +
\ +
\ +

%(item_name)s

\ +

%(description)s

\ +
', data); + + if(data.website_image) { + $(parent).find('.img-area').append(repl( + '', data)) + } else { + $(parent).find('.img-area').append(wn.dom.placeholder(100, + data.item_name)); + } + } + }); +} + +wn.pages['{{ name }}'].onshow = function(wrapper) { + // show default product category + erpnext.products.set_group(); +} + +erpnext.products.set_group = function() { + var cat = erpnext.products.get_group(); + + // get erpnext.products.default_category + var wrapper = erpnext.products.wrapper; + + $(wrapper).find('h1').html(cat.label); + erpnext.products.product_list.run(); +} + +erpnext.products.get_group = function() { + route = wn.get_route(); + if(route && route.length>1) { + // from url + var grp = route[1]; + var label = route[1]; + erpnext.products.cur_group = grp; + } else { + // default + var grp = 'Products'; + var label = 'Products'; + erpnext.products.cur_group = null; + } + return {grp:grp, label:label}; } {% endblock %} diff --git a/erpnext/website/web_cache.py b/erpnext/website/web_cache.py index c9f196dc5eb..42bd1d11111 100644 --- a/erpnext/website/web_cache.py +++ b/erpnext/website/web_cache.py @@ -15,7 +15,7 @@ # along with this program. If not, see . # used by web.py -def load_from_web_cache(page_name, comments, template): +def load_from_web_cache(page_name, comments, template): #, script=None): """ * search for page in cache * if html exists, return @@ -45,6 +45,9 @@ def load_from_web_cache(page_name, comments, template): from webnotes.utils import cstr html += """\n""" % cstr(comments) + + # show error in error console + # if script: html += """\n\n""" % cstr(script) return html def load_into_web_cache(page_name, template, doc_type, doc_name): diff --git a/public/js/all-app.js b/public/js/all-app.js index 026903bf418..30b3c96be63 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -252,8 +252,7 @@ wn.re_route={} wn.route=function(){if(wn.re_route[window.location.hash]){var re_route_val=wn.get_route_str(wn.re_route[window.location.hash]);var cur_route_val=wn.get_route_str(wn._cur_route);if(decodeURIComponent(re_route_val)===decodeURIComponent(cur_route_val)){window.history.back();return;}else{window.location.hash=wn.re_route[window.location.hash];}} wn._cur_route=window.location.hash;route=wn.get_route();switch(route[0]){case"List":wn.views.doclistview.show(route[1]);break;case"Form":if(route.length>3){route[2]=route.splice(2).join('/');} wn.views.formview.show(route[1],route[2]);break;case"Report":wn.views.reportview.show(route[1],route[2]);break;case"Report2":wn.views.reportview2.show();break;default:wn.views.pageview.show(route[0]);}} -wn.get_route=function(route){if(!wn.boot){return[window.page_name];} -return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});} +wn.get_route=function(route){return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});} wn.get_route_str=function(route){if(!route) route=window.location.hash;if(route.substr(0,1)=='#')route=route.substr(1);if(route.substr(0,1)=='!')route=route.substr(1);return route;} wn.set_route=function(){route=$.map(arguments,function(a){return encodeURIComponent(a)}).join('/');window.location.hash=route;wn.app.set_favicon();} diff --git a/public/js/all-web.js b/public/js/all-web.js index 9712ff6d141..b3ab4ed94ff 100644 --- a/public/js/all-web.js +++ b/public/js/all-web.js @@ -139,8 +139,7 @@ wn.re_route={} wn.route=function(){if(wn.re_route[window.location.hash]){var re_route_val=wn.get_route_str(wn.re_route[window.location.hash]);var cur_route_val=wn.get_route_str(wn._cur_route);if(decodeURIComponent(re_route_val)===decodeURIComponent(cur_route_val)){window.history.back();return;}else{window.location.hash=wn.re_route[window.location.hash];}} wn._cur_route=window.location.hash;route=wn.get_route();switch(route[0]){case"List":wn.views.doclistview.show(route[1]);break;case"Form":if(route.length>3){route[2]=route.splice(2).join('/');} wn.views.formview.show(route[1],route[2]);break;case"Report":wn.views.reportview.show(route[1],route[2]);break;case"Report2":wn.views.reportview2.show();break;default:wn.views.pageview.show(route[0]);}} -wn.get_route=function(route){if(!wn.boot){return[window.page_name];} -return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});} +wn.get_route=function(route){return $.map(wn.get_route_str(route).split('/'),function(r){return decodeURIComponent(r);});} wn.get_route_str=function(route){if(!route) route=window.location.hash;if(route.substr(0,1)=='#')route=route.substr(1);if(route.substr(0,1)=='!')route=route.substr(1);return route;} wn.set_route=function(){route=$.map(arguments,function(a){return encodeURIComponent(a)}).join('/');window.location.hash=route;wn.app.set_favicon();} diff --git a/public/js/product_category.js b/public/js/product_category.js index aac872f16d5..da50d78ac9e 100644 --- a/public/js/product_category.js +++ b/public/js/product_category.js @@ -3,5 +3,8 @@ * erpnext/website/js/product_category.js */ erpnext.make_product_categories=function(wrapper){wrapper.category_list=new wn.ui.Listing({parent:$(wrapper).find('.more-categories').get(0),query:'select count(name) as items, item_group \ - from tabItem where is_sales_item="Yes" \ - group by item_group order by items desc',hide_refresh:true,render_row:function(parent,data){parent.innerHTML=repl('%(item_group)s (%(items)s)',data);}});wrapper.category_list.run();} \ No newline at end of file + from tabItem \ + where is_sales_item="Yes" and \ + ifnull(show_in_website, "No")="Yes" and \ + docstatus = 0 \ + group by item_group order by items desc',hide_refresh:true,render_row:function(parent,data){parent.innerHTML=repl('%(item_group)s (%(items)s)',data);}});wrapper.category_list.run();console.log('product categories made');} \ No newline at end of file diff --git a/public/web.py b/public/web.py index 6f3569e3279..e70b61cd55a 100755 --- a/public/web.py +++ b/public/web.py @@ -48,13 +48,26 @@ def get_html(page_name): page_name = scrub_page_name(page_name) if page_name == '404': - comments = """error: %s""" % webnotes.getTraceback() - template = '404.html' + traceback = webnotes.getTraceback() + + # script is used to display traceback in error console + args = { + 'comments': """error: %s""" % traceback, + 'template': '404.html', + } + # 'script': """(function() { + # var error = "ERROR: %s"; + # console.log(error); + # })();""" % traceback.replace('"', '\\"').replace('\n', ' \\\n'), + # } + else: - comments = """page: %s""" % page_name - template = 'page.html' + args = { + 'comments': """page: %s""" % page_name, + 'template': 'page.html', + } - html = website.web_cache.load_from_web_cache(page_name, comments, template) + html = website.web_cache.load_from_web_cache(page_name, **args) return html