{#
/**
 * 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 %}
    {% set name = module.name %}
    {% trans %}Edit {{ type }} Transition for {{ name }}{% endtrans %}
{% endblock %}

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

{% block formFieldActions %}
    [{
    "field": "transitionType",
    "trigger": "init",
    "value": 0,
    "operation": "equals",
    "actions": {
    ".transition-group": { "display": "none" }
    }
    },{
    "field": "transitionType",
    "trigger": "init",
    "value": 0,
    "operation": "not",
    "actions": {
    ".transition-group": { "display": "" }
    }
    },{
    "field": "transitionType",
    "trigger": "change",
    "value": 0,
    "operation": "equals",
    "actions": {
    ".transition-group": { "display": "none" }
    }
    },{
    "field": "transitionType",
    "trigger": "change",
    "value": 0,
    "operation": "not",
    "actions": {
    ".transition-group": { "display": "" }
    }
    }]
{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <form id="moduleTransitionEditForm" class="XiboForm form-horizontal" method="put" action="{{ url_for("module.widget.transition.edit", {type: type, id: widget.widgetId}) }}">
                {% if type == "in" %}
                    {% set transitionsWithEmpty = [{code: "", transition: ""}]|merge(transitions.in) %}
                    {% set trans = widget.getOptionValue("transIn", null) %}
                    {% set transDuration = widget.getOptionValue("transInDuration", null) %}
                    {% set transDirection = widget.getOptionValue("transInDirection", null) %}
                    {% set helpText %}{% trans "What transition should be applied when this item starts?" %}{% endset %}
                {% elseif type == "out" %}
                    {% set transitionsWithEmpty = [{transitionId: null, transition: ""}]|merge(transitions.out) %}
                    {% set trans = widget.getOptionValue("transOut", null) %}
                    {% set transDuration = widget.getOptionValue("transOutDuration", null) %}
                    {% set transDirection = widget.getOptionValue("transOutDirection", null) %}
                    {% set helpText %}{% trans "What transition should be applied when this item finishes?" %}{% endset %}
                {% else %}
                    {% set message %}{% trans "Unknown Transition Type Requested" %}{% endset %}
                    {{ forms.message(message) }}
                {% endif %}

                {% set title %}{% trans "Transition" %}{% endset %}
                {{ forms.dropdown("transitionType", "single", title, trans, transitionsWithEmpty, "code", "transition", helpText) }}

                {% set title %}{% trans "Duration" %}{% endset %}
                {% set helpText %}{% trans "The duration for this transition, in milliseconds." %}{% endset %}
                {{ forms.number("transitionDuration", title, transDuration, helpText) }}

                {% set title %}{% trans "Direction" %}{% endset %}
                {% set helpText %}{% trans "The direction for this transition. Only appropriate for transitions that move, such as Fly." %}{% endset %}
                {{ forms.dropdown("transitionDirection", "single", title, transDirection, transitions.compassPoints, "id", "name", helpText, "transition-group transition-direction") }}
            </form>
        </div>
    </div>
{% endblock %}