[WIP] pos_restaurant: floor plan editing mostly complete

This commit is contained in:
Frederic van der Essen
2014-11-25 17:28:10 +01:00
committed by Frédéric van der Essen
parent 1f0f930054
commit bc190e512f
4 changed files with 149 additions and 30 deletions
+30 -6
View File
@@ -43,18 +43,42 @@ class restaurant_table(osv.osv):
'name': fields.char('Table Name', size=32, required=True, help='An internal identification of a table'),
'floor_id': fields.many2one('restaurant.floor','Floor'),
'shape': fields.selection([('square','Square'),('round','Round')],'Shape', required=True),
'position_h': fields.integer('Horizontal Position', help="The table's horizontal position from the left side to the table's center, in percentage of the floor's width"),
'position_v': fields.integer('Vertical Position', help="The table's vertical position from the top to the table's center, in percentage of the floor's height"),
'width': fields.integer('Width', help="The table's width in percentage of the floor's width"),
'height': fields.integer('Height', help="The table's height in percentage of the floor's height"),
'position_h': fields.float('Horizontal Position', help="The table's horizontal position from the left side to the table's center, in percentage of the floor's width"),
'position_v': fields.float('Vertical Position', help="The table's vertical position from the top to the table's center, in percentage of the floor's height"),
'width': fields.float('Width', help="The table's width in percentage of the floor's width"),
'height': fields.float('Height', help="The table's height in percentage of the floor's height"),
'color': fields.char('Color', size=32, help="The table's color"),
'active': fields.boolean('Active',help='If false, the table is deactivated and will not be available in the point of sale'),
}
_defaults = {
'shape': 'square',
'height': 10,
'width': 10,
'position_h': 10,
'position_v': 10,
'height': 50,
'width': 50,
'active': True,
}
def create_from_ui(self, cr, uid, table, context=None):
""" create or modify a table from the point of sale UI.
table contains the table's fields. If it contains an
id, it will modify the existing table. It then
returns the id of the table. """
if table.get('floor_id',False):
floor_id = table['floor_id'][0]
table['floor_id'] = floor_id
if table.get('id',False): # Modifiy existing table
table_id = table['id']
del table['id']
self.write(cr, uid, [table_id], table, context=context)
else:
table_id = self.create(cr, uid, table, context=context)
return table_id
class restaurant_printer(osv.osv):
_name = 'restaurant.printer'
@@ -44,6 +44,7 @@
position: relative;
width: auto;
background: rgba(0,0,0,0.1);
background-repeat: no-repeat;
}
.floor-map .table{
@@ -78,6 +79,10 @@
cursor: pointer;
border: solid 1px rgba(0,0,0,0.2);
}
.floor-map .edit-button.editing.active {
background: #444;
color: white;
}
.floor-map .edit-bar {
position: absolute;
top: 0;
+112 -22
View File
@@ -1,4 +1,5 @@
function openerp_restaurant_floors(instance,module){
var _t = instance.web._t;
module.PosModel.prototype.models.push({
model: 'restaurant.floor',
@@ -27,10 +28,10 @@ function openerp_restaurant_floors(instance,module){
},
});
module.TableWidget = instance.web.Widget.extend({
module.TableWidget = module.PosBaseWidget.extend({
template: 'TableWidget',
init: function(parent, options){
this._super(parent);
this._super(parent, options)
this.table = options.table;
this.selected = false;
this.moved = false;
@@ -47,23 +48,26 @@ function openerp_restaurant_floors(instance,module){
},
click_handler: function(){
var self = this;
setTimeout(function(){ // in a setTimeout to debounce with drag&drop
if (!self.dragging) {
if (self.moved) {
self.moved = false;
} else if (!self.selected) {
self.getParent().select_table(self);
} else {
self.getParent().deselect_tables();
}
}
},50);
var floorplan = this.getParent();
if (floorplan.editing) {
setTimeout(function(){ // in a setTimeout to debounce with drag&drop
if (!self.dragging) {
if (self.moved) {
self.moved = false;
} else if (!self.selected) {
self.getParent().select_table(self);
} else {
self.getParent().deselect_tables();
}
}
},50);
}
},
dragstart_handler: function(event,$el,drag){
if (this.selected && !this.handle_dragging) {
this.dragging = true;
this.dragpos = { x: drag.offsetX, y: drag.offsetY };
}
}
},
dragend_handler: function(event,$el){
this.dragging = false;
@@ -103,13 +107,13 @@ function openerp_restaurant_floors(instance,module){
var cl = this.handle.classList;
var tw = this.table.width;
var th = this.table.height;
var MIN_SIZE = 40;
var tw = Math.max(MIN_SIZE, this.table.width);
var th = Math.max(MIN_SIZE, this.table.height);
var tx = this.table.position_h;
var ty = this.table.position_v;
var MIN_SIZE = 40;
if (cl.contains('left') && tw - dx >= MIN_SIZE) {
tw -= dx;
tx += dx;
@@ -180,6 +184,49 @@ function openerp_restaurant_floors(instance,module){
deselect: function() {
this.selected = false;
this.renderElement();
this.save_changes();
},
save_changes: function(){
var self = this;
var model = new instance.web.Model('restaurant.table');
var fields = _.find(this.pos.models,function(model){ return model.model === 'restaurant.table'; }).fields;
model.call('create_from_ui',[this.table]).then(function(table_id){
model.query(fields).filter([['id','=',table_id]]).first().then(function(table){
for (field in table) {
self.table[field] = table[field];
}
self.renderElement();
});
});
},
trash: function(){
var self = this;
var model = new instance.web.Model('restaurant.table');
return model.call('create_from_ui',[{'active':false,'id':this.table.id}]).then(function(table_id){
// Removing all references from the table and the table_widget in in the UI ...
// This should probably be cleaned.
for (var i = 0; i < self.pos.floors.length; i++) {
var floor = self.pos.floors[i];
for (var j = 0; j < floor.tables.length; j++) {
if (floor.tables[j].id === table_id) {
floor.tables.splice(j,1);
break;
}
}
}
var floorplan = self.getParent();
for (var i = 0; i < floorplan.table_widgets.length; i++) {
if (floorplan.table_widgets[i] === self) {
floorplan.table_widgets.splice(i,1);
}
}
if (floorplan.selected_table === self) {
floorplan.selected_table = null;
}
floorplan.update_toolbar();
self.destroy();
});
},
renderElement: function(){
var self = this;
@@ -207,6 +254,7 @@ function openerp_restaurant_floors(instance,module){
this.floor = this.pos.floors[0];
this.table_widgets = [];
this.selected_table = null;
this.editing = false;
},
show: function(){
this._super();
@@ -214,11 +262,17 @@ function openerp_restaurant_floors(instance,module){
},
hide: function(){
this._super();
if (this.editing) {
this.toggle_editing();
}
this.pos_widget.$('.order-selector').removeClass('oe_invisible');
},
click_floor_button: function(event,$el){
var floor = this.pos.floors_by_id[$el.data('id')];
if (floor !== this.floor) {
if (this.editing) {
this.toggle_editing();
}
this.floor = floor;
this.selected_table = null;
this.renderElement();
@@ -231,8 +285,7 @@ function openerp_restaurant_floors(instance,module){
for (var i = 0; i < this.table_widgets.length; i++) {
var table = this.table_widgets[i];
if (table.selected) {
table.selected = false;
table.renderElement();
table.deselect();
}
}
this.selected_table = null;
@@ -275,7 +328,7 @@ function openerp_restaurant_floors(instance,module){
var self = this;
if (this.selected_table) {
this.pos_widget.screen_selector.show_popup('textinput',{
'message':'Table Name ?',
'message':_t('Table Name ?'),
'value': this.selected_table.table.name,
'confirm': function(value) {
self.selected_table.set_table_name(value);
@@ -288,6 +341,7 @@ function openerp_restaurant_floors(instance,module){
var tw = this.create_table(this.selected_table.table);
tw.table.position_h += 10;
tw.table.position_v += 10;
tw.save_changes();
this.select_table(tw);
}
},
@@ -308,7 +362,8 @@ function openerp_restaurant_floors(instance,module){
table[p] = params[p];
}
table.floor_id = this.floor.id;
delete table['id'];
table.floor_id = [this.floor.id,''];
this.floor.tables.push(table);
var tw = new module.TableWidget(this,{table: table});
@@ -316,7 +371,34 @@ function openerp_restaurant_floors(instance,module){
this.table_widgets.push(tw);
return tw;
},
tool_trash_table: function(){
var self = this;
if (this.selected_table) {
this.pos_widget.screen_selector.show_popup('confirm',{
'message':_t('Are you sure ?'),
'comment':_t('Removing a table cannot be undone'),
'confirm': function(){
self.selected_table.trash();
},
});
}
},
toggle_editing: function(){
this.editing = !this.editing;
this.update_toolbar();
if (!this.editing) {
this.deselect_tables();
}
},
update_toolbar: function(){
if (this.editing) {
this.$('.edit-bar').removeClass('oe_hidden');
} else {
this.$('.edit-bar').addClass('oe_hidden');
}
if (this.selected_table) {
this.$('.needs-selection').removeClass('disabled');
var table = this.selected_table.table;
@@ -375,6 +457,10 @@ function openerp_restaurant_floors(instance,module){
this.$('.edit-button.rename').click(function(event){
self.tool_rename_table();
});
this.$('.edit-button.trash').click(function(event){
self.tool_trash_table();
});
this.$('.color-picker .close-picker').click(function(event){
self.tool_colorpicker_close();
@@ -387,6 +473,10 @@ function openerp_restaurant_floors(instance,module){
event.stopPropagation();
});
this.$('.edit-button.editing').click(function(){
self.toggle_editing();
});
this.$('.floor-map').click(function(event){
if (event.target === self.$('.floor-map')[0]) {
self.deselect_tables();
@@ -41,7 +41,7 @@
</div>
<div class='floor-map' t-att-style='widget.floor.background_image ? ("background-image:url("+widget.background_image_url(widget.floor)+");") :"" '>
<span class='edit-button editing'><i class='fa fa-pencil'></i></span>
<div class='edit-bar'>
<div class='edit-bar oe_hidden'>
<span class='edit-button new-table'>
<i class='fa fa-plus'></i>
</span>
@@ -72,7 +72,7 @@
<span class='color br' style='background-color:#4ED2BE' />
</div>
</span>
<span class='edit-button remove needs-selection'>
<span class='edit-button trash needs-selection'>
<i class='fa fa-trash'></i>
</span>
</div>