{#
/*
 * Xibo - Digital Signage - http://www.xibo.org.uk
 * Copyright (C) 2022 Xibo Signage Ltd
 *
 * 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 Report Schedule" %}
{% endblock %}

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

{% block callBack %}proofOfPlayScheduleCallback{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <form id="proofofplayScheduleAddForm" class="XiboForm form-horizontal" method="post" action="{{ url_for("reportschedule.add") }}">

                {{ forms.hidden("hiddenFields", hiddenFields) }}
                {{ forms.hidden("reportName", reportName) }}

                {% set title %}{% trans "Name" %}{% endset %}
                {% set helpText %}{% trans "The name for this report schedule" %}{% endset %}
                {{ forms.input("name", title, "", helpText, "", "required") }}

                {% set title %}{% trans "Frequency" %}{% endset %}
                {% set helpText %}{% trans "Select how frequently you would like this report to run" %}{% endset %}
                {% set daily %}{% trans "Daily" %}{% endset %}
                {% set weekly %}{% trans "Weekly" %}{% endset %}
                {% set monthly %}{% trans "Monthly" %}{% endset %}
                {% set yearly %}{% trans "Yearly" %}{% endset %}
                {% set options = [
                    { name: "daily", filter: daily },
                    { name: "weekly", filter: weekly },
                    { name: "monthly", filter: monthly },
                    { name: "yearly", filter: yearly },
                ] %}
                {{ forms.dropdown("filter", "single", title, "", options, "name", "filter", helpText) }}

                {% set title %}{% trans "Start Time" %}{% endset %}
                {% set helpText %}{% trans "Set a future date and time to run this report. Leave blank to run from the next collection point." %}{% endset %}
                {{ forms.dateTime("fromDt", title, "", helpText, "starttime-control") }}

                {% set title %}{% trans "End Time" %}{% endset %}
                {% set helpText %}{% trans "Set a future date and time to end the schedule. Leave blank to run indefinitely." %}{% endset %}
                {{ forms.dateTime("toDt", title, "", helpText, "endtime-control") }}

                {% set title %}{% trans "Display" %}{% endset %}
                {% set attributes = [
                    { name: "data-width", value: "100%" },
                    { name: "data-allow-clear", value: "true" },
                    { name: "data-placeholder--id", value: null },
                    { name: "data-placeholder--value", value: "" },
                    { name: "data-search-url", value: url_for("display.search") },
                    { name: "data-search-term", value: "display" },
                    { name: "data-search-term-tags", value: "tags" },
                    { name: "data-default-values", value: displayId },
                    { name: "data-id-property", value: "displayId" },
                    { name: "data-text-property", value: "display" }
                ] %}
                {{ forms.dropdown("displayId", "single", title, "", null, "displayId", "display", "", "pagedSelect", "", "d", "", attributes) }}

                {% set title %}{% trans "Display Group" %}{% endset %}
                {% set attributes = [
                    { name: "data-width", value: "200px" },
                    { name: "data-allow-clear", value: "true" },
                    { name: "data-placeholder--id", value: null },
                    { name: "data-placeholder--value", value: "" },
                    { name: "data-search-url", value: url_for("displayGroup.search") },
                    { name: "data-search-term", value: "displayGroup" },
                    { name: "data-id-property", value: "displayGroupId" },
                    { name: "data-text-property", value: "displayGroup" }
                ] %}
                {{ inline.dropdown("displayGroupId[]", "dropdownmulti", title, "", null, "displayGroupId", "displayGroup", "", "pagedSelect", "", "d", "", attributes) }}

                {% set attributes = [
                    { name: "data-width", value: "100%" },
                    { name: "data-allow-clear", value: "true" },
                    { name: "data-placeholder--id", value: null },
                    { name: "data-placeholder--value", value: "" },
                    { name: "data-search-url", value: url_for("layout.search") },
                    { name: "data-search-term", value: "layout" },
                    { name: "data-search-term-tags", value: "tags" },
                    { name: "data-id-property", value: "layoutId" },
                    { name: "data-text-property", value: "layout" }
                ] %}

                {% set title %}{% trans "Layout" %}{% endset %}
                {{ forms.dropdown("layoutId[]", "dropdownmulti", title, "", null, "layoutId", "layout", "", "pagedSelect", "", "l", "", attributes) }}

                {% set attributes = [
                    { name: "data-width", value: "100%" },
                    { name: "data-allow-clear", value: "true" },
                    { name: "data-placeholder--id", value: null },
                    { name: "data-placeholder--value", value: "" },
                    { name: "data-search-url", value: url_for("library.search") },
                    { name: "data-search-term", value: "media" },
                    { name: "data-search-term-tags", value: "tags" },
                    { name: "data-id-property", value: "mediaId" },
                    { name: "data-text-property", value: "name" }
                ] %}
                {% set title %}{% trans "Media" %}{% endset %}
                {{ forms.dropdown("mediaId[]", "dropdownmulti", title, "", null, "mediaId", "name", "", "pagedSelect", "", "m", "", attributes) }}

                {% set title %}{% trans "Type" %}{% endset %}
                {% set layout %}{% trans "Layout" %}{% endset %}
                {% set media %}{% trans "Media" %}{% endset %}
                {% set widget %}{% trans "Widget" %}{% endset %}
                {% set event %}{% trans "Event" %}{% endset %}
                {% set options = [
                    { typeid: "", type: null },
                    { typeid: "layout", type: layout },
                    { typeid: "media", type: media },
                    { typeid: "widget", type: widget },
                    { typeid: "event", type: event }
                ] %}
                {{ forms.dropdown("type", "single", title, type, options, "typeid", "type") }}

                {% set title %}{% trans "Sort by" %}{% endset %}
                {% set widgetId %}{% trans "WidgetId" %}{% endset %}
                {% set type %}{% trans "Type" %}{% endset %}
                {% set display %}{% trans "Display" %}{% endset %}
                {% set displayId %}{% trans "Display ID" %}{% endset %}
                {% set media %}{% trans "Media" %}{% endset %}
                {% set layout %}{% trans "Layout" %}{% endset %}
                {% set layoutId %}{% trans "Layout ID" %}{% endset %}
                {% set tag %}{% trans "Tag" %}{% endset %}
                {% set options = [
                    { sortbyid: "widgetId", sortby: widgetId },
                    { sortbyid: "type", sortby: type },
                    { sortbyid: "display", sortby: display },
                    { sortbyid: "displayId", sortby: displayId },
                    { sortbyid: "media", sortby: media },
                    { sortbyid: "layout", sortby: layout },
                    { sortbyid: "layoutId", sortby: layoutId },
                    { sortbyid: "tag", sortby: tag }
                ] %}
                {{ forms.dropdown("sortBy", "single", title, "", options, "sortbyid", "sortby") }}

                {% set title %}{% trans "Tags from" %}{% endset %}
                {% set dg %}{% trans "Display Group" %}{% endset %}
                {% set layout %}{% trans "Layout" %}{% endset %}
                {% set media %}{% trans "Media" %}{% endset %}
                {% set options = [
                    { tagsTypeid: "dg", tagsType: dg },
                    { tagsTypeid: "layout", tagsType: layout },
                    { tagsTypeid: "media", tagsType: media }
                ] %}
                {{ forms.dropdown("tagsType", "single", title, tagsType, options, "tagsTypeid", "tagsType") }}

                {% set title %}{% trans "Tags" %}{% endset %}
                {% set exactTagTitle %}{% trans "Should Tags filter by exact match?" %}{% endset %}
                {% set logicalOperatorTitle %}{% trans "When filtering by multiple Tags, which logical operator should be used?" %}{% endset %}
                {% set helpText %}{% trans "A comma separated list of tags to filter by. Enter a tag|tag value to filter tags with values. Enter --no-tag to filter all items without tags. Enter - before a tag or tag value to exclude from results." %}{% endset %}
                {{ forms.inputWithTags("tags", title, tags, helpText, "", "", "", "exactTag", exactTagTitle, logicalOperatorTitle, 0, 'OR') }}

                {% set title %}{% trans "Should an email be sent?" %}{% endset %}
                {{ forms.checkbox("sendEmail", title, sendEmail) }}

                {% set title %}{% trans "Email addresses" %}{% endset %}
                {% set helpText %}{% trans "Additional emails separated by a comma." %}{% endset %}
                {{ forms.inputWithTags("nonusers", title, nonusers, helpText) }}
            </form>
        </div>
    </div>
{% endblock %}