{{ header }}
{{ column_left }}

<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-information" data-toggle="tooltip" title="{{ button_save }}"
                class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}"
           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"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{ heading_title }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-information"
              class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-10">
              <select name="module_omni_auth_status" id="input-status" class="form-control">
                {% if module_omni_auth_status %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  <option value="0">{{ text_disabled }}</option>
                {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-bind">{{ entry_bind }}</label>
            <div class="col-sm-10">
              <select name="module_omni_auth_bind" id="input-bind" class="form-control">
                {% if module_omni_auth_bind %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  <option value="0">{{ text_disabled }}</option>
                {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_debug }}</label>
            <div class="col-sm-10">
              <select name="module_omni_auth_debug" id="input-status" class="form-control">
                {% if module_omni_auth_debug %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  <option value="0">{{ text_disabled }}</option>
                {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>

          <div class="table-responsive">
            <table id="socials" class="table table-striped table-bordered table-hover">
              <thead>
              <tr>
                <td class="text-left" width="15%">{{ entry_provider }}</td>
                <td class="text-left" width="10%">{{ entry_status }}</td>
                <td class="text-left" width="20%">{{ entry_key }}</td>
                <td class="text-left" width="25%">{{ entry_secret }}</td>
                <td class="text-left" width="20%">{{ entry_callback }}</td>
                <td class="text-right" width="10%">{{ entry_sort_order }}</td>
                <td></td>
              </tr>
              </thead>
              <tbody>
              {% set row = 0 %}
              {% for omni_auth in module_omni_auth_items %}
                <tr id="row{{ row }}">
                  <td class="left">
                    <select name="module_omni_auth_items[{{ row }}][provider]" class="form-control auth-provider">
                      {% for code, provider in providers %}
                        {% if code == omni_auth.provider %}
                          <option value="{{ code }}" selected="selected">{{ provider }}</option>
                        {% else %}
                          <option value="{{ code }}">{{ provider }}</option>
                        {% endif %}
                      {% endfor %}
                    </select>
                  </td>
                  <td class="left">
                    <select name="module_omni_auth_items[{{ row }}][enabled]" class="form-control">
                      {% if omni_auth.enabled %}
                        <option value="1" selected="selected">{{ text_enabled }}</option>
                        <option value="0">{{ text_disabled }}</option>
                      {% else %}
                        <option value="1">{{ text_enabled }}</option>
                        <option value="0" selected="selected">{{ text_disabled }}</option>
                      {% endif %}
                    </select>
                  </td>
                  <td class="left">
                    <input type="text" name="module_omni_auth_items[{{ row }}][key]"
                           value="{{ omni_auth.key }}" size="50" class="form-control"/>
                  </td>
                  <td class="left">
                    <input type="text" name="module_omni_auth_items[{{ row }}][secret]"
                           value="{{ omni_auth.secret }}" size="50" class="form-control"/>
                  </td>
                  <td class="left">
                    <input type="text" name="module_omni_auth_items[{{ row }}][callback]" readonly="readonly"
                           value="{{ omni_auth.callback }}" size="50" class="form-control auth-callback"/>
                  </td>
                  <td class="right">
                    <input type="text" name="module_omni_auth_items[{{ row }}][sort_order]"
                           value="{{ omni_auth.sort_order }}" size="3" class="form-control"/>
                  </td>
                  <td class="text-left">
                    <button type="button" onclick="$('#row{{ row }}').remove();"
                            data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i
                        class="fa fa-minus-circle"></i></button>
                  </td>
                </tr>
                {% set row = row+1 %}
              {% endfor %}
              </tbody>
              <tfoot>
              <tr>
                <td colspan="6"></td>
                <td class="text-left">
                  <button type="button" onclick="addRow();" data-toggle="tooltip"
                          title="{{ button_add_row }}" class="btn btn-primary"><i
                      class="fa fa-plus-circle"></i></button>
                </td>
              </tr>
              </tfoot>
            </table>
          </div>
        </form>

      </div>
    </div>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{ text_help_msg }}</h3>
      </div>
      <div class="panel-body">
        <div class="help-wrapper">
          <ol style="line-height:20px;">
            {% if false %}
            <li>{{ text_omni_explain }}</li>
            {% endif %}
            <li>{{ text_omni_explain_2 }}</li>
            {% if false %}
            <li>{{ text_wechat_title }}
              <a target="_blank" href="https://open.weixin.qq.com/">{{ text_wechat_info }}</a>
            </li>
            <li>{{ text_qq_title }}
              <a target="_blank" href="https://connect.qq.com/">{{ text_qq_info }}</a>
            </li>
            <li>{{ text_weibo_title }}
              <a target="_blank" href="http://open.weibo.com/">{{ text_weibo_info }}</a>
            </li>
            {% endif %}
            <li>{{ text_facebook_title }}
              <a target="_blank" href="https://developers.facebook.com/">Facebook</a>
            </li>
            <li>{{ text_google_title }}
              <a target="_blank" href="https://console.developers.google.com/projectcreate/">Google</a>
            </li>
            <li>{{ text_Twitter_title }}
              <a target="_blank" href="https://apps.twitter.com/">Twitter</a>
            </li>
          </ol>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
  var row = {{ row }};

  function addRow() {
    html = '<tr id="row' + row + '">';
    html += '    <td class="text-left">';
    html += '      <select name="module_omni_auth_items[' + row + '][provider]" class="form-control auth-provider">';
    html += '        <option value=""></option>';
    {% for code, provider in providers %}
    html += '        <option value="{{ code }}">{{ provider }}</option>';
    {% endfor %}
    html += '      </select>';
    html += '    </td>';
    html += '    <td class="text-left">';
    html += '      <select name="module_omni_auth_items[' + row + '][enabled]" class="form-control">';
    html += '        <option value="1" selected="selected">{{ text_enabled }}</option>';
    html += '        <option value="0">{{ text_disabled }}</option>';
    html += '      </select>';
    html += '    </td>';
    html += '    <td class="text-left"><input type="text" name="module_omni_auth_items[' + row + '][key]" value="" size="50" class="form-control"/></td>';
    html += '    <td class="text-left"><input type="text" name="module_omni_auth_items[' + row + '][secret]" value="" size="50" class="form-control"/></td>';
    html += '    <td class="text-left"><input type="text" name="module_omni_auth_items[' + row + '][callback]" value="" size="50" class="form-control auth-callback" readonly="readonly" /></td>';
    html += '    <td class="text-right"><input type="text" name="module_omni_auth_items[' + row + '][sort_order]" value="' + row + '" size="3" class="form-control"/></td>';
    html += '    <td class="text-left"><button type="button" onclick="$(\'#row' + row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
    html += '  </tr>';

    $('#socials tbody').append(html);

    row++;
  }

  $(document).ready(function () {
    $(document).delegate(".auth-provider", "change", function () {
      var provider = $(this).val();
      if (provider) {
        var callback = '{{ helper.base_url }}callback/' + provider;
      } else {
        var callback = '';
      }
      $(this).parent().parent().find('.auth-callback').val(callback);
    });
  });

  //--></script>

{{ footer }}
