{% extends 'admin/publications/wrapper.html.twig' %}

{% block content %}

<form style="max-width:500px" class="no-ajax form_publication form-horizontal" method="post" action="{{ path('admin_feeds_create') }}">
    <fieldset>
        <legend>{% trans 'Ajouter une publication' %}</legend>
        <div class="control-group">
            <label class="control-label" for="add_pub_titre">{% trans 'Titre' %}</label>
            <div class="controls">
                <input type="text" id="add_pub_titre" class="required_text input-large" placeholder="{% trans 'Feed name' %}" maxlength="128" name="title" />
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" for="add_pub_subtitre">{% trans 'Sous-titre' %}</label>
            <div class="controls">
                <input type="text" id="add_pub_subtitre" class="input-large" placeholder="{% trans 'Short description' %}" maxlength="512" name="subtitle" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="add_pub_base_id">{% trans 'Etendue de la publication' %}</label>
            <div class="controls">
                <select id="add_pub_base_id" class="input-large" name="base_id">
                    <option value="">{% trans 'Non-Restreinte (publique)' %}</option>
                    {% for databox in app['authentication'].getUser().ACL().get_granted_sbas('bas_chupub') %}
                        <optgroup label="{{ databox.get_label(app['locale.I18n']) }}">
                            {% for collection in databox.get_collections() %}
                                <option value="{{ collection.get_base_id() }}">{{ collection.get_name() }}</option>
                            {% endfor %}
                        </optgroup>
                    {% endfor %}
                </select>
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <label class="checkbox" for="add_pub_public">
                    <input type="checkbox" id="add_pub_public" name="public" value="1" />
                    {% trans 'Publique' %}
                </label>
            </div>
        </div>
        <div class="form-actions">
            <button type="submit" class="btn btn-warning">{% trans 'boutton::valider' %}</button>
        </div>
    </fieldset>
</form>

<table class="admintable" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th style="width:40px;"></th>
            <th>{% trans 'Titre' %}</th>
            <th style="width:150px; text-align: center;">{% trans 'Date Creation' %}</th>
            <th style="width:220px; text-align: center;">{% trans 'Restriction' %}</th>
            <th style="width:80px; text-align: center;">{% trans 'Public' %}</th>
            <th style="width:80px;"></th>
        </tr>
    </thead>
    <tbody>
        {% for feed in feeds.get_feeds %}
            <tr class="{% if loop.index is odd %}odd{% else %}even{% endif %}">
                <td>
                    <div style="border:1px solid #ccc; width:22px; height:22px; margin:2px;">
                        <a href="{{ path('admin_feeds_feed', { 'id' : feed.get_id() }) }}">
                            <img src="{{feed.get_icon_url() ~ '?' ~ random(1000) }}" id="pub_icon" style="margin:3px; width:16px; height:16px;"/>
                        </a>
                    </div>
                </td>
                <td valign="center" align="left">
                    <a href="{{ path('admin_feeds_feed', { 'id' : feed.get_id() }) }}" style="display:block;">{{ feed.get_title() }}</a>
                </td>
                <td style="text-align: center;">
                    {{ app['date-formatter'].getDate(feed.get_created_on()) }}
                </td>
                <td valign="center" align="center">
                    {% if feed.get_collection() != null %}
                        {{ feed.get_collection().get_databox().get_label(app['locale.I18n']) }} /
                        {{ feed.get_collection().get_name() }}
                    {% endif %}
                </td>
                <td valign="center" align="center">
                    {% if feed.is_public() %}
                        <img src="/skins/icons/ligth-on.png" title="{% trans 'This feed is public' %}"/>
                    {% endif %}
                </td>
                <td valign="center" align="center">
                    {% if feed.is_owner(app['authentication'].getUser()) %}
                        <form class="no-ajax form_publication" action="{{ path('admin_feeds_feed_delete', { 'id' : feed.get_id() }) }}" method="post" style="margin:0;">
                            <button class="feed_remover btn btn-mini">{% trans 'boutton::supprimer' %}</button>
                        </form>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
    </tbody>
</table>

<script type="text/javascript">
  $(document).ready(function(){
    $('button.feed_remover').bind('click', function(event){
      if(!confirm('{% trans 'Une fois la publication supprimee, les donnees publiees seront definitivement perdues. Continuer ?' %}'))
      {
        event.stopPropagation();
        return false;
      }
    });
    $('#add_pub_public').bind('change', function(){
      if($(this).attr('checked'))
      {
        $('#add_pub_base_id').val('');
      }
    });
    $('#add_pub_base_id').bind('change', function(){
      if($(this).val() != '')
      {
        $('#add_pub_public').attr('checked', false);
      }
    });
  });
</script>

{% endblock %}
