<style>
    .dropdown-menu{
        max-width: 600px !important;

    }
</style>﻿
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="includes/js/bootstrap-select-1.12.4/dist/css/bootstrap-select-without-padding.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="includes/js/bootstrap-select-1.12.4/dist/js/bootstrap-select.min.js"></script>
<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<link href="includes/js/fancytree/skin-bootstrap/ui.fancytree.css" rel="stylesheet" class="skinswitcher">

<script src="includes/js/bootstrap-select-1.12.4/dist/js/i18n/defaults-[% if $user->language_type == "de" %]de_DE[% else %]en_US[% /if %].min.js"></script>
<script type="text/javascript">

    function switchPage(pos) {
        document.getElementById("pos").value = pos;
        $("#ManageErrorPatternForm").submit();
    }

</script>
<div class="card panel-fcs-border shadow-sm">
    <div class="card-header">
        <h2 class="card-title-fcs">[% $user->gettext('Fehlerbilder verwalten') %]</h2>
    </div>

    <div class="card-body">
        <div class="card panel-info shadow-sm rounded">
            <div class="card-body">
                <div class="row">
                    <div class="col-lg-12">
                        <form action="" method="post" name="hm" id="ManageErrorPatternForm" enctype="multipart/form-data" class="form-inline fcs-form-padding">

                            <input type="hidden" name="pos" value="[% $pos %]" id="pos">
                            <input type="hidden" name="sort" id="sort" value="[% $sort %]" />
                            <input type="hidden" name="sortorder" id="sortorder" value="[% $sortorder %]" />
                            <input type="hidden" name="export" id="export" value="0" />
                            <div class="form-group row mb-3">
                                <label class="control-label">
                                    [% $user->gettext('Eintr&auml;ge pro Seite') %]
                                </label>
                                <select name="entries_per_page" onchange="document.hm.submit();" class="form-control">
                                    <option value="10" [% if $entries_per_page == 10 %]selected="selected"[% /if %]>10</option>
                                    <option value="20" [% if $entries_per_page == 20 %]selected="selected"[% /if %]>20</option>
                                    <option value="50" [% if $entries_per_page == 50 %]selected="selected"[% /if %]>50</option>
                                    <option value="100" [% if $entries_per_page == 100 %]selected="selected"[% /if %]>100</option>
                                </select>&nbsp;&nbsp;&nbsp;

                            </div>
                            <div class="form-group row mb-3">
                                <select name="Filter[EPPattern.ID][]" id="EP" class="form-control select" multiple data-placeholder="[% $user->gettext('Fehlerbilder finden') %]">
                                    <option value="0">-- [% $user->gettext('Alle') %] --</option>
                                    [% html_options options=$FilterData['ErrorPattern'][$Lang] selected=$selectedFilters['EPPattern.ID'] %]
                                </select>
                            </div>

                            <div class="form-group row mb-3">
                                <select name="Filter[hm_EPErrorDescr.ID][]" id="EPDescr" class="form-control select" multiple data-placeholder="[% $user->gettext('Fehlerbeschreibungen filtern') %]">
                                    <option value="0">-- [% $user->gettext('Alle') %] --</option>
                                    [% html_options options=$FilterData['EPDescr'][$Lang] selected=$selectedFilters['hm_EPErrorDescr.ID'] %]
                                </select>
                            </div>

                            <div class="form-group row mb-3">
                                <select name="Filter[hm_EPErrorObject.ID][]" id="EPObject" class="form-control select" multiple data-placeholder="[% $user->gettext('Fehlerobjekte filtern') %]">
                                    <option value="0">-- [% $user->gettext('Alle') %] --</option>
                                    [% html_options options=$FilterData['EPObject'][$Lang] selected=$selectedFilters['hm_EPErrorObject.ID'] %]
                                </select>
                            </div>

                            <div class="form-group row mb-3">
                                <select name="Filter[hm_EPClassiEP.CodeID][]" id="Classifications" class="form-control select" multiple data-placeholder="[% $user->gettext('Klassifikationen filtern') %]">
                                    [% foreach $ClassificationsForSelect as $Classification %]
                                        <option value="'[% $Classification.formattedCode %]'" [% if $Tools->FCS_InArray($Classification.formattedCode, $selectedFilters['hm_EPClassiEP.CodeID']) %]selected="selected" [% /if %] >[% $Classification.code %]</option>
                                    [% /foreach %]
                                </select>
                            </div>

                            <div class="form-group row mb-3">
                                <input type='submit' class="btn btn-outline-secondary" value='[% $user->gettext('Filtern') %]'>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="card panel-info shadow-sm rounded">
            <div class="card-header">
                <div class="row">
                    <div class="col-lg-4 text-left" >
                        <h3 class="card-title text-left" style="font-size: 24px; display:inline">
                            [% $user->gettext('Fehlerbilder')%]
                        </h3>
                        </span>
                    </div>
                    <div class="text-end">
                        <div class="form-group row mb-3">
                            <span class="btn btn-outline-secondary" id="CSVExport" onclick="OnExportCSV();"><span class="fa fa-download"></span> CSV Export</span>
                            <a href="index.php?module=errorpatterns&event=AddErrorPattern"  class="btn btn-outline-secondary openInLargeModal" >[% $user->gettext('Hinzufügen')%]</a>
                        </div>

                    </div>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table id="ErrorPatternTable" class="table">
                        <thead>
                            <tr>
                                <th>[% $user->gettext('Fehlerbild DE')%]</th>
                                <th>[% $user->gettext('EN')%]</th>
                                <th>[% $user->gettext('Code')%]</th>
                                <th>[% $user->gettext('Verknüpft mit')%]</th>
                                <th>[% $user->gettext('Benutzer')%]</th>
                                <th>[% $user->gettext('Datum')%]</th>
                                <th>[% $user->gettext('Tickets je Fehlerbild')%]</th>
                                <th>[% $user->gettext('Aktion')%]</th>
                            </tr>
                        </thead>
                        <tbody id="ErrorPatternTableBody">
                            [% foreach from=$ErrorPatterns item=ErrorPattern %]

                                <tr>
                                    <td>[% $ErrorPattern.codestring_de %]</td>
                                    <td>[% $ErrorPattern.codestring_en %]</td>
                                    <td>[% $ErrorPattern.codeid %]</td>
                                    <td>
                                        <div class="SimpleField bg-default">
                                            <select name='selectClassification_[% $ErrorPattern.errorpatternid %]' id='selectClassification_[% $ErrorPattern.errorpatternid %]' multiple class="selectpicker ClassificationConnection" data-epid="[% $ErrorPattern.errorpatternid %]" data-size="10"  data-live-search="true" data-selected-text-format="count>0" data-count-selected-text= "[%$user->gettext('Klassifikationen')%] ({0} [%$user->gettext('gewählt')%])" data-title="[% $user->gettext('Klassifikation wählen') %]" title="[% $user->gettext('Klassifikation') %]" data-container="body">

                                                [% foreach $ClassificationsForSelect as $Classification %]
                                                    <option value="[% $Classification.codeid %]" [% if $Tools->FCS_InArray($Classification.formattedCode, $ErrorPattern.classifications) %]selected="selected" [% /if %] [% if false && $Classification.cnttickets > 0 %]disabled[% /if %]>[% $Classification.code %]</option>
                                                [% /foreach %]
                                            </select>
                                        </div>
                                    </td>
                                    <td>
                                        [% $ErrorPattern.username %]
                                    </td>
                                    <td>
                                        [% $ErrorPattern.createdate|date_format:"%d.%m.%Y" %]
                                    </td>
                                    <td>
                                        [% if $ErrorPattern.tickets > 0 %]<a href="index.php?module=ticketlist&ErrorPatternID[]=[% $ErrorPattern.errorpatternid %]" target="_blank">[% $ErrorPattern.tickets %]</a>[% /if %]
                                    </td>
                                    <td>
                                        <div class="btn-group">
                                            <button class="btn btn-outline-secondary btn-sm" id="deletePattern_[% $ErrorPattern.errorpatternid %]" [% if $ErrorPattern.tickets > 0 %]disabled="disabeld"[% /if %] onclick="OnDeletePattern('[% $ErrorPattern.errorpatternid %]');"><span  class="fa fa-trash"></span></button>
                                        </div>
                                    </td>
                                </tr>
                            [% /foreach %]

                        </tbody>
                    </table>
                </div>
                <div class="col-lg-12 col-sm-12 hidden-sm hidden-xs">
                    <div class="col-lg-6 col-sm-6"></div>
                    <div class="col-lg-6 col-sm-6 text-end">
                        [% $Paging %]
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script>
    $('.select').select2({theme: 'bootstrap-5',
        closeOnSelect: false
    }).on('select2:close', function (e) {
        document.getElementById("pos").value = 1;
        $('#ManageErrorPatternForm').submit();
    });

    function OnDeletePattern(errorpatternid)
    {
        bootbox.confirm("[% $user->gettext('Möchten Sie dieses Fehlerbild löschen?') %]", function (result)
        {
            if (result)
            {
                var url = "index.php?module=errorpatterns&event=DeletePattern";
                $.post(url, {errorpatternid: errorpatternid}, function (data)
                {
                    $('#btnAddPattern').removeAttr('disabled');
                    location.reload();
                });
            }
        });
    }
    ;
</script>
<script>
    function OnExportCSV()
    {
        document.getElementById("pos").value = 1;
        $('#export').val(1);
        $('#ManageErrorPatternForm').submit();
        $('#export').val(0);
    }

    $('.ClassificationConnection').on('hide.bs.select', function (e) {

        PatternID = $(this).data('epid');
        ClassiCodes = $(this).val();

        //console.log("PatternID: " + PatternID + " - ClassiCodes: " + ClassiCodes);

        $.post('index.php?module=errorpatterns&event=addPatternToClassi', {PatternID: PatternID, ClassiCodes: ClassiCodes}, function (Response)
        {
            //console.log("PatternID: "+PatternID);
            //console.log("ClassiCodes: "+ClassiCodes);
            if (Response.error) {
                return false;
            } else {

            }
        })
    })
</script>