0
votes

Hi this question is related with my own answer here the thing is that the widget run only once, when the first database record object is show on the form view, but when I change to another record, the view its not updated with the actual record. I think that is because I run all the code in the ´start´ but I dont know how and where put he code to do this.

the code again:

(function (instance) {
    var _t = instance.web._t,
        _lt = instance.web._lt;
    var QWeb = instance.web.qweb;

    openerp.chess_base = function (instance, local) {

        local.ShowBoard = instance.web.form.FormWidget.extend({
            start: function () {
                this.$el.append('<div id="board" style="width: 300px">BOARD GOES HERE</div>');
                this.show_board();
            },
            show_board: function () {
                var Game = new instance.web.Model("chess.game"),
                    record_id = this.field_manager.datarecord.id,
                    record_name = this.field_manager.datarecord.name,
                    self = this;
                    self.el_board = self.$('#board');

                Game.query(['pgn']).filter([['id', '=', record_id], ['name', '=', record_name]]).all().then(function (data) {
                    console.log(data);
                    self.cfg = {
                        position: data[0].pgn,
                        orientation: 'white',
                        pieceTheme: '/chess_base/static/img/chesspieces/wikipedia/{piece}.png'
                    };
                    ChessBoard(self.el_board, self.cfg);
                });
            }
        });

        instance.web.form.custom_widgets.add('board', 'instance.chess_base.ShowBoard');
    }
})(openerp);
1
I have encountered issues like this in the past. I never found a solution (although I am sure there is one) that I was really impressed with. However you could see if you can bind and event to a change in the browser's hash and then rerun your show_board function upon it firing. Please post your code if you find it. Or hopefully someone much smarter than me will post the answer.Phillip Stack

1 Answers

2
votes

In your start function:

this._ic_field_manager.on('view_content_has_changed', this, function() {
    'put your code here'
 })

EDIT:

Actually there's another event you could listen, 'load_record'. Because 'view_content_has_changed' is triggered every time a single field in the view is modified, and you maybe don't want this behavior.