{% extends 'announcement/announcement-modal-layout.html.twig' %}
{% do script(['libs/es-ckeditor/ckeditor.js','libs/jquery-validation.js','libs/bootstrap-datetimepicker.js', 'app/js/announcement/announcement-write/index.js']) %}
{% set tab="manage" %}

{% block content %}
  <form id="announcement-write-form" class="form-horizontal" 
    {% if announcement.id %}
      action="{{ path('announcement_update',{id:announcement.id, targetType:targetType,targetId:targetObject.id, }) }}"
    {% else %}
      action="{{ path('announcement_add',{targetType:targetType, targetId:targetObject.id}) }}"
    {% endif %}
  >

    {% if member|default(null) %}
      <input type="hidden" name="targetId" value="{{ targetId }}">
    {% else %}
      <div class="row form-group">
        <div class="col-md-2 control-label">
          <label for="startTime">{{'选择计划'|trans}}</label>
        </div>
        <div class="col-md-9 controls" style="z-index:2000;">
          <select class="form-control" name="targetId">
            {% for plan in plans if plan %}
              <option value="{{ plan.id }}" {% if plan.id == course.id|default(0) or plan.id == announcement.targetId|default(0) %}selected{% endif %}>{{ plan.title }}</option>
            {% endfor %}
          </select>
        </div>
      </div>
    {% endif %}

    <div class="row form-group">
      <div class="col-md-2 control-label">
        <label for="startTime">{{'发布时间'|trans}}</label>
      </div>
      <div class="col-md-9 controls" style="z-index:2000;">
        <input type="text" id="startTime"  name="startTime" class="form-control" value="{% if announcement.startTime|default('now') %}{{announcement.startTime|default('now')|date("Y-m-d H:i")}}{% endif %}">
      </div>
    </div>

    <div class="row form-group">
      <div class="col-md-2 control-label">
        <label for="endTime">{{'结束时间'|trans}}</label>
      </div>
      <div class="col-md-9 controls" style="z-index:2000;">
        <input type="text" id="endTime"  name="endTime" class="form-control" value="{% if announcement.endTime|default(null) %}{{announcement.endTime|date("Y-m-d H:i")}}{% endif %}">
      </div>
    </div>

    <div class="row form-group">
      <div class="col-md-2 control-label">
        <label for="content">{{'公告内容'|trans}}</label>
      </div>
      <div class="col-md-9 controls">
        <textarea class="form-control" id="announcement-content-field" name="content" data-display="{{'公告内容'|trans}}" data-image-upload-url="{{ path('editor_upload', {token:upload_token('default')}) }}">{{ announcement.content }}</textarea>
      </div>
    </div>

    {% if not announcement.id %}
    <div class="row form-group">
      <div class="col-md-2 control-label">
      </div>
      <div class="col-md-9 controls">
        <div class="checkbox">
          <label>
            <input type="checkbox" name="notify" value="notify"> {{'给%user_name%发送系统通知'|trans({'%user_name%': default.user_name|default('学员'|trans)})}}
          </label>
        </div>
      </div>
    </div>
    {% endif %}
    <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
  </form>

{% endblock %}
{% block footer %}
  <button type="button" class="btn btn-link" data-dismiss="modal">{{'取消'|trans}}</button>
  <button type="button" class="btn btn-primary pull-right js-save-btn" data-toggle="form-submit" data-target="#announcement-write-form" data-loading-text="{{'正在保存...'|trans}}">{{'保存'|trans}}</button>
{% endblock %}