{% extends 'TopxiaWebBundle::bootstrap-modal-layout.html.twig' %}

{% set modalSize = 'large' %}

{% block title %}编辑{% if 'ROLE_ADMIN' in user.roles or 'ROLE_SUPER_ADMIN' in user.roles %}管理员{% elseif 'ROLE_TEACHER' in user.roles %}教师{% else %}学生{% endif %}信息
{% endblock %}
{% block body %}

<form id="user-edit-form" class="form-horizontal" method="post" action="{{ url('admin_user_edit', {id:user.id}) }}">

  {% if user.roles|length == 1 and 'ROLE_USER' in user.roles %}

  <div class="row form-group">
    <div class="col-md-2 control-label">
      <label for="number">班级</label>
    </div>
    <div class="col-md-7 controls">
      <select id="classId" name="classId" class="form-control">
        <option value="">---请选择班级---</option>
        {% for class in classes %}
          <option value="{{ class.id }}" {% if class.id == currentClassId %}selected="true"{% endif %}>{{ grades[class['gradeId']]['name']|default('') }}{{ class['name'] }}</option>
        {% endfor %}
      </select>
    </div>
  </div>

  {% endif %}

  <div class="row form-group">
    <div class="col-md-2 control-label">
      <label for="truename">姓名</label>
    </div>
    <div class="col-md-7 controls">
      <input type="text" id="truename" name="truename" class="form-control" value="{{user.truename}}" >
    </div>
  </div>

  <div class="row form-group">
    <div class="col-md-2 control-label">
      <label for="email">邮箱地址</label>
    </div>
    <div class="col-md-7 controls">
      <input type="text" id="email" data-required={% if 'ROLE_TEACHER' in user.roles %}'true'{% else %}'false'{% endif %} data-url="{{path('admin_user_create_email_check',{id:user.id})}}" value="{{user.email}}" name="email" class="form-control" >
    </div>
  </div>

  <div class="form-group">
    <label class="col-md-2 control-label" for="number">{% if 'ROLE_TEACHER' in user.roles %}工号{% else %}学号{% endif %}</label>
    <div class="col-md-7 controls">
      <input type="text" id="number" data-url="{{path('admin_user_create_number_check',{id:user.id})}}" name="number" class="form-control" value="{{ user.number }}">
    </div>
  </div>

  <div class="row form-group">
    <div class="col-md-2 control-label">
      <label for="gender">性别</label>
    </div>
    <div class="col-md-7 controls radios">
      <div id="gender">
        <input type="radio" id="gender_0" name="gender" value="male"
        {% if profile.gender == 'male' %} checked="checked" {% endif %}>
        <label for="gender_0">男</label>

        <input type="radio" id="gender_1" name="gender" value="female"
        {% if profile.gender == 'female' %} checked="checked" {% endif %}>
        <label for="gender_1">女</label>
      </div>

    </div>
  </div>

    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="idcard">身份证号</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="idcard" name="idcard" class="form-control" value="{{profile.idcard}}">
     </div>
    </div>

    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="mobile">手机号码</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="mobile" data-url="{{path('admin_user_create_mobile_check',{id:user.id})}}"name="mobile" class="form-control" value="{{user.mobile}}">
     </div>
    </div>

    {# <div class="row form-group">
        <div class="col-md-2 control-label"> 
          <label for="company">公司</label>
        </div>
        <div class="col-md-7 controls">
          <input type="text" id="company" name="company" class="form-control" value="{{profile.company}}">
       </div>
    </div>
    
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="job">职业</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="job" name="job" class="form-control" value="{{profile.job}}">
     </div>
    </div> #}

    <p></p>
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="title">头衔</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="title" name="title" class="form-control" value="{{profile.title}}">
     </div>
    </div>
    <p></p>
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="signature">个人签名</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="signature" name="signature" class="form-control" value="{{profile.signature}}">
     </div>
    </div>
    <p></p>
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="about">自我介绍</label>
      </div>
      <div class="col-md-7 controls">
        <textarea id="about" name="about">{{profile.about}}</textarea>
      </div>
    </div>
    <p></p>
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="site">个人主页</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="site" name="site" class="form-control" value="{{profile.site}}">
     </div>
    </div>
    <p></p>
  <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="weibo">微博</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="weibo" name="weibo" class="form-control" value="{{profile.weibo}}">
     </div>
    </div>
    <p></p>
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="qq">QQ</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="qq" name="qq" class="form-control" value="{{profile.qq}}">
     </div>
    </div>
    <p></p>
    <div class="row form-group">
      <div class="col-md-2 control-label"> 
        <label for="weixin">微信</label>
      </div>
      <div class="col-md-7 controls">
        <input type="text" id="weixin" name="weixin" class="form-control" value="{{profile.weixin}}">
     </div>
    </div> 

    <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">           

{% if fields %}
          <hr>
          {% for field in fields %}
          {% if field.type=="text" %}
          <div class="form-group">
            <label for="{{field.fieldName}}" class="col-md-2 control-label">{{field.title}}</label>
            <div class="col-md-7 controls">
              <textarea id="{{field.fieldName}}" name="{{field.fieldName}}" class="{{field.type}} form-control" >{{ profile[field.fieldName]|default('') }}</textarea>
              <div class="help-block" style="display:none;"></div>
            </div>
          </div>
          {% elseif field.type=="int" %}
          <div class="form-group">
            <label for="{{field.fieldName}}" class="col-md-2 control-label">{{field.title}}</label>
            <div class="col-md-7 controls">
              <input type="text" id="{{field.fieldName}}" placeholder="最大值为9位整数" name="{{field.fieldName}}" class="{{field.type}} form-control"  value="{{ profile[field.fieldName]|default('') }}">
              <div class="help-block" style="display:none;"></div>
            </div>
          </div>
          {% elseif field.type=="float" %}
          <div class="form-group">
            <label for="{{field.fieldName}}" class="col-md-2 control-label">{{field.title}}</label>
            <div class="col-md-7 controls">
              <input type="text" id="{{field.fieldName}}" placeholder="保留到2位小数" name="{{field.fieldName}}" class="{{field.type}} form-control" value="{{ profile[field.fieldName]|default('') }}">
              <div class="help-block" style="display:none;"></div>
            </div>
          </div>
          {% elseif field.type=="date" %}
          <div class="form-group">
            <label for="{{field.fieldName}}" class="col-md-2 control-label">{{field.title}}</label>
            <div class="col-md-7 controls">
              <input type="text" id="{{field.fieldName}}" name="{{field.fieldName}}" class="{{field.type}} form-control"   value="{% if profile[field.fieldName] %}{{profile[field.fieldName]}}{% endif %}">
              <div class="help-block" style="display:none;"></div>
            </div>
          </div>
          {% elseif field.type=="varchar" %}
          <div class="form-group">
            <label for="{{field.fieldName}}" class="col-md-2 control-label">{{field.title}}</label>
            <div class="col-md-7 controls">
              <input type="text" id="{{field.fieldName}}" name="{{field.fieldName}}" class="form-control"  value="{{ profile[field.fieldName]|default('') }}">
              <div class="help-block" style="display:none;"></div>
            </div>
          </div>
          {% endif %}
          {% endfor %}
          {% endif %}

</form>
{% endblock %}

{% block footer %}
  <button id="edit-user-btn" data-submiting-text="正在提交" type="submit" class="btn btn-primary pull-right" data-toggle="form-submit" data-target="#user-edit-form">保存</button>
  <button type="button" class="btn btn-link pull-right" data-dismiss="modal">取消</button>
  <script>app.load('user/edit-modal')</script>
{% endblock %}