From 0947c0e555f50d9e63e03c3e7d92fc4d4a7dec71 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 9 Nov 2011 11:15:41 +0100 Subject: [PATCH] [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,