{% extends 'TopxiaWebBundle::bootstrap-modal-layout.html.twig' %}
{% set block = block|default(null) %}

{% block title %}编辑内容{% endblock %}

{% set modal_class = 'modal-lg' %}

{% block body %}


<h5>编辑区名称：{{block.title}}</h5>

<form id="block-form"  {% if block.mode == 'template' %}class="form-horizontal" {% endif %} action="{{ path('admin_block_update', {block:block.id}) }}" method="post">
  {% if block.mode == 'html' %}
  <div class="form-group">
      <div class="controls">
        <textarea class="form-control" id="blockContent" rows="10" name="content" data-role="editor-field" style="z-index:1000;">{{ block.content }}</textarea>
      </div>
  </div>
  {% else %}
    {% for item in templateItems %}
      {% set join = [item.title,item.type]|join(':') %}
      {% set template = templateData[join]|default(null) %}
      {% if item.type == 'a' or item.type == 'text' %}
        <div class="form-group">
          <div class="col-md-2 control-label"><label for="{{ item.title }}:{{ item.type }}">{{ item.title }}</label></div>
          <div class="col-md-8 controls"> 
          <input class="form-control" type="text" id="{{ item.title }}:{{ item.type }}" value="{{ template }}" name="{{ item.title }}:{{ item.type }}"></div>
        </div>
      {% else %}
        <div class="form-group">
          <div class="col-md-2 control-label"><label for="{{ item.title }}:{{ item.type }}">{{ item.title }}</label></div>
          <div class="col-md-8 controls">
            <button class="btn btn-default btn-sm upload-img" id="{{ item.title}}:{{ item.type }}" type="button" data-url="{{ path('file_upload', {group:'default'}) }}" data-name="{{ item.title}}:{{ item.type }}" >上传</button>       
            <button class="btn btn-default btn-sm upload-img-del" type="button"  data-name="{{ item.title}}:{{ item.type }}" {% if not template %}style="display:none;"{% endif %}>删除</button>
            <input type="hidden" name="{{ item.title }}:{{ item.type }}" value="{{ template }}">
            <a href="{{ template }}" target="_blank" {% if not template %}style="display:none;"{% endif %}>{{ item.title }}</a>
          </div>
        </div>
      {% endif %}
    {% endfor %}
  {% endif %}
  <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
</form>
{% if block.mode == 'html' %}
<form id="block-image-upload-form" action="{{ path('file_upload', {group:'default'}) }}" method="post" enctype="multipart/form-data">
  <input class="btn btn-default btn-sm" type="file" name="file" value="上传" style="display:inline-block;">
  <button class="btn btn-default btn-sm">上传图片</button>
  <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
</form>
{% endif %}

<div class="mbm mtl"><strong>编辑帮助</strong></div>
<div class="text-info">{{ block.tips|nl2br }}</div>

<div class="mbm mtl"><strong>变更记录</strong></div>
  <table id="block-history-table" class="table table-striped table-condensed">
    <tbody>
      {% for blockHistory in blockHistorys %}
      {% set templateData = blockHistory.templateData %}
        <tr id="{{ blockHistory.id }}">
          <td>{{ blockHistory.createdTime |date('Y-n-d H:i:s') }}</td>
          <td>{{ historyUsers[blockHistory.userId].nickname }}</td>
          <td>
            <a class="btn btn-xs btn-default edit-btn" 
            href="{{ path('admin_blockhistory_preview', {id:blockHistory.id}) }}" target="_blank"> 预览 </a>
          </td>
          {% if block.mode == 'template' %}
          <td>
            <button class="btn-recover-template btn btn-xs btn-default edit-btn">恢复此内容</button>
            <div class="data-role-content" style="display:none">{{ templateData|json_encode() }}</div>
          </td>
          {% else %}
          <td>
            <button class="btn-recover-content btn btn-xs btn-default edit-btn">恢复此内容</button>
            <div class="data-role-content" style="display:none"> {{ blockHistory.content }} </div>
          </td>
          {% endif %}
        </tr>
      {% endfor %}
    </tbody>
  </table>
   {{ web_macro.paginator(paginator) }} 
{% endblock %}

{% block footer %}
  <button type="button" class="btn btn-link" data-dismiss="modal">取消</button>
  <button id="block-update-btn" data-submiting-text="正在提交" type="submit" class="btn btn-primary" data-toggle="form-submit" data-target="#block-form">保存</button>
  <script type="text/javascript">app.load('block/update')</script>
{% endblock %}
