From d8bae900d1c58aa40c00891fa55e8664d0c0a0b3 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 15:46:59 +0100 Subject: [PATCH 1/7] [imp] nivified one more view bzr revid: nicolas.vanhoren@openerp.com-20111206144659-x2wfjupne5gxe8o9 --- addons/point_of_sale/static/src/js/pos.js | 70 +++++++++++------------ 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index d1611cd87d8..a6d1bacf204 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, CategoryWidget, - NumpadState, NumpadWidget, Order, OrderButtonView, OrderCollection, OrderWidget, Orderline, + NumpadState, NumpadWidget, Order, OrderButtonWidget, OrderCollection, OrderWidget, Orderline, OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentWidget, Paymentline, PaymentlineCollection, PaymentlineWidget, PaypadWidget, Product, ProductCollection, ProductListWidget, ProductWidget, ReceiptLineWidget, ReceiptWidget, Shop, ShopView, StepsWidget; @@ -977,50 +977,45 @@ openerp.point_of_sale = function(db) { $('#receipt-summary-change').html(change.toFixed(2)); }, }); - OrderButtonView = (function() { - __extends(OrderButtonView, Backbone.View); - function OrderButtonView() { - OrderButtonView.__super__.constructor.apply(this, arguments); - } - - OrderButtonView.prototype.tagName = 'li'; - OrderButtonView.prototype.className = 'order-selector-button'; - OrderButtonView.prototype.template = qweb_template('pos-order-selector-button-template'); - OrderButtonView.prototype.initialize = function(options) { + OrderButtonWidget = db.web.Widget.extend({ + tag_name: 'li', + template_fct: qweb_template('pos-order-selector-button-template'), + init: function(parent, options) { + this._super(parent); this.order = options.order; this.shop = options.shop; - this.order.bind('destroy', __bind( function() { - return $(this.el).remove(); + this.order.bind('destroy', _.bind( function() { + return this.stop(); }, this)); - return this.shop.bind('change:selectedOrder', __bind( function(shop) { + this.shop.bind('change:selectedOrder', _.bind( function(shop) { var selectedOrder; selectedOrder = shop.get('selectedOrder'); if (this.order === selectedOrder) { - return this.setButtonSelected(); + this.setButtonSelected(); } }, this)); - }; - OrderButtonView.prototype.events = { - 'click button.select-order': 'selectOrder', - 'click button.close-order': 'closeOrder' - }; - OrderButtonView.prototype.selectOrder = function(event) { - return this.shop.set({ + }, + start: function() { + $('button.select-order', this.$element).click(_.bind(this.selectOrder, this)); + $('button.close-order', this.$element).click(_.bind(this.closeOrder, this)); + }, + selectOrder: function(event) { + this.shop.set({ selectedOrder: this.order }); - }; - OrderButtonView.prototype.setButtonSelected = function() { + }, + setButtonSelected: function() { $('.selected-order').removeClass('selected-order'); - return $(this.el).addClass('selected-order'); - }; - OrderButtonView.prototype.closeOrder = function(event) { - return this.order.destroy(); - }; - OrderButtonView.prototype.render = function() { - return $(this.el).html(this.template(this.order.toJSON())); - }; - return OrderButtonView; - })(); + this.$element.addClass('selected-order'); + }, + closeOrder: function(event) { + this.order.destroy(); + }, + render_element: function() { + this.$element.html(this.template_fct(this.order.toJSON())); + this.$element.addClass('order-selector-button'); + } + }); ShopView = (function() { __extends(ShopView, Backbone.View); function ShopView() { @@ -1057,7 +1052,6 @@ openerp.point_of_sale = function(db) { this.receiptView = new ReceiptWidget(null, { shop: this.shop, }); - debugger; this.receiptView.replace($('#receipt-screen')); this.numpadView = new NumpadWidget(null, 'numpad', { state: this.numpadState @@ -1083,12 +1077,12 @@ openerp.point_of_sale = function(db) { }; ShopView.prototype.orderAdded = function(newOrder) { var newOrderButton; - newOrderButton = new OrderButtonView({ + newOrderButton = new OrderButtonWidget(null, { order: newOrder, shop: this.shop }); - $('#orders').append(newOrderButton.render()); - return newOrderButton.selectOrder(); + newOrderButton.appendTo($('#orders')); + newOrderButton.selectOrder(); }; return ShopView; })(); From d4f8cf113fcf3ab5432d033d374523059531c4d5 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 16:38:24 +0100 Subject: [PATCH 2/7] [imp] nivified last component bzr revid: nicolas.vanhoren@openerp.com-20111206153824-y38w73jenxgv0vxk --- addons/point_of_sale/static/src/js/pos.js | 49 +++++++++-------------- 1 file changed, 20 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 a6d1bacf204..0498eccde4f 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, OrderButtonWidget, OrderCollection, OrderWidget, Orderline, OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentWidget, Paymentline, PaymentlineCollection, PaymentlineWidget, PaypadWidget, Product, ProductCollection, - ProductListWidget, ProductWidget, ReceiptLineWidget, ReceiptWidget, Shop, ShopView, StepsWidget; + ProductListWidget, ProductWidget, ReceiptLineWidget, ReceiptWidget, Shop, ShopWidget, StepsWidget; /* --- @@ -921,9 +921,6 @@ openerp.point_of_sale = function(db) { this.bindOrderLineEvents(); this.bindPaymentLineEvents(); }, - start: function () { - $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this)); - }, finishOrder: function() { $('.step-screen').hide(); $('#products-screen').show(); @@ -958,6 +955,7 @@ openerp.point_of_sale = function(db) { }, render_element: function() { this.$element.html(qweb_template('pos-receipt-view')); + $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this)); this.currentOrderLines.each(__bind( function(orderItem) { var x = new ReceiptLineWidget(null, { model: orderItem @@ -1016,14 +1014,14 @@ openerp.point_of_sale = function(db) { this.$element.addClass('order-selector-button'); } }); - ShopView = (function() { - __extends(ShopView, Backbone.View); - function ShopView() { - ShopView.__super__.constructor.apply(this, arguments); - } - - ShopView.prototype.initialize = function(options) { + ShopWidget = db.web.Widget.extend({ + init: function(parent, options) { + this._super(parent); this.shop = options.shop; + }, + start: function() { + $('button#neworder-button', this.$element).click(_.bind(this.createNewOrder, this)); + (this.shop.get('orders')).bind('add', this.orderAdded, this); (this.shop.get('orders')).add(new Order); this.numpadState = new NumpadState({ @@ -1059,23 +1057,16 @@ 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() { + }, + createNewOrder: function() { var newOrder; newOrder = new Order; (this.shop.get('orders')).add(newOrder); - return this.shop.set({ + this.shop.set({ selectedOrder: newOrder }); - }; - ShopView.prototype.orderAdded = function(newOrder) { + }, + orderAdded: function(newOrder) { var newOrderButton; newOrderButton = new OrderButtonWidget(null, { order: newOrder, @@ -1083,9 +1074,8 @@ openerp.point_of_sale = function(db) { }); newOrderButton.appendTo($('#orders')); newOrderButton.selectOrder(); - }; - return ShopView; - })(); + }, + }); App = (function() { function App($element) { this.initialize($element); @@ -1093,10 +1083,11 @@ openerp.point_of_sale = function(db) { App.prototype.initialize = function($element) { this.shop = new Shop; - this.shopView = new ShopView({ - shop: this.shop, - el: $element + this.shopView = new ShopWidget(null, { + shop: this.shop }); + this.shopView.$element = $element; + this.shopView.start(); this.categoryView = new CategoryWidget(null, 'products-screen-categories'); this.categoryView.on_change_category.add_last(_.bind(this.category, this)); this.category(); From 1a6fa9ca6a89aa3c3d3bc6085cd1c51e8ec36121 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 16:49:42 +0100 Subject: [PATCH 3/7] [imp] removed element_id bzr revid: nicolas.vanhoren@openerp.com-20111206154942-d7mgnewp05i1mxf3 --- addons/point_of_sale/static/src/js/pos.js | 64 +++++++++++++---------- 1 file changed, 35 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 0498eccde4f..6b1852c383d 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -531,8 +531,8 @@ openerp.point_of_sale = function(db) { --- */ NumpadWidget = db.web.Widget.extend({ - init: function(parent, element_id, options) { - this._super(parent, element_id); + init: function(parent, options) { + this._super(parent); this.state = options.state; }, start: function() { @@ -564,8 +564,8 @@ openerp.point_of_sale = function(db) { Gives access to the payment methods (aka. 'cash registers') */ PaypadWidget = db.web.Widget.extend({ - init: function(parent, element_id, options) { - this._super(parent, element_id); + init: function(parent, options) { + this._super(parent); this.shop = options.shop; }, start: function() { @@ -612,8 +612,8 @@ openerp.point_of_sale = function(db) { Modifying an order after validation shouldn't be allowed. */ StepsWidget = db.web.Widget.extend({ - init: function(parent, element_id) { - this._super(parent, element_id); + init: function(parent) { + this._super(parent); this.step = "products"; }, start: function() { @@ -633,8 +633,8 @@ openerp.point_of_sale = function(db) { 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); + init: function(parent, options) { + this._super(parent); this.model = options.model; this.model.bind('change', __bind( function() { this.$element.hide(); @@ -666,8 +666,8 @@ openerp.point_of_sale = function(db) { }, }); OrderWidget = db.web.Widget.extend({ - init: function(parent, element_id, options) { - this._super(parent, element_id); + init: function(parent, options) { + this._super(parent); this.shop = options.shop; this.numpadState = options.numpadState; this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); @@ -685,7 +685,7 @@ openerp.point_of_sale = function(db) { return this.currentOrderLines.bind('remove', this.render, this); }, addLine: function(newLine) { - var line = new OrderlineWidget(null, null, { + var line = new OrderlineWidget(null, { model: newLine, order: this.shop.get('selectedOrder'), numpadState: this.numpadState @@ -696,7 +696,7 @@ openerp.point_of_sale = function(db) { render_element: function() { this.$element.empty(); this.currentOrderLines.each(__bind( function(orderLine) { - var line = new OrderlineWidget(null, null, { + var line = new OrderlineWidget(null, { model: orderLine, order: this.shop.get('selectedOrder'), numpadState: this.numpadState @@ -757,8 +757,8 @@ openerp.point_of_sale = function(db) { 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); + init: function(parent, options) { + this._super(parent); this.model = options.model; this.shop = options.shop; }, @@ -777,8 +777,8 @@ openerp.point_of_sale = function(db) { }, }); ProductListWidget = db.web.Widget.extend({ - init: function(parent, element_id, options) { - this._super(parent, element_id); + init: function(parent, options) { + this._super(parent); this.model = options.model; this.shop = options.shop; this.shop.get('products').bind('reset', this.render_element, this); @@ -786,7 +786,7 @@ openerp.point_of_sale = function(db) { render_element: function() { this.$element.empty(); (this.shop.get('products')).each(__bind( function(product) { - var p = new ProductWidget(null, null, { + var p = new ProductWidget(null, { model: product, shop: this.shop }); @@ -801,8 +801,8 @@ openerp.point_of_sale = function(db) { PaymentlineWidget = db.web.Widget.extend({ tag_name: 'tr', template_fct: qweb_template('pos-paymentline-template'), - init: function(parent, element_id, options) { - this._super(parent, element_id); + init: function(parent, options) { + this._super(parent); this.model = options.model; this.model.bind('change', this.render_element, this); }, @@ -828,8 +828,8 @@ openerp.point_of_sale = function(db) { }, }); PaymentWidget = db.web.Widget.extend({ - init: function(parent, element_id, options) { - this._super(parent, element_id); + init: function(parent, options) { + this._super(parent); this.model = options.model; this.shop = options.shop; this.shop.bind('change:selectedOrder', this.changeSelectedOrder, this); @@ -869,7 +869,7 @@ openerp.point_of_sale = function(db) { this.render_element(); }, addPaymentLine: function(newPaymentLine) { - var x = new PaymentlineWidget(null, null, { + var x = new PaymentlineWidget(null, { model: newPaymentLine }); x.appendTo(this.paymentLineList()); @@ -877,7 +877,7 @@ openerp.point_of_sale = function(db) { render_element: function() { this.paymentLineList().empty(); this.currentPaymentLines.each(__bind( function(paymentLine) { - var x = new PaymentlineWidget(null, null, { + var x = new PaymentlineWidget(null, { model: paymentLine }); this.paymentLineList().append(x); @@ -1027,35 +1027,41 @@ openerp.point_of_sale = function(db) { this.numpadState = new NumpadState({ shop: this.shop }); - this.productListView = new ProductListWidget(null, "products-screen-ol", { + this.productListView = new ProductListWidget(null, { shop: this.shop }); + this.productListView.$element = $("#products-screen-ol"); this.productListView.render_element(); this.productListView.start(); - this.paypadView = new PaypadWidget(null, 'paypad', { + this.paypadView = new PaypadWidget(null, { shop: this.shop }); + this.paypadView.$element = $('#paypad'); this.paypadView.render_element(); this.paypadView.start(); - this.orderView = new OrderWidget(null, 'current-order-content', { + this.orderView = new OrderWidget(null, { shop: this.shop, numpadState: this.numpadState }); + this.orderView.$element = $('#current-order-content'); this.orderView.start(); - this.paymentView = new PaymentWidget(null, 'payment-screen', { + this.paymentView = new PaymentWidget(null, { shop: this.shop }); + this.paymentView.$element = $('#payment-screen'); this.paymentView.render_element(); this.paymentView.start(); this.receiptView = new ReceiptWidget(null, { shop: this.shop, }); this.receiptView.replace($('#receipt-screen')); - this.numpadView = new NumpadWidget(null, 'numpad', { + this.numpadView = new NumpadWidget(null, { state: this.numpadState }); + this.numpadView.$element = $('#numpad'); this.numpadView.start(); - this.stepsView = new StepsWidget(null, 'steps'); + this.stepsView = new StepsWidget(null); + this.stepsView.$element = $('#steps'); this.stepsView.start(); }, createNewOrder: function() { From 25bf8e867294a658c09f0ac43bbe1ac9f6286f14 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 16:57:47 +0100 Subject: [PATCH 4/7] [imp] removed some useless methods bzr revid: nicolas.vanhoren@openerp.com-20111206155747-huv425omxs6kzik1 --- addons/point_of_sale/static/src/js/pos.js | 45 ++++++++--------------- 1 file changed, 16 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 6b1852c383d..675db3ea8b6 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -1,14 +1,9 @@ openerp.point_of_sale = function(db) { + db.point_of_sale = {}; - /* Some utility functions defined by Coffee script */ - var __bind = function(fn, me) { - return function() { - return fn.apply(me, arguments); - }; - }; - var __hasProp = Object.prototype.hasOwnProperty; var __extends = function(child, parent) { + var __hasProp = Object.prototype.hasOwnProperty; for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; @@ -22,14 +17,6 @@ openerp.point_of_sale = function(db) { child.__super__ = parent.prototype; return child; }; - var __indexOf = Array.prototype.indexOf || - function(item) { - for (var i = 0, l = this.length; i < l; i++) { - if (this[i] === item) - return i; - } - return -1; - }; /* end */ var QWeb = db.web.qweb; @@ -65,7 +52,7 @@ openerp.point_of_sale = function(db) { */ var Pos = (function() { function Pos(session) { - this.build_tree = __bind(this.build_tree, this); + this.build_tree = _.bind(this.build_tree, this); this.session = session; $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']), this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'img'], [['pos_categ_id', '!=', 'false']]), @@ -386,11 +373,11 @@ openerp.point_of_sale = function(db) { Order.prototype.exportAsJSON = function() { var orderLines, paymentLines, result; orderLines = []; - (this.get('orderLines')).each(__bind( function(item) { + (this.get('orderLines')).each(_.bind( function(item) { return orderLines.push([0, 0, item.exportAsJSON()]); }, this)); paymentLines = []; - (this.get('paymentLines')).each(__bind( function(item) { + (this.get('paymentLines')).each(_.bind( function(item) { return paymentLines.push([0, 0, item.exportAsJSON()]); }, this)); result = { @@ -429,7 +416,7 @@ openerp.point_of_sale = function(db) { this.set({ cashRegisters: new CashRegisterCollection(pos.store.get('account.bank.statement')), }); - return (this.get('orders')).bind('remove', __bind( function(removedOrder) { + return (this.get('orders')).bind('remove', _.bind( function(removedOrder) { if ((this.get('orders')).isEmpty()) { this.addAndSelectOrder(new Order); } @@ -579,14 +566,14 @@ openerp.point_of_sale = function(db) { cashRegisterId = event.currentTarget.attributes['cash-register-id'].nodeValue; cashRegisterCollection = this.shop.get('cashRegisters'); - cashRegister = cashRegisterCollection.find(__bind( function(item) { + cashRegister = cashRegisterCollection.find(_.bind( function(item) { return (item.get('id')) === parseInt(cashRegisterId, 10); }, this)); return (this.shop.get('selectedOrder')).addPaymentLine(cashRegister); }, render_element: function() { this.$element.empty(); - return (this.shop.get('cashRegisters')).each(__bind( function(cashRegister) { + return (this.shop.get('cashRegisters')).each(_.bind( function(cashRegister) { var button = new PaymentButtonWidget(); button.model = cashRegister; button.appendTo(this.$element); @@ -636,11 +623,11 @@ openerp.point_of_sale = function(db) { init: function(parent, options) { this._super(parent); this.model = options.model; - this.model.bind('change', __bind( function() { + this.model.bind('change', _.bind( function() { this.$element.hide(); this.render_element(); }, this)); - this.model.bind('remove', __bind( function() { + this.model.bind('remove', _.bind( function() { return this.$element.remove(); }, this)); this.order = options.order; @@ -695,7 +682,7 @@ openerp.point_of_sale = function(db) { }, render_element: function() { this.$element.empty(); - this.currentOrderLines.each(__bind( function(orderLine) { + this.currentOrderLines.each(_.bind( function(orderLine) { var line = new OrderlineWidget(null, { model: orderLine, order: this.shop.get('selectedOrder'), @@ -785,7 +772,7 @@ openerp.point_of_sale = function(db) { }, render_element: function() { this.$element.empty(); - (this.shop.get('products')).each(__bind( function(product) { + (this.shop.get('products')).each(_.bind( function(product) { var p = new ProductWidget(null, { model: product, shop: this.shop @@ -845,7 +832,7 @@ openerp.point_of_sale = function(db) { validateCurrentOrder: function() { var callback, currentOrder; currentOrder = this.shop.get('selectedOrder'); - callback = __bind(function() { + callback = _.bind(function() { return currentOrder.set({ validated: true }); @@ -876,7 +863,7 @@ openerp.point_of_sale = function(db) { }, render_element: function() { this.paymentLineList().empty(); - this.currentPaymentLines.each(__bind( function(paymentLine) { + this.currentPaymentLines.each(_.bind( function(paymentLine) { var x = new PaymentlineWidget(null, { model: paymentLine }); @@ -956,7 +943,7 @@ openerp.point_of_sale = function(db) { render_element: function() { this.$element.html(qweb_template('pos-receipt-view')); $('button#pos-finish-order', this.$element).click(_.bind(this.finishOrder, this)); - this.currentOrderLines.each(__bind( function(orderItem) { + this.currentOrderLines.each(_.bind( function(orderItem) { var x = new ReceiptLineWidget(null, { model: orderItem }); @@ -1110,7 +1097,7 @@ openerp.point_of_sale = function(db) { 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; + return _ref = p.pos_categ_id[0], _.indexOf(c.subtree, _ref) >= 0; }); (this.shop.get('products')).reset(products); var self = this; From 02af656b3e14729ed690c9b2f312e80a00f06ea5 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 17:00:27 +0100 Subject: [PATCH 5/7] [imp] removed separate vars bzr revid: nicolas.vanhoren@openerp.com-20111206160027-kk2zcfm1i6k77zcw --- addons/point_of_sale/static/src/js/pos.js | 66 +++++++++++------------ 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 675db3ea8b6..603e9e3b649 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -149,18 +149,12 @@ openerp.point_of_sale = function(db) { /* global variable */ var pos; - var App, CashRegister, CashRegisterCollection, Category, CategoryCollection, CategoryWidget, - NumpadState, NumpadWidget, Order, OrderButtonWidget, OrderCollection, OrderWidget, Orderline, - OrderlineCollection, OrderlineWidget, PaymentButtonWidget, PaymentWidget, Paymentline, - PaymentlineCollection, PaymentlineWidget, PaypadWidget, Product, ProductCollection, - ProductListWidget, ProductWidget, ReceiptLineWidget, ReceiptWidget, Shop, ShopWidget, StepsWidget; - /* --- Models --- */ - CashRegister = (function() { + var CashRegister = (function() { __extends(CashRegister, Backbone.Model); function CashRegister() { CashRegister.__super__.constructor.apply(this, arguments); @@ -168,7 +162,7 @@ openerp.point_of_sale = function(db) { return CashRegister; })(); - CashRegisterCollection = (function() { + var CashRegisterCollection = (function() { __extends(CashRegisterCollection, Backbone.Collection); function CashRegisterCollection() { CashRegisterCollection.__super__.constructor.apply(this, arguments); @@ -177,7 +171,7 @@ openerp.point_of_sale = function(db) { CashRegisterCollection.prototype.model = CashRegister; return CashRegisterCollection; })(); - Product = (function() { + var Product = (function() { __extends(Product, Backbone.Model); function Product() { Product.__super__.constructor.apply(this, arguments); @@ -185,7 +179,7 @@ openerp.point_of_sale = function(db) { return Product; })(); - ProductCollection = (function() { + var ProductCollection = (function() { __extends(ProductCollection, Backbone.Collection); function ProductCollection() { ProductCollection.__super__.constructor.apply(this, arguments); @@ -194,7 +188,7 @@ openerp.point_of_sale = function(db) { ProductCollection.prototype.model = Product; return ProductCollection; })(); - Category = (function() { + var Category = (function() { __extends(Category, Backbone.Model); function Category() { Category.__super__.constructor.apply(this, arguments); @@ -202,7 +196,7 @@ openerp.point_of_sale = function(db) { return Category; })(); - CategoryCollection = (function() { + var CategoryCollection = (function() { __extends(CategoryCollection, Backbone.Collection); function CategoryCollection() { CategoryCollection.__super__.constructor.apply(this, arguments); @@ -217,7 +211,7 @@ openerp.point_of_sale = function(db) { To add more of the same product, just update the quantity accordingly. The Order also contains payment information. */ - Orderline = (function() { + var Orderline = (function() { __extends(Orderline, Backbone.Model); function Orderline() { Orderline.__super__.constructor.apply(this, arguments); @@ -248,7 +242,7 @@ openerp.point_of_sale = function(db) { }; return Orderline; })(); - OrderlineCollection = (function() { + var OrderlineCollection = (function() { __extends(OrderlineCollection, Backbone.Collection); function OrderlineCollection() { OrderlineCollection.__super__.constructor.apply(this, arguments); @@ -260,7 +254,7 @@ openerp.point_of_sale = function(db) { /* Every PaymentLine has all the attributes of the corresponding CashRegister. */ - Paymentline = (function() { + var Paymentline = (function() { __extends(Paymentline, Backbone.Model); function Paymentline() { Paymentline.__super__.constructor.apply(this, arguments); @@ -285,7 +279,7 @@ openerp.point_of_sale = function(db) { }; return Paymentline; })(); - PaymentlineCollection = (function() { + var PaymentlineCollection = (function() { __extends(PaymentlineCollection, Backbone.Collection); function PaymentlineCollection() { PaymentlineCollection.__super__.constructor.apply(this, arguments); @@ -294,7 +288,7 @@ openerp.point_of_sale = function(db) { PaymentlineCollection.prototype.model = Paymentline; return PaymentlineCollection; })(); - Order = (function() { + var Order = (function() { __extends(Order, Backbone.Model); function Order() { Order.__super__.constructor.apply(this, arguments); @@ -393,7 +387,7 @@ openerp.point_of_sale = function(db) { }; return Order; })(); - OrderCollection = (function() { + var OrderCollection = (function() { __extends(OrderCollection, Backbone.Collection); function OrderCollection() { OrderCollection.__super__.constructor.apply(this, arguments); @@ -402,7 +396,7 @@ openerp.point_of_sale = function(db) { OrderCollection.prototype.model = Order; return OrderCollection; })(); - Shop = (function() { + var Shop = (function() { __extends(Shop, Backbone.Model); function Shop() { Shop.__super__.constructor.apply(this, arguments); @@ -439,7 +433,7 @@ openerp.point_of_sale = function(db) { The numpad handles both the choice of the property currently being modified (quantity, price or discount) and the edition of the corresponding numeric value. */ - NumpadState = (function() { + var NumpadState = (function() { __extends(NumpadState, Backbone.Model); function NumpadState() { NumpadState.__super__.constructor.apply(this, arguments); @@ -517,7 +511,7 @@ openerp.point_of_sale = function(db) { Views --- */ - NumpadWidget = db.web.Widget.extend({ + var NumpadWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.state = options.state; @@ -550,7 +544,7 @@ openerp.point_of_sale = function(db) { /* Gives access to the payment methods (aka. 'cash registers') */ - PaypadWidget = db.web.Widget.extend({ + var PaypadWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.shop = options.shop; @@ -580,7 +574,7 @@ openerp.point_of_sale = function(db) { }, this)); } }); - PaymentButtonWidget = db.web.Widget.extend({ + var PaymentButtonWidget = db.web.Widget.extend({ template_fct: qweb_template('pos-payment-button-template'), render_element: function() { this.$element.html(this.template_fct({ @@ -598,7 +592,7 @@ 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. */ - StepsWidget = db.web.Widget.extend({ + var StepsWidget = db.web.Widget.extend({ init: function(parent) { this._super(parent); this.step = "products"; @@ -617,7 +611,7 @@ openerp.point_of_sale = function(db) { /* Shopping carts. */ - OrderlineWidget = db.web.Widget.extend({ + var OrderlineWidget = db.web.Widget.extend({ tagName: 'tr', template_fct: qweb_template('pos-orderline-template'), init: function(parent, options) { @@ -652,7 +646,7 @@ openerp.point_of_sale = function(db) { return this.order.selected = this.model; }, }); - OrderWidget = db.web.Widget.extend({ + var OrderWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.shop = options.shop; @@ -706,7 +700,7 @@ openerp.point_of_sale = function(db) { /* "Products" step. */ - CategoryWidget = db.web.Widget.extend({ + var CategoryWidget = db.web.Widget.extend({ start: function() { this.$element.find(".oe-pos-categories-list a").click(_.bind(this.changeCategory, this)); }, @@ -741,7 +735,7 @@ openerp.point_of_sale = function(db) { }, on_change_category: function(id) {}, }); - ProductWidget = db.web.Widget.extend({ + var ProductWidget = db.web.Widget.extend({ tag_name:'li', template_fct: qweb_template('pos-product-template'), init: function(parent, options) { @@ -763,7 +757,7 @@ openerp.point_of_sale = function(db) { return this; }, }); - ProductListWidget = db.web.Widget.extend({ + var ProductListWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.model = options.model; @@ -785,7 +779,7 @@ openerp.point_of_sale = function(db) { /* "Payment" step. */ - PaymentlineWidget = db.web.Widget.extend({ + var PaymentlineWidget = db.web.Widget.extend({ tag_name: 'tr', template_fct: qweb_template('pos-paymentline-template'), init: function(parent, options) { @@ -814,7 +808,7 @@ openerp.point_of_sale = function(db) { return this; }, }); - PaymentWidget = db.web.Widget.extend({ + var PaymentWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.model = options.model; @@ -886,7 +880,7 @@ openerp.point_of_sale = function(db) { /* "Receipt" step. */ - ReceiptLineWidget = db.web.Widget.extend({ + var ReceiptLineWidget = db.web.Widget.extend({ tag_name: 'tr', template_fct: qweb_template('pos-receiptline-template'), init: function(parent, options) { @@ -899,7 +893,7 @@ openerp.point_of_sale = function(db) { this.$element.html(this.template_fct(this.model.toJSON())); }, }); - ReceiptWidget = db.web.Widget.extend({ + var ReceiptWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.model = options.model; @@ -962,7 +956,7 @@ openerp.point_of_sale = function(db) { $('#receipt-summary-change').html(change.toFixed(2)); }, }); - OrderButtonWidget = db.web.Widget.extend({ + var OrderButtonWidget = db.web.Widget.extend({ tag_name: 'li', template_fct: qweb_template('pos-order-selector-button-template'), init: function(parent, options) { @@ -1001,7 +995,7 @@ openerp.point_of_sale = function(db) { this.$element.addClass('order-selector-button'); } }); - ShopWidget = db.web.Widget.extend({ + var ShopWidget = db.web.Widget.extend({ init: function(parent, options) { this._super(parent); this.shop = options.shop; @@ -1069,7 +1063,7 @@ openerp.point_of_sale = function(db) { newOrderButton.selectOrder(); }, }); - App = (function() { + var App = (function() { function App($element) { this.initialize($element); } From d9e3ae58354daf6edbba50b5c7414deb9610f10a Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 17:03:50 +0100 Subject: [PATCH 6/7] [imp] remove comment bzr revid: nicolas.vanhoren@openerp.com-20111206160350-q6natt2pp210boss --- addons/point_of_sale/static/src/js/pos.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 603e9e3b649..fb8daa1f197 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -17,7 +17,6 @@ openerp.point_of_sale = function(db) { child.__super__ = parent.prototype; return child; }; - /* end */ var QWeb = db.web.qweb; QWeb.add_template("/point_of_sale/static/src/xml/pos.xml"); From 491b9fe56e27570c6a622bee13c1f0a50e4d7315 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Tue, 6 Dec 2011 17:56:18 +0100 Subject: [PATCH 7/7] [fix] made the multi order correctly switch between states bzr revid: nicolas.vanhoren@openerp.com-20111206165618-82plw0yzfj7la46r --- addons/point_of_sale/static/src/js/pos.js | 40 +++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index fb8daa1f197..8c3402819b2 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -294,7 +294,8 @@ openerp.point_of_sale = function(db) { } Order.prototype.defaults = { - validated: false + validated: false, + step: 'products', }; Order.prototype.initialize = function() { this.set({ @@ -313,8 +314,7 @@ openerp.point_of_sale = function(db) { }; Order.prototype.validatedChanged = function() { if (this.get("validated") && !this.previous("validated")) { - $('.step-screen').hide(); - $('#receipt-screen').show(); + this.set({'step': 'receipt'}); } } Order.prototype.generateUniqueId = function() { @@ -554,8 +554,7 @@ openerp.point_of_sale = function(db) { performPayment: function(event) { var cashRegister, cashRegisterCollection, cashRegisterId; /* set correct view */ - $('.step-screen').hide(); - $('#payment-screen').show(); + this.shop.get('selectedOrder').set({'step': 'payment'}); cashRegisterId = event.currentTarget.attributes['cash-register-id'].nodeValue; cashRegisterCollection = this.shop.get('cashRegisters'); @@ -592,20 +591,27 @@ openerp.point_of_sale = function(db) { Modifying an order after validation shouldn't be allowed. */ var StepsWidget = db.web.Widget.extend({ - init: function(parent) { + init: function(parent, options) { this._super(parent); - this.step = "products"; + this.shop = options.shop; + this.change_order(); + this.shop.bind('change:selectedOrder', this.change_order, this); }, - start: function() { - this.$element.find('input.step-button').click(_.bind(this.clickChangeStep, this)); + change_order: function() { + if (this.selected_order) { + this.selected_order.unbind('change:step', this.change_step); + } + this.selected_order = this.shop.get('selectedOrder'); + if (this.selected_order) { + this.selected_order.bind('change:step', this.change_step, this); + } + this.change_step(); }, - clickChangeStep: function(event) { - var newStep; - newStep = event.currentTarget.attributes['data-step'].nodeValue; + change_step: function() { + var new_step = this.selected_order ? this.selected_order.get('step') : 'products'; $('.step-screen').hide(); - $('#' + newStep + '-screen').show(); - return this.step = newStep; - } + $('#' + new_step + '-screen').show(); + }, }); /* Shopping carts. @@ -902,8 +908,6 @@ openerp.point_of_sale = function(db) { this.bindPaymentLineEvents(); }, finishOrder: function() { - $('.step-screen').hide(); - $('#products-screen').show(); this.shop.get('selectedOrder').destroy(); }, receiptLineList: function() { @@ -1040,7 +1044,7 @@ openerp.point_of_sale = function(db) { }); this.numpadView.$element = $('#numpad'); this.numpadView.start(); - this.stepsView = new StepsWidget(null); + this.stepsView = new StepsWidget(null, {shop: this.shop}); this.stepsView.$element = $('#steps'); this.stepsView.start(); },