{#
/**
 * 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 "Add New User" %}
{% endblock %}

{% block callBack %}onboardingFormOpen{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <div class="stepwizard" data-active="onboarding-step-1">
                <div class="stepwizard-row setup-panel">
                    <div class="stepwizard-step col-xs-3">
                        <a href="#onboarding-step-1" type="button" class="btn btn-success btn-circle">1</a>
                        <p><small>{{ "Create"|trans }}</small></p>
                    </div>
                    <div class="stepwizard-step col-xs-3">
                        <a href="#onboarding-step-2" type="button" class="btn btn-default btn-circle" disabled="disabled">2</a>
                        <p><small>{{ "Credentials"|trans }}</small></p>
                    </div>
                    {% if currentUser.featureEnabled("folder.view") %}
                    <div class="stepwizard-step col-xs-3">
                        <a href="#onboarding-step-3" type="button" class="btn btn-default btn-circle" disabled="disabled">3</a>
                        <p><small>{{ "Sharing"|trans }}</small></p>
                    </div>
                    {% endif %}
                </div>
            </div>
            <form id="userOnboardingForm" class="stepwizard-form form-horizontal" role="form" method="post" action="{{ url_for("user.add") }}">
                <div class="panel panel-default setup-content" id="onboarding-step-1" data-next="onboarding-step-2">
                    <div class="panel-heading">
                        <h3 class="panel-title">{{ "Create"|trans }}</h3>
                    </div>
                    <div class="panel-body">
                        <p>
                            {{ "Select the role which most closely matches what you want this User to do, or select manual."|trans }}
                            &nbsp;<span class="fa fa-info-circle"
                                        title="{{ "What does this mean?"|trans }}"
                                        data-toggle="popover"
                                        data-placement="right"
                                        data-html="true"
                                        data-content="{{ "The User account you are using has full access to the CMS and all of its features and configuration. If you are not adding an administrator type User, then it is likely you'll want to restrict and simplify what this new User can do. <br><br>You may even want to create a simplified User for your own usage to administer the system in a way tailored to your needs."|trans }}"
                            ></span>
                        </p>
                        <div class="card card-body bg-light">
                            {% for group in groups %}
                                <div class="radio">
                                    <label>
                                        <input type="radio"
                                               data-default-homepage-id="{{ group.defaultHomepageId }}"
                                               name="groupId"
                                               value="{{ group.groupId }}">
                                        {{ group.group }}<br>
                                        {{ group.description }}
                                    </label>
                                </div>
                            {% endfor %}
                            <div class="radio">
                                <label>
                                    <input type="radio" name="groupId" value="manual">
                                    {{ "Manually create a user"|trans }}<br>
                                    {{ "Selecting this option will direct you to the Add User form where you can manually
                                    create user."|trans }}
                                </label>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="panel panel-default setup-content" style="display:none;" id="onboarding-step-2" {% if currentUser.featureEnabled("folder.view") %}data-next="onboarding-step-3"{% else %}data-next="finished"{% endif %}>
                    <div class="panel-heading">
                        <h3 class="panel-title">{{ "Credentials"|trans }}</h3>
                    </div>
                    <div class="panel-body">
                        {{ forms.hidden("userTypeId", "3") }}
                        {{ forms.hidden("libraryQuota", "0") }}
                        {{ forms.hidden("homePageId", "") }}

                        {% set title %}{% trans "User Name" %}{% endset %}
                        {% set helpText %}{% trans "The Login Name of the user." %}{% endset %}
                        {{ forms.input("userName", title, "", helpText, "", "required maxlength='50'") }}

                        {% set title %}{% trans "Password" %}{% endset %}
                        {% set helpText %}{% trans "The Password for this user." %}{% endset %}
                        {{ forms.password("password", title, "", helpText, "", "required") }}

                        {% set title %}{% trans "Email" %}{% endset %}
                        {% set helpText %}{% trans "The Email Address for this user." %}{% endset %}
                        {{ forms.email("email", title, "", helpText) }}
                    </div>
                </div>

                <div class="panel panel-default setup-content" style="display:none;" id="onboarding-step-3" data-next="finished">
                    <div class="panel-heading">
                        <h3 class="panel-title">{{ "Content"|trans }}</h3>
                    </div>
                    <div class="panel-body">
                        {{ forms.hidden("homeFolderId", 1) }}

                        {% if currentUser.featureEnabled("folder.view") %}
                            <p>{{ "Select any folders the new user should have shared with them for viewing and editing."|trans }}</p>
                            <div class="folder-tree-buttons">
                                <button type="button" id="selectAllBtn" class="btn btn-sm btn-outline-primary">{% trans "Select All" %}</button>
                                <button type="button" id="selectNoneBtn" class="btn btn-sm btn-outline-secondary">{% trans "Clear Selection" %}</button>
                            </div>
                            <div id="container-form-folder-tree" class="card card-body bg-light"></div>
                        {% endif %}
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}