试图在odoo表单小部件中显示棋盘js,没有错误,没有片段 [英] trying to show chessboard js in odoo form widget, no error no pieces

查看:99
本文介绍了试图在odoo表单小部件中显示棋盘js,没有错误,没有片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在odoo后端的表单视图上显示 chessboardjs 向董事会展示,但是这些部分是隐藏的,我不知道为什么,因为除了这些部分,看起来还不错.如果我在选项中使用dragable : true并移动了一块隐藏的棋子,那么该棋盘将与所有棋子一起呈现.我在我的代码上缺少一些东西吗,棋盘的渲染效果不佳? 这是mi小部件代码:

Hi i´m trying to show chessboardjs on a form view in odoo backend, I finally make the widget to show the board, but the pieces are hidden, I don´t know why because seems to work fine, except for the pieces. If I use dragable : true in the options and move a hidden piece then the board is rendered with all the pieces. do I´m missing something, on my code that the chessboard its not rendered well?? here is mi widget code:

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

    openerp.chess_base = function (instance, local) {

        local.YourWidgetClassName = instance.web.form.FormWidget.extend({
            start: function () {
                this.$el.append('<div id="board" style="width: 300px">BOARD GOES HERE</div>'); // creating the board in the DOM
                this.onBoard();
            },
            onBoard: function (position, orientation) {
                if (!position) {
                    this.position = 'start'
                } else {
                    this.position = position
                }
                if (!orientation) {
                    this.orientation = 'white'
                } else {
                    this.orientation = orientation
                }
                this.el_board = this.$('#board');
                this.cfg = {
                    position: this.position,
                    orientation: this.orientation,
                    draggable: false,
                    pieceTheme: '/chess_base/static/img/chesspieces/wikipedia/{piece}.png'
                };
                this.board = ChessBoard(this.el_board, this.cfg);
            }
        });

        instance.web.form.custom_widgets.add('widget_tag_name', 'instance.chess_base.YourWidgetClassName');
    }
})(openerp);

推荐答案

我不知道为什么,但这可以解决问题,如果有人对我有解释,请...

I don't know why but this solve the issue, if someone have an explanation to me please ...

(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);

这篇关于试图在odoo表单小部件中显示棋盘js,没有错误,没有片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆