<form method="POST" action="{{ path('prod_baskets') }}">
    <label>{% trans 'Nom du nouveau panier' %}</label>
    <input name="name" class="input-block-level" value="" type="text"/>

    <label>{% trans 'paniers::description du nouveau panier' %}</label>
    <textarea name="description" class="input-block-level" ></textarea>

    <label for="new_basket_add_sel" class="checkbox">
        <input type="checkbox" name="lst" value="" id="new_basket_add_sel"/>
        {% trans 'Ajouter ma selection courrante' %}
    </label>
</form>

  <script type="text/javascript">
    $(document).ready(function(){

      var $dialog = p4.Dialog.get(1);
      var $dialogBox = $dialog.getDomElement();

      $('input[name="lst"]', $dialogBox).val(p4.Results.Selection.serialize());

      var buttons = $dialog.getOption('buttons');

      buttons[language.create] = function(){
          $('form', $dialogBox).trigger('submit')
      };

      $dialog.setOption('buttons', buttons);

      $('form', $dialogBox).bind('submit', function(event){

        var $form = $(this);
        var dialog = $dialogBox.closest('.ui-dialog');
        var buttonPanel = dialog.find('.ui-dialog-buttonpane');

        $.ajax({
          type: $form.attr('method'),
          url: $form.attr('action'),
          data: $form.serializeArray(),
          dataType: 'json',
          beforeSend:function(){
              $(":button:contains('" + language.create + "')", buttonPanel)
              .attr("disabled", true).addClass("ui-state-disabled");
          },
          success: function(data){

            p4.WorkZone.refresh(data.basket.id);
            p4.Dialog.Close(1);

            return;
          },
          error: function(){
              $(":button:contains('" + language.create + "')", buttonPanel)
              .attr("disabled", false).removeClass("ui-state-disabled");
          },
          timeout: function(){

          }
        });

        return false;
      });
    });
  </script>
