{#
/**
 * Copyright (C) 2020 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 Notification" %}
{% endblock %}

{% block callBack %}attachmentFormSetup{% endblock %}

{% block formButtons %}
    {% trans "Cancel" %}, XiboDialogClose()
    {% trans "Save" %}, $("#notificationForm").submit()
{% 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" role="tab" data-toggle="tab"><span>{% trans "General" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#message-body" role="tab" data-toggle="tab"><span>{% trans "Message" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#audience" role="tab" data-toggle="tab"><span>{% trans "Audience" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#attachment" role="tab" data-toggle="tab"><span>{% trans "Attachment" %}</span></a></li>
            </ul>
            <form id="notificationForm" class="form-horizontal" method="post" action="{{ url_for("notification.add") }}">
                <div class="tab-content">
                    <div class="tab-pane active" id="general">
                        {% set title %}{% trans "Subject" %}{% endset %}
                        {% set helpText %}{% trans "A subject line for the notification - used as a title." %}{% endset %}
                        {{ forms.input("subject", title, "", helpText, "", "required") }}

                        {% set title %}{% trans "Release Date" %}{% endset %}
                        {% set helpText %}{% trans "The date when this notification will be published" %}{% endset %}
                        {{ forms.dateTime("releaseDt", title, "", helpText, "starttime-control", "required") }}

                        {% set title %}{% trans "Email?" %}{% endset %}
                        {% set helpText %}{% trans "Should the notification be emailed?" %}{% endset %}
                        {{ forms.checkBox("isEmail", title, "", helpText) }}

                        {% set title %}{% trans "Interrupt?" %}{% endset %}
                        {% set helpText %}{% trans "Should the notification interrupt nagivation in the Web Portal? Including Login." %}{% endset %}
                        {{ forms.checkBox("isInterrupt", title, "", helpText) }}

                    </div>
                    <div class="tab-pane" id="message-body">
                        {% set title %}{% trans "Add the body of your message in the box below. If you are going to target this message to a Display/DisplayGroup be aware that the formatting you apply here will be removed." %}{% endset %}
                        {{ forms.message(title) }}

                        {{ forms.textarea("body", "", "", "", "", 10) }}
                    </div>
                    <div class="tab-pane" id="audience">
                        {% set title %}{% trans "Users" %}{% endset %}
                        {% set helpText %}{% trans "Please select one or more users / groups who will receive this notification." %}{% endset %}
                        {% set attributes = [
                            { name: "data-width", value: "100%" }
                        ] %}
                        {% set transUserGroups %}{% trans "Groups" %}{% endset %}
                        {% set transUsers %}{% trans "Users" %}{% endset %}
                        {% set optionGroups = [
                        {id: "group", label: transUserGroups},
                        {id: "user", label: transUsers}
                        ] %}
                        {{ forms.dropdown("userGroupIds[]", "dropdownmulti", title, "", {group: userGroups, user: users}, "groupId", "group", helpText, "selectPicker", "", "", "", attributes, optionGroups) }}

                        {% set title %}{% trans "Non users" %}{% endset %}
                        {% set helpText %}{% trans "Additional emails separated by a comma." %}{% endset %}
                        {{ forms.inputWithTags("nonusers", title, "", helpText, "", "", "", false, "", "", "", "", 0) }}

                        {% set title %}{% trans "Displays" %}{% endset %}
                        {% set helpText %}{% trans "Please select one or more displays / groups for this notification to be shown on - Layouts will need the notification widget." %}{% endset %}
                        {% set attributes = [
                            { name: "data-width", value: "100%" }
                        ] %}
                        {% set transGroups %}{% trans "Groups" %}{% endset %}
                        {% set transDisplays %}{% trans "Display" %}{% endset %}
                        {% set optionGroups = [
                        {id: "group", label: transGroups},
                        {id: "display", label: transDisplays}
                        ] %}
                        {{ forms.dropdown("displayGroupIds[]", "dropdownmulti", title, "", {group: displayGroups, display: displays}, "displayGroupId", "displayGroup", helpText, "selectPicker", "", "", "", attributes, optionGroups) }}

                    </div>

                    <div class="tab-pane" id="attachment">
                        <div class="row attachment-fields attachment-add-button text-center">
                            <div class="col-12">
                                <button id="attachmentAddButton" class="btn btn-white" type="">
                                    <i class="fa fa-plus"></i>
                                    {% trans "Add an attachment?" %}
                                </button>
                            </div>
                        </div>
                        <div class="form-group">
                            <div id="notificationAddFormAttachmentUpload" style="display: none;"></div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}