{extends "orderView.tpl"}

{block "body"}
   <form method="post" id="cart">
      <h1>{t}Objednávka č.{/t} {$body.order.order_no}</h1>

      <div class="c-alert c-alert-warning">
         {t}Proveďte změny v objednávce a poté klikněte Potvrdit změny.{/t}
      </div>

      <div class="orderview-buttons">
         {insert_cart_info return='cartInfo'}
         {if $cartInfo.cartInfo.totalProducts > 0}
            <button class="btn btn-outline" type="submit" name="acn" value="addCart">{t}Přidat obsah z košíku{/t}</button>
         {/if}
         <button class="btn btn-outline" type="submit" name="acn" value="cancel">{t}Zrušit editaci{/t}</button>
         <button class="btn btn-error" type="submit" name="acn" value="storno" title="{t}stornovat objednávku{/t}">{t}Stornovat{/t}</button>
         <button class="btn btn-ctr" type="submit" name="acn" value="send">{t}Potvrdit změny{/t}</button>
         <button class="btn btn-primary" style="display: none;" type="submit" name="acn" value="setPieces">{t}Přepočítat{/t}</button>
      </div>

      {include "account/orderViewEdit-inner.tpl"}
   </form>
{/block}


{block "js-dynamic-load" append}
   <script src="/common/static/wpj/wpj.cart.js"></script>
{/block}

<script>
   {block onready append}
   var $cart = $('#cart');

   $cart.cart();

   $cart.on('click', 'button[value=storno]', function() {
      return confirm('{t}Opravdu chcete stornovat celou objednávku?{/t}');
   });

   $cart.on('change', '[data-cart="pieces"]', function() {
      var $input = $(this);
      var step = parseFloat($input.attr('step'));
      var value = $input.val();

      if (value < 0)
         $input.val(step);

      if (value % step > 0) {
         var newVal = Math.round(value / step) * step;
         if (newVal <= 0)
            newVal = step;

         $input.val(newVal);
      }
   });

   $cart.on('keydown', '.pieces input.form-control', function(e) {
      if (e.keyCode === 13) {
         e.preventDefault();
         $(this).blur();
      }
   });
   {/block}
</script>


