Removed qweb_template and OldWidget

bzr revid: fva@openerp.com-20120514140340-5cjkget2wjfsnuva
This commit is contained in:
Frédéric van der Essen 2012-05-14 16:03:40 +02:00
parent aff86833ff
commit c48ae3cf5b
7 changed files with 76 additions and 192 deletions

View File

@ -86,6 +86,7 @@ Main features :
'js': [
'static/lib/backbone/backbone-0.5.3.js',
'static/src/js/pos_models.js',
'static/src/js/pos_basewidget.js',
'static/src/js/pos_widgets.js',
'static/src/js/pos_devices.js',
'static/src/js/pos_screens.js',

View File

@ -1,7 +1,7 @@
function openerp_pos_devices(module, instance){ //module is instance.point_of_sale
function openerp_pos_devices(instance,module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
var QWeb = instance.web.qweb; //TODO FIXME this should NOT be of any use in this file
window.debug_devices = new (instance.web.Class.extend({
payment_status: 'waiting_for_payment',

View File

@ -5,13 +5,15 @@ openerp.point_of_sale = function(instance) {
var module = instance.point_of_sale;
openerp_pos_models(module,instance); // import pos_models.js
openerp_pos_models(instance,module); // import pos_models.js
openerp_pos_screens(module,instance); // import pos_screens.js
openerp_pos_basewidget(instance,module); // import pos_basewidget.js
openerp_pos_screens(instance,module); // import pos_screens.js
openerp_pos_widgets(module,instance); // import pos_widgets.js
openerp_pos_widgets(instance,module); // import pos_widgets.js
openerp_pos_devices(module,instance); // import pos_devices.js
openerp_pos_devices(instance,module); // import pos_devices.js
instance.web.client_actions.add('pos.ui', 'instance.point_of_sale.PosWidget');
};

View File

@ -1,4 +1,4 @@
function openerp_pos_models(module, instance){ //module is instance.point_of_sale
function openerp_pos_models(instance, module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
module.LocalStorageDAO = instance.web.Class.extend({

View File

@ -15,34 +15,9 @@
// that only one screen is shown at the same time and that show() is called after all
// hide()s
function openerp_pos_screens(module, instance){ //module is instance.point_of_sale
function openerp_pos_screens(instance, module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
var qweb_template = function(template,pos){
return function(ctx){
if(!pos){ //this is a huge hack that needs to be removed ... TODO
var HackPosModel = Backbone.Model.extend({
initialize:function(){
this.set({
'currency': {symbol: '$', position: 'after'},
});
},
});
pos = new HackPosModel();
}
return QWeb.render(template, _.extend({}, ctx,{
'currency': pos.get('currency'),
'format_amount': function(amount) {
if (pos.get('currency').position == 'after') {
return amount + ' ' + pos.get('currency').symbol;
} else {
return pos.get('currency').symbol + ' ' + amount;
}
},
}));
};
};
module.ScreenSelector = instance.web.Class.extend({
init: function(options){
this.pos = options.pos;
@ -154,11 +129,10 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
},
});
module.ScreenWidget = instance.web.Widget.extend({
module.ScreenWidget = module.PosBaseWidget.extend({
init: function(parent, options){
this._super(parent, options);
options = options || {};
this.pos = options.pos;
this.pos_widget = options.pos_widget;
},
show: function(){
@ -679,12 +653,12 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
},
refresh: function() {
this.currentOrder = this.pos.get('selectedOrder');
$('.pos-receipt-container', this.$element).html(qweb_template('pos-ticket')({widget:this}));
$('.pos-receipt-container', this.$element).html(QWeb.render('PosTicket',{widget:this}));
},
});
module.PaymentScreenWidget = module.ScreenWidget.extend({
template_fct: qweb_template('PaymentScreenWidget'),
template: 'PaymentScreenWidget',
init: function(parent, options) {
this._super(parent,options);
this.model = options.model;
@ -755,7 +729,6 @@ function openerp_pos_screens(module, instance){ //module is instance.point_of_sa
},
renderElement: function() {
this._super();
this.$element.html(this.template_fct());
this.paymentLineList().empty();
this.currentPaymentLines.each(_.bind( function(paymentLine) {
this.addPaymentLine(paymentLine);

View File

@ -1,66 +1,6 @@
function openerp_pos_widgets(module, instance){ //module is instance.point_of_sale
function openerp_pos_widgets(instance, module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
var qweb_template = function(template,pos){
return function(ctx){
if(!pos){ //this is a huge hack that needs to be removed ... TODO
var HackPosModel = Backbone.Model.extend({
initialize:function(){
this.set({
'currency': {symbol: '$', position: 'after'},
});
},
});
pos = new HackPosModel();
}
return QWeb.render(template, _.extend({}, ctx,{
'currency': pos.get('currency'),
'format_amount': function(amount) {
if (pos.get('currency').position == 'after') {
return Math.round(amount*100)/100 + ' ' + pos.get('currency').symbol;
} else {
return pos.get('currency').symbol + ' ' + amount;
}
},
}));
};
};
// This is a base class for all Widgets in the POS. It exposes relevant data to the
// templates :
// - widget.currency : { symbol: '$' | '€' | ..., position: 'before' | 'after }
// - widget.format_currency(amount) : this method returns a formatted string based on the
// symbol, the position, and the amount of money.
// if the PoS is not fully loaded when you instanciate the widget, the currency might not
// yet have been initialized. Use __build_currency_template() to recompute with correct values
// before rendering.
module.PosBaseWidget = instance.web.Widget.extend({
init:function(parent,options){
this._super(parent);
options = options || {};
this.pos = options.pos;
this.build_currency_template();
},
build_currency_template: function(){
if(this.pos && this.pos.get('currency')){
this.currency = this.pos.get('currency');
}else{
this.currency = {symbol: '$', position: 'after'};
}
this.format_currency = function(amount){
if(this.currency.position === 'after'){
return Math.round(amount*100)/100 + ' ' + this.currency.symbol;
}else{
return this.currency.symbol + ' ' + Math.round(amount*100)/100;
}
}
},
});
module.NumpadWidget = instance.web.Widget.extend({
template:'NumpadWidget',
init: function(parent, options) {
@ -312,13 +252,11 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
// ---------- "Payment" step. ----------
module.PaymentlineWidget = instance.web.OldWidget.extend({
tagName: 'tr',
template_fct: qweb_template('pos-paymentline-template'),
module.PaymentlineWidget = module.PosBaseWidget.extend({
template: 'PaymentlineWidget',
init: function(parent, options) {
this._super(parent);
this._super(parent,options);
this.model = options.model;
console.log('PaymentlineWidget.model:',this.model);
this.model.bind('change', this.changedAmount, this);
},
on_delete: function() {},
@ -338,23 +276,17 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
},
renderElement: function() {
this.amount = this.model.get('amount');
this.$element.html(this.template_fct({
name: (this.model.get('journal_id'))[1],
amount: this.amount,
}));
this.$element.addClass('paymentline');
this.name = this.model.get('journal_id')[1];
$('input', this.$element).keyup(_.bind(this.changeAmount, this));
$('.delete-payment-line', this.$element).click(this.on_delete);
},
});
module.OrderButtonWidget = instance.web.OldWidget.extend({
tagName: 'li',
template_fct: qweb_template('pos-order-selector-button-template'),
module.OrderButtonWidget = module.PosBaseWidget.extend({
template:'OrderButtonWidget',
init: function(parent, options) {
this._super(parent);
this._super(parent,options);
this.order = options.order;
this.pos = options.pos;
this.order.bind('destroy', _.bind( function() {
this.destroy();
}, this));
@ -382,14 +314,10 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
closeOrder: function(event) {
this.order.destroy();
},
renderElement: function() {
this.$element.html(this.template_fct({widget:this}));
this.$element.addClass('order-selector-button');
}
});
module.ActionButtonWidget = instance.web.Widget.extend({
template:'pos-action-button',
template:'ActionButtonWidget',
init: function(parent, options){
this._super(parent, options);
this.label = options.label || 'button';
@ -397,7 +325,7 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
this.click_action = options.click;
if(options.icon){
this.icon = options.icon;
this.template = 'pos-action-button-with-icon';
this.template = 'ActionButtonWidgetWithIcon';
}
},
start: function(){
@ -476,17 +404,15 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
},
});
module.ProductCategoriesWidget = instance.web.Widget.extend({
module.ProductCategoriesWidget = module.PosBaseWidget.extend({
init: function(parent, options){
this._super(parent);
this.pos = options.pos;
this._super(parent,options);
this.on_change_category.add_last(_.bind(this.search_and_categories, this));
this.search_and_categories();
},
start: function() {
this.search_and_categories();
},
template_fct: qweb_template('ProductCategoriesWidget'),
template:'ProductCategoriesWidget',
renderElement: function() {
var self = this;
@ -625,34 +551,18 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
// automatically shown when the input_selector gets focused.
module.OnscreenKeyboardWidget = instance.web.Widget.extend({
tagName: 'div',
template: 'OnscreenKeyboardSimple',
init: function(parent, options){
var self = this;
this._super(parent,options);
function get_option(opt,default_value){
if(options){
return options[opt] || default_value;
}else{
return default_value;
}
options = options || {};
this.keyboard_model = options.keyboard_model || 'full';
if(this.keyboard_model === 'full'){
this.template = 'OnscreenKeyboardFull';
}
this.keyboard_model = get_option('keyboard_model','full');
this.template_simple = qweb_template('pos-onscreen-keyboard-simple-template');
this.template_full = qweb_template('pos-onscreen-keyboard-full-template');
this.template_fct = function(){
if( this.keyboard_model == 'full' ){
return this.template_full.apply(this,arguments);
}else{
return this.template_simple.apply(this,arguments);
}
};
this.input_selector = get_option('input_selector','.searchbox input');
this.input_selector = options.input_selector || '.searchbox input';
//show the keyboard when the input zone is clicked.
$(this.input_selector).focus(function(){self.show();});
@ -695,10 +605,7 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
$input.keydown();
$input.keyup();
},
renderElement: function(){
this.$element.html(this.template_fct());
},
// Makes the keyboard show and slide from the bottom of the screen.
show: function(){
$('.keyboard_frame').show().animate({'height':'235px'}, 500, 'swing');
@ -814,14 +721,14 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
// ---------- Main Point of Sale Widget ----------
// this is used to notify the user that data is being synchronized on the network
module.SynchNotification = instance.web.OldWidget.extend({
template: "pos-synch-notification",
init: function() {
this._super.apply(this, arguments);
module.SynchNotificationWidget = instance.web.Widget.extend({
template: "SynchNotificationWidget",
init: function(parent) {
this._super(parent);
this.nbr_pending = 0;
},
renderElement: function() {
this._super.apply(this, arguments);
this._super();
$('.oe_pos_synch-notification-button', this.$element).click(this.on_synch);
},
on_change_nbr_pending: function(nbr_pending) {
@ -858,8 +765,8 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
return self.pos.ready.then(_.bind(function() {
this.build_currency_template();
this.renderElement();
this.synch_notification = new module.SynchNotification(this);
this.synch_notification.replace($('.oe_pos_synch-notification', this.$element));
this.synch_notification = new module.SynchNotificationWidget(this);
this.synch_notification.replace($('.placeholder-SynchNotificationWidget', this.$element));
this.synch_notification.on_synch.add(_.bind(self.pos.flush, self.pos));
self.pos.bind('change:nbr_pending_operations', this.changed_pending_operations, this);
@ -1126,7 +1033,7 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
var close = _.bind(this.close, this);
if (self.pos.get('nbr_pending_operations').length > 0) {
var confirm = false;
$(QWeb.render('pos-close-warning')).dialog({
$(QWeb.render('PosCloseWarning')).dialog({
resizable: false,
height:160,
modal: true,

View File

@ -9,7 +9,7 @@
<img src="/point_of_sale/static/src/img/logo.png" />
</div>
<div id="loggedas">
<span class="oe_pos_synch-notification"></span>
<span class="placeholder-SynchNotificationWidget"></span>
<button>Close</button>
</div>
<div id="rightheader">
@ -74,17 +74,14 @@
</table>
</div>
</t>
<t t-name="pos-synch-notification">
<t t-name="SynchNotificationWidget">
<span>
<a t-if="widget.nbr_pending &gt; 0" href="javascript:void(0)" class="oe_pos_synch-notification-button">
<t t-esc="widget.nbr_pending"/> pending orders
</a>
</span>
</t>
<t t-name="pos-scan-warning">
<div>The product could not be recognized. Please contact an employee.</div>
</t>
<t t-name="pos-close-warning">
<t t-name="PosCloseWarning">
<div>There are pending operations that could not be saved into the database, are you sure you want to exit?</div>
</t>
<t t-name="PaypadWidget">
@ -177,9 +174,9 @@
<tr>
<td class="paymentline-type">Total:</td>
<td class="paymentline-amount pos-right-align">
<t t-if="currency.position == 'before'" t-esc="currency.symbol"/>
<t t-if="widget.currency.position == 'before'" t-esc="widget.currency.symbol"/>
<span id="payment-due-total"></span>
<t t-if="currency.position == 'after'" t-esc="currency.symbol"/>
<t t-if="widget.currency.position == 'after'" t-esc="widget.currency.symbol"/>
</td>
</tr>
</table>
@ -189,17 +186,17 @@
<tr>
<td class="paymentline-type">Paid:</td>
<td class="paymentline-amount pos-right-align">
<t t-if="currency.position == 'before'" t-esc="currency.symbol"/>
<t t-if="widget.currency.position == 'before'" t-esc="widget.currency.symbol"/>
<span id="payment-paid-total"></span>
<t t-if="currency.position == 'after'" t-esc="currency.symbol"/>
<t t-if="widget.currency.position == 'after'" t-esc="widget.currency.symbol"/>
</td>
</tr>
<tr>
<td class="paymentline-type">Change:</td>
<td class="paymentline-amount pos-right-align">
<t t-if="currency.position == 'before'" t-esc="currency.symbol"/>
<t t-if="widget.currency.position == 'before'" t-esc="widget.currency.symbol"/>
<span id="payment-remaining"></span>
<t t-if="currency.position == 'after'" t-esc="currency.symbol"/>
<t t-if="widget.currency.position == 'after'" t-esc="widget.currency.symbol"/>
</td>
</tr>
</table>
@ -338,7 +335,7 @@
<t t-name="OrderlineWidget">
<tr>
<td>
<t t-esc="name"/>
<t t-esc="widget.model.get('name')"/>
</td>
<td>
<t t-esc="widget.format_currency(widget.model.get('list_price'))"/>
@ -363,14 +360,16 @@
</tr>
</t>
<t t-name="pos-paymentline-template">
<td class="paymentline-type">
<t t-esc="name"/>
</td>
<td class="paymentline-amount pos-right-align">
<input type="text" t-att-value="amount.toFixed(2)" />
<a href='javascript:void(0)' class='delete-payment-line'><img src="/point_of_sale/static/src/img/search_reset.gif" /></a>
</td>
<t t-name="PaymentlineWidget">
<tr class="paymentline">
<td class="paymentline-type">
<t t-esc="name"/>
</td>
<td class="paymentline-amount pos-right-align">
<input type="text" t-att-value="amount.toFixed(2)" />
<a href='javascript:void(0)' class='delete-payment-line'><img src="/point_of_sale/static/src/img/search_reset.gif" /></a>
</td>
</tr>
</t>
<t t-name="PaymentButtonWidget">
@ -380,10 +379,12 @@
<br />
</t>
<t t-name="pos-order-selector-button-template">
<button class="select-order"><t t-esc="widget.order.get('creationDate').toString('t')"/></button>
<t t-name="OrderButtonWidget">
<li class="order-selector-button">
<button class="select-order"><t t-esc="widget.order.get('creationDate').toString('t')"/></button>
</li>
</t>
<t t-name="pos-ticket">
<t t-name="PosTicket">
<div class="pos-sale-ticket">
<div class="pos-right-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +
Date.CultureInfo.formatPatterns.longTime)"/></div>
@ -402,17 +403,17 @@
<t t-esc="order.get('quantity').toFixed(0)"/>
</td>
<td class="pos-right-align">
<t t-esc="format_amount((order.get('list_price') * (1 - order.get('discount')/100) * order.get('quantity')).toFixed(2))"/>
<t t-esc="widget.format_currency((order.get('list_price') * (1 - order.get('discount')/100) * order.get('quantity')).toFixed(2))"/>
</td>
</tr>
</table>
<br />
<table>
<tr><td>Tax:</td><td class="pos-right-align">
<t t-esc="format_amount(widget.currentOrder.getTax().toFixed(2))"/>
<t t-esc="widget.format_currency(widget.currentOrder.getTax().toFixed(2))"/>
</td></tr>
<tr><td>Total:</td><td class="pos-right-align">
<t t-esc="format_amount(widget.currentOrder.getTotal().toFixed(2))"/>
<t t-esc="widget.format_currency(widget.currentOrder.getTotal().toFixed(2))"/>
</td></tr>
</table>
<br />
@ -422,14 +423,14 @@
<t t-esc="pline.get('journal_id')[1]"/>
</td>
<td class="pos-right-align">
<t t-esc="format_amount((pline.getAmount()).toFixed(2))"/>
<t t-esc="widget.format_currency((pline.getAmount()).toFixed(2))"/>
</td>
</tr>
</table>
<br />
<table>
<tr><td>Change:</td><td class="pos-right-align">
<t t-esc="format_amount((widget.currentOrder.getPaidTotal() - widget.currentOrder.getTotal()).toFixed(2))"/>
<t t-esc="widget.format_currency((widget.currentOrder.getPaidTotal() - widget.currentOrder.getTotal()).toFixed(2))"/>
</td></tr>
</table>
</div>
@ -461,14 +462,14 @@
</div>
</t>
<t t-name="pos-action-button">
<t t-name="ActionButtonWidget">
<li t-att-class=" 'button '+ (widget.rightalign ? 'rightalign ' : '')">
<div class='label'>
<t t-esc="widget.label" />
</div>
</li>
</t>
<t t-name="pos-action-button-with-icon">
<t t-name="ActionButtonWidgetWithIcon">
<li t-att-class=" 'button '+ (widget.rightalign ? 'rightalign ' : '')">
<div class='icon'>
<img t-att-src="widget.icon" />
@ -478,7 +479,7 @@
</t>
<!-- Onscreen Keyboard :
http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/ -->
<t t-name="pos-onscreen-keyboard-full-template">
<t t-name="OnscreenKeyboardFull">
<div class="keyboard_frame">
<ul class="keyboard full_keyboard">
<li class="symbol"><span class="off">`</span><span class="on">~</span></li>
@ -539,7 +540,7 @@
<p class="close_button">close</p>
</div>
</t>
<t t-name="pos-onscreen-keyboard-simple-template">
<t t-name="OnscreenKeyboardSimple">
<div class="keyboard_frame">
<ul class="keyboard simple_keyboard">
<li class="symbol firstitem row_qwerty"><span class="off">q</span><span class="on">1</span></li>