{% extends "sysadmin/base.html" %}
{% load i18n %}

{% block cur_notice %}tab-cur{% endblock %}

{% block right_panel %}
<div class="hd ovhd">
    <h3 class="fleft">{% trans "All Notifications" %}</h3>
    <button id="add-n" class="fright btn-white">{% trans "Add new notification" %}</button>
</div>
<form action="{% url 'notification_add' %}" method="post" class="hide" id="add-n-form">{% csrf_token %}
    <h3>{% trans "Add new notification" %}</h3>
    <textarea name="message" class="textarea"></textarea><br />
    <p class="error hide"></p>
    <input type="submit" value="{% trans "Submit" %}" class="submit" />
</form>

{% if notes %}
<table>
    <thead>
        <tr>
            <th width="75%">{% trans "Notification Detail" %}</th>
            <th width="25%">{% trans "Operations" %}</th>
        </tr>
    </thead>
    <tbody>
    {% for note in notes %}
    <tr>
        <td>{{ note.message }}
        {% if note.primary == 1 %}
        <span class="cur-note">{% trans "(current notification)" %}</span>
        {% endif %}
        <td>
          {% if note.primary != 1 %}
          <a href="#" data-id="{{ note.id }}" class="set-cur-btn op vh">{% trans "Set to current" %}</a>
          {% endif %}
          <a href="#" data-url="{{ SITE_ROOT }}notification/delete/{{ note.id }}/" data-target="{{ note.message }}" class="note-delete-btn op vh">{% trans "Delete" %}</a>
        </td>
    </tr>
    {% endfor %}
    </tbody>
</table>
{% else %}
<p>{% trans "Empty" %}</p>
{% endif %}
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
$('#add-n').on('click', function() {
    $('#add-n-form').modal();
    $('#simplemodal-container').css({'width':'auto', 'height':'auto'});
    return false;
});
$('#add-n-form').on('submit', function() {
    var $form = $(this);
    var msg = $.trim($('[name="message"]', $form).val());
    if (!msg) {
        $('.error', $form).html("{% trans "It is required." %}").show();
        return false;
    }
});
addConfirmTo($('.note-delete-btn'), {
    'title':"{% trans "Delete Notification" %}",
    'con':"{% trans "Are you sure you want to delete %s ?" %}"
});

$('.set-cur-btn').on('click', function() {
    location.href = '{{ SITE_ROOT }}notification/set-primary/' + $(this).attr('data-id') + '/';
});
</script>
{% endblock %}
 
