// Generated by CoffeeScript 1.9.1
(function() {
  var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  define(function() {
    var Form;
    return Form = (function() {
      function Form(path) {
        var checkbox, checkboxes, error, i, len;
        this.path = path;
        this.update_hidden_checkbox = bind(this.update_hidden_checkbox, this);
        try {
          $('.form-control.datetimepicker').datetimepicker({
            language: 'fr',
            format: 'DD/MM/YYYY hh:mm:ss',
            weekStart: 1
          });
          $('.form-control.datepicker').datetimepicker({
            language: 'fr',
            format: 'DD/MM/YYYY',
            weekStart: 1
          });
          $('.form-control.timepicker').datetimepicker({
            language: 'fr',
            format: 'hh:mm:ss',
            weekStart: 1
          });
        } catch (_error) {
          error = _error;
          null;
        }
        $("#editer").one("click", (function(_this) {
          return function(evt) {
            var bocall;
            if (evt != null) {
              evt.preventDefault();
            }
            bocall = new BOCall;
            bocall.done = function() {
              return window.location.reload();
            };
            return bocall.applyCommand(_this.path, "$Lock");
          };
        })(this));
        $(".liberer").one("click", (function(_this) {
          return function() {
            var bocall;
            bocall = new BOCall;
            bocall.done = function() {};
            return bocall.applyCommand(_this.path, "$Unlock");
          };
        })(this));
        $('form').one("submit", (function(_this) {
          return function(evt) {
            var checkbox, form, i, len, ref, results;
            form = $(evt.delegateTarget);
            ref = form.find("[type=checkbox]");
            results = [];
            for (i = 0, len = ref.length; i < len; i++) {
              checkbox = ref[i];
              if (!checkbox.checked) {
                results.push(form.append($('<input />').attr('type', 'hidden').attr('name', checkbox.name).attr('value', "false")));
              } else {
                results.push(void 0);
              }
            }
            return results;
          };
        })(this));
        checkboxes = $("[type=checkbox]").on("change", (function(_this) {
          return function(evt) {
            var checkbox;
            checkbox = $(evt.target);
            return _this.update_hidden_checkbox(checkbox);
          };
        })(this));
        for (i = 0, len = checkboxes.length; i < len; i++) {
          checkbox = checkboxes[i];
          this.update_hidden_checkbox($(checkbox));
        }
      }

      Form.prototype.update_hidden_checkbox = function(checkbox) {
        var disabled, hidden;
        hidden = checkbox.siblings("[type=hidden]");
        if (hidden.size()) {
          disabled = checkbox.is(":checked");
          return hidden.prop("disabled", disabled);
        }
      };

      return Form;

    })();
  });

}).call(this);
