// Generated by CoffeeScript 1.9.1
(function() {
  var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    extend = 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; },
    hasProp = {}.hasOwnProperty;

  define(["studiogdo/skeleton"], function(Skeleton) {
    var ListSelectionForm;
    return ListSelectionForm = (function(superClass) {
      extend(ListSelectionForm, superClass);

      function ListSelectionForm(list) {
        this.list = list;
        this.unlock = bind(this.unlock, this);
        this.lock = bind(this.lock, this);
        this.commit_release_list = bind(this.commit_release_list, this);
        this.commit = bind(this.commit, this);
        this.cancel = bind(this.cancel, this);
        this.showSelectedCallback = bind(this.showSelectedCallback, this);
        this.skel = this.list.selected_skel;
      }

      ListSelectionForm.prototype.showSelectedCallback = function(selected) {
        var form;
        form = selected.querySelector("form");
        if (form != null) {
          this.path = form.dataset.apath;
        }
        $("#annuler", selected).on("click", this.cancel);
        $('#valider', selected).on("click", this.commit);
        $("#validerLibererListe", selected).on("click", this.commit_release_list);
        $("#editer", selected).on("click", this.lock);
        return $("#liberer", selected).on("click", this.unlock);
      };

      ListSelectionForm.prototype.cancel = function(evt) {
        if (evt != null) {
          evt.preventDefault();
        }
        return this.list.drawList(null, null, (function(_this) {
          return function() {
            return _this.list.closeSelected();
          };
        })(this));
      };

      ListSelectionForm.prototype.commit = function(evt) {
        if (evt != null) {
          evt.preventDefault();
        }
        return this.list.commitSelected();
      };

      ListSelectionForm.prototype.commit_release_list = function(evt) {
        var container, map;
        if (evt != null) {
          evt.preventDefault();
        }
        if ($("#liberer").length) {
          container = $(evt.delegateTarget).closest("*[data-apath]");
          map = {};
          map["s_" + (container.attr('data-apath'))] = "";
          return this.list.commitSelectedList(map);
        } else {
          return this.list.commitSelectedList();
        }
      };

      ListSelectionForm.prototype.lock = function(evt) {
        var data;
        if (evt != null) {
          evt.preventDefault();
        }
        data = new FormData;
        data.append("p_JExvY2tlZA==", "L1Nlc3Npb24vVXNlcigxKQ==");
        return this.list.drawSelected(data);
      };

      ListSelectionForm.prototype.unlock = function(evt) {
        var data;
        if (evt != null) {
          evt.preventDefault();
        }
        data = new FormData;
        data.append("p_JExvY2tlZA==", "");
        return this.list.drawSelected(data);
      };

      return ListSelectionForm;

    })(Skeleton);
  });

}).call(this);
