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

{% do script(['libs/jquery-validation.js', 'app/js/course-chapter-manage/index.js']) %}

{% set chapter = chapter|default(null) %}

{% block title %}
  {% if chapter %}{{'编辑'|trans}}{% else %}{{'添加'|trans}}{% endif %}{% if type == 'unit' %}{% if setting('default.part_name') %}{{ setting('default.part_name')|default('节'|trans) }}{% else %}{{'节'|trans}}{% endif %}{% elseif type == 'lesson' %}任务{% else %}{% if setting('default.chapter_name') %}{{ setting('default.chapter_name')|default('章'|trans) }}{% else %}{{'章'|trans}}{% endif %}{% endif %}
{% endblock %}

{% block body %}
<form id="course-chapter-form" class="form-horizontal" method="post" {% if parentId is defined%}data-parentId="{{parentId}}" {% endif %}
  {% if chapter %}
	  action="{{ path('course_manage_chapter_edit', {courseId:course.id, chapterId:chapter.id}) }}"
	{% else %}
	  action="{{ path('course_manage_chapter_create', {id:course.id}) }}"
  {% endif %}
  >
  <div class="row form-group">
    <div class="col-md-3 control-label">
      {% if type == 'unit' %}
        <label for="chapter-title-field">{% if setting('default.part_name') %}{{ setting('default.part_name')|default('节'|trans) }}{% else %}{{'节'|trans}}{% endif %}{{'标题'|trans}}</label>
      {% elseif type == 'lesson' %}
        <label for="chapter-title-field">{{'任务'|trans}}</label>
      {% else %}
        <label for="chapter-title-field">{% if setting('default.chapter_name') %}{{ setting('default.chapter_name')|default('章'|trans) }}{% else %}{{'章'|trans}}{% endif %}{{'标题'|trans}}</label>
      {% endif %}
    </div>
    <div class="col-md-8 controls"><input id="chapter-title-field" type="text" name="title" value="{{ field_value(chapter, 'title') }}" class="form-control"></div>
  </div>
  <input type="hidden" name="type" value="{{ type }}">
</form>

{% endblock %}

{% block footer %}
    <button type="button" class="btn btn-link" data-dismiss="modal">{{'取消'|trans}}</button>
    <button id="course-chapter-btn" data-loading-text="{{'正在提交'|trans}}" type="button" class="btn btn-primary" data-toggle="form-submit" data-target="#course-chapter-form" data-chapter="{{ setting('default.chapter_name')|default('章'|trans) }}" data-part="{{ setting('default.part_name')|default('节'|trans) }}">{% if chapter %}{{'保存'|trans}}{% else %}{{'添加'|trans}}{% endif %}</button>
{% endblock %}

{% set hideFooter = true %}
