2012-05-14 14:03:40 +00:00
|
|
|
function openerp_pos_widgets(instance, module){ //module is instance.point_of_sale
|
2012-04-24 16:25:46 +00:00
|
|
|
var QWeb = instance.web.qweb;
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
module.NumpadWidget = instance.web.Widget.extend({
|
|
|
|
template:'NumpadWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.state = new module.NumpadState();
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.state.bind('change:mode', this.changedMode, this);
|
|
|
|
this.changedMode();
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
clickSwitchSign: function() {
|
|
|
|
return this.state.switchSign();
|
|
|
|
},
|
|
|
|
clickAppendNewChar: function(event) {
|
|
|
|
var newChar;
|
|
|
|
newChar = event.currentTarget.innerText || event.currentTarget.textContent;
|
|
|
|
return this.state.appendNewChar(newChar);
|
|
|
|
},
|
|
|
|
clickChangeMode: function(event) {
|
|
|
|
var newMode = event.currentTarget.attributes['data-mode'].nodeValue;
|
|
|
|
return this.state.changeMode(newMode);
|
|
|
|
},
|
|
|
|
changedMode: function() {
|
|
|
|
var mode = this.state.get('mode');
|
|
|
|
$('.selected-mode').removeClass('selected-mode');
|
|
|
|
$(_.str.sprintf('.mode-button[data-mode="%s"]', mode), this.$element).addClass('selected-mode');
|
|
|
|
},
|
|
|
|
});
|
2012-05-21 16:57:21 +00:00
|
|
|
|
|
|
|
// The paypad allows to select the payment method (cashRegisters)
|
|
|
|
// used to pay the order.
|
|
|
|
module.PaypadWidget = module.PosBaseWidget.extend({
|
2012-05-11 16:02:23 +00:00
|
|
|
template: 'PaypadWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-21 16:57:21 +00:00
|
|
|
var self = this;
|
2012-05-16 13:01:42 +00:00
|
|
|
this._super();
|
2012-05-21 16:57:21 +00:00
|
|
|
console.log('PaypadWidget:',this);
|
|
|
|
|
|
|
|
this.pos.get('cashRegisters').each(function(cashRegister) {
|
|
|
|
var button = new module.PaypadButtonWidget(self,{
|
|
|
|
pos: self.pos,
|
|
|
|
pos_widget : self.pos_widget,
|
|
|
|
cashRegister: cashRegister,
|
2012-05-11 16:02:23 +00:00
|
|
|
});
|
2012-05-21 16:57:21 +00:00
|
|
|
button.appendTo(self.$element);
|
|
|
|
});
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
module.PaypadButtonWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'PaypadButtonWidget',
|
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent, options);
|
|
|
|
this.cashRegister = options.cashRegister;
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-21 16:57:21 +00:00
|
|
|
var self = this;
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super();
|
2012-05-21 16:57:21 +00:00
|
|
|
|
|
|
|
this.$element.click(function(){
|
|
|
|
if (self.pos.get('selectedOrder').get('screen') === 'receipt'){ //TODO Why ?
|
|
|
|
console.log('TODO should not get there...?');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.pos.get('selectedOrder').addPaymentLine(self.cashRegister);
|
|
|
|
self.pos_widget.screen_selector.set_current_screen('payment');
|
|
|
|
});
|
2012-05-11 16:02:23 +00:00
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
2012-04-25 14:55:55 +00:00
|
|
|
|
|
|
|
// ---------- "Shopping Carts" ----------
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
module.OrderlineWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'OrderlineWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super(parent,options);
|
2012-04-24 16:25:46 +00:00
|
|
|
this.model = options.model;
|
|
|
|
this.model.bind('change', _.bind( function() {
|
|
|
|
this.refresh();
|
|
|
|
}, this));
|
|
|
|
this.model.bind('remove', _.bind( function() {
|
|
|
|
this.$element.remove();
|
|
|
|
}, this));
|
|
|
|
this.order = options.order;
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
this.$element.click(_.bind(this.clickHandler, this));
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
clickHandler: function() {
|
|
|
|
this.select();
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super();
|
2012-04-24 16:25:46 +00:00
|
|
|
this.select();
|
|
|
|
},
|
|
|
|
refresh: function() {
|
|
|
|
this.renderElement();
|
|
|
|
var heights = _.map(this.$element.prevAll(), function(el) {return $(el).outerHeight();});
|
|
|
|
heights.push($('#current-order thead').outerHeight());
|
|
|
|
var position = _.reduce(heights, function(memo, num){ return memo + num; }, 0);
|
|
|
|
$('#current-order').scrollTop(position);
|
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
$('tr.selected').removeClass('selected');
|
|
|
|
this.$element.addClass('selected');
|
|
|
|
this.order.selected = this.model;
|
|
|
|
this.on_selected();
|
|
|
|
},
|
|
|
|
on_selected: function() {},
|
|
|
|
});
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
module.OrderWidget = module.PosBaseWidget.extend({
|
|
|
|
template:'OrderWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super(parent,options);
|
|
|
|
console.log('OrderWidget init:',options)
|
|
|
|
this.set_numpad_state(options.numpadState);
|
|
|
|
this.pos.bind('change:selectedOrder', this.change_selected_order, this);
|
|
|
|
this.bind_orderline_events();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
set_numpad_state: function(numpadState) {
|
2012-04-24 16:25:46 +00:00
|
|
|
if (this.numpadState) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this.numpadState.unbind('set_value', this.set_value);
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
this.numpadState = numpadState;
|
|
|
|
if (this.numpadState) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this.numpadState.bind('set_value', this.set_value, this);
|
2012-04-24 16:25:46 +00:00
|
|
|
this.numpadState.reset();
|
|
|
|
}
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
set_value: function(val) {
|
2012-04-24 16:25:46 +00:00
|
|
|
var param = {};
|
|
|
|
param[this.numpadState.get('mode')] = val;
|
2012-04-24 17:20:47 +00:00
|
|
|
var order = this.pos.get('selectedOrder');
|
2012-04-24 16:25:46 +00:00
|
|
|
if (order.get('orderLines').length !== 0) {
|
|
|
|
order.selected.set(param);
|
|
|
|
} else {
|
2012-04-24 17:20:47 +00:00
|
|
|
this.pos.get('selectedOrder').destroy();
|
2012-04-24 16:25:46 +00:00
|
|
|
}
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
change_selected_order: function() {
|
2012-04-24 16:25:46 +00:00
|
|
|
this.currentOrderLines.unbind();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.bind_orderline_events();
|
2012-04-24 16:25:46 +00:00
|
|
|
this.renderElement();
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
bind_orderline_events: function() {
|
2012-04-24 17:20:47 +00:00
|
|
|
this.currentOrderLines = (this.pos.get('selectedOrder')).get('orderLines');
|
2012-05-11 16:02:23 +00:00
|
|
|
this.currentOrderLines.bind('add', this.add_line, this);
|
2012-04-24 16:25:46 +00:00
|
|
|
this.currentOrderLines.bind('remove', this.renderElement, this);
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
add_line: function(newLine) {
|
2012-04-24 16:25:46 +00:00
|
|
|
var line = new module.OrderlineWidget(null, {
|
|
|
|
model: newLine,
|
2012-05-11 16:02:23 +00:00
|
|
|
pos: this.pos,
|
2012-04-24 17:20:47 +00:00
|
|
|
order: this.pos.get('selectedOrder')
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
2012-05-11 16:02:23 +00:00
|
|
|
line.on_selected.add(_.bind(this.selected_line, this));
|
|
|
|
this.selected_line();
|
|
|
|
line.appendTo(this.$element.find('#current-order-content'));
|
|
|
|
this.update_summary();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
selected_line: function() {
|
2012-04-24 16:25:46 +00:00
|
|
|
var reset = false;
|
2012-04-24 17:20:47 +00:00
|
|
|
if (this.currentSelected !== this.pos.get('selectedOrder').selected) {
|
2012-04-24 16:25:46 +00:00
|
|
|
reset = true;
|
|
|
|
}
|
2012-04-24 17:20:47 +00:00
|
|
|
this.currentSelected = this.pos.get('selectedOrder').selected;
|
2012-04-24 16:25:46 +00:00
|
|
|
if (reset && this.numpadState)
|
|
|
|
this.numpadState.reset();
|
2012-05-11 16:02:23 +00:00
|
|
|
this.update_summary();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
renderElement: function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super();
|
|
|
|
var $content = this.$element.find('#current-order-content');
|
|
|
|
$content.empty();
|
2012-04-24 16:25:46 +00:00
|
|
|
this.currentOrderLines.each(_.bind( function(orderLine) {
|
|
|
|
var line = new module.OrderlineWidget(null, {
|
|
|
|
model: orderLine,
|
2012-04-24 17:20:47 +00:00
|
|
|
order: this.pos.get('selectedOrder')
|
2012-04-24 16:25:46 +00:00
|
|
|
});
|
2012-05-11 16:02:23 +00:00
|
|
|
line.on_selected.add(_.bind(this.selected_line, this));
|
|
|
|
line.appendTo($content);
|
2012-04-24 16:25:46 +00:00
|
|
|
}, this));
|
2012-05-11 16:02:23 +00:00
|
|
|
this.update_summary();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
update_summary: function() {
|
2012-04-24 16:25:46 +00:00
|
|
|
var currentOrder, tax, total, totalTaxExcluded;
|
2012-04-24 17:20:47 +00:00
|
|
|
currentOrder = this.pos.get('selectedOrder');
|
2012-04-24 16:25:46 +00:00
|
|
|
total = currentOrder.getTotal();
|
|
|
|
totalTaxExcluded = currentOrder.getTotalTaxExcluded();
|
|
|
|
tax = currentOrder.getTax();
|
2012-05-07 12:39:32 +00:00
|
|
|
this.pos_widget.action_bar.set_total_value(Math.round(total*100)/100);
|
2012-04-24 16:25:46 +00:00
|
|
|
$('#subtotal').html(totalTaxExcluded.toFixed(2)).hide().fadeIn();
|
|
|
|
$('#tax').html(tax.toFixed(2)).hide().fadeIn();
|
|
|
|
$('#total').html(total.toFixed(2)).hide().fadeIn();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
// ---------- Product Screen ----------
|
2012-04-25 14:55:55 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
module.ProductWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'ProductWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super(parent,options);
|
2012-04-24 16:25:46 +00:00
|
|
|
this.model = options.model;
|
2012-05-06 21:34:39 +00:00
|
|
|
this.model.attributes.weight = options.weight || undefined;
|
2012-05-08 12:37:01 +00:00
|
|
|
this.next_screen = options.next_screen || undefined;
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
addToOrder: function(event) {
|
|
|
|
/* Preserve the category URL */
|
|
|
|
event.preventDefault();
|
2012-04-24 17:20:47 +00:00
|
|
|
return (this.pos.get('selectedOrder')).addProduct(this.model);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-08 12:37:01 +00:00
|
|
|
set_weight: function(weight){
|
2012-05-06 21:34:39 +00:00
|
|
|
this.model.attributes.weight = weight;
|
|
|
|
this.renderElement();
|
|
|
|
},
|
2012-05-08 12:37:01 +00:00
|
|
|
set_next_screen: function(screen){
|
|
|
|
this.next_screen = screen;
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
this._super();
|
2012-05-08 12:37:01 +00:00
|
|
|
var self = this;
|
|
|
|
$("a", this.$element).click(function(e){
|
|
|
|
self.addToOrder(e);
|
|
|
|
if(self.next_screen){
|
2012-05-11 16:02:23 +00:00
|
|
|
self.pos_widget.screen_selector.set_current_screen(self.next_screen); //FIXME There ought to be a better way to do this ...
|
2012-05-08 12:37:01 +00:00
|
|
|
}
|
|
|
|
});
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
module.PaymentlineWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'PaymentlineWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options) {
|
2012-05-14 14:03:40 +00:00
|
|
|
this._super(parent,options);
|
2012-05-22 10:32:25 +00:00
|
|
|
this.payment_line = options.payment_line;
|
|
|
|
this.payment_line.bind('change', this.changedAmount, this);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
on_delete: function() {},
|
|
|
|
changeAmount: function(event) {
|
|
|
|
var newAmount;
|
|
|
|
newAmount = event.currentTarget.value;
|
|
|
|
if (newAmount && !isNaN(newAmount)) {
|
|
|
|
this.amount = parseFloat(newAmount);
|
2012-05-22 10:32:25 +00:00
|
|
|
this.payment_line.set({
|
2012-04-24 16:25:46 +00:00
|
|
|
amount: this.amount,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
changedAmount: function() {
|
2012-05-22 10:32:25 +00:00
|
|
|
if (this.amount !== this.payment_line.get('amount'))
|
2012-04-24 16:25:46 +00:00
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
2012-05-22 10:32:25 +00:00
|
|
|
this.name = this.payment_line.get('journal_id')[1];
|
|
|
|
this._super();
|
2012-04-24 16:25:46 +00:00
|
|
|
$('input', this.$element).keyup(_.bind(this.changeAmount, this));
|
|
|
|
$('.delete-payment-line', this.$element).click(this.on_delete);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
module.OrderButtonWidget = module.PosBaseWidget.extend({
|
|
|
|
template:'OrderButtonWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options) {
|
2012-05-14 14:03:40 +00:00
|
|
|
this._super(parent,options);
|
2012-05-02 15:30:00 +00:00
|
|
|
this.order = options.order;
|
|
|
|
this.order.bind('destroy', _.bind( function() {
|
|
|
|
this.destroy();
|
|
|
|
}, this));
|
|
|
|
this.pos.bind('change:selectedOrder', _.bind( function(pos) {
|
|
|
|
var selectedOrder;
|
|
|
|
selectedOrder = pos.get('selectedOrder');
|
|
|
|
if (this.order === selectedOrder) {
|
|
|
|
this.setButtonSelected();
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
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.pos.set({
|
|
|
|
selectedOrder: this.order
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setButtonSelected: function() {
|
|
|
|
$('.selected-order').removeClass('selected-order');
|
|
|
|
this.$element.addClass('selected-order');
|
|
|
|
},
|
|
|
|
closeOrder: function(event) {
|
|
|
|
this.order.destroy();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.ActionButtonWidget = instance.web.Widget.extend({
|
2012-05-14 14:03:40 +00:00
|
|
|
template:'ActionButtonWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent, options);
|
|
|
|
this.label = options.label || 'button';
|
|
|
|
this.rightalign = options.rightalign || false;
|
|
|
|
this.click_action = options.click;
|
|
|
|
if(options.icon){
|
|
|
|
this.icon = options.icon;
|
2012-05-14 14:03:40 +00:00
|
|
|
this.template = 'ActionButtonWidgetWithIcon';
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
if(this.click_action){
|
|
|
|
this.$element.click(_.bind(this.click_action, this));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-04 12:24:48 +00:00
|
|
|
module.ActionBarWidget = instance.web.Widget.extend({
|
|
|
|
template:'ActionBarWidget',
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
this._super(parent,options);
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list = [];
|
2012-05-06 21:34:39 +00:00
|
|
|
this.total_visibility = true;
|
|
|
|
this.help_visibility = true;
|
|
|
|
this.logout_visibility = true;
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-05-03 16:27:46 +00:00
|
|
|
destroy_buttons:function(){
|
|
|
|
for(var i = 0; i < this.button_list.length; i++){
|
|
|
|
this.button_list[i].destroy();
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list = [];
|
2012-05-02 15:30:00 +00:00
|
|
|
return this;
|
|
|
|
},
|
2012-05-03 16:27:46 +00:00
|
|
|
add_new_button: function(button_options){
|
|
|
|
if(arguments.length == 1){
|
2012-05-02 15:30:00 +00:00
|
|
|
var button = new module.ActionButtonWidget(this,button_options);
|
2012-05-03 16:27:46 +00:00
|
|
|
this.button_list.push(button);
|
2012-05-04 12:24:48 +00:00
|
|
|
button.appendTo($('.pos-actionbar-button-list'));
|
2012-05-24 13:39:30 +00:00
|
|
|
return button;
|
2012-05-02 15:30:00 +00:00
|
|
|
}else{
|
2012-05-03 16:27:46 +00:00
|
|
|
for(var i = 0; i < arguments.length; i++){
|
|
|
|
this.add_new_button(arguments[i]);
|
2012-05-02 15:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-24 13:39:30 +00:00
|
|
|
return undefined;
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
|
|
|
set_total_visible: function(visible){
|
|
|
|
if(visible !== this.total_visibility){
|
|
|
|
this.total_visibility = visible;
|
|
|
|
if(visible){
|
|
|
|
this.$element.find('.total').show();
|
|
|
|
}else{
|
|
|
|
this.$element.find('.total').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_help_visible: function(visible,action){
|
|
|
|
if(visible !== this.help_visibility){
|
|
|
|
this.help_visibility = visible;
|
|
|
|
if(visible){
|
|
|
|
this.$element.find('.help-button').show();
|
|
|
|
}else{
|
|
|
|
this.$element.find('.help-button').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(visible && action){
|
|
|
|
this.$element.find('.help-button').off('click').click(action);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_logout_visible: function(visible,action){
|
|
|
|
if(visible !== this.logout_visibility){
|
|
|
|
this.logout_visibility = visible;
|
|
|
|
if(visible){
|
|
|
|
this.$element.find('.logout-button').show();
|
|
|
|
}else{
|
|
|
|
this.$element.find('.logout-button').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(visible && action){
|
|
|
|
this.$element.find('.logout-button').off('click').click(action);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set_total_value: function(value){
|
2012-05-07 12:39:32 +00:00
|
|
|
this.$element.find('.value').html(value);
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
});
|
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
module.ProductCategoriesWidget = module.PosBaseWidget.extend({
|
2012-05-02 15:30:00 +00:00
|
|
|
init: function(parent, options){
|
2012-05-14 14:03:40 +00:00
|
|
|
this._super(parent,options);
|
2012-05-02 15:30:00 +00:00
|
|
|
this.on_change_category.add_last(_.bind(this.search_and_categories, this));
|
|
|
|
this.search_and_categories();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2012-05-02 15:30:00 +00:00
|
|
|
this.search_and_categories();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
template:'ProductCategoriesWidget',
|
2012-04-24 16:25:46 +00:00
|
|
|
renderElement: function() {
|
2012-05-02 15:30:00 +00:00
|
|
|
var self = this;
|
|
|
|
var c;
|
|
|
|
this.$element.empty();
|
|
|
|
this.$element.html(QWeb.render(this.template, {
|
|
|
|
breadcrumb: (function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = self.ancestors.length; _i < _len; _i++) {
|
|
|
|
c = self.ancestors[_i];
|
|
|
|
_results.push(self.pos.categories[c]);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})(),
|
|
|
|
categories: (function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = self.children.length; _i < _len; _i++) {
|
|
|
|
c = self.children[_i];
|
|
|
|
_results.push(self.pos.categories[c]);
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})()
|
|
|
|
}));
|
2012-05-11 16:02:23 +00:00
|
|
|
this.$element.find(".oe-pos-categories-list a").click(_.bind(this.change_category, this));
|
|
|
|
},
|
|
|
|
reset_category: function(){
|
|
|
|
this.on_change_category(0);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
change_category: function(a) {
|
2012-05-02 15:30:00 +00:00
|
|
|
var id = $(a.target).data("category-id");
|
|
|
|
this.on_change_category(id);
|
2012-04-26 11:26:55 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
search_and_categories: function(id){
|
|
|
|
var self = this,
|
|
|
|
c,
|
|
|
|
product_list,
|
|
|
|
allProducts,
|
|
|
|
allPackages;
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
id = id || 0;
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
c = this.pos.categories[id];
|
|
|
|
this.ancestors = c.ancestors;
|
|
|
|
this.children = c.children;
|
|
|
|
this.renderElement();
|
2012-04-26 14:47:01 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
allProducts = this.pos.get('product_list');
|
2012-04-26 14:47:01 +00:00
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
allPackages = this.pos.get('product.packaging');
|
|
|
|
|
|
|
|
product_list = this.pos.get('product_list').filter( function(p){
|
|
|
|
var _ref = p.pos_categ_id[0];
|
|
|
|
return _.indexOf(c.subtree, _ref) >= 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.pos.get('products').reset(product_list);
|
|
|
|
|
|
|
|
this.$element.find('.searchbox input').keyup(function(){
|
|
|
|
var results, search_str;
|
|
|
|
search_str = $(this).val().toLowerCase();
|
|
|
|
if(search_str){
|
|
|
|
results = product_list.filter( function(p){
|
|
|
|
return p.name.toLowerCase().indexOf(search_str) != -1;
|
|
|
|
});
|
|
|
|
self.$element.find('.search-clear').fadeIn();
|
|
|
|
}else{
|
|
|
|
results = product_list;
|
|
|
|
self.$element.find('.search-clear').fadeOut();
|
|
|
|
}
|
|
|
|
self.pos.get('products').reset(results);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$element.find('.search-clear').click(function(){
|
|
|
|
self.pos.get('products').reset(product_list);
|
|
|
|
self.$element.find('.searchbox input').val('').focus();
|
|
|
|
self.$element.find('.search-clear').fadeOut();
|
|
|
|
});
|
2012-04-26 14:47:01 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
on_change_category: function(id) {},
|
2012-04-26 14:47:01 +00:00
|
|
|
});
|
|
|
|
|
2012-05-02 15:30:00 +00:00
|
|
|
module.ProductListWidget = module.ScreenWidget.extend({
|
|
|
|
template:'ProductListWidget',
|
|
|
|
init: function(parent, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.model = options.model;
|
2012-04-26 14:47:01 +00:00
|
|
|
this.pos = options.pos;
|
2012-05-02 15:30:00 +00:00
|
|
|
this.pos.get('products').bind('reset', this.renderElement, this);
|
2012-05-06 21:34:39 +00:00
|
|
|
this.product_list = [];
|
|
|
|
this.weight = options.weight;
|
2012-05-24 15:33:15 +00:00
|
|
|
this.only_weightable = options.only_weightable || false;
|
2012-05-08 12:37:01 +00:00
|
|
|
this.next_screen = options.next_screen || false;
|
|
|
|
},
|
|
|
|
set_weight: function(weight){
|
|
|
|
for(var i = 0; i < this.product_list.length; i++){
|
|
|
|
this.product_list[i].set_weight(weight);
|
|
|
|
}
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2012-05-08 12:37:01 +00:00
|
|
|
set_next_screen: function(screen){
|
2012-05-06 21:34:39 +00:00
|
|
|
for(var i = 0; i < this.product_list.length; i++){
|
2012-05-08 12:37:01 +00:00
|
|
|
this.product_list[i].set_next_screen(screen);
|
2012-05-06 21:34:39 +00:00
|
|
|
}
|
2012-04-26 14:47:01 +00:00
|
|
|
},
|
2012-05-02 15:30:00 +00:00
|
|
|
renderElement: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super();
|
2012-05-06 21:34:39 +00:00
|
|
|
this.product_list = [];
|
2012-05-24 15:33:15 +00:00
|
|
|
this.pos.get('products')
|
|
|
|
.chain()
|
|
|
|
.filter(function(product){
|
|
|
|
// if only weightable, only keeps those with a to_weight category, keep all otherwise
|
|
|
|
return !self.only_weightable || (product.get('pos_category') && product.get('pos_category').to_weight);
|
2012-05-02 15:30:00 +00:00
|
|
|
})
|
2012-05-24 15:33:15 +00:00
|
|
|
.map(function(product) {
|
|
|
|
var product = new module.ProductWidget(this, {
|
|
|
|
model: product,
|
|
|
|
weight: self.weight,
|
|
|
|
})
|
|
|
|
self.product_list.push(product);
|
|
|
|
return product;
|
|
|
|
})
|
|
|
|
.invoke('appendTo', this.$element);
|
2012-04-26 14:47:01 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-03 16:27:46 +00:00
|
|
|
// ---------- OnScreen Keyboard Widget ----------
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
// A Widget that displays an onscreen keyboard.
|
|
|
|
// There are two options when creating the widget :
|
|
|
|
//
|
|
|
|
// * 'keyboard_model' : 'simple' | 'full' (default)
|
|
|
|
// The 'full' emulates a PC keyboard, while 'simple' emulates an 'android' one.
|
|
|
|
//
|
|
|
|
// * 'input_selector : (default: '.searchbox input')
|
|
|
|
// defines the dom element that the keyboard will write to.
|
|
|
|
//
|
|
|
|
// The widget is initially hidden. It can be shown with this.show(), and is
|
|
|
|
// automatically shown when the input_selector gets focused.
|
2012-04-26 10:05:48 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
module.OnscreenKeyboardWidget = instance.web.Widget.extend({
|
2012-05-14 14:03:40 +00:00
|
|
|
template: 'OnscreenKeyboardSimple',
|
2012-04-24 16:25:46 +00:00
|
|
|
init: function(parent, options){
|
|
|
|
var self = this;
|
|
|
|
this._super(parent,options);
|
2012-05-14 14:03:40 +00:00
|
|
|
options = options || {};
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
this.keyboard_model = options.keyboard_model || 'full';
|
|
|
|
if(this.keyboard_model === 'full'){
|
|
|
|
this.template = 'OnscreenKeyboardFull';
|
|
|
|
}
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-14 14:03:40 +00:00
|
|
|
this.input_selector = options.input_selector || '.searchbox input';
|
2012-04-24 16:25:46 +00:00
|
|
|
|
|
|
|
//show the keyboard when the input zone is clicked.
|
|
|
|
$(this.input_selector).focus(function(){self.show();});
|
|
|
|
|
|
|
|
//Keyboard state
|
|
|
|
this.capslock = false;
|
|
|
|
this.shift = false;
|
|
|
|
this.numlock = false;
|
|
|
|
},
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
connect : function(){
|
|
|
|
$(this.input_selector).focus(function(){self.show();});
|
|
|
|
},
|
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
// Write a character to the input zone
|
|
|
|
writeCharacter: function(character){
|
|
|
|
var $input = $(this.input_selector);
|
|
|
|
$input[0].value += character;
|
|
|
|
$input.keydown();
|
|
|
|
$input.keyup();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sends a 'return' character to the input zone. TODO
|
|
|
|
sendReturn: function(){
|
|
|
|
},
|
|
|
|
|
|
|
|
// Removes the last character from the input zone.
|
|
|
|
deleteCharacter: function(){
|
|
|
|
var $input = $(this.input_selector);
|
|
|
|
var input_value = $input[0].value;
|
|
|
|
$input[0].value = input_value.substr(0, input_value.length - 1);
|
|
|
|
$input.keydown();
|
|
|
|
$input.keyup();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Clears the content of the input zone.
|
|
|
|
deleteAllCharacters: function(){
|
|
|
|
var $input = $(this.input_selector);
|
|
|
|
$input[0].value = "";
|
|
|
|
$input.keydown();
|
|
|
|
$input.keyup();
|
|
|
|
},
|
2012-05-14 14:03:40 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
// Makes the keyboard show and slide from the bottom of the screen.
|
|
|
|
show: function(){
|
|
|
|
$('.keyboard_frame').show().animate({'height':'235px'}, 500, 'swing');
|
|
|
|
},
|
|
|
|
|
|
|
|
// Makes the keyboard hide by sliding to the bottom of the screen.
|
|
|
|
hide: function(){
|
|
|
|
var self = this;
|
|
|
|
var frame = $('.keyboard_frame');
|
|
|
|
frame.animate({'height':'0'}, 500, 'swing', function(){ frame.hide(); self.reset(); });
|
|
|
|
},
|
|
|
|
|
|
|
|
//What happens when the shift key is pressed : toggle case, remove capslock
|
|
|
|
toggleShift: function(){
|
|
|
|
$('.letter').toggleClass('uppercase');
|
|
|
|
$('.symbol span').toggle();
|
|
|
|
|
|
|
|
self.shift = (self.shift === true) ? false : true;
|
|
|
|
self.capslock = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
//what happens when capslock is pressed : toggle case, set capslock
|
|
|
|
toggleCapsLock: function(){
|
|
|
|
$('.letter').toggleClass('uppercase');
|
|
|
|
self.capslock = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
//What happens when numlock is pressed : toggle symbols and numlock label
|
|
|
|
toggleNumLock: function(){
|
|
|
|
$('.symbol span').toggle();
|
|
|
|
$('.numlock span').toggle();
|
|
|
|
self.numlock = (self.numlock === true ) ? false : true;
|
|
|
|
},
|
|
|
|
|
|
|
|
//After a key is pressed, shift is disabled.
|
|
|
|
removeShift: function(){
|
|
|
|
if (self.shift === true) {
|
|
|
|
$('.symbol span').toggle();
|
|
|
|
if (this.capslock === false) $('.letter').toggleClass('uppercase');
|
|
|
|
|
|
|
|
self.shift = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Resets the keyboard to its original state; capslock: false, shift: false, numlock: false
|
|
|
|
reset: function(){
|
|
|
|
if(this.shift){
|
|
|
|
this.toggleShift();
|
|
|
|
}
|
|
|
|
if(this.capslock){
|
|
|
|
this.toggleCapsLock();
|
|
|
|
}
|
|
|
|
if(this.numlock){
|
|
|
|
this.toggleNumLock();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//called after the keyboard is in the DOM, sets up the key bindings.
|
|
|
|
start: function(){
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
//this.show();
|
|
|
|
|
|
|
|
|
|
|
|
$('.close_button').click(function(){
|
|
|
|
self.deleteAllCharacters();
|
|
|
|
self.hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Keyboard key click handling
|
|
|
|
$('.keyboard li').click(function(){
|
|
|
|
|
|
|
|
var $this = $(this),
|
|
|
|
character = $this.html(); // If it's a lowercase letter, nothing happens to this variable
|
|
|
|
|
|
|
|
if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
|
|
|
|
self.toggleShift();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this.hasClass('capslock')) {
|
|
|
|
self.toggleCapsLock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this.hasClass('delete')) {
|
|
|
|
self.deleteCharacter();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this.hasClass('numlock')){
|
|
|
|
self.toggleNumLock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special characters
|
|
|
|
if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
|
|
|
|
if ($this.hasClass('space')) character = ' ';
|
|
|
|
if ($this.hasClass('tab')) character = "\t";
|
|
|
|
if ($this.hasClass('return')) character = "\n";
|
|
|
|
|
|
|
|
// Uppercase letter
|
|
|
|
if ($this.hasClass('uppercase')) character = character.toUpperCase();
|
|
|
|
|
|
|
|
// Remove shift once a key is clicked.
|
|
|
|
self.removeShift();
|
|
|
|
|
|
|
|
self.writeCharacter(character);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-05-03 16:27:46 +00:00
|
|
|
// ---------- Main Point of Sale Widget ----------
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
// this is used to notify the user that data is being synchronized on the network
|
2012-05-14 14:03:40 +00:00
|
|
|
module.SynchNotificationWidget = instance.web.Widget.extend({
|
|
|
|
template: "SynchNotificationWidget",
|
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2012-04-26 10:05:48 +00:00
|
|
|
this.nbr_pending = 0;
|
|
|
|
},
|
|
|
|
renderElement: function() {
|
2012-05-14 14:03:40 +00:00
|
|
|
this._super();
|
2012-04-26 10:05:48 +00:00
|
|
|
$('.oe_pos_synch-notification-button', this.$element).click(this.on_synch);
|
|
|
|
},
|
|
|
|
on_change_nbr_pending: function(nbr_pending) {
|
|
|
|
this.nbr_pending = nbr_pending;
|
|
|
|
this.renderElement();
|
|
|
|
},
|
|
|
|
on_synch: function() {}
|
|
|
|
});
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
// The PosWidget is the main widget that contains all other widgets in the PointOfSale.
|
|
|
|
// It is mainly composed of :
|
|
|
|
// - a header, containing the list of orders
|
|
|
|
// - a leftpane, containing the list of bought products (orderlines)
|
|
|
|
// - a rightpane, containing the screens (see pos_screens.js)
|
|
|
|
// - an actionbar on the bottom, containing various action buttons
|
|
|
|
// - popups
|
|
|
|
// - an onscreen keyboard
|
|
|
|
// a screen_selector which controls the switching between screens and the showing/closing of popups
|
|
|
|
|
|
|
|
module.PosWidget = module.PosBaseWidget.extend({
|
|
|
|
template: 'PosWidget',
|
2012-04-26 10:05:48 +00:00
|
|
|
init: function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
console.log('PosArguments:',arguments);
|
|
|
|
this._super(arguments[0],{});
|
2012-05-21 16:57:21 +00:00
|
|
|
|
2012-04-26 10:05:48 +00:00
|
|
|
this.pos = new module.PosModel(this.session);
|
2012-05-21 16:57:21 +00:00
|
|
|
this.pos_widget = this; //So that pos_widget's childs have pos_widget set automatically
|
|
|
|
|
2012-05-04 10:27:37 +00:00
|
|
|
this.numpad_visible = true;
|
|
|
|
this.leftpane_visible = true;
|
|
|
|
this.leftpane_width = '440px';
|
|
|
|
this.cashier_controls_visible = true;
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
start: function() {
|
2012-04-26 10:05:48 +00:00
|
|
|
var self = this;
|
|
|
|
return self.pos.ready.then(_.bind(function() {
|
2012-05-11 16:02:23 +00:00
|
|
|
this.build_currency_template();
|
2012-04-26 10:05:48 +00:00
|
|
|
this.renderElement();
|
2012-05-14 14:03:40 +00:00
|
|
|
this.synch_notification = new module.SynchNotificationWidget(this);
|
|
|
|
this.synch_notification.replace($('.placeholder-SynchNotificationWidget', this.$element));
|
2012-04-26 10:05:48 +00:00
|
|
|
this.synch_notification.on_synch.add(_.bind(self.pos.flush, self.pos));
|
|
|
|
|
|
|
|
self.pos.bind('change:nbr_pending_operations', this.changed_pending_operations, this);
|
|
|
|
this.changed_pending_operations();
|
|
|
|
|
|
|
|
this.$element.find("#loggedas button").click(function() {
|
|
|
|
self.try_close();
|
|
|
|
});
|
2012-05-11 16:02:23 +00:00
|
|
|
|
|
|
|
$('button#neworder-button', this.$element).click(_.bind(this.create_new_order, this));
|
|
|
|
|
|
|
|
//when a new order is created, add an order button widget
|
2012-05-21 16:57:21 +00:00
|
|
|
this.pos.get('orders').bind('add', function(new_order){
|
2012-05-11 16:02:23 +00:00
|
|
|
var new_order_button = new module.OrderButtonWidget(null, {
|
|
|
|
order: new_order,
|
|
|
|
pos: this.pos
|
|
|
|
});
|
|
|
|
new_order_button.appendTo($('#orders'));
|
|
|
|
new_order_button.selectOrder();
|
|
|
|
}, this);
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.pos.get('orders').add(new module.Order({ pos: this.pos }));
|
2012-04-26 10:05:48 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.build_widgets();
|
2012-04-26 10:05:48 +00:00
|
|
|
|
|
|
|
instance.webclient.set_content_full_screen(true);
|
2012-05-16 13:01:42 +00:00
|
|
|
|
|
|
|
if (!self.pos.get('pos_session')) {
|
|
|
|
self.screen_selector.show_popup('error',
|
|
|
|
'Sorry, we could not create a user session');
|
2012-05-21 09:14:42 +00:00
|
|
|
//}else if (!self.pos.get('bank_statements') || self.pos.get('bank_statements').length === 0){
|
|
|
|
// self.screen_selector.show_popup('error',
|
|
|
|
// 'Sorry, we could not find any accounting journals in the configuration');
|
2012-05-16 13:01:42 +00:00
|
|
|
}else if(!self.pos.get('pos_config')){
|
|
|
|
self.screen_selector.show_popup('error',
|
|
|
|
'Sorry, we could not find any PoS Configuration for this session');
|
2012-05-09 09:55:55 +00:00
|
|
|
}
|
2012-05-16 13:01:42 +00:00
|
|
|
|
|
|
|
$('.loader').animate({opacity:0},3000,'swing',function(){$('.loader').hide();});
|
|
|
|
$('.loader img').hide();
|
|
|
|
|
2012-04-26 10:05:48 +00:00
|
|
|
}, this));
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
build_widgets: function() {
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2012-05-14 14:31:21 +00:00
|
|
|
// -------- Screens ---------
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.search_product_screen = new module.SearchProductScreenWidget(this,{});
|
2012-05-02 15:30:00 +00:00
|
|
|
this.search_product_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.scan_product_screen = new module.ScanProductScreenWidget(this,{});
|
2012-05-03 16:27:46 +00:00
|
|
|
this.scan_product_screen.appendTo($('#rightpane'));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.receipt_screen = new module.ReceiptScreenWidget(this, {});
|
2012-05-02 15:30:00 +00:00
|
|
|
this.receipt_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.payment_screen = new module.PaymentScreenWidget(this, {});
|
2012-05-02 15:30:00 +00:00
|
|
|
this.payment_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.welcome_screen = new module.WelcomeScreenWidget(this,{});
|
2012-05-03 16:27:46 +00:00
|
|
|
this.welcome_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.client_payment_screen = new module.ClientPaymentScreenWidget(this, {});
|
2012-05-03 16:27:46 +00:00
|
|
|
this.client_payment_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.scale_invite_screen = new module.ScaleInviteScreenWidget(this, {});
|
2012-05-03 16:27:46 +00:00
|
|
|
this.scale_invite_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.scale_product_screen = new module.ScaleProductScreenWidget(this, {});
|
2012-05-03 16:40:32 +00:00
|
|
|
this.scale_product_screen.appendTo($('#rightpane'));
|
|
|
|
|
2012-05-14 14:31:21 +00:00
|
|
|
// -------- Popups ---------
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.help_popup = new module.HelpPopupWidget(this, {});
|
2012-05-06 21:34:39 +00:00
|
|
|
this.help_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.receipt_popup = new module.ReceiptPopupWidget(this, {});
|
2012-05-07 12:39:32 +00:00
|
|
|
this.receipt_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.error_popup = new module.ErrorPopupWidget(this, {});
|
2012-05-07 12:39:32 +00:00
|
|
|
this.error_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.error_product_popup = new module.ErrorProductNotRecognizedPopupWidget(this, {});
|
2012-05-14 14:31:21 +00:00
|
|
|
this.error_product_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.error_session_popup = new module.ErrorNoSessionPopupWidget(this, {});
|
2012-05-14 14:31:21 +00:00
|
|
|
this.error_session_popup.appendTo($('.point-of-sale'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
// -------- Misc ---------
|
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.action_bar = new module.ActionBarWidget(this);
|
|
|
|
this.action_bar.appendTo($(".point-of-sale #content"));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.paypad = new module.PaypadWidget(this, {});
|
2012-05-16 13:01:42 +00:00
|
|
|
this.paypad.replace($('#placeholder-PaypadWidget'));
|
2012-05-11 16:02:23 +00:00
|
|
|
|
|
|
|
this.numpad = new module.NumpadWidget(this);
|
|
|
|
this.numpad.replace($('#placeholder-NumpadWidget'));
|
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
this.order_widget = new module.OrderWidget(this, {});
|
2012-05-11 16:02:23 +00:00
|
|
|
this.order_widget.replace($('#placeholder-OrderWidget'));
|
2012-05-03 16:27:46 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.onscreen_keyboard = new module.OnscreenKeyboardWidget(this, {
|
2012-05-03 16:27:46 +00:00
|
|
|
'keyboard_model': 'simple'
|
|
|
|
});
|
|
|
|
this.onscreen_keyboard.appendTo($(".point-of-sale #content"));
|
2012-05-02 15:30:00 +00:00
|
|
|
|
2012-05-21 16:57:21 +00:00
|
|
|
// -------- Screen Selector ---------
|
2012-05-16 13:01:42 +00:00
|
|
|
|
2012-05-11 16:02:23 +00:00
|
|
|
this.screen_selector = new module.ScreenSelector({
|
2012-04-24 17:20:47 +00:00
|
|
|
pos: this.pos,
|
2012-05-02 15:30:00 +00:00
|
|
|
screen_set:{
|
|
|
|
'products': this.search_product_screen,
|
2012-05-03 16:27:46 +00:00
|
|
|
'scan': this.scan_product_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
'payment' : this.payment_screen,
|
2012-05-03 16:27:46 +00:00
|
|
|
'client_payment' : this.client_payment_screen,
|
|
|
|
'scale_invite' : this.scale_invite_screen,
|
2012-05-03 16:40:32 +00:00
|
|
|
'scale_product' : this.scale_product_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
'receipt' : this.receipt_screen,
|
2012-05-03 16:27:46 +00:00
|
|
|
'welcome' : this.welcome_screen,
|
2012-05-02 15:30:00 +00:00
|
|
|
},
|
2012-05-06 21:34:39 +00:00
|
|
|
popup_set:{
|
|
|
|
'help': this.help_popup,
|
2012-05-07 12:39:32 +00:00
|
|
|
'error': this.error_popup,
|
2012-05-14 14:31:21 +00:00
|
|
|
'error-product': this.error_product_popup,
|
|
|
|
'error-session': this.error_session_popup,
|
2012-05-07 12:39:32 +00:00
|
|
|
'receipt': this.receipt_popup,
|
2012-05-06 21:34:39 +00:00
|
|
|
},
|
2012-05-04 09:48:25 +00:00
|
|
|
default_client_screen: 'welcome',
|
|
|
|
default_cashier_screen: 'products',
|
2012-05-16 13:01:42 +00:00
|
|
|
default_mode: this.pos.get('pos_config').iface_self_checkout ? 'client' : 'cashier',
|
2012-04-26 11:26:55 +00:00
|
|
|
});
|
2012-05-21 16:57:21 +00:00
|
|
|
|
|
|
|
window.screen_selector = this.screen_selector; //DEBUG
|
2012-05-03 12:14:41 +00:00
|
|
|
|
|
|
|
this.pos.barcode_reader.connect();
|
2012-04-26 11:26:55 +00:00
|
|
|
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-08 15:40:30 +00:00
|
|
|
|
|
|
|
//FIXME this method is probably not at the right place ...
|
|
|
|
scan_product: function(parsed_ean){
|
|
|
|
var selectedOrder = this.pos.get('selectedOrder');
|
2012-05-09 09:44:38 +00:00
|
|
|
var scannedProductModel = this.get_product_by_ean(parsed_ean);
|
2012-05-08 15:40:30 +00:00
|
|
|
if (!scannedProductModel){
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
selectedOrder.addProduct(new module.Product(scannedProductModel));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// returns a product that has a packaging with an EAN matching to provided parsed ean .
|
|
|
|
// returns undefined if no such product is found.
|
|
|
|
get_product_by_ean: function(parsed_ean) {
|
|
|
|
var allProducts = this.pos.get('product_list');
|
|
|
|
var allPackages = this.pos.get('product.packaging');
|
|
|
|
var scannedProductModel = undefined;
|
|
|
|
|
|
|
|
if (parsed_ean.type === 'price') {
|
2012-05-11 16:02:23 +00:00
|
|
|
var itemCode = parsed_ean.id;
|
|
|
|
console.log('price! id:',itemCode);
|
|
|
|
var scannedPackaging = _.detect(allPackages, function(pack) {
|
|
|
|
return pack.ean && pack.ean.substring(0,7) === itemCode;
|
|
|
|
});
|
|
|
|
if (scannedPackaging) {
|
|
|
|
console.log('found matching package, finding matching product...');
|
2012-05-08 15:40:30 +00:00
|
|
|
scannedProductModel = _.detect(allProducts, function(pc) { return pc.id === scannedPackaging.product_id[0];});
|
2012-05-11 16:02:23 +00:00
|
|
|
}else{
|
|
|
|
console.log('matching package not found, finding matching product...');
|
|
|
|
scannedProductModel = _.detect(allProducts, function(pc) { return pc.ean13 && (pc.ean13.substring(0,7) === parsed_ean.id);});
|
|
|
|
}
|
|
|
|
if(scannedProductModel){
|
2012-05-08 15:40:30 +00:00
|
|
|
scannedProductModel.list_price = parsed_ean.value;
|
|
|
|
}
|
|
|
|
} else if (parsed_ean.type === 'weight') {
|
|
|
|
var weight = parsed_ean.value;
|
|
|
|
var itemCode = parsed_ean.id;
|
2012-05-11 16:02:23 +00:00
|
|
|
var scannedPackaging = _.detect(allPackages, function(pack) {
|
|
|
|
return pack.ean && pack.ean.substring(0,7) === itemCode;
|
|
|
|
});
|
|
|
|
if (scannedPackaging){
|
|
|
|
console.log('found matching package, finding matching product...');
|
2012-05-08 15:40:30 +00:00
|
|
|
scannedProductModel = _.detect(allProducts, function(pc) { return pc.id === scannedPackaging.product_id[0];});
|
2012-05-11 16:02:23 +00:00
|
|
|
}else{
|
|
|
|
console.log('matching package not found, finding matching product...');
|
|
|
|
scannedProductModel = _.detect(allProducts, function(pc) { return pc.ean13 && (pc.ean13.substring(0,7) === parsed_ean.id);});
|
|
|
|
}
|
|
|
|
if(scannedProductModel){
|
2012-05-08 15:40:30 +00:00
|
|
|
scannedProductModel.list_price *= weight;
|
|
|
|
scannedProductModel.name += ' - ' + weight + ' Kg.';
|
|
|
|
}
|
|
|
|
} else if(parsed_ean.type === 'unit'){
|
|
|
|
scannedProductModel = _.detect(allProducts, function(pc) { return pc.ean13 === parsed_ean.ean;}); //TODO DOES NOT SCALE
|
|
|
|
}
|
|
|
|
return scannedProductModel;
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
// creates a new order, and add it to the list of orders.
|
|
|
|
create_new_order: function() {
|
|
|
|
var new_order;
|
2012-05-21 16:57:21 +00:00
|
|
|
new_order = new module.Order({ pos: this.pos });
|
2012-05-11 16:02:23 +00:00
|
|
|
this.pos.get('orders').add(new_order);
|
|
|
|
this.pos.set({ selectedOrder: new_order });
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
changed_pending_operations: function () {
|
|
|
|
var self = this;
|
2012-04-24 17:20:47 +00:00
|
|
|
this.synch_notification.on_change_nbr_pending(self.pos.get('nbr_pending_operations').length);
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
// shows or hide the numpad and related controls like the paypad.
|
2012-05-04 10:27:37 +00:00
|
|
|
set_numpad_visible: function(visible){
|
|
|
|
if(visible != this.numpad_visible){
|
|
|
|
this.numpad_visible = visible;
|
|
|
|
if(visible){
|
|
|
|
$('#numpad').show();
|
|
|
|
$('#paypad').show();
|
2012-05-08 12:37:01 +00:00
|
|
|
$('#current-order').css({'bottom':'271px'});
|
2012-05-04 10:27:37 +00:00
|
|
|
}else{
|
|
|
|
$('#numpad').hide();
|
|
|
|
$('#paypad').hide();
|
2012-05-08 12:37:01 +00:00
|
|
|
$('#current-order').css({'bottom':'0px'});
|
2012-05-04 10:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
//shows or hide the leftpane (contains the list of orderlines, the numpad, the paypad, etc.)
|
2012-05-04 10:27:37 +00:00
|
|
|
set_leftpane_visible: function(visible){
|
|
|
|
if(visible != this.leftpane_visible){
|
|
|
|
this.leftpane_visible = visible;
|
|
|
|
if(visible){
|
|
|
|
$('#leftpane').show().animate({'width':this.leftpane_width},500,'swing');
|
|
|
|
$('#rightpane').animate({'left':this.leftpane_width},500,'swing');
|
|
|
|
}else{
|
|
|
|
var leftpane = $('#leftpane');
|
|
|
|
$('#leftpane').animate({'width':'0px'},500,'swing', function(){ leftpane.hide(); });
|
|
|
|
$('#rightpane').animate({'left':'0px'},500,'swing');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-05-11 16:02:23 +00:00
|
|
|
//shows or hide the controls in the PosWidget that are specific to the cashier ( Orders, close button, etc. )
|
2012-05-04 10:27:37 +00:00
|
|
|
set_cashier_controls_visible: function(visible){
|
|
|
|
if(visible != this.cashier_controls_visible){
|
|
|
|
this.cashier_controls_visible = visible;
|
|
|
|
if(visible){
|
|
|
|
$('#loggedas').show();
|
|
|
|
$('#rightheader').show();
|
|
|
|
}else{
|
|
|
|
$('#loggedas').hide();
|
|
|
|
$('#rightheader').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-04-24 16:25:46 +00:00
|
|
|
try_close: function() {
|
|
|
|
var self = this;
|
2012-04-24 17:20:47 +00:00
|
|
|
self.pos.flush().then(_.bind(function() {
|
2012-04-24 16:25:46 +00:00
|
|
|
var close = _.bind(this.close, this);
|
2012-04-24 17:20:47 +00:00
|
|
|
if (self.pos.get('nbr_pending_operations').length > 0) {
|
2012-04-24 16:25:46 +00:00
|
|
|
var confirm = false;
|
2012-05-14 14:03:40 +00:00
|
|
|
$(QWeb.render('PosCloseWarning')).dialog({
|
2012-04-24 16:25:46 +00:00
|
|
|
resizable: false,
|
|
|
|
height:160,
|
|
|
|
modal: true,
|
|
|
|
title: "Warning",
|
|
|
|
buttons: {
|
|
|
|
"Yes": function() {
|
|
|
|
confirm = true;
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
},
|
|
|
|
"No": function() {
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
if (confirm)
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
close: function() {
|
2012-05-03 12:14:41 +00:00
|
|
|
this.pos.barcode_reader.disconnect();
|
2012-04-24 16:25:46 +00:00
|
|
|
},
|
|
|
|
destroy: function() {
|
|
|
|
instance.webclient.set_content_full_screen(false);
|
2012-04-24 17:20:47 +00:00
|
|
|
self.pos = undefined;
|
2012-04-24 16:25:46 +00:00
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|