// Generated by CoffeeScript 1.7.1
(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  window.Controls.logs__log = (function(_super) {
    __extends(logs__log, _super);

    function logs__log() {
      this.add = __bind(this.add, this);
      return logs__log.__super__.constructor.apply(this, arguments);
    }

    logs__log.prototype.createDom = function() {
      return "<textarea class=\"control textbox log\">\n</textarea>";
    };

    logs__log.prototype.setupDom = function(dom) {
      logs__log.__super__.setupDom.call(this, dom);
      if (this.properties.path) {
        this.socket = ajentiConnectSocket('/log');
        this.socket.send(JSON.stringify({
          type: 'select',
          path: this.properties.path
        }));
        return this.socket.on('add', this.add);
      }
    };

    logs__log.prototype.add = function(data) {
      console.log('Received: +' + data.length + ', total ' + $(this.dom)[0].value.length);
      $(this.dom)[0].value += data;
      if ($(this.dom)[0].value.length > 128 * 1024) {
        $(this.dom)[0].value = $(this.dom)[0].value.slice($(this.dom)[0].value.length - 128 * 1024);
      }
      return this.dom.scrollTop = this.dom.scrollHeight;
    };

    logs__log.prototype.onBroadcast = function(msg) {
      if (msg === 'destruct') {
        if (this.socket) {
          return this.socket.disconnect();
        }
      }
    };

    return logs__log;

  })(window.Control);

}).call(this);
