{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <a href="{{ return }}" data-toggle="tooltip" title="{{ button_back }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{ heading_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">
    {% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}</div>
    {% endif %}
  </div>
  <div class="container-fluid">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i> {{ text_sync }}</h3>
      </div>
      <div class="panel-body">
        {% if validation == true %}
          <p>{{ text_sync_desc }}</p>
          <form id="form-ebay-sync" class="form-horizontal">
            <div class="form-group">
              <label class="col-sm-2 control-label" for="update-categories"><span data-toggle="tooltip" title="{{ help_sync_categories }}">{{ entry_sync_categories }}</span></label>
              <div class="col-sm-10">
                <a class="btn btn-primary" id="update-categories">{{ button_update }}</a>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="update-store"><span data-toggle="tooltip" title="{{ help_sync_shop }}">{{ entry_sync_shop }}</span></label>
              <div class="col-sm-10">
                <a class="btn btn-primary" id="update-store">{{ button_update }}</a>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="update-settings"><span data-toggle="tooltip" title="{{ help_sync_setting }}">{{ entry_sync_setting }}</span></label>
              <div class="col-sm-10">
                <a class="btn btn-primary" id="update-settings">{{ button_update }}</a>
              </div>
            </div>
          </form>
        {% else %}
          <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_validation }}
            <button type="button" class="close" data-dismiss="alert">&times;</button>
          </div>
        {% endif %}
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
  $('#update-categories').bind('click', function() {
    $.ajax({
      url: 'index.php?route=extension/openbay/ebay/updatecategories&user_token={{ user_token }}',
      beforeSend: function(){
        $('#update-categories').empty().html('<i class="fa fa-cog fa-lg fa-spin"></i>').attr('disabled','disabled');
        alert('{{ text_ebay_categories }}');
      },
      type: 'post',
      dataType: 'json',
      success: function(json) {
        $('#update-categories').empty().removeClass('btn-primary').addClass('btn-success').html('{{ text_complete }}');
        alert(json.msg);
      },
      error: function (xhr, ajaxOptions, thrownError) {
        $('#update-categories').empty().removeClass('btn-primary').addClass('btn-danger').html('{{ error_failed }}').removeAttr('disabled');
        if (xhr.status != 0) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
      }
    });
  });

  $('#update-settings').bind('click', function() {
    $.ajax({
      url: 'index.php?route=extension/openbay/ebay/updatesettings&user_token={{ user_token }}',
      beforeSend: function(){
        $('#update-settings').empty().html('<i class="fa fa-cog fa-lg fa-spin"></i>').attr('disabled','disabled');
      },
      type: 'post',
      dataType: 'json',
      success: function(json) {
        $('#update-settings').empty().removeClass('btn-primary').addClass('btn-success').html('{{ text_complete }}');

        if (json.error == false){
            alert('{{ text_setting_import }}');
        }else{
            alert('{{ error_settings }}');
        }
      },
      error: function (xhr, ajaxOptions, thrownError) {
        $('#update-settings').empty().removeClass('btn-primary').addClass('btn-danger').html('{{ error_failed }}').removeAttr('disabled');
        if (xhr.status != 0) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
      }
    });
  });

  $('#update-store').bind('click', function() {
    $.ajax({
      url: 'index.php?route=extension/openbay/ebay/updatestore&user_token={{ user_token }}',
      beforeSend: function(){
        $('#update-store').empty().html('<i class="fa fa-cog fa-lg fa-spin"></i>').attr('disabled','disabled');
      },
      type: 'post',
      dataType: 'json',
      success: function(json) {
        $('#update-store').empty().removeClass('btn-primary').addClass('btn-success').html('{{ text_complete }}');

        if (json.error == 'false'){
          alert('{{ text_category_import }}');
        }else{
          alert(json.msg);
        }
      },
      error: function (xhr, ajaxOptions, thrownError) {
        $('#update-store').empty().removeClass('btn-primary').addClass('btn-danger').html('{{ error_failed }}').removeAttr('disabled');
        if (xhr.status != 0) { alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); }
      }
    });
  });
//--></script>
{{ footer }}
