// 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; },
    __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() {
      var button, container, _i, _len, _ref, _results,
        _this = this;
      this.dom = $("<div class=\"control container dialog\">\n    <div class=\"backdrop\">\n        <div class=\"content\">\n            <div class=\"children\">\n            </div>\n        </div>\n    </div>\n</div>");
      this.childContainer = this.dom.find('.children');
      if (this.properties.buttons) {
        this.buttons = $("<div class=\"buttons\"></div>");
        this.dom.find('.content').append(this.buttons);
        container = new Controls.hc(this.ui);
        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(button) {
            var b;
            b = new Controls.button(_this.ui, {
              text: button.text,
              icon: button.icon,
              style: 'normal'
            });
            b.on_click = function() {
              return _this.event('button', {
                button: button.id
              });
            };
            return container.append(b);
          })(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() {
      this.properties.buttons = [
        {
          text: 'OK',
          id: 'ok'
        }, {
          text: 'Cancel',
          id: 'cancel'
        }
      ];
      inputdialog.__super__.createDom.call(this);
      this.input = new Controls.textbox(this.ui, {
        value: this.properties.value
      }, []);
      return this.append(new Controls.pad(this.ui, {}, [
        new Controls.hc(this.ui, {}, [
          new Controls.label(this.ui, {
            text: this.properties.text
          }, []), this.input
        ])
      ]));
    };

    inputdialog.prototype.detectUpdates = function() {
      var r, value;
      r = {};
      value = this.input.properties.value;
      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.createDom = function() {
      var dir, file, _fn, _i, _j, _len, _len1, _ref, _ref1, _results,
        _this = this;
      this.properties.buttons = [
        {
          text: 'Cancel',
          id: 'cancel'
        }
      ];
      openfiledialog.__super__.createDom.call(this);
      this.container = new Controls.list(this.ui);
      this.append(new Controls.pad(this.ui, {}, [
        new Controls.box(this.ui, {
          width: 'auto',
          height: 300,
          scroll: true
        }, [this.container])
      ]));
      _ref = this.properties._dirs;
      _fn = function(dir) {
        var item;
        item = new Controls.hc(_this.ui, {}, [
          new Controls.icon(_this.ui, {
            icon: 'folder-open'
          }), new Controls.label(_this.ui, {
            text: dir
          })
        ]);
        $(item.dom).click(function() {
          return _this.event('item-click', {
            item: dir
          });
        });
        return _this.container.append(new Controls.listitem(_this.ui, {}, [item]));
      };
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        dir = _ref[_i];
        _fn(dir);
      }
      _ref1 = this.properties._files;
      _results = [];
      for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
        file = _ref1[_j];
        _results.push((function(file) {
          var item;
          item = new Controls.hc(_this.ui, {}, [
            new Controls.icon(_this.ui, {
              icon: 'file'
            }), new Controls.label(_this.ui, {
              text: file
            })
          ]);
          $(item.dom).click(function() {
            return _this.event('item-click', {
              item: file
            });
          });
          return _this.container.append(new Controls.listitem(_this.ui, {}, [item]));
        })(file));
      }
      return _results;
    };

    return openfiledialog;

  })(Controls.dialog);

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

    __extends(opendirdialog, _super);

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

    opendirdialog.prototype.createDom = function() {
      var dir, _i, _len, _ref, _results,
        _this = this;
      this.properties.buttons = [
        {
          text: 'Select',
          id: 'select'
        }, {
          text: 'Cancel',
          id: 'cancel'
        }
      ];
      opendirdialog.__super__.createDom.call(this);
      this.container = new Controls.list(this.ui);
      this.append(new Controls.pad(this.ui, {}, [
        new Controls.box(this.ui, {
          width: 'auto',
          height: 300,
          scroll: true
        }, [this.container])
      ]));
      _ref = this.properties._dirs;
      _results = [];
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        dir = _ref[_i];
        _results.push((function(dir) {
          var item;
          item = new Controls.hc(_this.ui, {}, [
            new Controls.icon(_this.ui, {
              icon: 'folder-open'
            }), new Controls.label(_this.ui, {
              text: dir
            })
          ]);
          $(item.dom).click(function() {
            return _this.event('item-click', {
              item: dir
            });
          });
          return _this.container.append(new Controls.listitem(_this.ui, {}, [item]));
        })(dir));
      }
      return _results;
    };

    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.createDom = function() {
      var dir, _i, _len, _ref, _results,
        _this = this;
      this.properties.buttons = [
        {
          text: 'Cancel',
          id: 'cancel'
        }, {
          text: 'Save',
          id: 'ok'
        }
      ];
      savefiledialog.__super__.createDom.call(this);
      this.input = new Controls.textbox(this.ui, {
        value: ''
      });
      this.container = new Controls.list(this.ui);
      this.append(new Controls.pad(this.ui, {}, [
        new Controls.vc(this.ui, {}, [
          new Controls.box(this.ui, {
            width: 'auto',
            height: 300,
            scroll: true
          }, [this.container]), new Controls.hc(this.ui, {}, [
            new Controls.label(this.ui, {
              text: 'Name: '
            }), this.input
          ])
        ])
      ]));
      _ref = this.properties._dirs;
      _results = [];
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        dir = _ref[_i];
        _results.push((function(dir) {
          var item;
          item = new Controls.hc(_this.ui, {}, [
            new Controls.icon(_this.ui, {
              icon: 'folder-open'
            }), new Controls.label(_this.ui, {
              text: dir
            })
          ]);
          $(item.dom).click(function() {
            return _this.event('item-click', {
              item: dir
            });
          });
          return _this.container.append(new Controls.listitem(_this.ui, {}, [item]));
        })(dir));
      }
      return _results;
    };

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

    return savefiledialog;

  })(Controls.dialog);

}).call(this);
