<div class="panel panel-danger">
  <div class="panel-heading">
    <span class="panel-title">Ustawienia baselinker.com</span>
  </div>
  <div class="panel-body">
    <div class="row">
      <div class="col-lg-6">
        <div class="form-group">
          <label class="col-lg-3 control-label" for="inputDefault">Baselinker API</label>
          <div class="col-lg-9">
            <div class="bs-component">
              <div class="input-group">
                <input class="form-control" type="text" id="api_code" name="api_code" placeholder="" value="<?= $this -> settings['api_code'];?>">
                <span class="input-group-addon cursor" field-id="api_code">
                  <i class="fa fa-save"></i>
                </span>
              </div>
            </div>
          </div>
        </div>
        <!-- magazyn -->
        <? $storages_list = unserialize( $this -> settings['storages_list'] );?>
        <div class="form-group mb10">
          <label class="col-lg-3 control-label" for="inputDefault">Magazyn</label>
          <div class="col-lg-9">
            <div class="bs-component">
              <div class="input-group">
                <select name="storage_id" id="storage_id" class="form-control">
                  <option value="">--- wybierz ---</option>
                  <? foreach ( $storages_list as $storage ):?>
                    <option value="<?= $storage['storage_id'];?>" <? if ( $this -> settings['storage_id'] == $storage['storage_id'] ):?>selected<? endif;?>><?= $storage['name'];?></option>
                  <? endforeach;?>
                </select>
                <span class="input-group-addon cursor" field-id="storage_id">
                  <i class="fa fa-save"></i>
                </span>
              </div>
            </div>
          </div>
        </div>
        <div class="form-group mb10">
          <label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację z baselinker.com</label>
          <div class="col-lg-9">
            <div class="bs-component">
              <div class="input-group">
                <select class="form-control" id="enabled" name="enabled">
                  <option value="">--- wybierz ---</option>
                  <option value="0" <? if ( !$this -> settings['enabled'] ):?>selected<? endif;?>>nie</option>
                  <option value="1" <? if ( $this -> settings['enabled'] ):?>selected<? endif;?>>tak</option>
                </select>
                <span class="input-group-addon cursor" field-id="enabled">
                  <i class="fa fa-save"></i>
                </span>
              </div>
            </div>
          </div>
        </div>
        <div class="form-group mb10">
          <label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację produktów</label>
          <div class="col-lg-9">
            <div class="bs-component">
              <div class="input-group">
                <select class="form-control" id="sync_products" name="sync_products">
                  <option value="">--- wybierz ---</option>
                  <option value="0" <? if ( !$this -> settings['sync_products'] ):?>selected<? endif;?>>nie</option>
                  <option value="1" <? if ( $this -> settings['sync_products'] ):?>selected<? endif;?>>tak</option>
                </select>
                <span class="input-group-addon cursor" field-id="sync_products">
                  <i class="fa fa-save"></i>
                </span>
              </div>
            </div>
          </div>
        </div>
        <div class="form-group mb10">
          <label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację zamówień</label>
          <div class="col-lg-9">
            <div class="bs-component">
              <div class="input-group">
                <select class="form-control" id="sync_orders" name="sync_orders">
                  <option value="">--- wybierz ---</option>
                  <option value="0" <? if ( !$this -> settings['sync_orders'] ):?>selected<? endif;?>>nie</option>
                  <option value="1" <? if ( $this -> settings['sync_orders'] ):?>selected<? endif;?>>tak</option>
                </select>
                <span class="input-group-addon cursor" field-id="sync_orders">
                  <i class="fa fa-save"></i>
                </span>
              </div>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label" for="inputDefault">Data rozpoczęcia synchronizacji zamówień</label>
          <div class="col-lg-9">
            <div class="bs-component">
              <div class="input-group">
                <input class="form-control" type="text" id="sync_orders_date_start" name="sync_orders_date_start" placeholder="" value="<?= $this -> settings['sync_orders_date_start'];?>">
                <span class="input-group-addon cursor" field-id="sync_orders_date_start">
                  <i class="fa fa-save"></i>
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-lg-6">
        <a href="/admin/integrations/baselinker_get_order_status_list/" class="btn btn-primary btn-block">Pobierz statusy zamówień</a>
        <!-- pobierz listę magazynów -->
        <a href="/admin/integrations/baselinker_get_storages_list/" class="btn btn-primary btn-block">Pobierz listę magazynów</a>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  $(function() {
    $('body').on('click', '.input-group-addon', function() {
      var field_id = $(this).attr('field-id');
      var value = $('#' + field_id).val();
      $.ajax({
        url: '/admin/integrations/baselinker_settings_save/',
        type: 'POST',
        data: {
          field_id: field_id,
          value: value
        },
        success: function(response) {
          response = JSON.parse(response);
          if (response.status == 'ok') {
            $('#' + field_id).val(response.value);
            $('#' + field_id).closest('.form-group').addClass('has-success');
            setTimeout(function() {
              $('#' + field_id).closest('.form-group').removeClass('has-success');
            }, 5000);
          }
        }
      });
    })
  });
</script>