{% extends 'generic/object_edit.html' %}
{% load i18n %}

{% block buttons %}
    <a href="{{ return_url }}" class="btn btn-outline-secondary protect-btn">{% trans "Cancel" %}</a>
    {% if object.pk %}
    <button type="submit" name="_update" class="btn btn-primary protect-btn">
        {% trans "Save" %}
    </button>
    {% else %}
    <div class="btn-group" role="group" aria-label="{% trans "Actions" %}">
        <button type="submit" name="_create" class="btn btn-primary">
        {% trans "Create" %}
        </button>
        <button type="submit" name="_addanother" class="btn btn-outline-primary">
        {% trans "Create & Add Another" %}
        </button>
    </div>
    {% endif %}

    <script>
        const projectButtons = document.querySelectorAll('.protect-btn');

        projectButtons.forEach(button => {
        button.addEventListener('click', protectButton);
        });
        function protectButton(event) {
        event.target.classList.add('disabled');
        event.target.textContent = 'Please wait'
        }
    </script>
{% endblock buttons %}