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

  define(function() {
    var List;
    return List = (function() {
      List.prototype.fnSettings = {
        "aaSorting": [],
        'aLengthMenu': [[25, 100, 500, -1], [25, 100, 500, 'Tous']],
        "bStateSave": true,
        "bLengthChange": true,
        "iDisplayLength": 25,
        "sDom": "Tlfrtip<'clear'>",
        "sPaginationType": "full_numbers",
        "oLanguage": {
          "sLengthMenu": "Afficher _MENU_ lignes par page",
          "sZeroRecords": "Pas trouvé..",
          "sInfo": "Affichage de _START_ à _END_ sur _TOTAL_ lignes",
          "sInfoEmpty": "Affichage de 0 à 0 sur 0 lignes",
          "sInfoFiltered": "(filtrage sur _MAX_ lignes)",
          "sSearch": "Rechercher",
          "oPaginate": {
            "sFirst": "&nbsp;&nbsp;&nbsp;",
            "sLast": "&nbsp;&nbsp;&nbsp;",
            "sNext": "&nbsp;&nbsp;&nbsp;",
            "sPrevious": "&nbsp;&nbsp;&nbsp;"
          }
        }
      };

      List.prototype.table_selector = 'table.datatable';

      List.prototype.view = 'details';

      List.prototype.nodraw = false;

      List.prototype.detail_selector = ".list-details tbody tr";

      List.prototype.detail_event = "dblclick";

      List.prototype.detail_data_selector = "apath";

      function List(settings) {
        this.addDeleteButtons = __bind(this.addDeleteButtons, this);
        this.draw = __bind(this.draw, this);
        if ((settings != null ? settings['fnSettings'] : void 0) != null) {
          this.fnSettings = settings['fnSettings'];
        }
        if ((settings != null ? settings['nodraw'] : void 0) != null) {
          this.nodraw = settings['nodraw'];
        }
        if ((settings != null ? settings['table_selector'] : void 0) != null) {
          this.table = settings['table_selector'];
        }
        if ((settings != null ? settings['view'] : void 0) != null) {
          this.view = settings['view'];
        }
        if ((settings != null ? settings['detail_selector'] : void 0) != null) {
          this.detail_selector = settings['detail_selector'];
        }
        if ((settings != null ? settings['detail_event'] : void 0) != null) {
          this.detail_event = settings['detail_event'];
        }
        if ((settings != null ? settings['detail_data_selector'] : void 0) != null) {
          this.detail_data_selector = settings['detail_data_selector'];
        }
        $(this.detail_selector).on(this.detail_event, (function(_this) {
          return function(evt) {
            var details_path, row;
            row = $(evt.delegateTarget).closest('tr');
            details_path = row.data(_this.detail_data_selector);
            return window.location.href = "/" + _this.view + "/" + details_path + "/";
          };
        })(this));
        this.addDeleteButtons();
        if (!this.nodraw) {
          this.draw();
        }
      }

      List.prototype.draw = function() {
        this.table = $(this.table_selector).dataTable(this.fnSettings);
        if (this.table.hasClass("hidden")) {
          return this.table.removeClass("hidden");
        }
      };

      List.prototype.addDeleteButtons = function(msg, where) {
        var button, td, _i, _len, _ref, _results;
        if (msg == null) {
          msg = "Voulez-vous réellement faire cette action?";
        }
        if (where == null) {
          where = "tbody tr > td:last-child";
        }

        /*
        Adds delete button on each line.
        Should be added after showListCallback
            showListCallback: (oSettings) =>
            super(oSettings)
            @addDeleteButtons()
         */
        _ref = $(".add-delete-bouton").find(where);
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          td = _ref[_i];
          if (!(!($(td).hasClass("dataTables_empty") || $(td).hasClass("delete_button")))) {
            continue;
          }
          button = $('<span title="Détruire" class="glyphicon glyphicon-trash"/>').appendTo(td);
          button.css('float', 'right');
          $(td).addClass("delete_button");
          _results.push(button.on("click", (function(_this) {
            return function(evt) {
              var bocall, path, tr;
              if (evt != null) {
                evt.stopImmediatePropagation();
              }
              if (evt != null) {
                evt.preventDefault();
              }
              if (confirm("Confirmation : " + msg)) {
                tr = $(evt.delegateTarget).closest("tr");
                path = tr.data("apath");
                bocall = new BOCall;
                bocall.done = function() {
                  return window.location.reload();
                };
                return bocall.applyCommand(path, "Unplug");
              }
            };
          })(this)));
        }
        return _results;
      };

      return List;

    })();
  });

}).call(this);

//# sourceMappingURL=list.js.map
