Technical archives des diffusions par email

technical@mail.odoo.com

Avatar

Re: Trying to embed xterm.js as Odoo widget

par
Max
- 16/05/2017 04:14:34
Thank all for your comments!
After the modification proposed by Alex now xterm gets loaded into the right div every time.
I do use className and id, and this.el as container for xterm (the code will follow).
And now I am facing another/same issue.
When tab is not focused and visible xterm does not initialize correctly.
When I give 3 seconds delay for term.open(this.el) I can manage to click on Console tab and term.opens correctly.
So now I guess this is related to visibility.
But! 
What if we don't struggle with too quick loading and instead call term.open() only when Console tab is clicked?
Can somebody give me a hint how to manage it?
Thanks!

P.S. The latest code:

odoo.define('asterisk.server_cli', function(require) {
    "use strict";

    var core = require('web.core');
    var common = require('web.form_common');

    var ServerCli = common.AbstractField.extend({
      className: 'terminal-container',
      id: _.uniqueId('terminal-container-'),

      renderElement: function() {
        var sup = this._super();
        console.log('render');
        var self = this;
        self.term = new Terminal({
          cols: 100,
          rows: 24
        });
      },

      start: function() {
        console.log('start');
        this._super();
        var self = this;
        var socketURL = self.get('value');
        var sock = new WebSocket(socketURL);
        sock.addEventListener('open', function () {
          self.term.terminadoAttach(sock);
        });
        setTimeout(function() {
                  self.term.open(self.el, focus=false);
                  self.set_dimensions('100%', '100%');
                }, 3000);
        //self.term.open(this.el, focus=false);
        //self.set_dimensions('100%', '100%');

      },

    });

    core.form_widget_registry.add('server_cli', ServerCli);

  });



Référence