701
.. topic:: Exercise - Usage of QWeb in Widgets
703
Create a widget whose constructor contains two parameters aside from ``parent``: ``product_names`` and ``color``.
704
``product_names`` is a list of strings, each one being a name of product. ``color`` is a string containing a color
705
in CSS color format (ie: ``#000000`` for black). That widget should display the given product names one under the
706
other, each one in a separate box with a background color with the value of ``color`` and a border. You must use
707
QWeb to render the HTML. This exercise will necessitate some CSS that you should put in
708
``oepetstore/static/src/css/petstore.css``. Display that widget in the ``HomePage`` widget with a list of five
709
products and green as the background color for boxes.
711
.. only:: not nosolutions
717
openerp.oepetstore = function(instance) {
718
var _t = instance.web._t,
719
_lt = instance.web._lt;
720
var QWeb = instance.web.qweb;
722
instance.oepetstore = {};
724
instance.oepetstore.HomePage = instance.web.Widget.extend({
726
var products = new instance.oepetstore.ProductsWidget(this, ["cpu", "mouse", "keyboard", "graphic card", "screen"], "#00FF00");
727
products.appendTo(this.$el);
731
instance.oepetstore.ProductsWidget = instance.web.Widget.extend({
732
template: "ProductsWidget",
733
init: function(parent, products, color) {
735
this.products = products;
740
instance.web.client_actions.add('petstore.homepage', 'instance.oepetstore.HomePage');
745
<?xml version="1.0" encoding="UTF-8"?>
747
<templates xml:space="preserve">
748
<t t-name="ProductsWidget">
750
<t t-foreach="widget.products" t-as="product">
751
<span class="oe_products_item" t-att-style="'background-color: ' + widget.color + ';'"><t t-esc="product"/></span><br/>
760
display: inline-block;
763
border: 1px solid black;
767
.. image:: img/qweb.png
b'\\ No newline at end of file'