{#
/**
 * Copyright (C) 2024 Xibo Signage Ltd
 *
 * Xibo - Digital Signage - https://xibosignage.com
 *
 * 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 "Add User Group" %}
{% endblock %}

{% block formButtons %}
    {% trans "Cancel" %}, XiboDialogClose()
    {% trans "Save" %}, $("#userGroupAddForm").submit()
{% endblock %}

{% block callBack %}userGroupFormOpen{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item"><a class="nav-link active" href="#general-tab" role="tab" data-toggle="tab"><span>{% trans "General" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#description-tab" role="tab" data-toggle="tab"><span>{% trans "Description" %}</span></a></li>
                {% if currentUser.userTypeId == 1 %}
                <li class="nav-item"><a class="nav-link" href="#notifications-tab" role="tab" data-toggle="tab"><span>{% trans "Notifications" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#onboarding-tab" role="tab" data-toggle="tab"><span>{% trans "Onboarding Settings" %}</span></a></li>
                {% endif %}
            </ul>
            <form id="userGroupAddForm" class="UserGroupForm form-horizontal" method="post" action="{{ url_for("group.add") }}">
                <div class="tab-content">
                    <div class="tab-pane active" id="general-tab">
                        {% set title %}{% trans "Name" %}{% endset %}
                        {% set helpText %}{% trans "The Name for this User Group" %}{% endset %}
                        {{ forms.input("group", title, "", helpText, "", "required maxlength='50'") }}

                        {% set title %}{% trans "Library Quota" %}{% endset %}
                        {% set helpText %}{% trans "The quota that should be applied. Enter 0 for no quota." %}{% endset %}
                        <div class="form-group row">
                            <label class="col-sm-2 control-label" for="libraryQuota">{{ title }}</label>
                            <div class="col-sm-6">
                                <input class="form-control" name="libraryQuota" type="number" id="libraryQuota" />
                                <span class="help-block">{{ helpText }}</span>
                            </div>
                            <div class="col-sm-4">
                                <select name="libraryQuotaUnits" class="form-control">
                                    <option value="kb">KiB</option>
                                    <option value="mb">MiB</option>
                                    <option value="gb">GiB</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    {% if currentUser.userTypeId == 1 %}
                        <div class="tab-pane" id="notifications-tab">
                            {% set title %}{% trans "Receive System Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive system notifications?" %}{% endset %}
                            {{ forms.checkbox("isSystemNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive Display Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Display notifications for Displays they have permission to see?" %}{% endset %}
                            {{ forms.checkbox("isDisplayNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive DataSet Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive DataSet notification emails?" %}{% endset %}
                            {{ forms.checkbox("isDataSetNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive Layout Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Layout notification emails?" %}{% endset %}
                            {{ forms.checkbox("isLayoutNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive Library Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Library notification emails?" %}{% endset %}
                            {{ forms.checkbox("isLibraryNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive Report Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Report notification emails?" %}{% endset %}
                            {{ forms.checkbox("isReportNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive Schedule Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive Schedule notification emails?" %}{% endset %}
                            {{ forms.checkbox("isScheduleNotification", title, 0, helpText) }}

                            {% set title %}{% trans "Receive Custom Notifications?" %}{% endset %}
                            {% set helpText %}{% trans "Should members of this Group receive notifications emails for Notifications manually created in CMS?" %}{% endset %}
                            {{ forms.checkbox("isCustomNotification", title, 0, helpText) }}
                        </div>
                    {% endif %}

                    <div class="tab-pane" id="description-tab">
                        {% set title %}{% trans "Description" %}{% endset %}
                        {% set helpText %}{% trans "An optional description of the user group. (1 - 500 characters)" %}{% endset %}
                        {{ forms.textarea("description", title, "", helpText, "", "", 15) }}
                    </div>

                    {% if currentUser.userTypeId == 1 %}
                        <div class="tab-pane" id="onboarding-tab">
                            {% set title %}{% trans "Show when onboarding a new user?" %}{% endset %}
                            {% set helpText %}{% trans "Should this User Group be available for selection when creating a New User via the onboarding form?" %}{% endset %}
                            {{ forms.checkbox("isShownForAddUser", title, 0, helpText) }}

                            {% set title %}{% trans "Default Homepage" %}{% endset %}
                            {% set helpText %}{% trans "Default Homepage for users created with this group." %}{% endset %}
                            {% set homepagesUrl %}{{ url_for("user.homepages.search") }}?userTypeId=1{% endset %}
                            {% set attributes = [
                                { name: "data-live-search", value: "true" },
                                { name: "data-allow-clear", value: "true" },
                                { name: "data-placeholder--id", value: null },
                                { name: "data-placeholder--value", value: "" },
                                { name: "data-search-url", value: homepagesUrl },
                                { name: "data-search-term", value: "homepage" },
                                { name: "data-id-property", value: "homepage" },
                                { name: "data-text-property", value: "title" },
                                { name: "data-initial-key", value: "homepage" },
                                { name: "data-initial-value", value: group.defaultHomepageId }
                            ] %}
                            {{ forms.dropdown("defaultHomepageId", "single", title, "", null, "homepage", "title", helpText, "pagedSelect", "", "", "", attributes) }}
                        </div>
                    {% endif %}
                </div>
            </form>
        </div>
    </div>
{% endblock %}