{#
/*
 * Spring Signage Ltd - http://www.springsignage.com
 * Copyright (C) 2015 Spring Signage Ltd
 * (${FILE_NAME})
 */

#}
{% extends "authed.twig" %}
{% import "forms.twig" as forms %}

{% block actionMenu %}
    <ul class="nav nav-pills pull-right">
        <li class="btn btn-info btn-xs" ><a class="XiboFormButton btns" title="{% trans "Export database" %}" href="{{ urlFor("maintenance.export.form") }}"> <i class="fa fa-cloud-upload" aria-hidden="true"></i> {% trans "Export" %}</a></li>

        {% if settings.SETTING_LIBRARY_TIDY_ENABLED %}
            <li class="btn btn-danger btn-xs"><a class="XiboFormButton btns" title="{% trans "Run through the library and remove unused and unnecessary files" %}" href="{{ urlFor("maintenance.libraryTidy.form") }}"> <i class="fa fa-trash" aria-hidden="true"></i> {% trans "Tidy Library" %}</a></li>
        {% endif %}
    </ul>
{% endblock %}

{% block pageContent %}
    <div class="widget">
        <div class="widget-title">{% trans "Settings" %}</div>
        <div class="widget-body">
            <div class="row">
                <div class="col-md-12">
                    <ul class="nav nav-tabs" role="tablist">
                        {% set first = true %}
                        {% for category in categories %}
                            {% set transCatTabName = category.tabName %}
                            <li {% if first %}class="active"{% endif %}><a href="#{{ category.tabId }}" role="tab" data-toggle="tab"><span>{% trans transCatTabName %}</span></a></li>
                            {% set first = false %}
                        {% endfor %}
                    </ul>
                    <form id="SettingsForm" class="XiboForm form-horizontal" method="put" action="{{ urlFor("settings.update") }}">
                        <div class="tab-content">
                            {% for field in fields %}
                                {% if currentCat != field.cat %}
                                    {% if currentCat != "" %}
                                    </div>
                                    {% endif %}

                                    <div class="tab-pane {% if currentCat == "" %}active{% endif %}" id="{{ field.catId }}">
                                    {% set currentCat = field.cat %}
                                    {% set transFieldCat = field.cat %}
                                    <h3 class="section-heading">{% trans transFieldCat %}</h3>
                                {% endif %}
                                {# Now we have to output the relevant form field #}
                                {% if field.enabled != 1 %}
                                    {{ forms.disabled(field.name, field.title, field.value, field.helpText) }}
                                {% elseif field.fieldType == "text" %}
                                    {{ forms.input(field.name, field.title, field.value, field.helpText) }}
                                {% elseif field.fieldType == "number" %}
                                    {{ forms.number(field.name, field.title, field.value, field.helpText) }}
                                {% elseif field.fieldType == "email" %}
                                    {{ forms.email(field.name, field.title, field.value, field.helpText) }}
                                {% elseif field.fieldType == "checkbox" %}
                                    {{ forms.checkbox(field.name, field.title, field.value, field.helpText) }}
                                {% elseif field.fieldType == "dropdown" and field.name == "DEFAULT_LAYOUT" %}
                                    {% set attributes = [
                                        { name: "data-width", value: "100%" },
                                        { name: "data-search-url", value: urlFor("layout.search") },
                                        { name: "data-search-term", value: "layout" },
                                        { name: "data-id-property", value: "layoutId" },
                                        { name: "data-text-property", value: "layout" }
                                    ] %}
                                    {{ forms.dropdown(field.name, "single", field.title, field.value, field.options, "layoutId", "layout", field.helpText, "pagedSelect", "", "", "", attributes) }}
                                {% elseif field.fieldType == 'dropdown' and field.name == "DEFAULT_USERGROUP" %}
                                    {% set attributes = [
                                    { name: "data-width", value: "100%" },
                                    { name: "data-search-url", value: urlFor("group.search") },
                                    { name: "data-search-term", value: "group" },
                                    { name: "data-id-property", value: "groupId" },
                                    { name: "data-text-property", value: "group" }
                                    ] %}
                                    {{ forms.dropdown(field.name, "single", field.title, field.value, field.options, "groupId", "group", field.helpText, "pagedSelect", "", "", "", attributes) }}
                                {% elseif field.fieldType == "dropdown" %}
                                    {{ forms.dropdown(field.name, "single", field.title, field.value, field.options, "id", "value", field.helpText) }}
                                {% elseif field.fieldType == "timezone" %}
                                    {{ forms.dropdown(field.name, "single", field.title, field.value, field.options, "id", "value", field.helpText) }}
                                {% elseif field.fieldType == "datetime" %}
                                    {{ forms.datetime(field.name, field.title, field.value, field.helpText) }}
                                {% endif %}
                            {% endfor %}
                        </div>
                        <button class="btn btn-save btn-block btn-success" href="#"><span>{% trans "Save" %}</span></button>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javaScript %}
    <script type="text/javascript">

        function dbExportFormSubmit() {
            $("#exportForm").submit();
            XiboDialogClose();
        }
    </script>
{% endblock %}