{% extends 'base.html' %}

{% block bodydata %}
data-project-id="{{ project.id }}"
data-project-locked="{{ project.islocked }}"
{% endblock %}

{% block title %} | Project: {{ project.name }} - Settings{% endblock %}

{% block main %}
<div class="page-header">
    <div class="container">
        <h1 class="smaller">
            <span class="glyphicon glyphicon-lock {% if not project.islocked %} hidden{% endif %}" aria-hidden="true"></span>
            <a href="{% url 'admin:project_overview' project.id %}">{{ project.name }}</a>
        </h1>

        {% include 'projects/navigation.html' %}
    </div>
</div>

<div class="container">
    {% include 'snippets/messages.html' %}

    <div class="row">
        <div class="col-sm-8 col-sm-offset-2">
            <h3 class="header">Settings</h3>

            <form method="POST" action="{% url 'admin:project_settings' project.id %}" novalidate>
                {% csrf_token %}

                <div class="form-group">
                    <label for="name" class="control-label">Name (required)</label>
                    <input type="text" class="form-control input-lg" id="name" name="name" maxlength="100" value="{{ project.name }}" required />
                </div>

                <div class="form-group">
                    <label for="description" class="control-label">Description</label>
                    <textarea class="form-control input-lg" rows="5" id="description" name="description">{{ project.description }}</textarea>
                </div>

                <div class="form-group">
                    <label for="everyone_contributes" class="control-label">Project permissions</label>

                    <div class="radio public {% if project.isprivate %}hidden{% endif %}">
                        <label>
                            <input type="radio" name="everyone_contributes" value="true" {% if project.everyone_contributes == 'true' %}checked{% endif %} />
                            <strong>All users</strong>
                            <p>All users can contribute. This includes anonymous contributions from users, who are not logged in.</p>
                        </label>
                    </div>

                    <div class="radio">
                        <label>
                            <input type="radio" name="everyone_contributes" value="auth" {% if project.everyone_contributes == 'auth' %}checked{% endif %} />
                            <span class="private {% if not project.isprivate %}hidden{% endif %}">
                                <strong>All users</strong>
                                <p>All users that have access to the project can contribute.</p>
                            </span>
                            <span class="public {% if project.isprivate %}hidden{% endif %}">
                                <strong>All authenticated users</strong>
                                <p>Users have to be logged in to contribute.</p>
                            </span>
                        </label>
                    </div>

                    <div class="radio">
                        <label>
                            <input type="radio" name="everyone_contributes" value="false" {% if project.everyone_contributes == 'false' %}checked{% endif %} />
                            <strong>Only members of contributor groups can contribute</strong>
                            <p>Only users, who are members of a user groups that have been granted contribute permissions, can contribute.</p>
                        </label>
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary">Save</button>
                    <button type="reset" class="btn btn-link">Reset</button>
                </div>
            </form>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-8 col-sm-offset-2">
            <div class="panel panel-danger">
                <div class="panel-heading">
                    <h2 class="panel-title">Be careful!</h2>
                </div>

                <div class="panel-body becareful">
                    <div class="toggle-active {% if project.status == status_types.active %} hidden{% endif %}">
                        <strong>Activate the project</strong>
                        <p>The project will accessible again.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#make-active-confirm">Activate</a>
                    </div>

                    <div class="toggle-active {% if project.status == status_types.inactive %} hidden{% endif %}">
                        <strong>Archive the project</strong>
                        <p>The project will be no longer accessible.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#make-inactive-confirm">Archive</a>
                    </div>

                    <div class="toggle-private {% if not project.isprivate %} hidden{% endif %}">
                        <strong>Make the project public</strong>
                        <p>Make this project visible to the general public.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#make-public-confirm">Make public</a>
                    </div>

                    <div class="toggle-private {% if project.isprivate %} hidden{% endif %}">
                        <strong>Make the project private</strong>
                        <p>Hide this project from the public.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#make-private-confirm">Make private</a>
                    </div>

                    <div class="toggle-locked {% if project.islocked %} hidden{% endif %}">
                        <strong>Lock this project</strong>
                        <p>Make sure the structure of this project will not change.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#lock-confirm">Lock this project</a>
                    </div>

                    <div class="toggle-locked {% if not project.islocked %} hidden{% endif %}">
                        <strong>Unlock this project</strong>
                        <p>Allow to edit the structure of this project.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#unlock-confirm">Unlock this project</a>
                    </div>

                    <div class="toggle-locked {% if project.islocked %} hidden{% endif %}">
                        <strong>Delete project</strong>
                        <p>Deleting a project cannot be undone. All data contributed to the project will be deleted too.</p>
                        <a href="#" class="text-danger" data-toggle="modal" data-target="#delete-confirm">Delete this project</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block modals %}
<div role="dialog" class="modal fade" id="make-active-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-warning">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you activate the project, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>The project will be accessible to users according to project permissions.</li>
                    <li>It will be possible to access existing data and contribute new data to the project.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <button type="button" class="btn btn-warning" name="confirm" value="{{ status_types.active }}" data-loading-text="Loading...">Yes, activate the project</button>
            </div>
        </div>
    </div>
</div>

<div role="dialog" class="modal fade" id="make-inactive-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-warning">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you archive the project, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>The project will be accessible to project administrators only.</li>
                    <li>All data, user groups and subsets will be kept in the database.</li>
                    <li>It will not be possible to access existing data or contribute new data to the project.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <button type="button" class="btn btn-warning" name="confirm" value="{{ status_types.inactive }}" data-loading-text="Loading...">Yes, archive the project</button>
            </div>
        </div>
    </div>
</div>

<div role="dialog" class="modal fade" id="make-public-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-warning">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you make the project public, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>The project will be accessible to any user.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <button type="button" class="btn btn-warning" name="confirm" value="false" data-loading-text="Loading...">Yes, make the project public</button>
            </div>
        </div>
    </div>
</div>

<div role="dialog" class="modal fade" id="make-private-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-warning">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you make the project private, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>The project will be accessible administrators and moderators, contributors and members of any user group that is assigned to at least one subsets.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <button type="button" class="btn btn-warning" name="confirm" value="true" data-loading-text="Loading...">Yes, make the project private</button>
            </div>
        </div>
    </div>
</div>

<div role="dialog" class="modal fade" id="lock-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-warning">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you lock the project, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>It will no longer be possible to change the structure of the project.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <button type="button" class="btn btn-warning" name="confirm" value="true" data-loading-text="Loading...">Yes, lock the project</button>
            </div>
        </div>
    </div>
</div>

<div role="dialog" class="modal fade" id="unlock-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-warning">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you unlock the project, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>It will be possible to change the structure of the project.</li>
                    <li>Making such changes may affect some GeoKey extensions or linked applications.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <button type="button" class="btn btn-warning" name="confirm" value="false" data-loading-text="Loading...">Yes, unlock the project</button>
            </div>
        </div>
    </div>
</div>

<div role="dialog" class="modal fade" id="delete-confirm" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content panel-danger">
            <div class="modal-header panel-heading">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Are you sure?</h4>
            </div>

            <div class="modal-body panel-body">
                <p><strong>Before you delete the project, please read through the consequences of this action:</strong></p>
                <ul>
                    <li>Deleting a project cannot be undone.</li>
                    <li>Deleting a project will delete all data contributed to the project.</li>
                </ul>
            </div>

            <div class="modal-footer panel-footer">
                <a href="{% url 'admin:project_delete' project.id %}" class="btn btn-danger">I'm absolutely sure, delete the project!</a>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block libraries %}
<script src="/static/js/admin.ui.forms.validate.js"></script>
<script src="/static/js/admin.ui.updater.js"></script>
<script src="/static/js/admin.control.ajax.js"></script>
{% endblock %}
