{% extends 'admin/layout.html.twig' %}

{% set script_controller = 'system/user-fields' %}

{% set menu = 'admin_setting_user_fields' %}
{% block page_buttons %}
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#myModal">{{'添加字段'|trans}}</button>
{% endblock %}
{% block main %}

{{ web_macro.flash_messages() }}
<form action="" class="form-horizontal" method="post">
  <fieldset>
    <legend>{{'自定义字段设置'|trans}}</legend>
    <table class="table table-striped table-hover" id="course-table">
      <thead>
      <tr>
        <th>{{'字段名称'|trans}}</th>
        <th>{{'类型'|trans}}</th>
        <th>{{'是否显示'|trans}}</th>
        <th>{{'显示序号'|trans}}</th>
        <!-- <th>创建时间</th> -->
        <th>{{'操作'|trans}}</th>
      </tr>
      </thead>
      <tbody>
        {% include 'admin/system/user-fields.table.tr.html.twig' %}
      </tbody>
    </table>
  </fieldset>
  
  
  <fieldset>
    <legend>{{'个人资料设置'|trans}}</legend>

    {% set commonFields = dict('userInfoFields')|default(null) %}

    <div class="form-group">
      <div class="col-md-3 control-label">
        <label >{{'购买课程或班级时填写个人资料'|trans}}</label>
      </div>
      <div class="controls col-md-8 radios">
        {{ radios('buy_fill_userinfo', {1:'开启'|trans, 0:'关闭'|trans}, courseSetting.buy_fill_userinfo|default(0)) }}
        <p class="help-block">{{'开启后，'|trans}}{% if setting('default.user_name') %}{{'%user_name%购买课程时，需填写个人资料'|trans({'%user_name%': setting('default.user_name')|default('学员'|trans)})}}{% endif %}</p>
      </div>

      <div class="controls col-md-8 col-md-offset-3" id="show-list">
        <div class="pull-left">
          {% for sort in courseSetting.userinfoFields|default([]) %}
            {% set userCustomField = userFields[sort]|default(null) %}
            {% set userInfoFieldsDict = dict_text('userInfoFields', sort)|default(null) %}
            {% if userCustomField %}
              <button type="button" class="btn btn-default btn-xs">
                {{ userCustomField.title }}
              </button>
            {% elseif userInfoFieldsDict %}
              <button type="button" class="btn btn-default btn-xs">
                {{ userInfoFieldsDict }}
              </button>
            {% endif %}
          {% endfor %}
        </div>
          
        <div class="pull-right ">
          <a href="javascript:" id="show-list-btn">{{'编辑'|trans}} 
            <span class="glyphicon glyphicon-chevron-down"></span>
          </a>
        </div>
      </div>

      <div class="controls col-md-8 col-md-offset-2" id="show-register-list" style="display:none">
        <div class="form-group">
          <ul class="register-list sortable-list list-unstyled col-md-12" data-role="list">
            {% set checkedFieldsKeys = courseSetting.userinfoFields|default([]) %}
            {% for key,field in commonFields if commonFields %}
              <li class="list-group-item clearfix" data-role="item" >
                <span class="glyphicon glyphicon-resize-vertical sort-handle"></span>&nbsp;
                <input type="checkbox" name="userinfoFields[]" value="{{ key }}" {% if key in checkedFieldsKeys %}checked=true{% endif %} />
                <input type="hidden"  name="userinfoFieldNameArray[]" value="{{ key }}" /> 
                {{ field }}
                {% if key == 'email' or key == 'mobile' %}<span class="text-muted">  ({{'带格式校检'|trans}})</span>{% endif %}
              </li>
            {% endfor %}

            {% for field in userFields if userFields|default(null) %}
              <li class="list-group-item clearfix" data-role="item" >
                <span class="glyphicon glyphicon-resize-vertical sort-handle"></span>&nbsp;
                <input type="checkbox" name="userinfoFields[]" value="{{field.fieldName}}" {% if field.fieldName in checkedFieldsKeys %}checked=true{% endif %} />
                <input type="hidden"  name="userinfoFieldNameArray[]" value="{{field.fieldName}}" /> {{field.title}}
              </li>
            {% endfor %}
          </ul>

          <div class="help-block col-md-12"><span class="text-success">{{'可拖动调整次序。酌情勾选需要收集的字段，若需要新的字段，请在［自定义字段设置］中添加。'|trans}}</span></div>

        </div>
        <div class="mbl" style="text-align:center;">
          <a href="javascript:" id="hide-list-btn">{{'收起 '|trans}}
            <span class="glyphicon glyphicon-chevron-up"></span>
          </a>
        </div>
      </div>
    </div>

    <div class="form-group">
      <div class="col-md-3 control-label">
        <label >{{'登录后填写个人资料'|trans}}</label>
      </div>
      <div class="controls col-md-8 radios">
        {{ radios('fill_userinfo_after_login', {1:'开启'|trans, 0:'关闭'|trans}, setting('auth.fill_userinfo_after_login')|default(0)) }}
        <p class="help-block">{{'开启后，'|trans}}{% if setting('default.user_name') %}{{'%user_name%登录后需填写个人资料'|trans({'%user_name%': setting('default.user_name')|default('学员'|trans)})}}{% endif %}</p>
      </div>

      <div class="controls col-md-8 col-md-offset-3" id="show-checked-fields-list">
        <div class="pull-left">
          {% for sort in authSetting.registerSort|default([]) %}
            {% if sort == 'emailOrMobile' %}{% set sort = 'email' %}{% endif %}
            {% set userCustomField = userFields[sort]|default(null) %}
            {% set userInfoFieldsDict = dict_text('userInfoFields', sort)|default(null) %}
            {% if userCustomField %}
              <button type="button" class="btn btn-default btn-xs">
                {{ userCustomField.title }}
              </button>
            {% elseif userInfoFieldsDict %}
              <button type="button" class="btn btn-default btn-xs">
                {{ userInfoFieldsDict }}
              </button>
            {% endif %}
          {% endfor %}
        </div>
          
        <div class="pull-right ">
          <a href="javascript:" id="show-fields-list-btn">{{'编辑 '|trans}}
            <span class="glyphicon glyphicon-chevron-down"></span>
          </a>
        </div>
      </div>

      <div class="controls col-md-8 col-md-offset-2" id="show-fields-list" style="display:none">
        <div class="form-group">
          <ul class="fill-userinfo-list sortable-list list-unstyled col-md-12" data-role="list">
            {% set checkedUserFieldsKeys = authSetting.registerSort|default([]) %}

            {% for key,field in commonFields if commonFields %}
              <li class="list-group-item clearfix" data-role="item" >
                <span class="glyphicon glyphicon-resize-vertical sort-handle"></span>&nbsp;
                <input type="checkbox" name="registerSort[]" value="{{ key }}" {% if key in checkedUserFieldsKeys %}checked=true{% endif %} />
                <input type="hidden"  name="registerFieldNameArray[]" value="{{ key }}" /> 
                {{ field }}
                {% if key == 'email' or key == 'mobile' %}<span class="text-muted">  ({{'带格式校检'|trans}})</span>{% endif %}
              </li>
            {% endfor %}

            {% for field in userFields if userFields|default(null) %}
              <li class="list-group-item clearfix" data-role="item" >
                <span class="glyphicon glyphicon-resize-vertical sort-handle"></span>&nbsp;
                <input type="checkbox" name="registerSort[]" value="{{field.fieldName}}" {% if field.fieldName in checkedUserFieldsKeys %}checked=true{% endif %} />
                <input type="hidden"  name="registerFieldNameArray[]" value="{{field.fieldName}}" /> {{field.title}}
              </li>
            {% endfor %}
          </ul>

          <div class="help-block col-md-12"><span class="text-success">{{'可拖动调整次序。酌情勾选需要收集的字段，若需要新的字段，请在［自定义字段设置］中添加。'|trans}}</span></div>

        </div>
        <div class="mbl" style="text-align:center;">
          <a href="javascript:" id="hide-fields-list-btn">{{'收起 '|trans}}
            <span class="glyphicon glyphicon-chevron-up"></span>
          </a>
        </div>
      </div>
    </div>
  </fieldset>

  <fieldset>
    <legend>{{'其它设置'|trans}}</legend>
    <div class="form-group">
      <div class="col-md-3 control-label">
        <label>{{'加入免费课程要求设置头像'|trans}}</label>
      </div>
      <div class="controls col-md-8 radios">
        {{ radios('avatar_alert', {'open':'开启'|trans, 'close':'关闭'|trans}, setting('user_partner.avatar_alert')|default('close')) }}
      </div>
    </div>
    <div class="form-group">
      <div class="col-md-3 control-label">
        <label>{{'用户修改用户名'|trans}}</label>
      </div>
      <div class="controls col-md-8 radios">
        {{ radios('nickname_enabled', {1:'开启'|trans, 0:'关闭'|trans}, setting('user_partner.nickname_enabled')|default(0)) }}
      </div>
    </div>
  </fieldset>

  <div class="form-group">
    <div class="col-md-3 control-label"></div>
    <div class="controls col-md-8">
      <button type="submit" class="btn btn-primary">{{'提交'|trans}}</button>  
    </div>
  </div>
  <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
  <input type="hidden" name='_cloud_sms'  value= "{{setting('cloud_sms.sms_enabled')}}">
</form>

{% include 'admin/system/user-fields.modal.html.twig' %}

{% endblock %}