{#
 * 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 Action for {{ source }}{% endtrans %}
{% endblock %}

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

{% block callBack %}actionFormOpen{% endblock %}

{% block formHtml %}

    <div class="row">
        <div class="col-md-12">
            <form id="actionFormAdd" class="XiboForm form-horizontal" method="post" action="{{ url_for("action.add", {id: id, source: source}) }}">
                {% set title %}{% trans "Trigger Type" %}{% endset %}
                {% set helpText %}{% trans "How should the Player listen for this Action to be triggered?" %}{% endset %}
                {% set touch %}{% trans "Touch/Click" %}{% endset %}
                {% set webhook %}{% trans "Web hook" %}{% endset %}
                {% set options = [
                    { typeid: "touch", type: touch },
                    { typeid: "webhook", type: webhook },
                ] %}
                {{ forms.dropdown("triggerType", "single", title, "", options, "typeid", "type", helpText) }}

                {% set title %}{% trans "Trigger Code" %}{% endset %}
                {% set helpText %}{% trans "If this Action is triggered by a Web Hook then this Trigger Code must be present in the URL `trigger=` parameter." %}{% endset %}
                {{ forms.input("triggerCode", title, "", helpText, 'trigger-code-control') }}

                {% set title %}{% trans "Action Type" %}{% endset %}
                {% set helpText %}{% trans "Please select action Type" %}{% endset %}

                {% if source == 'layout' %}
                    {% set next %}{% trans "Next item in the Schedule" %}{% endset %}
                    {% set previous %}{% trans "Previous item in the Schedule" %}{% endset %}
                {% else %}
                    {% set next %}{% trans "Next Widget in the Region Timeline" %}{% endset %}
                    {% set previous %}{% trans "Previous Widget in the Region Timeline" %}{% endset %}
                {% endif %}

                {% set navLayout %}{% trans "Navigate to Layout" %}{% endset %}
                {% set navWidget %}{% trans "Navigate to Widget" %}{% endset %}
                {% set options = [
                    { typeid: "next", type: next },
                    { typeid: "previous", type: previous },
                    { typeid: "navLayout", type: navLayout },
                    { typeid: "navWidget", type: navWidget },
                ] %}
                {{ forms.dropdown("actionType", "single", title,"", options, "typeid","type", helpText) }}

                {% set title %}{% trans "Widget" %}{% endset %}
                {% set helpText %}{% trans "Which Widget would you like to Navigate to? The Widget must be in the Interactive drawer for this Layout." %}{% endset %}
                {{ forms.dropdown("widgetId", "single", title, "", [{widgetId:null, name:""}]|merge(widgets), "widgetId", "name", helpText, "nav-control-widget") }}

                {% set title %}{% trans "Layout Code" %}{% endset %}
                {% set helpText %}{% trans "Please enter the Code identifier for the Layout as assigned in the Add / Edit Layout form." %}{% endset %}

                {% set attributes = [
                    { name: "data-width", value: "100%" },
                    { name: "data-search-url", value: url_for("layout.code.search") },
                    { name: "data-search-term", value: "code" },
                    { name: "data-id-property", value: "code" },
                    { name: "data-text-property", value: "code" }
                ] %}
                {{ forms.dropdown("layoutCode", "single", title, "", null, "code", "code", helpText, "pagedSelect nav-control-layout", "", "", "", attributes) }}

                {% set title %}{% trans "Target" %}{% endset %}
                {% set helpText %}{% trans "If your Widget is a Shell Command you can select to target 'Screen' to run the command without affecting any Regions. For all other Widgets select 'Region' as target." %}{% endset %}
                {% set screen %}{% trans "Screen" %}{% endset %}
                {% set region %}{% trans "Region" %}{% endset %}
                {% set options = [
                    { typeid: "screen", type: screen },
                    { typeid: "region", type: region },
                ] %}
                {{ forms.dropdown("target", "single", title, "region", options, "typeid", "type", helpText, "target-control") }}

                {% set title %}{% trans "Target Region" %}{% endset %}
                {% set helpText %}{% trans "Select the Region this Widget will be loaded into." %}{% endset %}
                {{ forms.dropdown("targetId", "single", title, "", [{regionId:null, name:""}]|merge(regions), "regionId", "name", helpText, "targetid-control") }}
            </form>
        </div>
    </div>
{% endblock %}