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

{% set modal_class = 'modal-lg' %}
{% block title %}指定课程{% endblock %}
{% block body %}

<form id="message-search-form" class="form-inline well well-sm" action="{{ path('admin_course_chooser') }}" method="get" novalidate>
	<div class="form-group">
	  <select class="form-control" name="categoryId">
	    {{ select_options(category_choices('course'), app.request.query.get('categoryId'), '课程分类') }}
	  </select>
	</div>
	<div class="form-group">
	  <select class="form-control" name="status">
	    {{ select_options(dict('courseStatus'), app.request.query.get('status'), '课程状态') }}
	  </select>
	</div>
	<div class="form-group">
	  <input class="form-control" type="text" placeholder="标题" name="title" value="{{ app.request.get('title') }}">
	</div>
	<div class="form-group">
	  <input class="form-control" type="text" placeholder="创建者" name="creator" value="{{ app.request.get('creator') }}">
	</div>
	<button class="btn btn-primary">搜索</button>
</form>

<table class="table table-striped table-hover" id="course-table">
	<thead>
		<tr>
		 <th>编号</th>
	     <th width="30%">名称</th>
	     <th>学生数</th>
	     <th>价格</th>
	     <th>状态</th>
	     <th>创建者</th>
	     <th>操作</th>
		</tr>
	</thead>
	<tbody>
	  {% for course in courses %}
	    {% set user = users[course.userId]|default(null) %}
	    {% set category = categories[course.categoryId]|default(null) %}
		{% import "TopxiaAdminBundle::macro.html.twig" as admin_macro %}
		<tr id="course-tr-{{ course.id }}">
		  <td>{{ course.id }}</td>
		  <td>
		    <a href="{{ path('course_show', {id:course.id}) }}" target="_blank"><strong>{{ course.title }}</strong></a>
		    <br>
		    <span class="text-muted text-sm">分类：{{ category.name|default('--') }}</span>
		    {% if course.recommended %}
		      <span class="label label-default">荐:{{ course.recommendedTime|date('Y-m-d') }}</span>
		    {% endif %}
		  </td>
		  <td>{{ course.studentNum }}</td>
		  <td class="text-danger">{{ course.price }}</td>
		  <td>{{ dict_text('courseStatus:html', course.status) }}</td>
		  <td>
		    {{ admin_macro.user_link(user) }}
		    <br>
		    <span class="text-muted text-sm">{{ course.createdTime|date('Y-n-d H:i') }}</span>
		  </td>
		  <td>
		 	<button type="button" class="btn btn-primary btn-sm choose-course" data-target="{{ course.id }}" data-name="{{ course.title}}">选择</button>
		  </td>
		</tr>
	  {% else %}
	    <tr><td colspan="20"><div class="empty">暂无课程记录</div></td></tr>
	  {% endfor %}
	</tbody>
</table>

{{ web_macro.paginator(paginator) }}

{% endblock %}
{% block footer %}
  <button type="button" class="btn btn-default pull-right" data-dismiss="modal">关闭</button>
  <script>app.load('course/chooser')</script>
{% endblock %}