{#
/**
 * Copyright (C) 2021 Xibo Signage Ltd
 *
 * Xibo - Digital Signage - http://www.xibo.org.uk
 *
 * This file is part of Xibo.
 *
 * Xibo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Xibo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 */
#}

{% extends "form-base.twig" %}
{% import "forms.twig" as forms %}

{% block formTitle %}
    {% trans "Delete" %}
{% endblock %}

{% block formButtons %}
    {% trans "No" %}, XiboDialogClose()
    {% trans "Yes" %}, $("#userDeleteForm").submit()
{% endblock %}

{% block formFieldActions %}
    [{
    "field": "deleteAllItems",
    "trigger": "init",
    "value": 1,
    "operation": "is:checked",
    "actions": {
    ".user-selector-group": { "display": "none" }
    }
    },{
    "field": "deleteAllItems",
    "trigger": "change",
    "value": 1,
    "operation": "is:checked",
    "actions": {
    ".user-selector-group": { "display": "none" }
    }
    },{
    "field": "deleteAllItems",
    "trigger": "init",
    "value": 0,
    "operation": "is:checked",
    "actions": {
    ".user-selector-group": { "display": "" }
    }
    },{
    "field": "deleteAllItems",
    "trigger": "change",
    "value": 0,
    "operation": "is:checked",
    "actions": {
    ".user-selector-group": { "display": "" }
    }
    }]
{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <form id="userDeleteForm" class="XiboForm form-horizontal" method="delete" action="{{ url_for("user.delete", {id: user.userId}) }}">
                {% set message %}{% trans "Are you sure you want to delete? You may not be able to delete this user if they have associated content. You can retire users by using the Edit Button." %}{% endset %}
                {{ forms.message(message) }}

                {% if not user.isSuperAdmin() %}
                    {% set title %}{% trans "Delete all items owned by this User?" %}{% endset %}
                    {% set helpText %}{% trans "Check to delete all items owned by this user, including Layouts, Media, Schedules, etc." %}{% endset %}
                    {{ forms.checkbox("deleteAllItems", title, 0, helpText) }}
                {% endif %}

                {% set title %}{% trans "Reassign items to another User" %}{% endset %}
                {% set helpText %}{% trans "Reassign all items this User owns to the selected User." %}{% endset %}
                {{ forms.dropdown("reassignUserId", "single", title, 0, [{userId:null, userName:""}]|merge(users), "userId", "userName", helpText, "user-selector-group") }}
            </form>
        </div>
    </div>
{% endblock %}