{{ header }}{{ column_left }}
<!-- Content Wrapper. Contains page content -->
<div id="content" class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <div>
      <div class="pull-right">
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default btn-sm"><i class="fa fa-reply"></i> {{ button_cancel }}</a>
      </div>
      <h1>
        {{ heading_title }}
      </h1>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <ul class="breadcrumb">
          {% for breadcrumb in breadcrumbs %}
          <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </section>

  <!-- Alert -->
  <section class="content-header">
    <div class="alert alert-warning">{{ text_confirm_change_text }}: <strong>{{ status_mapped.change_order_status_id }}</strong></div>
  </section>
  <!-- /.alert -->

  <!-- Main content -->
  <section class="content">

    <!-- Default box -->
    <div class="box">
      <div class="box-body">
        <div class="alert alert-info text-center"><h3 style="margin-bottom: 0px;">{{ text_confirm_change_text }}: <strong>{{ status_mapped[change_order_status_id] }}</strong></h3></div>
        <table class="table table-bordered">
          <thead>
          <tr>
            <th class="text-center">{{ column_order_id }}</th>
            <th class="text-center">{{ column_market_order_ref }}</th>
            <th class="text-center">{{ column_channel }}</th>
            <th class="text-center">{{ column_customer }}</th>
            <th class="text-center">{{ column_status }}</th>
            <th class="text-center">{{ column_date_added }}</th>
            <th class="text-left">{{ column_additional }}</th>
            <th class="text-left">{{ column_comments }}</th>
            <th class="text-center"><input type="checkbox" name="notify_all" id="notify-all" value="1" /><br />{{ column_send_mail }}</th>
            <th class="text-center">{{ column_option }}</th>
          </tr>
          </thead>
          <tbody>
          <input type="hidden" name="order_status_id" id="order-status-id" value="{{ change_order_status_id }}"/>
          {% for order in orders %}
            <tr id="row-order-id-{{ order.order_id }}" class="">
              <input type="hidden" class="order-id" value="{{ order.order_id }}" />
              <input type="hidden" id="old-status-id-{{ order.order_id }}" value="{{ order.order_status_id }}" />
              <input type="hidden" id="order-channel-{{ order.order_id }}" value="{{ order.channel }}" />

              <td class="text-center">{{ order.order_id }}</td>
              <td class="text-center">{{ order.market_order_ref }}</td>
              <td class="text-center">{{ order.channel }}</td>
              <td class="text-left">{{ order.customer }}</td>
              <td class="text-center" id="status-text-{{ order.order_id }}">{{ order.status }}</td>
              <td class="text-center">{{ order.date_added }}</td>
              <td class="text-left" id="additional-info-{{ order.order_id }}">

                {% 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_id" class="form-control marketplace-data-{{ order.order_id }}">
                        {% 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_no" value="" placeholder="{{ entry_tracking_no }}" class="form-control marketplace-data-{{ order.order_id }}" />
                    </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="courier_id" class="form-control amazon_carrier marketplace-data-{{ order.order_id }}" 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="courier_other" value="" placeholder="{{ entry_other }}" class="form-control marketplace-data-{{ order.order_id }}" 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_no" value="" placeholder="{{ entry_tracking_no }}" class="form-control marketplace-data-{{ order.order_id }}" />
                    </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="courier_id" class="form-control amazonus_carrier marketplace-data-{{ order.order_id }}" 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="courier_other" value="" placeholder="{{ entry_other }}" class="form-control marketplace-data-{{ order.order_id }}" 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_no" value="" placeholder="{{ entry_tracking_no }}" class="form-control marketplace-data-{{ order.order_id }}" />
                    </div>
                  {% endif %}
                {% endif %}

              </td>
              <td class="text-left" id="comments-{{ order.order_id }}"><textarea name="comments" class="form-control" rows="2" id="order-comments-{{ order.order_id }}"></textarea></td>
              <td class="text-center" id="notify-{{ order.order_id }}">
                {% if order.channel == 'Amazon EU' or order.channel == 'Amazon US' %}
                  <input type="hidden" name="notify" id="order-notify-{{ order.order_id }}" value="0" />
                  <i class="fa fa-times-circle-o" data-toggle="tooltip" title="{{ text_link_policy }}"></i>
                {% else %}
                  <input class="notify-checkbox" type="checkbox" name="notify" id="order-notify-{{ order.order_id }}" value="1" />
                {% endif %}
              </td>
              <td class="text-center">
                <a href="{{ order.view_order_link }}" data-toggle="tooltip" title="{{ text_view_order }}" class="btn btn-info" target="_blank"><i class="fa fa-eye"></i></a>
                <button class="btn btn-danger button-remove-order" onclick="removeOrderFromUpdate({{ order.order_id }}); return false;" data-toggle="tooltip" title="{{ button_remove_order }}"><i class="fa fa-trash-o"></i></button>
              </td>
            </tr>
          {% endfor %}
          </tbody>
        </table>
        <div class="pull-right"> <button id="button-update-orders" class="btn btn-primary">{{ button_update }}</button> </div>
      </div>
      <!-- /.box-body -->
    </div>
    <!-- /.box -->
    <div class="row" style="display:none;" id="status-update-summary-container">
      <div class="col-md-4 col-md-offset-4">
        <!-- Default box -->
        <div class="box">
          <div class="box-body">
            <table class="table table-bordered table-hover">
              <tbody>
              <tr>
                <td style="width: 80%;">{{ text_total }}</td>
                <td id="report-orders-total" class="text-center"></td>
              </tr>
              <tr>
                <td style="width: 80%;">{{ text_successful }}</td>
                <td id="report-total-success" class="text-center"></td>
              </tr>
              <tr>
                <td style="width: 80%;">{{ text_failed }}</td>
                <td id="report-total-error" class="text-center"></td>
              </tr>
              </tbody>
            </table>
            <div class="pull-right"> <a href="{{ cancel }}" id="button-finished" class="btn btn-primary">{{ button_finished }}</a></div>
          </div>
          <!-- /.box-body -->
        </div>
        <!-- /.box -->
      </div>
    </div>

  </section>
  <!-- /.content -->
</div>
<!-- /.content-wrapper -->

<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" id="overlay-processing" data-backdrop="static" data-keyboard="false">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-body">
        <div class="progress">
          <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100" style="width: 0%" id="loading-bar"></div>
        </div>
        <p class="text-center">{{ text_order_id }}<span id="status-message-order-id">"waiting for id"</span>. {{ text_modal_status_1 }}<span id="status-message-current-count">0</span>{{ text_modal_status_2 }}<span id="status-message-total-count"></span>{{ text_modal_status_3 }}</p>
      </div>
    </div>
  </div>
</div>

<input type="hidden" id="orders-total" value="{{ order_count }}" />
<input type="hidden" id="orders-total-success" value="0" />
<input type="hidden" id="orders-total-fail" value="0" />
<input type="hidden" id="orders-total-processed" value="0" />

<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 }}
