{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right"> <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a> </div>
      <h1>{{ text_confirm_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    <div class="alert alert-warning">{{ text_confirm_change_text }}: <strong>{{ status_mapped.change_order_status_id }}</strong></div>
    <form action="{{ link_complete }}" method="post" enctype="multipart/form-data" id="form" class="form">
      <table class="table table-bordered table-hover">
        <thead>
          <tr>
            <td class="text-center">{{ column_order_id }}</td>
            <td class="text-left">{{ column_customer }}</td>
            <td class="text-left">{{ column_status }}</td>
            <td class="text-left">{{ column_channel }}</td>
            <td class="text-left">{{ column_date_added }}</td>
            <td class="text-left">{{ column_additional }}</td>
            <td class="text-left">{{ column_comments }}</td>
            <td class="text-center">{{ column_notify }}<input type="checkbox" name="notify_all" id="notify_all" value="1" onchange="notifyAll();" /></td>
          </tr>
        </thead>
        <tbody>
          <input type="hidden" name="order_status_id" value="{{ change_order_status_id }}"/>
          {% for order in orders %}
            <input type="hidden" name="order_id[]" value="{{ order.order_id }}"/>
            <input type="hidden" name="old_status[{{ order.order_id }}]" value="{{ order.order_status_id }}"/>
            <tr>
              <td class="text-center">{{ order.order_id }}</td>
              <td class="text-left">{{ order.customer }}</td>
              <td class="text-left">{{ order.status }}</td>
              <td class="text-left">
                <input type="hidden" name="channel[{{ order.order_id }}]" value="{{ order.channel }}"/>
                {{ order.channel }}
              </td>
              <td class="text-left">{{ order.date_added }}</td>
              <td class="text-left">
                {% if order.channel == 'eBay' %}
                  {% if change_order_status_id == ebay_status_shipped_id %}
                    <div class="form-group">
                      <label class="control-label">{{ entry_carrier }}</label>
                      <select name="carrier[{{ order.order_id }}]" class="form-control">
                        {% for carrier in market_options.ebay.carriers %}
                          <option{% if carrier.description == order.shipping_method %} selected{% endif %}>{{ carrier.description }}</option>
                        {% endfor %}
                      </select>
                    </div>
                    <div class="form-group">
                      <label class="control-label">{{ entry_tracking_no }}</label>
                      <input type="text" name="tracking[{{ order.order_id }}]" value="" placeholder="{{ entry_tracking_no }}" class="form-control" />
                    </div>
                  {% endif %}
                {% endif %}
                {% if order.channel == 'Amazon EU' %}
                  {% if change_order_status_id == openbay_amazon_order_status_shipped %}
                    <div class="form-group">
                      <label class="control-label">{{ entry_carrier }}</label>
                      <select name="carrier[{{ order.order_id }}]" class="form-control amazon_carrier" id="amazon_carrier_{{ order.order_id }}">
                        {% for carrier in market_options.amazon.carriers %}
                          <option{% if carrier == market_options.amazon.default_carrier %} selected{% endif %}>{{ carrier }}</option>
                        {% endfor %}
                        <option value="other">{{ text_other }}</option>
                      </select>
                    </div>
                    <div class="form-group">
                      <label class="control-label">{{ entry_other }}</label>
                      <input type="text" name="carrier_other[{{ order.order_id }}]" value="" placeholder="{{ entry_other }}" class="form-control" id="amazon_carrier_{{ order.order_id }}_other" />
                    </div>
                    <div class="form-group">
                      <label class="control-label">{{ entry_tracking_no }}</label>
                      <input type="text" name="tracking[{{ order.order_id }}]" value="" placeholder="{{ entry_tracking_no }}" class="form-control" />
                    </div>
                  {% endif %}
                {% endif %}
                {% if order.channel == 'Amazon US' %}
                  {% if change_order_status_id == openbay_amazonus_order_status_shipped %}
                  <div class="form-group">
                    <label class="control-label">{{ entry_carrier }}</label>
                    <select name="carrier[{{ order.order_id }}]" class="form-control amazonus_carrier" id="amazonus_carrier_{{ order.order_id }}">
                      {% for carrier in market_options.amazonus.carriers %}
                        <option{% if carrier == market_options.amazonus.default_carrier %} selected{% endif %}>{{ carrier }}</option>
                      {% endfor %}
                      <option value="other">{{ text_other }}</option>
                    </select>
                  </div>
                  <div class="form-group">
                    <label class="control-label">{{ entry_other }}</label>
                    <input type="text" name="carrier_other[{{ order.order_id }}]" value="" placeholder="{{ entry_other }}" class="form-control" id="amazonus_carrier_{{ order.order_id }}_other" />
                  </div>
                  <div class="form-group">
                    <label class="control-label">{{ entry_tracking_no }}</label>
                    <input type="text" name="tracking[{{ order.order_id }}]" value="" placeholder="{{ entry_tracking_no }}" class="form-control" />
                  </div>
                  {% endif %}
                {% endif %}
              </td>
              <td class="text-left"><textarea name="comments[{{ order.order_id }}]" class="form-control" rows="3"></textarea></td>
              <td class="text-center"><input type="hidden" name="notify[{{ order.order_id }}]" value="0"/>
              <input type="checkbox" name="notify[{{ order.order_id }}]" class="notify_checkbox" value="1"/></td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </form>
    <div class="pull-right"> <a onclick="validate();" class="btn btn-primary">{{ button_update }}</a> </div>
  </div>
</div>
<script type="text/javascript"><!--
  function notifyAll() {
    var value_checked = $('#notify_all').prop('checked');

    if(value_checked == true) {
      $('.notify_checkbox').prop('checked', true);
    }else{
      $('.notify_checkbox').prop('checked', false);
    }
  }

  function validate() {
    var element_id;
    var error = false;
    var error_amazon_carrier = false;
    var error_amazonus_carrier = false;

    $.each($('.amazon_carrier'), function(k,v) {
      if($(this).val() == 'other') {
        element_id = $(this).attr("id");

        if($('#'+element_id+'_other').val() == '') {
          error = true;
          error_amazon_carrier = true;
          $('#'+element_id+'_other').css('border-color','#FF0000');
        }
      }
    });

    $.each($('.amazonus_carrier'), function(k,v) {
      if($(this).val() == 'other') {
        element_id = $(this).attr("id");

        if($('#'+element_id+'_other').val() == '') {
          error = true;
          error_amazonus_carrier = true;
          $('#'+element_id+'_other').css('border-color','#FF0000');
        }
      }
    });

    if(error_amazon_carrier == true) {
      alert('{{ text_error_carrier_other }}');
    }

    if(error_amazonus_carrier == true) {
      alert('{{ text_error_carrier_other }}');
    }

    if(error == false) {
      $('#form').submit();
    }else{
      return false;
    }
  }
//--></script>
{{ footer }}
