{#
/**
 * 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 %}
{% import _self as flow %}

{% block formTitle %}
    {% trans %}Turn Features on/off for {{ group }}{% endtrans %}
{% endblock %}

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

{% block callBack %}forms.featureAclFormOpen{% endblock %}

{% macro hasFeature(features, feature) %}
    {% if feature in features %}
        checked
    {% endif %}
{% endmacro %}

{% macro featureTitleRow(title, description, isUserSpecific) %}
    <tr class="feature-group-row">
        <td class="feature-group-header-cell closed">
            <strong>{{ title }}</strong> <i class="fa fa-arrow-circle-down"></i>
            <p class="feature-group-description">
                {{ description }}
            </p>
        </td>
        <td><input class="feature-select-all" type="checkbox" /></td>
        {% if isUserSpecific == 1 %}
            <td>
                <input type="checkbox" class="inherit-group-all" disabled>
            </td>
        {% endif %}
    </tr>
{% endmacro %}

{% macro featureRow(feature, title, features, inheritedFeatures, isUserSpecific) %}
    <tr class="feature-row">
        <td>{{ title }}</td>
        <td>
            <input type="checkbox" name="features[]" value="{{ feature }}" {{ flow.hasFeature(features, feature) }}>
        </td>
        {% if isUserSpecific == 1 %}
            <td>
                <input type="checkbox" class="inherit-group" disabled {{ flow.hasFeature(inheritedFeatures, feature) }}>
            </td>
        {% endif %}
    </tr>
{% endmacro %}

{% block formHtml %}

    <div class="row">
        <div class="col-md-12">

            {% set helpText %}{% trans %}Check or un-check the options against each item to control whether access to a Feature is allowed or not.{% endtrans %}{% endset %}
            {{ forms.message(helpText) }}

            <ul class="nav nav-tabs" role="tablist">
                <li class="nav-item"><a class="nav-link active" href="#mediaTab" role="tab" data-toggle="tab"><span>{% trans "Content" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#displaysTab" role="tab" data-toggle="tab"><span>{% trans "Displays" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#homepagesTab" role="tab" data-toggle="tab"><span>{% trans "Reports" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#usersTab" role="tab" data-toggle="tab"><span>{% trans "Users" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#systemTab" role="tab" data-toggle="tab"><span>{% trans "System" %}</span></a></li>
                <li class="nav-item"><a class="nav-link" href="#customTab" role="tab" data-toggle="tab"><span>{% trans "Custom" %}</span></a></li>
            </ul>
            <form id="AclForm" class="XiboForm form-horizontal" method="post" action="{{ url_for("group.acl", {id: groupId}) }}">
                <div class="tab-content">
                    <div class="tab-pane" id="homepagesTab">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ "Feature"|trans }}</th>
                                    <th>
                                        {% trans "Enabled?" %}
                                        <i class="fa fa-info-circle" title="{{ "Check this box to give this User access to this Feature." }}"></i>
                                    </th>
                                    {% if isUserSpecific == 1 %}
                                        <th>
                                            {% trans "Inherited?" %}
                                            <i class="fa fa-info-circle" title="{{ "If checked this User already has access to this Feature due to the User Groups they belong to." }}"></i>
                                        </th>
                                    {% endif %}
                                </tr>
                            </thead>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Reporting"|trans, "Run reporting on a variety of different KPI's and metrics applicable to the Features enabled."|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("reporting") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    <div class="tab-pane active" id="mediaTab">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ "Feature"|trans }}</th>
                                    <th>
                                        {% trans "Enabled?" %}
                                        <i class="fa fa-info-circle" title="{{ "Check this box to give this User access to this Feature." }}"></i>
                                    </th>
                                    {% if isUserSpecific == 1 %}
                                        <th>
                                            {% trans "Inherited?" %}
                                            <i class="fa fa-info-circle" title="{{ "If checked this User already has access to this Feature due to the User Groups they belong to." }}"></i>
                                        </th>
                                    {% endif %}
                                </tr>
                            </thead>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Folders"|trans, "Organise content sharing with Folders"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("folders") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Library"|trans, "Media Library that stores file based content for use in Layouts, DataSets, Playlists and Menu Boards"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("library") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("playlist-design") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("menuboard-design") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Layout Design"|trans, "Allow content creators to create Layouts - which hold the content you want to show on your Displays"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("layout-design") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Campaigns"|trans, "Ensure ordering by grouping Layouts into Campaigns"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("campaigns") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Tagging"|trans, "Organise and filter items by using Tags"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("tagging") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Fonts"|trans, "Administrative access to Fonts"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("fonts") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    <div class="tab-pane" id="displaysTab">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ "Feature"|trans }}</th>
                                    <th>
                                        {% trans "Enabled?" %}
                                        <i class="fa fa-info-circle" title="{{ "Check this box to give this User access to this Feature." }}"></i>
                                    </th>
                                    {% if isUserSpecific == 1 %}
                                        <th>
                                            {% trans "Inherited?" %}
                                            <i class="fa fa-info-circle" title="{{ "If checked this User already has access to this Feature due to the User Groups they belong to." }}"></i>
                                        </th>
                                    {% endif %}
                                </tr>
                            </thead>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Scheduling"|trans, "Create and manage Scheduled Events for Displays and Display Groups"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("scheduling") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Display Management"|trans, "Connect and manage Displays."|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("displays") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                        </table>
                    </div>
                    <div class="tab-pane" id="usersTab">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ "Feature"|trans }}</th>
                                    <th>
                                        {% trans "Enabled?" %}
                                        <i class="fa fa-info-circle" title="{{ "Check this box to give this User access to this Feature." }}"></i>
                                    </th>
                                    {% if isUserSpecific == 1 %}
                                        <th>
                                            {% trans "Inherited?" %}
                                            <i class="fa fa-info-circle" title="{{ "If checked this User already has access to this Feature due to the User Groups they belong to." }}"></i>
                                        </th>
                                    {% endif %}
                                </tr>
                            </thead>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("User functions"|trans, "User profile preferences for the logged in User"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("users") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Notifications"|trans, "Notification Centre allows for users to to create/edit Notifications sent to other Users or used in Layouts"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("notifications") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("User Management"|trans, "Manage Users that can authenticate with the CMS. Create and organise them into User Groups to enable 'Group Features'"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("users-management") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Dashboards"|trans, "Dashboards bring together key features for Users"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("dashboards") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                        </table>
                    </div>
                    <div class="tab-pane" id="systemTab">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ "Feature"|trans }}</th>
                                    <th>
                                        {% trans "Enabled?" %}
                                        <i class="fa fa-info-circle" title="{{ "Check this box to give this User access to this Feature." }}"></i>
                                    </th>
                                    {% if isUserSpecific == 1 %}
                                        <th>
                                            {% trans "Inherited?" %}
                                            <i class="fa fa-info-circle" title="{{ "If checked this User already has access to this Feature due to the User Groups they belong to." }}"></i>
                                        </th>
                                    {% endif %}
                                </tr>
                            </thead>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Configuration"|trans, "Restricted high level access advised - potentially damaging system settings"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("system") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Troubleshooting"|trans, "Tools to diagnose problems when seeking help"|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("troubleshooting") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                        </table>
                    </div>
                    <div class="tab-pane" id="customTab">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ "Feature"|trans }}</th>
                                    <th>
                                        {% trans "Enabled?" %}
                                        <i class="fa fa-info-circle" title="{{ "Check this box to give this User access to this Feature." }}"></i>
                                    </th>
                                    {% if isUserSpecific == 1 %}
                                        <th>
                                            {% trans "Inherited?" %}
                                            <i class="fa fa-info-circle" title="{{ "If checked this User already has access to this Feature due to the User Groups they belong to." }}"></i>
                                        </th>
                                    {% endif %}
                                </tr>
                            </thead>

                            <tbody class="feature-group">
                                {{ flow.featureTitleRow("Custom"|trans, "Third party extensions to the platform."|trans, isUserSpecific) }}
                                {% for customFeature in userGroupFactory.getFeaturesByGroup("custom") %}
                                    {{ flow.featureRow(customFeature.feature, customFeature.title, features, inheritedFeatures, isUserSpecific) }}
                                {% endfor %}
                            </tbody>

                        </table>
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}