{% extends 'old-bootstrap-modal-layout.html.twig' %}
{% import "macro.html.twig" as web_macro %}

  {% set modalSize = 'large' %}

{% block title %}{{ '我的分享历史'|trans }}{% endblock %}

{% set side_nav = 'material-lib' %}
{% set parentId = parentId | default(null) %}

{% block body %}

  <div id="share-history-table-container" class="materials-modal-body">
    <form id="share-materials-form" class="form-horizontal" method="post"
          action="{{ path('material_lib_save_sharing') }}">
      <div class="form-group">
        <label class="control-label col-md-3" for="login_username">{{ '分享资料给'|trans }}</label>
        <div class="controls col-md-8">
          <div class="select2-container select2-container-multi width-full"
               id="target-teachers-input" placeholder="{{ '输入用户名'|trans }}"></div>
          <div class="help-block"></div>
        </div>
      </div>
    </form>
    <div class="nav-btn-tab">
      <ul class="nav nav-tabs" role="tablist">
        <li data-target="#user-tab" class="active">
          <a href="javascript:;" data-url="{{ path('material_lib_my_sharing_users') }}"
             class="active js-share-users">{{ '分享用户'|trans }}</a>
        </li>
        <li data-target="#detail-tab">
          <a href="javascript:;" class="js-share-history-detail"
             data-url="{{ path('material_lib_my_sharing_detail') }}">{{ '历史记录'|trans }}</a>
        </li>
      </ul>
    </div>
    <table class="table table-hover table-striped" id="share-history-table">
      <tbody class="share-show-users-tbody">
        <tr>
          <th width="40%" class="text-center">{{ '昵称'|trans }}</th>
          <th width="40%" class="text-center">{{ '时间'|trans }}</th>
          <th width="20%" class="text-center">{{ '操作'|trans }}</th>
        </tr>
        {% for history in shareHistories %}
          <tr class="share-history-record" data-role="item">
            <td class="text-center">
              {{ '将资料分享给%nickname%老师。'|trans({'%nickname%':(targetUsers[history['targetUserId']])['nickname']}) }}
              {# 将资料分享给 {{ (targetUsers[history['targetUserId']])['nickname'] }} 老师。 #}
            </td>
            <td class="text-center">{{ history['updatedTime']|date('Y-n-d H:i') }}</td>
            <td class="text-center">
              {% if history['isActive'] == '1' %}
                <div class="pull-right">
                  <a data-url="{{ path('material_lib_cancel_sharing') }}" targetUserId="{{ history['targetUserId'] }}"
                     class="btn btn-default btn-sm cancel-share-btn">{{ '取消分享'|trans }}</a>
                </div>
              {% endif %}
            </td>
          </tr>
        {% else %}
          <tr class="empty">
            <td colspan="3">{{ '无资料分享记录'|trans }}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>

  {% include 'seajs_loader_compatible.html.twig' with {topxiawebbundle: true} %}
  <script>
    app.lazyLoad = function () {
      app.load('topxiawebbundle/controller/material-lib/share-history');
      app.load('topxiawebbundle/controller/material-lib/teachers');
    };
  </script>
{% endblock %}
{% block footer %}
  <button id="share-materials-form-submit" type="submit"
          class="btn btn-primary pull-right" data-toggle="form-submit"
          data-target="#share-materials-form" data-submiting-text="正在保存...">{{ '保存'|trans }}</button>
  <button type="button" class="btn btn-link pull-right"
          data-dismiss="modal">{{ '取消'|trans }}</button>

  <script type="text/javascript">
    $("#target-teachers-input").select2({
      multiple: true,
      data: [
        {% for contact in allTeachers %}
        {% if contact.id != currentUserId %}
        {id: '{{ contact.id }}', text: '{{ contact.nickname }}'},
        {% endif %}
        {% endfor %}
      ]
    });

  </script>
{% endblock %}
