// Generated by CoffeeScript 1.7.1
(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; },
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

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

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

    dialog.prototype.createDom = function() {
      return "<div class=\"control container dialog " + (this.s(this.properties.style)) + "\">\n    <div class=\"backdrop\">\n        <div class=\"content\">\n            <div class=\"__child-container\">\n                <children>\n            </div>\n        </div>\n    </div>\n</div>";
    };

    dialog.prototype.setupDom = function(dom) {
      var button, container, _i, _len, _ref, _results;
      dialog.__super__.setupDom.call(this, dom);
      if (this.properties.buttons) {
        this.buttons = $("<div class=\"buttons\"></div>");
        $(this.dom.children[0].children[0]).append(this.buttons);
        container = new Controls.hc(this.ui);
        container.setupDom();
        this.buttons.append(container.dom);
        _ref = this.properties.buttons;
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          button = _ref[_i];
          _results.push((function(_this) {
            return function(button) {
              var b;
              b = new Controls.button(_this.ui, {
                text: button.text,
                icon: button.icon,
                style: 'normal'
              });
              b.setupDom();
              b.on_click = function() {
                return _this.event('button', {
                  button: button.id
                });
              };
              return container.append(b);
            };
          })(this)(button));
        }
        return _results;
      }
    };

    return dialog;

  })(window.Control);

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

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

    inputdialog.prototype.createDom = function() {
      var body;
      this.input = new Controls.textbox(this.ui, {
        value: this.properties.value
      }, []);
      body = new Controls.pad(this.ui, {}, [
        new Controls.hc(this.ui, {}, [
          new Controls.label(this.ui, {
            text: this.properties.text
          }, []), this.input
        ])
      ]);
      return inputdialog.__super__.createDom.call(this);
    };

    inputdialog.prototype.setupDom = function(dom) {
      this.properties.buttons = [
        {
          text: 'OK',
          id: 'ok'
        }, {
          text: 'Cancel',
          id: 'cancel'
        }
      ];
      return inputdialog.__super__.setupDom.call(this, dom);
    };

    inputdialog.prototype.detectUpdates = function() {
      var r, value;
      r = {};
      value = this.input.getValue();
      if (value !== this.properties.value) {
        r.value = value;
      }
      this.properties.value = value;
      return r;
    };

    return inputdialog;

  })(Controls.dialog);

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

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

    openfiledialog.prototype.setupDom = function(dom) {
      this.properties.buttons = [
        {
          text: 'Cancel',
          id: 'cancel'
        }
      ];
      return openfiledialog.__super__.setupDom.call(this, dom);
    };

    return openfiledialog;

  })(Controls.dialog);

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

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

    opendirdialog.prototype.setupDom = function(dom) {
      this.properties.buttons = [
        {
          text: 'Select',
          id: 'select'
        }, {
          text: 'Cancel',
          id: 'cancel'
        }
      ];
      return opendirdialog.__super__.setupDom.call(this, dom);
    };

    return opendirdialog;

  })(Controls.dialog);

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

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

    savefiledialog.prototype.setupDom = function(dom) {
      this.properties.buttons = [
        {
          text: 'Cancel',
          id: 'cancel'
        }, {
          text: 'Save',
          id: 'ok'
        }
      ];
      savefiledialog.__super__.setupDom.call(this, dom);
      return this.input = $(this.dom).find('input');
    };

    savefiledialog.prototype.on_button = function(params) {
      if (params.button !== 'ok') {
        return true;
      }
      if (this.input.val().length > 0) {
        return this.event('select', {
          path: this.properties.path + '/' + this.input.val()
        });
      }
    };

    return savefiledialog;

  })(Controls.dialog);

}).call(this);
