{{ include_javascript('javascripts/vendor/datatables-full/jquery.dataTables.min.js') }}
{{ include_javascript('tools/bazar/presentation/javascripts/forms-import.js') }}
{{ include_css('styles/vendor/datatables-full/dataTables.bootstrap.min.css') }}

{% set tooltipMessage =  isWikiHibernated ? _t('WIKI_IN_HIBERNATION') : _t('BAZ_NEED_ADMIN_RIGHTS') %}

{% if message %}
<div class="alert alert-success">
  <a data-dismiss="alert" class="close" type="button">&times;</a>
  {{ _t(message) }}
</div>
{% endif %}

{% if forms|length > 0 %}
<div class="table-responsive">
  <table id="existing-forms-table" class="bazar-table table table-condensed table-striped">
    <thead>
      <tr>
        <th>{{ _t('BAZ_FORMULAIRE') }}</th>
        <th style="width:100px;">{{ _t('BAZ_ACTIONS_FICHES') }}</th>
        <th style="width:240px;">{{ _t('BAZ_DATA_FORMAT') }}</th>
        <th style="width:40px;">{{ _t('BAZ_ID') }}</th>
        <th style="width:100px;">{{ _t('BAZ_ACTIONS') }}</th>
      </tr>
    </thead>
    <tbody>
      {% for key, form in forms %}
        <tr>
          <td>
            <strong>{{ form.title }}</strong>
            {% if form.description %}<br />{{ form.description }}{% endif %}
          </td>
          <td>
            <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_RECHERCHER') }}" href="{{ url({ params: { vue: 'consulter', action: 'recherche', id: key }}) }}" data-toggle="tooltip" data-placement="bottom">
              <i class="fa fa-search icon-search"></i>
            </a>
            <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_SAISIR_UNE_NOUVELLE_FICHE') }}" href="{{ url({ params: { vue: 'saisir', action: 'saisir_fiche', id: key }}) }}" data-toggle="tooltip" data-placement="bottom">
              <i class="fa fa-plus icon-plus"></i>
            </a>
          </td>
          <td>
            <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_RSS') }}" href="{{ url({ handler: 'rss', params: { id: key }}) }}" data-toggle="tooltip" data-placement="bottom" >
              <i class="fa fa-signal"></i>
            </a>
            <a class="btn btn-default btn-xs" title="{{ _t('BAZ_CSV') }}" href="{{ url({ tag: 'api',handler:'forms/' ~ key ~'/entries/csv'}) }}" data-toggle="tooltip" data-placement="bottom">
              CSV
            </a>
            <a class="btn btn-default btn-mini btn-xs" target="_blank" title="{{ _t('BAZ_JSON') }}" href="{{ url({ tag: 'api',handler:'forms/' ~ key ~'/entries'}) }}" data-toggle="tooltip" data-placement="bottom">
              JSON
            </a>
            {% if form.isSemantic %}
              <a class="btn btn-default btn-mini btn-xs" target="_blank" title="{{ _t('BAZ_JSON_LD') }}" href="{{ url({ tag: 'api',handler:'forms/' ~ key ~'/entries/json-ld'}) }}" data-toggle="tooltip" data-placement="bottom">
                JSON-LD
              </a>
            {% endif %}
            {% if form.isGeo %}
              <a class="btn btn-default btn-mini btn-xs" target="_blank" title="{{ _t('BAZ_GEOJSON') }}" href="{{ url({ tag: 'api',handler:'forms/' ~ key ~'/entries/geojson'}) }}" data-toggle="tooltip" data-placement="bottom">
                Geo
              </a>
            {% endif %}
            {% if form.isDate %}
              <a class="btn btn-default btn-mini btn-xs" 
                target="_blank" title="{{ _t('BAZ_ICAL') }}" 
                href="{{ url({ tag: 'api',handler:'forms/' ~ key ~'/entries/ical'}) }}" 
                data-toggle="tooltip" data-placement="bottom">
                ICAL
              </a>
            {% endif %}
            {% if form.isActivityPubEnabled %}
              <a class="btn btn-default btn-mini btn-xs" target="_blank" title="{{ _t('BAZ_ACTIVITYPUB_ACTOR') }}" href="/actors/{{ key }}" data-toggle="tooltip" data-placement="bottom">
                AP
              </a>
            {% endif %}
            <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_WIDGET') }}" href="{{ url({ handler: 'widget', params: { id: key }}) }}" data-toggle="tooltip" data-placement="bottom">
              {{ _t('BAZ_WIDGET') }}
            </a>
          </td>
          <td>
            {{ key }}
          </td>
          <td>
            <div class="create-actions">
            {% if form.canEdit %}
            <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_CLONE_FORM') }}" href="{{ url({ params: { vue: 'formulaire', action: 'clone', idformulaire: key }}) }}" data-toggle="tooltip" data-placement="bottom" >
              <i class="far fa-clone"></i>
            </a>
            {% else %}
              <button type="button" class="btn btn-default btn-mini btn-xs" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage }}">
                <i class="far fa-clone"></i>
              </button>
            {% endif %}
            {% if form.canEdit %}
              <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_MODIFIER_FORMULAIRE') }}" href="{{ url({ params: { vue: 'formulaire', action: 'modif', idformulaire: key }}) }}" data-toggle="tooltip" data-placement="bottom" >
                <i class="fa fa-pencil-alt"></i>
              </a>
            {% else %}
              <button type="button" class="btn btn-default btn-mini btn-xs" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage }}">
                <i class="fa fa-pencil-alt"></i>
              </button>
            {% endif %}
            {% if form.isActivityPubEnabled %}
              <a class="btn btn-default btn-mini btn-xs" title="{{ _t('BAZ_GESTION_ABONNEMENTS') }}" href="{{ url({ params: { vue: 'abonnements', action: 'list', idformulaire: key }}) }}" data-toggle="tooltip" data-placement="bottom" >
                <i class="fa fa-user-plus"></i>
              </a>
            {% endif %}
            </div>
            <div class="erase-actions">
            {% if form.canDelete %}
              <a class="btn btn-danger btn-xs modalbox" title="{{ _t('BAZ_VIDER_FORMULAIRE') }}" href="{{ url({ params: { vue: 'formulaire', action: 'confirm_empty', idformulaire: key, voirmenu: 0 }}) }}" data-toggle="tooltip" data-placement="bottom">
                <i class="fas fa-eraser"></i>
              </a>
              <a class="btn btn-danger btn-xs modalbox" title="{{ _t('BAZ_SUPPRIMER_FORMULAIRE') }}" href="{{ url({ params: { vue: 'formulaire', action: 'confirm_delete', idformulaire: key, voirmenu: 0 }}) }}" data-toggle="tooltip" data-placement="bottom">
                <i class="fa fa-trash"></i>
              </a>
            {% else %}
              <button type="button" class="btn btn-danger btn-xs" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage }}">
                <i class="fas fa-eraser"></i>
              </button>
              <button type="button" class="btn btn-danger btn-xs" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage }}">
                <i class="fa fa-trash"></i>
              </button>
            {% endif %}
            </div>
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
</div> <!-- /.table-responsive -->
{% else %}
<div class="alert alert-info">
	<a data-dismiss="alert" class="close">&times;</a>{{ _t('BAZ_INTRO_AJOUT_FORMULAIRE')|raw }}
</div>
{% endif %}

{% if userIsAdmin and not isWikiHibernated %}
  <a class="btn btn-primary" href="{{ url({ params: { vue: 'formulaire', action: 'new' }}) }}">
    {% block createformbutton %}
      <i class="fa fa-plus icon-plus icon-white"></i>
      {{ _t('BAZ_NOUVEAU_FORMULAIRE') }}
    {% endblock createformbutton %}
  </a>
{% else %}
  <button type="button" class="btn btn-primary" disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage  }}">
    {{ block('createformbutton') }}
  </button>
{% endif %}

<hr>

<strong>{{ _t('BAZ_IMPORT_FORMS_FROM_URL') }}</strong>
<form action="javascript:undefined" class="form-horizontal">
	<div class="input-prepend input-append input-group">
		<span class="add-on input-group-addon">
      <i class="fa fa-link icon-globe"></i>
    </span>
		<input id="url-import-forms" class="form-control input-xxlarge" {% if not userIsAdmin or isWikiHibernated %}disabled  data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage }}"{% endif %} placeholder="{{ _t('BAZ_URL_IMPORT_LISTS_INFO') }}" type="url" />
		<span class="input-group-btn">
      <button id="btn-import-forms" {% if not userIsAdmin or isWikiHibernated %}disabled  disabled="disabled" data-toggle="tooltip" data-placement="bottom" title="{{ tooltipMessage }}"{% endif %} class="btn btn-primary" type="submit">{{ _t('BAZ_GO') }} !</button>
    </span>
	</div>
  <p class="text-info">Exemple d'url pour obtenir des formulaires types: <code>https://yeswiki.net/serveur</code></p>
</form>
<br>
<div id="import-forms-result"></div>
<form id="import-forms-form" action="" class="hide" method="post">
  <div class="table-responsive">
    <table id="import-forms-table" class="table table-condensed table-striped prevent-auto-init">
      <thead>
        <tr>
          <th class="prevent-sorting">
            <label class="check-all-container">
              <input data-target="#import-forms-table tbody" type="checkbox" class="selectall">
              <span></span>
            </label>
          </th>
          <th>{{ _t('BAZ_FORMULAIRE') }}</th>
          <th>{{ _t('BAZ_ID') }}</th>
        </tr>
      </thead>
      <tbody>
      </tbody>
    </table>
  </div> <!-- /.table-responsive -->
  <div class="checkbox">
    <label class="checkbox">
      <input data-target="#import-forms-table tbody" type="checkbox" class="selectall">
      <span>{{ _t('BAZ_SELECT_ALL') }}</span>
    </label>
  </div>
  <button id="btn-import-selection" type="submit" class="btn btn-primary">
    {{ _t('BAZ_IMPORT_SELECTION') }}
  </button>
</form>
<div
    id="form-translations"
    data-nbformsfound="{{ _t('BAZ_NBFORMSFOUND') }}"
    data-noanswers="{{ _t('BAZ_NOANSWERS') }}"
    data-notvalidurl="{{ _t('BAZ_NOTVALIDURL') }}"
    data-recuperation="{{ _t('BAZ_RECUPERATION') }}"
    data-loading="{{ _t('BAZ_LOADING') }}"
    data-existingmessage="{{ _t('BAZ_EXISTINGMESSAGEFORM') }}"
    data-existingmessagereplace="{{ _t('BAZ_EXISTINGMESSAGEREPLACEFORM') }}">
</div>
