{% extends 'course-manage/tasks/layout.html.twig' %}
{% do script(['libs/jquery-sortable.js','app/js/course-manage/index.js']) %}

{% block main %}
  <div class="panel panel-default">
    {% include 'course-manage/panel-header/course-publish-header.html.twig' with {code: side_nav} %}
    <div class="panel-body">
      <div class="task-list-header clearfix js-task-list-header">
        任务总数：<span class="color-warning space" id="task-num">{{ course.taskNum }}</span>  {% if taskPerDay|default(false) %}日均约需完成：<span class="color-warning">{{ taskPerDay }}</span> 个任务{% endif %}
        <div class="pull-right">
          <button class="btn btn-primary btn-sm" id="step-3" data-toggle="modal" data-target="#modal" data-backdrop="static" data-keyboard="false" data-url="{{ path('course_manage_task_create', {courseId:course.id,type:'lesson'}) }}"> <i class="es-icon es-icon-anonymous-iconfont"></i>
            任务
          </button>
          {% if courseSet.type|default('') == 'normal'  %}
          <button class="btn btn-info btn-sm js-batch-add
            {% if not (courseSet.type|default('') =='normal' and setting('storage.upload_mode', 'local') != 'local' )%}
            disabled
            {% endif %}"
            {% if not (courseSet.type|default('') =='normal' and setting('storage.upload_mode', 'local') != 'local' )%}
              data-toggle="popover" data-placement="top" data-trigger="hover" data-container=".js-batch-add"
              data-content='批量创建课时需要开通云视频服务，点击<a target="__blank" href="http://open.edusoho.com/show/cloud/video">这里</a>了解详情'
            {% else %}
              data-toggle="modal" data-target="#modal" data-backdrop="static" data-keyboard="false"
              data-url="{{ path('course_manage_task_batch_create', {courseId:course.id, mode:'lesson', token:uploader_token('course-task', app.user.id, 'private')}) }}"
            {% endif %}>
            <i class="es-icon es-icon-anonymous-iconfont"></i>
            批量添加
          </button>
          {% endif %}
          <div class="btn-group">
            <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
              <i class="es-icon es-icon-anonymous-iconfont"></i>
              {{ setting('default.chapter_name')|default('章'|trans) }}/{{ setting('default.part_name')|default('节'|trans) }}
              <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
              <li>
                <a href="#" id="chapter-create-btn" data-toggle="modal" data-target="#modal" data-backdrop="static"
                  data-keyboard="false" data-url="{{ path('course_manage_chapter_create', {id:course.id}) }}">
                  <i class="es-icon es-icon-anonymous-iconfont"></i>
                  {{ '添加%chapter_name%'|trans({'%chapter_name%': setting('default.chapter_name')|default('章'|trans)}) }}
                </a>
              </li>
              <li>
                <a href="#" id="chapter-create-btn" data-toggle="modal" data-target="#modal" data-backdrop="static"
                  data-keyboard="false" data-url="{{ path('course_manage_chapter_create', {id:course.id, type:'unit'}) }}">
                  <i class="es-icon es-icon-anonymous-iconfont"></i>
                  {{ '添加%part_name%'|trans({'%part_name%': setting('default.part_name')|default('节')}) }}
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <ul id="sortable-list" class="task-manage-list sortable-list"
          data-sort-url='{{ path("course_manage_items_sort",{courseId: course.id}) }}'>
        {% for key, item in items %}
          {% if item.type == 'lesson' %}
            {% include 'task-manage/item/default-list-item.html.twig' with {task:item} %}
          {% else %}
            {% include 'course-manage/chapter/list-item.html.twig' with {chapter:item, course:course} %}
          {% endif %}
        {% endfor %}
      </ul>
      <div class="empty task-empty js-task-empty {% if items %}  hidden {% endif %}">
        <i class="es-icon es-icon-book task-empty-icon"></i>
        什么都没有，快去添加一个学习任务!
      </div>
    </div>
  </div>
{% endblock %}
