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

  define(function() {
    var Main;
    if (typeof moment !== "undefined" && moment !== null) {
      moment.locale("fr");
    }
    if (typeof numeral !== "undefined" && numeral !== null) {
      numeral.language("fr");
    }
    return Main = (function() {
      function Main() {
        this.for_all = __bind(this.for_all, this);
        this.disconnect = __bind(this.disconnect, this);
        var main_menu, url;
        url = window.location.pathname;
        main_menu = $("ul.nav#mainMenu");
        main_menu.find("li").removeClass('active');
        main_menu.find("a[href='" + url + "']").parents("li").addClass('active');
        $("#disconnect").on("click", (function(_this) {
          return function(evt) {
            return _this.disconnect();
          };
        })(this));
        $("body").on("DOMNodeInserted", (function(_this) {
          return function(evt) {
            return _this.for_all(evt.target);
          };
        })(this));
        this.for_all($("body"));
      }

      Main.prototype.disconnect = function(evt) {
        var bocall;
        if (evt != null) {
          evt.preventDefault();
        }
        bocall = new BOCall;
        return bocall.disconnect();
      };

      Main.prototype.for_all = function(target) {
        var alert_edition, datepicker, post, toggle_next, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
        $("body").off("DOMNodeInserted");
        alert_edition = function(evt) {
          var detail, panel;
          target = $(evt.delegateTarget);
          if (target.hasClass("no_change")) {
            return;
          }
          detail = target.closest(".details-form");
          if (detail.length > 0) {
            panel = target.closest(".panel");
            if (panel.find(".save-changes").length > 0) {
              panel.addClass("panel-danger");
              return panel.find(".save-changes").show();
            } else if (detail.find('#editer').length > 0) {
              return alert("Attention: Vous n'êtes pas en mode édition!");
            }
          }
        };
        _ref = $("input", target);
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          post = _ref[_i];
          if ($(post).attr("name") !== "" && $(post).attr("type") !== "button" && $(post).attr("type") !== "file") {
            $(post).change(alert_edition);
          }
        }
        _ref1 = $("textarea", target);
        for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
          post = _ref1[_j];
          if ($(post).attr("name") !== "") {
            $(post).change(alert_edition);
          }
        }
        _ref2 = $("select", target);
        for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
          post = _ref2[_k];
          if ($(post).attr("name") !== "") {
            $(post).change(alert_edition);
          }
        }
        datepicker = $(".datepicker", target);
        if (datepicker.length > 0 && datepicker.find("input").size() > 0) {
          datepicker.datetimepicker({
            locale: 'fr',
            format: "L"
          });
          datepicker.filter(".start").on("dp.change", function(e) {
            var end;
            end = $(e.delegateTarget).closest(".form-group").parent().find(".datepicker.end");
            return end.data("DateTimePicker").setMinDate(e.date);
          });
          datepicker.filter(".end").on("dp.change", function(e) {
            var start;
            start = $(e.delegateTarget).closest(".form-group").parent().find(".datepicker.start");
            return start.data("DateTimePicker").setMaxDate(e.date);
          });
        }
        toggle_next = $(".toggle-next", target);
        toggle_next.on("click", function(e) {
          return $(e.delegateTarget).next().toggle();
        });
        toggle_next = $(".fade-toggle-next", target);
        toggle_next.on("click", function(e) {
          return $(e.delegateTarget).next().fadeToggle();
        });
        return $("body").on("DOMNodeInserted", (function(_this) {
          return function(evt) {
            return _this.for_all(evt.target);
          };
        })(this));
      };

      return Main;

    })();
  });

}).call(this);
