// Generated by CoffeeScript 1.4.0
(function() {
  var __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.pad = (function(_super) {

    __extends(pad, _super);

    function pad() {
      return pad.__super__.constructor.apply(this, arguments);
    }

    pad.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container pad\">\n</div>");
      return this.childContainer = this.dom;
    };

    return pad;

  })(window.Control);

  window.Controls.indent = (function(_super) {

    __extends(indent, _super);

    function indent() {
      return indent.__super__.constructor.apply(this, arguments);
    }

    indent.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container indent\">\n</div>");
      return this.childContainer = this.dom;
    };

    return indent;

  })(window.Control);

  window.Controls.box = (function(_super) {

    __extends(box, _super);

    function box() {
      return box.__super__.constructor.apply(this, arguments);
    }

    box.prototype.createDom = function() {
      var h, w;
      w = this._int_to_px(this.properties.width);
      h = this._int_to_px(this.properties.height);
      this.dom = $$("<div class=\"control container box\" style=\"width: " + w + "; height: " + h + "; \n    overflow: " + (this.properties.scroll ? 'auto' : 'hidden') + "\">\n</div>");
      return this.childContainer = this.dom;
    };

    return box;

  })(window.Control);

  window.Controls.well = (function(_super) {

    __extends(well, _super);

    function well() {
      return well.__super__.constructor.apply(this, arguments);
    }

    well.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container well\">\n</div>");
      return this.childContainer = this.dom;
    };

    return well;

  })(window.Control);

  window.Controls.center = (function(_super) {

    __extends(center, _super);

    function center() {
      return center.__super__.constructor.apply(this, arguments);
    }

    center.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container center\">\n</div>");
      return this.childContainer = this.dom;
    };

    return center;

  })(window.Control);

  window.Controls.right = (function(_super) {

    __extends(right, _super);

    function right() {
      return right.__super__.constructor.apply(this, arguments);
    }

    right.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container right\">\n</div>");
      return this.childContainer = this.dom;
    };

    return right;

  })(window.Control);

  window.Controls.hc = (function(_super) {

    __extends(hc, _super);

    function hc() {
      return hc.__super__.constructor.apply(this, arguments);
    }

    hc.prototype.createDom = function() {
      this.dom = $$("<table class=\"control container hc " + this.properties.style + "\"><tr></tr></table>");
      return this.childContainer = this.dom.getElementsByTagName('tr')[0];
    };

    hc.prototype.wrapChild = function(child) {
      return $('<td></td>').append(child.dom)[0];
    };

    return hc;

  })(window.Control);

  window.Controls.vc = (function(_super) {

    __extends(vc, _super);

    function vc() {
      return vc.__super__.constructor.apply(this, arguments);
    }

    vc.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container vc " + this.properties.style + "\"></div>");
      return this.childContainer = this.dom;
    };

    vc.prototype.wrapChild = function(child) {
      return $('<div></div>').append(child.dom)[0];
    };

    return vc;

  })(window.Control);

  window.Controls.formline = (function(_super) {

    __extends(formline, _super);

    function formline() {
      return formline.__super__.constructor.apply(this, arguments);
    }

    formline.prototype.createDom = function() {
      this.dom = $$("<div class=\"control formline\">\n    <div class=\"control label\">" + this.properties.text + "</div>\n    <div class=\"--child-container\">\n    </div>\n</div>");
      return this.childContainer = this.dom.getElementsByClassName('--child-container');
    };

    return formline;

  })(window.Control);

  window.Controls.formgroup = (function(_super) {

    __extends(formgroup, _super);

    function formgroup() {
      return formgroup.__super__.constructor.apply(this, arguments);
    }

    formgroup.prototype.createDom = function() {
      this.dom = $("<div class=\"control formgroup\">\n    <div>" + this.properties.text + "</div>\n    <div class=\"--child-container\">\n    </div>\n</div>");
      return this.childContainer = this.dom.find('.--child-container');
    };

    return formgroup;

  })(window.Control);

  window.Controls.toolbar = (function(_super) {

    __extends(toolbar, _super);

    function toolbar() {
      return toolbar.__super__.constructor.apply(this, arguments);
    }

    toolbar.prototype.createDom = function() {
      this.dom = $$("<div class=\"control container toolbar\">\n</div>");
      return this.childContainer = this.dom;
    };

    return toolbar;

  })(window.Control);

  window.Controls.dt = (function(_super) {

    __extends(dt, _super);

    function dt() {
      return dt.__super__.constructor.apply(this, arguments);
    }

    dt.prototype.createDom = function() {
      var w;
      w = this._int_to_px(this.properties.width);
      this.dom = $$("<table cellspacing=\"0\" cellpadding=\"0\" class=\"control table " + this.properties.style + "\" style=\"width: " + w + "\">\n    <tbody></tbody>\n</table>");
      return this.childContainer = this.dom.getElementsByTagName('tbody')[0];
    };

    dt.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return dt;

  })(window.Control);

  window.Controls.sortabledt = (function(_super) {

    __extends(sortabledt, _super);

    function sortabledt() {
      return sortabledt.__super__.constructor.apply(this, arguments);
    }

    sortabledt.prototype.createDom = function() {
      sortabledt.__super__.createDom.call(this);
      this.tbody = $(this.dom).find('tbody');
      this.tbody.sortable({
        distance: 5,
        cancel: 'input,button,a'
      });
      return this.order = [];
    };

    sortabledt.prototype.detectUpdates = function() {
      var hasChanges, i, r, _i, _ref,
        _this = this;
      this.newOrder = [];
      hasChanges = false;
      this.tbody.find('>*').each(function(i, e) {
        var idx;
        idx = parseInt($(e).attr('data-order'));
        if ((i + 1) !== idx) {
          hasChanges = true;
        }
        return _this.newOrder.push(idx);
      });
      r = {};
      if (!hasChanges) {
        return r;
      }
      for (i = _i = 0, _ref = this.order.length; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
        if (this.newOrder[i] !== this.order[i]) {
          r.order = this.newOrder;
          break;
        }
      }
      this.order = this.newOrder;
      return r;
    };

    sortabledt.prototype.wrapChild = function(child) {
      $(child.dom).attr('data-order', this.children.length);
      return child.dom;
    };

    sortabledt.prototype.append = function(child) {
      sortabledt.__super__.append.call(this, child);
      return this.order.push(this.children.length);
    };

    return sortabledt;

  })(window.Controls.dt);

  window.Controls.dtr = (function(_super) {

    __extends(dtr, _super);

    function dtr() {
      return dtr.__super__.constructor.apply(this, arguments);
    }

    dtr.prototype.createDom = function() {
      this.dom = $$("<tr></tr>", 'tbody');
      return this.childContainer = this.dom;
    };

    dtr.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return dtr;

  })(window.Control);

  window.Controls.dtd = (function(_super) {

    __extends(dtd, _super);

    function dtd() {
      return dtd.__super__.constructor.apply(this, arguments);
    }

    dtd.prototype.createDom = function() {
      var fw, w;
      w = this._int_to_px(this.properties.width);
      fw = this._int_to_px(this.properties.forcewidth);
      this.dom = $$("<td style=\"width: " + w + "; max-width: " + fw + "\"></td>", 'tr');
      return this.childContainer = this.dom;
    };

    dtd.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return dtd;

  })(window.Control);

  window.Controls.dth = (function(_super) {

    __extends(dth, _super);

    function dth() {
      return dth.__super__.constructor.apply(this, arguments);
    }

    dth.prototype.createDom = function() {
      var w;
      w = this._int_to_px(this.properties.width);
      this.dom = $$("<th style=\"width: " + w + "\">" + this.properties.text + "</th>", 'tr');
      return this.childContainer = this.dom;
    };

    dth.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return dth;

  })(window.Control);

  window.Controls.lt = (function(_super) {

    __extends(lt, _super);

    function lt() {
      return lt.__super__.constructor.apply(this, arguments);
    }

    lt.prototype.createDom = function() {
      var w;
      w = this._int_to_px(this.properties.width);
      this.dom = $$("<table cellspacing=\"0\" cellpadding=\"0\" class=\"control layout-table\" style=\"width: " + w + "\">\n    <tbody></tbody>\n</table>");
      return this.childContainer = this.dom.getElementsByTagName('tbody')[0];
    };

    lt.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return lt;

  })(window.Control);

  window.Controls.ltr = (function(_super) {

    __extends(ltr, _super);

    function ltr() {
      return ltr.__super__.constructor.apply(this, arguments);
    }

    ltr.prototype.createDom = function() {
      this.dom = $$("<tr></tr>", 'tbody');
      return this.childContainer = this.dom;
    };

    ltr.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return ltr;

  })(window.Control);

  window.Controls.ltd = (function(_super) {

    __extends(ltd, _super);

    function ltd() {
      return ltd.__super__.constructor.apply(this, arguments);
    }

    ltd.prototype.createDom = function() {
      var w;
      w = this._int_to_px(this.properties.width);
      this.dom = $$("<td style=\"width: " + w + "\"></td>", 'tr');
      return this.childContainer = this.dom;
    };

    ltd.prototype.wrapChild = function(child) {
      return child.dom;
    };

    return ltd;

  })(window.Control);

  window.Controls.collapserow = (function(_super) {

    __extends(collapserow, _super);

    function collapserow() {
      return collapserow.__super__.constructor.apply(this, arguments);
    }

    collapserow.prototype.createDom = function() {
      var _this = this;
      this.dom = $("<tr>\n    <td colspan=\"999\" class=\"control container collapserow\">\n        <div class=\"header\"></div>\n        <div class=\"children\"></div>\n    </td>\n</tr>");
      this.container = this.dom.find('.children')[0];
      this.header = this.dom.find('.header')[0];
      this.hasHeader = false;
      this.expanded = this.properties.expanded;
      if (!this.properties.expanded) {
        $(this.container).hide();
      }
      return $(this.header).click(function(e) {
        _this.expanded = !_this.expanded;
        _this.publish();
        $(_this.container).toggle('blind');
        if (_this.expanded) {
          _this.broadcast('visible');
        }
        return _this.cancel(e);
      });
    };

    collapserow.prototype.detectUpdates = function() {
      var r;
      r = {};
      if (this.expanded !== this.properties.expanded) {
        r.expanded = this.expanded;
      }
      this.properties.expanded = this.expanded;
      return r;
    };

    collapserow.prototype.append = function(child) {
      if (this.hasHeader) {
        $(this.container).append(child.dom);
      } else {
        $(this.header).append(child.dom);
        this.hasHeader = true;
      }
      return this.children.push(child);
    };

    return collapserow;

  })(window.Control);

  window.Controls.tabs = (function(_super) {

    __extends(tabs, _super);

    function tabs() {
      return tabs.__super__.constructor.apply(this, arguments);
    }

    tabs.prototype.createDom = function() {
      this.dom = $("<div class=\"control tabs\">\n    <ul></ul>\n</div>");
      this.childContainer = this.dom;
      this.active = this.properties.active;
      this.headers = this.dom.find('ul');
      return this.dom.tabs();
    };

    tabs.prototype.detectUpdates = function() {
      var r;
      r = {};
      if (this.active !== this.properties.active) {
        r.active = this.active;
      }
      this.properties.active = this.active;
      return r;
    };

    tabs.prototype.append = function(child) {
      var header,
        _this = this;
      tabs.__super__.append.call(this, child);
      header = $$("<li><a href=\"#" + child.uid + "\">" + child.properties.title + "</a></li>");
      this.headers.append(header);
      this.dom.tabs('destroy');
      return this.dom.tabs({
        beforeActivate: function(e, ui) {
          _this.active = parseInt($(ui.newPanel).attr('data-index'));
          _this.event('switch', {});
          if (!_this.properties.client) {
            return e.preventDefault();
          }
        },
        selected: this.active
      });
    };

    tabs.prototype.wrapChild = function(child) {
      return $("<div data-index=\"" + (this.children.length - 1) + "\" id=\"" + child.uid + "\"></div>").append(child.dom)[0];
    };

    return tabs;

  })(window.Control);

  window.Controls.collapse = (function(_super) {

    __extends(collapse, _super);

    function collapse() {
      return collapse.__super__.constructor.apply(this, arguments);
    }

    collapse.prototype.createDom = function() {
      var _this = this;
      this.dom = $("<div class=\"control collapse\">\n    <div class=\"header\"></div>\n    <div class=\"children\"></div>\n</div>");
      this.container = this.dom.find('>.children');
      this.header = this.dom.find('>.header');
      this.hasHeader = false;
      this.expanded = this.properties.expanded;
      if (!this.properties.expanded) {
        this.container.hide();
      }
      return this.header.click(function(e) {
        _this.expanded = !_this.expanded;
        _this.publish();
        _this.container.toggle('blind');
        if (_this.expanded) {
          _this.broadcast('visible');
        }
        return _this.cancel(e);
      });
    };

    collapse.prototype.detectUpdates = function() {
      var r;
      r = {};
      if (this.expanded !== this.properties.expanded) {
        r.expanded = this.expanded;
      }
      this.properties.expanded = this.expanded;
      return r;
    };

    collapse.prototype.append = function(child) {
      if (this.hasHeader) {
        this.container.append(child.dom);
      } else {
        this.header.append(child.dom);
        this.hasHeader = true;
      }
      return this.children.push(child);
    };

    return collapse;

  })(window.Control);

}).call(this);
