2016-11-09 24 views
1

您好,我試圖在odoo後端的窗體視圖上顯示chessboardjs,我最終使小部件顯示板,但件被隱藏,我不知道爲什麼,因爲似乎工作正常,除了件。如果我在選項中使用了dragable : true並移動了一個隱藏的棋子,那麼棋盤上的所有棋子都會呈現出來。我是否錯過了一些東西,在我的代碼中,棋盤沒有被渲染好? 這裏是MI部件代碼:試圖顯示在odoo窗體部件中的棋盤js,沒有錯誤沒有片段

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

回答

1

我不知道爲什麼,但是這不能解決問題,如果有人有一個解釋,我請...

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