From 75b5fb12bf0a1003a33fb34fd9782cb4525167f6 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 8 Nov 2011 17:38:24 +0100 Subject: [PATCH 01/13] [imp] nivified NumpadView bzr revid: nicolas.vanhoren@openerp.com-20111108163824-scthlsj4ej2z5pp2 --- addons/point_of_sale/static/src/js/pos.js | 53 ++++++++++------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 59c13e0553c..8f58122dd8b 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -163,7 +163,7 @@ openerp.point_of_sale = function(db) { var pos; var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryView, - NumpadState, NumpadView, Order, OrderButtonView, OrderCollection, OrderView, Orderline, + NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderView, Orderline, OrderlineCollection, OrderlineView, PaymentButtonView, PaymentView, Paymentline, PaymentlineCollection, PaymentlineView, PaypadView, Product, ProductCollection, ProductListView, ProductView, ReceiptLineView, ReceiptView, Shop, ShopView, StepsView; @@ -530,41 +530,36 @@ openerp.point_of_sale = function(db) { Views --- */ - NumpadView = (function() { - __extends(NumpadView, Backbone.View); - function NumpadView() { - NumpadView.__super__.constructor.apply(this, arguments); - } - - NumpadView.prototype.initialize = function(options) { - return this.state = options.state; - }; - NumpadView.prototype.events = { - 'click button#numpad-backspace': 'clickDeleteLastChar', - 'click button#numpad-minus': 'clickSwitchSign', - 'click button.number-char': 'clickAppendNewChar', - 'click button.mode-button': 'clickChangeMode' - }; - NumpadView.prototype.clickDeleteLastChar = function() { + NumpadWidget = db.web.Widget.extend({ + init: function(parent, element_id, options) { + this._super(parent, element_id); + this.state = options.state; + }, + start: function() { + this.$element.find('button#numpad-backspace').click(__bind(this.clickDeleteLastChar, this)); + this.$element.find('button#numpad-minus').click(__bind(this.clickSwitchSign, this)); + this.$element.find('button.number-char').click(__bind(this.clickAppendNewChar, this)); + this.$element.find('button.mode-button').click(__bind(this.clickChangeMode, this)); + }, + clickDeleteLastChar: function() { return this.state.deleteLastChar(); - }; - NumpadView.prototype.clickSwitchSign = function() { + }, + clickSwitchSign: function() { return this.state.switchSign(); - }; - NumpadView.prototype.clickAppendNewChar = function(event) { + }, + clickAppendNewChar: function(event) { var newChar; newChar = event.currentTarget.innerText; return this.state.appendNewChar(newChar); - }; - NumpadView.prototype.clickChangeMode = function(event) { + }, + clickChangeMode: function(event) { var newMode; $('.selected-mode').removeClass('selected-mode'); $(event.currentTarget).addClass('selected-mode'); newMode = event.currentTarget.attributes['data-mode'].nodeValue; return this.state.changeMode(newMode); - }; - return NumpadView; - })(); + } + }); /* Gives access to the payment methods (aka. 'cash registers') */ @@ -1108,10 +1103,10 @@ openerp.point_of_sale = function(db) { shop: this.shop, el: $('#receipt-screen') }); - this.numpadView = new NumpadView({ - state: this.numpadState, - el: $('#numpad') + this.numpadView = new NumpadWidget(null, 'numpad', { + state: this.numpadState }); + this.numpadView.start(); return this.stepsView = new StepsView({ el: $('#steps') }); From 0947c0e555f50d9e63e03c3e7d92fc4d4a7dec71 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 9 Nov 2011 11:15:41 +0100 Subject: [PATCH 02/13] [imp] widgetified PaypadView bzr revid: nicolas.vanhoren@openerp.com-20111109101541-akyu15jm6qfg7lr8 --- addons/point_of_sale/static/src/js/pos.js | 51 ++++++++++------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 8f58122dd8b..0d86f7ecf8a 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -536,10 +536,10 @@ openerp.point_of_sale = function(db) { this.state = options.state; }, start: function() { - this.$element.find('button#numpad-backspace').click(__bind(this.clickDeleteLastChar, this)); - this.$element.find('button#numpad-minus').click(__bind(this.clickSwitchSign, this)); - this.$element.find('button.number-char').click(__bind(this.clickAppendNewChar, this)); - this.$element.find('button.mode-button').click(__bind(this.clickChangeMode, this)); + this.$element.find('button#numpad-backspace').click(_.bind(this.clickDeleteLastChar, this)); + this.$element.find('button#numpad-minus').click(_.bind(this.clickSwitchSign, this)); + this.$element.find('button.number-char').click(_.bind(this.clickAppendNewChar, this)); + this.$element.find('button.mode-button').click(_.bind(this.clickChangeMode, this)); }, clickDeleteLastChar: function() { return this.state.deleteLastChar(); @@ -563,19 +563,15 @@ openerp.point_of_sale = function(db) { /* Gives access to the payment methods (aka. 'cash registers') */ - PaypadView = (function() { - __extends(PaypadView, Backbone.View); - function PaypadView() { - PaypadView.__super__.constructor.apply(this, arguments); - } - - PaypadView.prototype.initialize = function(options) { - return this.shop = options.shop; - }; - PaypadView.prototype.events = { - 'click button': 'performPayment' - }; - PaypadView.prototype.performPayment = function(event) { + PaypadWidget = db.web.Widget.extend({ + init: function(parent, element_id, options) { + this._super(parent, element_id); + this.shop = options.shop; + }, + start: function() { + this.$element.find('button').click(_.bind(this.performPayment, this)); + }, + performPayment: function(event) { var cashRegister, cashRegisterCollection, cashRegisterId; /* set correct view */ $('.step-screen').hide(); @@ -587,17 +583,16 @@ openerp.point_of_sale = function(db) { return (item.get('id')) === parseInt(cashRegisterId, 10); }, this)); return (this.shop.get('selectedOrder')).addPaymentLine(cashRegister); - }; - PaypadView.prototype.render = function() { - $(this.el).empty(); + }, + display: function() { + this.$element.empty(); return (this.shop.get('cashRegisters')).each(__bind( function(cashRegister) { - return $(this.el).append((new PaymentButtonView({ + return this.$element.append((new PaymentButtonView({ model: cashRegister })).render()); }, this)); - }; - return PaypadView; - })(); + } + }); PaymentButtonView = (function() { __extends(PaymentButtonView, Backbone.View); function PaymentButtonView() { @@ -1085,11 +1080,11 @@ openerp.point_of_sale = function(db) { this.productListView = new ProductListView({ shop: this.shop }); - this.paypadView = new PaypadView({ - shop: this.shop, - el: $('#paypad') + this.paypadView = new PaypadWidget(null, 'paypad', { + shop: this.shop }); - this.paypadView.render(); + this.paypadView.display(); + this.paypadView.start(); this.orderView = new OrderView({ shop: this.shop, numpadState: this.numpadState, From 526d8e32dd775bd3844adcc57128128c1f70235f Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 9 Nov 2011 16:11:59 +0100 Subject: [PATCH 03/13] [imp] widgetified payment button + strenghtened core framework for easier compatiblity with backbone bzr revid: nicolas.vanhoren@openerp.com-20111109151159-zruqnyb0kgu9oqpz --- addons/point_of_sale/static/src/js/pos.js | 29 ++++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 0d86f7ecf8a..d9e5575ad3f 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -584,30 +584,25 @@ openerp.point_of_sale = function(db) { }, this)); return (this.shop.get('selectedOrder')).addPaymentLine(cashRegister); }, - display: function() { + render_element: function() { this.$element.empty(); return (this.shop.get('cashRegisters')).each(__bind( function(cashRegister) { - return this.$element.append((new PaymentButtonView({ - model: cashRegister - })).render()); + var button = new PaymentButtonWidget(); + button.model = cashRegister; + button.appendTo(this.$element); }, this)); } }); - PaymentButtonView = (function() { - __extends(PaymentButtonView, Backbone.View); - function PaymentButtonView() { - PaymentButtonView.__super__.constructor.apply(this, arguments); - } - - PaymentButtonView.prototype.template = qweb_template('pos-payment-button-template'); - PaymentButtonView.prototype.render = function() { - return $(this.el).html(this.template({ + PaymentButtonWidget = db.web.Widget.extend({ + template_fct: qweb_template('pos-payment-button-template'), + render_element: function() { + this.$element.html(this.template_fct({ id: this.model.get('id'), name: (this.model.get('journal_id'))[1] })); - }; - return PaymentButtonView; - })(); + return this; + } + }); /* There are 3 steps in a POS workflow: 1. prepare the order (i.e. chose products, quantities etc.) @@ -1083,7 +1078,7 @@ openerp.point_of_sale = function(db) { this.paypadView = new PaypadWidget(null, 'paypad', { shop: this.shop }); - this.paypadView.display(); + this.paypadView.render_element(); this.paypadView.start(); this.orderView = new OrderView({ shop: this.shop, From 5503571ace9f877b8481a4719795e21488c1284b Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 9 Nov 2011 16:19:41 +0100 Subject: [PATCH 04/13] [imp] widgetified steps view bzr revid: nicolas.vanhoren@openerp.com-20111109151941-crdnkufr4nxtpccg --- addons/point_of_sale/static/src/js/pos.js | 32 +++++++++-------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index d9e5575ad3f..92769f6deeb 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -611,27 +611,22 @@ openerp.point_of_sale = function(db) { It should be possible to go back to any step as long as step 3 hasn't been completed. Modifying an order after validation shouldn't be allowed. */ - StepsView = (function() { - __extends(StepsView, Backbone.View); - function StepsView() { - StepsView.__super__.constructor.apply(this, arguments); - } - - StepsView.prototype.initialize = function(options) { - return this.step = "products"; - }; - StepsView.prototype.events = { - 'click input.step-button': 'clickChangeStep' - }; - StepsView.prototype.clickChangeStep = function(event) { + StepsWidget = db.web.Widget.extend({ + init: function(parent, element_id) { + this._super(parent, element_id); + this.step = "products"; + }, + start: function() { + this.$element.find('input.step-button').click(_.bind(this.clickChangeStep, this)); + }, + clickChangeStep: function(event) { var newStep; newStep = event.currentTarget.attributes['data-step'].nodeValue; $('.step-screen').hide(); $('#' + newStep + '-screen').show(); return this.step = newStep; - }; - return StepsView; - })(); + } + }); /* Shopping carts. */ @@ -1097,9 +1092,8 @@ openerp.point_of_sale = function(db) { state: this.numpadState }); this.numpadView.start(); - return this.stepsView = new StepsView({ - el: $('#steps') - }); + this.stepsView = new StepsWidget(null, 'steps'); + this.stepsView.start(); }; ShopView.prototype.events = { 'click button#neworder-button': 'createNewOrder' From 15baa78e04767585a636758be4aa87186278c423 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 9 Nov 2011 16:38:02 +0100 Subject: [PATCH 05/13] [imp] widgetified order line bzr revid: nicolas.vanhoren@openerp.com-20111109153802-ghctc2spt882b9nk --- addons/point_of_sale/static/src/js/pos.js | 66 +++++++++++------------ 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 92769f6deeb..061f8b7f383 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -164,9 +164,9 @@ openerp.point_of_sale = function(db) { var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryView, NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderView, Orderline, - OrderlineCollection, OrderlineView, PaymentButtonView, PaymentView, Paymentline, - PaymentlineCollection, PaymentlineView, PaypadView, Product, ProductCollection, - ProductListView, ProductView, ReceiptLineView, ReceiptView, Shop, ShopView, StepsView; + OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentView, Paymentline, + PaymentlineCollection, PaymentlineView, PaypadWidget, Product, ProductCollection, + ProductListView, ProductView, ReceiptLineView, ReceiptView, Shop, ShopView, StepsWidget; /* --- @@ -630,45 +630,41 @@ openerp.point_of_sale = function(db) { /* Shopping carts. */ - OrderlineView = (function() { - __extends(OrderlineView, Backbone.View); - function OrderlineView() { - OrderlineView.__super__.constructor.apply(this, arguments); - } - - OrderlineView.prototype.tagName = 'tr'; - OrderlineView.prototype.template = qweb_template('pos-orderline-template'); - OrderlineView.prototype.initialize = function(options) { + OrderlineWidget = db.web.Widget.extend({ + tagName: 'tr', + template_fct: qweb_template('pos-orderline-template'), + init: function(parent, element_id, options) { + this._super(parent, element_id); + this.model = options.model; this.model.bind('change', __bind( function() { - $(this.el).hide(); - return this.render(); + this.$element.hide(); + this.render_element(); }, this)); this.model.bind('remove', __bind( function() { - return $(this.el).remove(); + return this.$element.remove(); }, this)); this.order = options.order; - return this.numpadState = options.numpadState; - }; - OrderlineView.prototype.events = { - 'click': 'clickHandler' - }; - OrderlineView.prototype.clickHandler = function() { + this.numpadState = options.numpadState; + }, + start: function() { + this.$element.click(_.bind(this.clickHandler, this)); + }, + clickHandler: function() { this.numpadState.reset(); return this.select(); - }; - OrderlineView.prototype.render = function() { + }, + render_element: function() { this.select(); - return $(this.el).html(this.template(this.model.toJSON())).fadeIn(400, function() { + return this.$element.html(this.template_fct(this.model.toJSON())).fadeIn(400, function() { return $('#current-order').scrollTop($(this).offset().top); }); - }; - OrderlineView.prototype.select = function() { + }, + select: function() { $('tr.selected').removeClass('selected'); - $(this.el).addClass('selected'); + this.$element.addClass('selected'); return this.order.selected = this.model; - }; - return OrderlineView; - })(); + }, + }); OrderView = (function() { __extends(OrderView, Backbone.View); function OrderView() { @@ -693,21 +689,23 @@ openerp.point_of_sale = function(db) { return this.currentOrderLines.bind('remove', this.render, this); }; OrderView.prototype.addLine = function(newLine) { - $(this.el).append((new OrderlineView({ + var line = new OrderlineWidget(null, null, { model: newLine, order: this.shop.get('selectedOrder'), numpadState: this.numpadState - })).render()); + }); + line.appendTo($(this.el)); return this.updateSummary(); }; OrderView.prototype.render = function() { $(this.el).empty(); this.currentOrderLines.each(__bind( function(orderLine) { - return $(this.el).append((new OrderlineView({ + var line = new OrderlineWidget(null, null, { model: orderLine, order: this.shop.get('selectedOrder'), numpadState: this.numpadState - })).render()); + }); + line.appendTo($(this.el)); }, this)); return this.updateSummary(); }; From efc28d1925c1f37526215f65b27b534026ae7beb Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 9 Nov 2011 17:08:41 +0100 Subject: [PATCH 06/13] [imp] widgetified order view bzr revid: nicolas.vanhoren@openerp.com-20111109160841-3u7l2bqmysg065n1 --- addons/point_of_sale/static/src/js/pos.js | 55 +++++++++++------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 061f8b7f383..d9ed87f4ae9 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -163,7 +163,7 @@ openerp.point_of_sale = function(db) { var pos; var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryView, - NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderView, Orderline, + NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderWidget, Orderline, OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentView, Paymentline, PaymentlineCollection, PaymentlineView, PaypadWidget, Product, ProductCollection, ProductListView, ProductView, ReceiptLineView, ReceiptView, Shop, ShopView, StepsWidget; @@ -665,51 +665,47 @@ openerp.point_of_sale = function(db) { return this.order.selected = this.model; }, }); - OrderView = (function() { - __extends(OrderView, Backbone.View); - function OrderView() { - OrderView.__super__.constructor.apply(this, arguments); - } - - OrderView.prototype.initialize = function(options) { + OrderWidget = db.web.Widget.extend({ + init: function(parent, element_id, options) { + this._super(parent, element_id); this.shop = options.shop; this.numpadState = options.numpadState; this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); - return this.bindOrderLineEvents(); - }; - OrderView.prototype.changeSelectedOrder = function() { + this.bindOrderLineEvents(); + }, + changeSelectedOrder: function() { this.currentOrderLines.unbind(); this.bindOrderLineEvents(); - return this.render(); - }; - OrderView.prototype.bindOrderLineEvents = function() { + return this.render_element(); + }, + bindOrderLineEvents: function() { this.currentOrderLines = (this.shop.get('selectedOrder')).get('orderLines'); this.currentOrderLines.bind('add', this.addLine, this); - this.currentOrderLines.bind('change', this.render, this); + this.currentOrderLines.bind('change', this.render_element, this); return this.currentOrderLines.bind('remove', this.render, this); - }; - OrderView.prototype.addLine = function(newLine) { + }, + addLine: function(newLine) { var line = new OrderlineWidget(null, null, { model: newLine, order: this.shop.get('selectedOrder'), numpadState: this.numpadState }); - line.appendTo($(this.el)); + line.appendTo(this.$element); return this.updateSummary(); - }; - OrderView.prototype.render = function() { - $(this.el).empty(); + }, + render_element: function() { + this.$element.empty(); this.currentOrderLines.each(__bind( function(orderLine) { var line = new OrderlineWidget(null, null, { model: orderLine, order: this.shop.get('selectedOrder'), numpadState: this.numpadState }); - line.appendTo($(this.el)); + line.appendTo(this.$element); }, this)); return this.updateSummary(); - }; - OrderView.prototype.updateSummary = function() { + }, + updateSummary: function() { var currentOrder, tax, total, totalTaxExcluded; currentOrder = this.shop.get('selectedOrder'); total = currentOrder.getTotal(); @@ -718,9 +714,8 @@ openerp.point_of_sale = function(db) { $('#subtotal').html(totalTaxExcluded.toFixed(2)).hide().fadeIn(); $('#tax').html(tax.toFixed(2)).hide().fadeIn(); return $('#total').html(total.toFixed(2)).hide().fadeIn(); - }; - return OrderView; - })(); + }, + }); /* "Products" step. */ @@ -1073,11 +1068,11 @@ openerp.point_of_sale = function(db) { }); this.paypadView.render_element(); this.paypadView.start(); - this.orderView = new OrderView({ + this.orderView = new OrderWidget(null, 'current-order-content', { shop: this.shop, - numpadState: this.numpadState, - el: $('#current-order-content') + numpadState: this.numpadState }); + this.orderView.start(); this.paymentView = new PaymentView({ shop: this.shop, el: $('#payment-screen') From 48bd70a64a99239c59057e44ef263a9136de8091 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 17 Nov 2011 13:09:56 +0530 Subject: [PATCH 07/13] [imp] nivified category view bzr revid: nicolas.vanhoren@openerp.com-20111117073956-m0u6ehdd0lg9o71g --- addons/point_of_sale/static/src/js/pos.js | 52 +++++++++++------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index d9ed87f4ae9..609641fc913 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -719,25 +719,20 @@ openerp.point_of_sale = function(db) { /* "Products" step. */ - CategoryView = (function() { - __extends(CategoryView, Backbone.View); - function CategoryView() { - CategoryView.__super__.constructor.apply(this, arguments); - } - - CategoryView.prototype.events = { - 'click .oe-pos-categories-list a': 'changeCategory' - }; - - CategoryView.prototype.template = qweb_template('pos-category-template'); - CategoryView.prototype.render = function(ancestors, children) { + CategoryWidget = db.web.Widget.extend({ + start: function() { + this.$element.find(".oe-pos-categories-list a").click(_.bind(this.changeCategory, this)); + }, + template_fct: qweb_template('pos-category-template'), + render_element: function() { + var self = this; var c; - return $(this.el).html(this.template({ + this.$element.html(this.template_fct({ breadcrumb: (function() { var _i, _len, _results; _results = []; - for (_i = 0, _len = ancestors.length; _i < _len; _i++) { - c = ancestors[_i]; + for (_i = 0, _len = self.ancestors.length; _i < _len; _i++) { + c = self.ancestors[_i]; _results.push(pos.categories[c]); } return _results; @@ -745,20 +740,20 @@ openerp.point_of_sale = function(db) { categories: (function() { var _i, _len, _results; _results = []; - for (_i = 0, _len = children.length; _i < _len; _i++) { - c = children[_i]; + for (_i = 0, _len = self.children.length; _i < _len; _i++) { + c = self.children[_i]; _results.push(pos.categories[c]); } return _results; })() })); - }; - CategoryView.prototype.changeCategory = function(a) { + }, + changeCategory: function(a) { var id = $(a.target).data("category-id"); - this.trigger("changeCategory", id); - }; - return CategoryView; - })(); + this.on_change_category(id); + }, + on_change_category: function(id) {}, + }); ProductView = (function() { __extends(ProductView, Backbone.View); function ProductView() { @@ -1121,10 +1116,9 @@ openerp.point_of_sale = function(db) { shop: this.shop, el: $element }); - this.categoryView = new CategoryView; - this.categoryView.bind("changeCategory", this.category, this); + this.categoryView = new CategoryWidget(null, 'products-screen'); + this.categoryView.on_change_category.add_last(_.bind(this.category, this)); this.category(); - return this.categoryView; }; App.prototype.category = function(id) { var c, products; @@ -1132,8 +1126,10 @@ openerp.point_of_sale = function(db) { id = 0; } c = pos.categories[id]; - $('#products-screen').html(this.categoryView.render(c.ancestors, c.children)); - this.categoryView.delegateEvents(); + this.categoryView.ancestors = c.ancestors; + this.categoryView.children = c.children; + this.categoryView.render_element(); + this.categoryView.start(); products = pos.store.get('product.product').filter( function(p) { var _ref; return _ref = p.pos_categ_id[0], __indexOf.call(c.subtree, _ref) >= 0; From 207933a632d36394c85de225ec4aea80a1c5808e Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Thu, 17 Nov 2011 17:04:10 +0530 Subject: [PATCH 08/13] [imp] nivified product view bzr revid: nicolas.vanhoren@openerp.com-20111117113410-c8coka92ujkrqufv --- addons/point_of_sale/static/src/js/pos.js | 50 +++++++++++------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 609641fc913..d4fbfc6f6ed 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -162,11 +162,11 @@ openerp.point_of_sale = function(db) { /* global variable */ var pos; - var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryView, + var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryWidget, NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderWidget, Orderline, OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentView, Paymentline, PaymentlineCollection, PaymentlineView, PaypadWidget, Product, ProductCollection, - ProductListView, ProductView, ReceiptLineView, ReceiptView, Shop, ShopView, StepsWidget; + ProductListView, ProductWidget, ReceiptLineView, ReceiptView, Shop, ShopView, StepsWidget; /* --- @@ -754,31 +754,28 @@ openerp.point_of_sale = function(db) { }, on_change_category: function(id) {}, }); - ProductView = (function() { - __extends(ProductView, Backbone.View); - function ProductView() { - ProductView.__super__.constructor.apply(this, arguments); - } - - ProductView.prototype.tagName = 'li'; - ProductView.prototype.className = 'product'; - ProductView.prototype.template = qweb_template('pos-product-template'); - ProductView.prototype.events = { - 'click a': 'addToOrder' - }; - ProductView.prototype.initialize = function(options) { - return this.shop = options.shop; - }; - ProductView.prototype.addToOrder = function(event) { + ProductWidget = db.web.Widget.extend({ + tag_name:'li', + template_fct: qweb_template('pos-product-template'), + init: function(parent, element_id, options) { + this._super(parent, element_id); + this.model = options.model; + this.shop = options.shop; + }, + start: function(options) { + $("a", this.$element).click(_.bind(this.addToOrder, this)); + }, + addToOrder: function(event) { /* Preserve the category URL */ event.preventDefault(); return (this.shop.get('selectedOrder')).addProduct(this.model); - }; - ProductView.prototype.render = function() { - return $(this.el).html(this.template(this.model.toJSON())); - }; - return ProductView; - })(); + }, + render_element: function() { + this.$element.addClass("product"); + this.$element.html(this.template_fct(this.model.toJSON())); + return this; + }, + }); ProductListView = (function() { __extends(ProductListView, Backbone.View); function ProductListView() { @@ -794,10 +791,11 @@ openerp.point_of_sale = function(db) { ProductListView.prototype.render = function() { $(this.el).empty(); (this.shop.get('products')).each(__bind( function(product) { - return $(this.el).append((new ProductView({ + var p = new ProductWidget(null, null, { model: product, shop: this.shop - })).render()); + }); + p.appendTo($(this.el)); }, this)); return $('#products-screen').append(this.el); }; From 263ff95a19e236ba5707790ca1c8650a940abcb0 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 21 Nov 2011 17:06:17 +0530 Subject: [PATCH 09/13] [imp] nivified product list bzr revid: nicolas.vanhoren@openerp.com-20111121113617-75h2d5ka302rnf3c --- addons/point_of_sale/static/src/js/pos.js | 41 ++++++++++----------- addons/point_of_sale/static/src/xml/pos.xml | 5 ++- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index d4fbfc6f6ed..2a66005af2c 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -166,7 +166,7 @@ openerp.point_of_sale = function(db) { NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderWidget, Orderline, OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentView, Paymentline, PaymentlineCollection, PaymentlineView, PaypadWidget, Product, ProductCollection, - ProductListView, ProductWidget, ReceiptLineView, ReceiptView, Shop, ShopView, StepsWidget; + ProductListWidget, ProductWidget, ReceiptLineView, ReceiptView, Shop, ShopView, StepsWidget; /* --- @@ -776,31 +776,24 @@ openerp.point_of_sale = function(db) { return this; }, }); - ProductListView = (function() { - __extends(ProductListView, Backbone.View); - function ProductListView() { - ProductListView.__super__.constructor.apply(this, arguments); - } - - ProductListView.prototype.tagName = 'ol'; - ProductListView.prototype.className = 'product-list'; - ProductListView.prototype.initialize = function(options) { + ProductListWidget = db.web.Widget.extend({ + init: function(parent, element_id, options) { + this._super(parent, element_id); this.shop = options.shop; - return (this.shop.get('products')).bind('reset', this.render, this); - }; - ProductListView.prototype.render = function() { - $(this.el).empty(); + this.shop.get('products').bind('reset', this.render_element, this); + }, + render_element: function() { + this.$element.empty(); (this.shop.get('products')).each(__bind( function(product) { var p = new ProductWidget(null, null, { model: product, shop: this.shop }); - p.appendTo($(this.el)); + p.appendTo(this.$element); }, this)); - return $('#products-screen').append(this.el); - }; - return ProductListView; - })(); + return this; + }, + }); /* "Payment" step. */ @@ -1053,9 +1046,11 @@ openerp.point_of_sale = function(db) { this.numpadState = new NumpadState({ shop: this.shop }); - this.productListView = new ProductListView({ + this.productListView = new ProductListWidget(null, "products-screen-ol", { shop: this.shop }); + this.productListView.render_element(); + this.productListView.start(); this.paypadView = new PaypadWidget(null, 'paypad', { shop: this.shop }); @@ -1080,10 +1075,14 @@ openerp.point_of_sale = function(db) { this.numpadView.start(); this.stepsView = new StepsWidget(null, 'steps'); this.stepsView.start(); + this.start(); }; ShopView.prototype.events = { 'click button#neworder-button': 'createNewOrder' }; + ShopView.prototype.start = function() { + this.productListView.start(); + }; ShopView.prototype.createNewOrder = function() { var newOrder; newOrder = new Order; @@ -1114,7 +1113,7 @@ openerp.point_of_sale = function(db) { shop: this.shop, el: $element }); - this.categoryView = new CategoryWidget(null, 'products-screen'); + this.categoryView = new CategoryWidget(null, 'products-screen-categories'); this.categoryView.on_change_category.add_last(_.bind(this.category, this)); this.category(); }; diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index b9148395cbe..feeec5bdc4c 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -88,7 +88,10 @@
-
+
+
+
    +
    - +
    @@ -240,4 +219,28 @@ + + + \ No newline at end of file