{#
/**
 * 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 "Edit Column" %}
{% endblock %}

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

{% block callBack %}dataSetColumnFormOpen{% endblock %}

{% block formFieldActions %}
[
    {
      "field": "dataSetColumnTypeId", "trigger": "init",
      "operation": "equals", "value": "1",
      "actions": { ".formula": { "display": "none" }, ".listContent": { "display": "" }, ".remoteField": { "display": "none" }, ".helperFields": { "display": "" } }
    },{
      "field": "dataSetColumnTypeId", "trigger": "change",
      "operation": "equals", "value": "1",
      "actions": { ".formula": { "display": "none" }, ".listContent": { "display": "" }, ".remoteField": { "display": "none" }, ".helperFields": { "display": "" } }
    },
    {
      "field": "dataSetColumnTypeId", "trigger": "init",
      "operation": "equals", "value": "2",
      "actions": { ".formula": { "display": "" }, ".listContent": { "display": "none" }, ".remoteField": { "display": "none" }, ".helperFields": { "display": "none" } }
    },{
      "field": "dataSetColumnTypeId", "trigger": "change",
      "operation": "equals", "value": "2",
      "actions": { ".formula": { "display": "" }, ".listContent": { "display": "none" }, ".remoteField": { "display": "none" }, ".helperFields": { "display": "none" } }
    },
    {
      "field": "dataSetColumnTypeId", "trigger": "init",
      "operation": "equals", "value": "3",
      "actions": { ".formula": { "display": "none" }, ".listContent": { "display": "none" }, ".remoteField": { "display": "" }, ".helperFields": { "display": "none" } }
    },{
      "field": "dataSetColumnTypeId", "trigger": "change",
      "operation": "equals", "value": "3",
      "actions": { ".formula": { "display": "none" }, ".listContent": { "display": "none" }, ".remoteField": { "display": "" }, ".helperFields": { "display": "none" } }
    }
]
{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <form id="dataSetColumnEditForm" class="XiboForm form-horizontal" method="put" action="{{ url_for("dataSet.column.edit", {id: dataSet.dataSetId, colId: dataSetColumn.dataSetColumnId}) }}">
                {% set title %}{% trans "Heading" %}{% endset %}
                {% set helpText %}{% trans "The heading for this Column. You cannot use a column name with spaces." %}{% endset %}
                {{ forms.input("heading", title, dataSetColumn.heading, helpText, "", "required") }}

                {% set title %}{% trans "Column Type" %}{% endset %}
                {% set helpText %}{% trans "Select the Column Type" %}{% endset %}
                {{ forms.dropdown("dataSetColumnTypeId", "single", title, dataSetColumn.dataSetColumnTypeId, dataSetColumnTypes, "dataSetColumnTypeId", "dataSetColumnType", helpText) }}

                {% set title %}{% trans "Data Type" %}{% endset %}
                {% set helpText %}{% trans "The DataType of the Intended Data" %}{% endset %}
                {{ forms.dropdown("dataTypeId", "single", title, dataSetColumn.dataTypeId, dataTypes, "dataTypeId", "dataType", helpText) }}

                {% set title %}{% trans "List Content" %}{% endset %}
                {% set helpText %}{% trans "A comma separated list of items to present in a combo box" %}{% endset %}
                {{ forms.input("listContent", title, dataSetColumn.listContent, helpText, "listContent") }}

                {% set title %}{% trans "Remote Data Path" %}{% endset %}
                {% if dataSet.sourceId == 1 %}
                    {% set helpText %}{% trans "Give the JSON-path in the remote data for the value that you want to fill this column. This path should be relative to the DataRoot configured on the DataSet." %}{% endset %}
                {% else %}
                    {% set helpText %}{% trans "Provide Column number relative to the spreadsheet, numeration starts from 0 ie to get values from Column A from spreadsheet to this column enter 0" %}{% endset %}
                {% endif %}
                {{ forms.input("remoteField", title, dataSetColumn.remoteField, helpText, "remoteField") }}

                {% set title %}{% trans "Column Order" %}{% endset %}
                {% set helpText %}{% trans "The order this column should be displayed in when entering data" %}{% endset %}
                {{ forms.number("columnOrder", title, dataSetColumn.columnOrder, helpText) }}

                {% set title %}{% trans "Tooltip" %}{% endset %}
                {% set helpText %}{% trans "Optional message to be displayed under the input when entering data for this column" %}{% endset %}
                {{ forms.input("tooltip", title, dataSetColumn.tooltip, helpText, 'helperFields') }}

                {% set title %}{% trans "Formula" %}{% endset %}
                {% set helpText %}{% trans "Enter a MySQL statement suitable to use in a 'SELECT' statement" %}{% endset %}
                {{ forms.input("formula", title, dataSetColumn.formula, helpText, "formula") }}

                {% set title %}{% trans "Filter?" %}{% endset %}
                {% set helpText %}{% trans "Show as a filter option on the Data Entry Page?" %}{% endset %}
                {{ forms.checkbox("showFilter", title, dataSetColumn.showFilter, helpText) }}

                {% set title %}{% trans "Date Format" %}
                    <span class="fa fa-info-circle date-format-table"
                          data-toggle="popover"
                          data-trigger="hover">
                            </span>
                {% endset %}
                {% set helpText %}{% trans "Enter a PHP date format to parse the dates from the source." %}{% endset %}
                {{ forms.input("dateFormat", title, dataSetColumn.dateFormat, helpText, 'dateFormat') }}

                {% set title %}{% trans "Sort?" %}{% endset %}
                {% set helpText %}{% trans "Enable sorting on the Data Entry Page? We recommend that the number of sortable columns is kept to a minimum." %}{% endset %}
                {{ forms.checkbox("showSort", title, dataSetColumn.showSort, helpText) }}

                {% set title %}{% trans "Required?" %}{% endset %}
                {% set helpText %}{% trans "Should the value for this Column be required?" %}{% endset %}
                {{ forms.checkbox("isRequired", title, dataSetColumn.isRequired, helpText, 'helperFields') }}

                {% set message %}{% trans "Two substitutions are available for Formula columns: [DisplayId] and [DisplayGeoLocation]. They will be substituted at run time with the Display ID / Display Geo Location (MySQL GEOMETRY)." %}{% endset %}
                {% set message2 %}{% trans "Client side formula is also available for Formula columns : $dateFormat(columnName,format,language), for example $dateFormat(date,l,de), would return textual representation of a day in German language from the full date in date column" %}{% endset %}

                {{ forms.message(message, "alert alert-info formula") }}
                {{ forms.message(message2, "alert alert-info formula") }}
            </form>
        </div>
    </div>
{% endblock %}