1e4c9489f226bb02bf9cdc15649856045cefbcf5
[odoo/odoo.git] / addons / pos_restaurant / static / src / js / notes.js
1 function openerp_restaurant_notes(instance,module){
2     "use strict";
3
4     var QWeb = instance.web.qweb;
5     var _t   = instance.web._t;
6
7     var _super_orderline = module.Orderline.prototype;
8
9     module.Orderline = module.Orderline.extend({
10         initialize: function(attr, options) {
11             _super_orderline.initialize.call(this,attr,options);
12             this.note = this.note || "";
13         },
14         set_note: function(note){
15             this.note = note;
16             this.trigger('change',this);
17         },
18         get_note: function(note){
19             return this.note;
20         },
21         can_be_merged_with: function(orderline) {
22             if (orderline.get_note() !== this.get_note()) {
23                 return false;
24             } else {
25                 return _super_orderline.can_be_merged_with.call(this,orderline);
26             }
27         },
28         clone: function(){
29             var orderline = _super_orderline.clone.call(this);
30             orderline.note = this.note;
31             return orderline;
32         },
33         export_as_JSON: function(){
34             var json = _super_orderline.export_as_JSON.call(this);
35             json.note = this.note;
36             return json;
37         },
38         init_from_JSON: function(json){
39             _super_orderline.init_from_JSON.apply(this,arguments);
40             this.note = json.note;
41         },
42     });
43
44     module.PosWidget.include({
45         orderline_note_click: function(){
46             var self = this;
47             var line = this.pos.get_order().get_selected_orderline();
48
49             if (line) {
50                 this.screen_selector.show_popup('textarea',{
51                     message: _t('Orderline Note'),
52                     value:   line.get_note(),
53                     confirm: function(note) {
54                         line.set_note(note);
55                     },
56                 });
57             }
58         },
59         build_widgets: function(){
60             var self = this;
61             this._super();
62
63             if (this.pos.config.iface_orderline_notes) {
64                 var button = $(QWeb.render('OrderlineNoteButton'));
65                 button.click(function(){ self.orderline_note_click(); });
66                 button.appendTo(this.$('.control-buttons'));
67                 this.$('.control-buttons').removeClass('oe_hidden');
68             }
69         },
70     });
71 }