<link rel="stylesheet" href="includes/js/bootstrap-select-1.12.4/dist/css/bootstrap-select.min.css">
<script src="includes/js/bootstrap-select-1.12.4/dist/js/bootstrap-select.min.js"></script>
<style>
    .hightlightDropZone{
        background-color: lightgray;
    }
    .modal-content{
        min-width: 700px !important; 
    }

    .grid-striped .striped_row:nth-of-type(odd) {
        background-color: rgba(0,0,0,.05);
    }

    .striped_row{
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .badge {
        padding: 1px 9px 2px;
        font-size: 12.025px;
        font-weight: bold;
        white-space: nowrap;
        color: #ffffff;
        background-color: #70b9c5;
        -webkit-border-radius: 9px;
        -moz-border-radius: 9px;
        border-radius: 9px;
    }
    .badge:hover {
        color: #ffffff;
        text-decoration: none;
        cursor: pointer;
    }
    .badge-error {
        background-color: #b94a48;
    }
    .badge-error:hover {
        background-color: #953b39;
    }
    .badge-warning {
        background-color: #f89406;
    }
    .badge-warning:hover {
        background-color: #c67605;
    }
    .badge-success {
        background-color: #5cc45e;
    }
    .badge-success:hover {
        background-color: #356635;
    }
    .badge-info {
        background-color: #3a87ad;
    }
    .badge-info:hover {
        background-color: #2d6987;
    }
    .badge-inverse {
        background-color: #333333;
    }
    .badge-inverse:hover {
        background-color: #1a1a1a;
    }

    #TicketList{
        max-height: 800px;
        overflow-y: scroll;
        overflow-x: hidden;    
    }

    #IframeDiv {
        position: fixed;
        margin-top: auto;
        margin-left: 58.33%;
        margin-right: auto;
        max-height: 80%;
    }
    @media(max-width:768px){
        #IframeDiv {
            position: fixed;
            margin-top: auto;
            margin-left: 0;
            margin-right: auto;
            max-height: 80%;
        }
    }

    .type-icon{
        max-height: 20px !important;
    }

</style>
<form action='index.php?module=backlog&event=edit&id=[% $backlog.id %]' method="POST" id="blform" class="form-horizontal form-inline">

    <input type="hidden" value="[% $backlog.id %]" name="id" id="id">
    <input type="hidden" value="[% $SprintID %]" name="sprintid" id="sprintid">
    <input type="hidden" value="[% $NewSprintID %]" name="newsprintid" id="newsprintid">
    <input type="hidden" value="[% $backlog.name %]" name="name" id="blname">
    <input type="hidden" value="1" name="save">
    <div class='card panel-fcs-border shadow-sm'>
        <div class='card-header'>
            <div class="row">
                <div class="col-sm-7">
                    <span class='fcs-card-title h2'>
                        [% $user->gettext('Backlog') %]: 
                        [% $backlog.name %] </span> &nbsp;<b>[% $backlog.number_done %]   / [% $count_tickets %] [% $user->gettext('Tickets erledigt')%]  &nbsp; [% $backlog.exp_expense|Default:"0" %] [%$user->gettext('Geplant')%]</b>

                </div>

                <div class="col-sm-5 text-end">
                    <input type="checkbox" id="StoryTicketCB" onclick="toggleStoryTickets();"> <b>[% $user->gettext('Storytickets anzeigen') %]</b> &nbsp;
                    [% if $SprintID %]
                        [% if $user->hasRight(900) %] 
                            <a class='btn btn-outline-primary openInLargeModal' href="index.php?module=backlog&class=sprint&event=create&id=[% $backlog.id %]&active=3">[% $user->gettext('Weiteren Sprint zufügen') %]</a>
                        [% /if %]
                    [% /if %]
                    [% if $backlog.id %]   
                        [% if $user->hasRight(900) %]
                            <a class='btn btn-outline-primary openInLargeModal' href="index.php?module=backlog&event=update&id=[% $backlog.id %]">[% $user->gettext('Bearbeiten') %]</a>
                        [% /if %]
                        <a class='btn btn-outline-primary' href='index.php?module=backlog&class=sprint&BacklogID=[% $backlog.id %]'>[% $user->gettext('Sprints im Backlog') %] </a>
                    [% /if %]
                    <a class='btn btn-outline-primary' href='index.php?module=backlog'>[% $user->gettext('Liste') %] </a> 

                </div>
            </div>
        </div>

        <div class="card-body">
            [%* SPRINT *%]
            <div class="row">
                <div class="col-sm-12 col-12" id="BacklogCol">
                    <div class="card panel-info shadow-sm rounded">
                        <div class="card-header">
                                <div class="row"  data-toggle="collapse">
                                    <div class="col-sm-6">
                                        <h3 class="card-title">
                                            [% if $Sprint->ID %]
                                                [% if $Sprint->Params['active']['value'] == 0 %]
                                                    [% $user->gettext('Geplanter Sprint') %]:
                                                [% else %]
                                                    [% $user->gettext('Aktiver Sprint') %]:
                                                [% /if %]
                                                [% $SprintName %]       
                                            [% else %]
                                                [% $user->gettext('Sprint anlegen') %]
                                            [% /if %]

                                        </h3>
                                    </div>

                                    <div class="col-sm-6 text-end">
                                        [% if FALSE && $Sprint->Params['active']['value'] == 0 %]                                                    
                                            <span class="btn btn-outline-secondary" onclick="activate([% $Sprint->ID %]);">[% $user->gettext('Aktivieren') %]</span>
                                        [% /if %]
                                        [% if $SprintID %]
                                            <a href="index.php?module=backlog&class=sprint&event=edit&id=[% $SprintID %]" class="btn btn-outline-primary">[% $user->gettext('Zum Sprint') %]</a>
                                        [% /if %]
                                        <a class="collapsed" href="#SprintContent"><span class="fa fa-chevron-up"></span></a>
                                    </div>
                                </div>
                        </div>
                        <div id="SprintContent" class="collapse in">
                            <div class="card-body [% if $Sprint->ID %]dropable[% /if %]" data-sprintid="[% $SprintID %]" >
                                <div class="col-sm-12 grid-striped sortable" id="SprintList" >

                                    [% if $SprintID %]
                                        [% foreach from=$TagsWithSprintTickets.tickets item=$ticket key=$id %]
                                            <div class='row striped_row' id="row_[% $ticket.id %]" >
                                                <div class='col-sm-12'>
                                                    <span class="pull-left">
                                                [% if $ticket.isstory %]
                                                    <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;">
                                                        [% if $ticket.SetIconFromDir %]
                                                            <img title="[% $smarty.const.STORY_NAME %]" src="[% $ticket.IconFromDir %]" class="type-icon">
                                                        [% else %]
                                                            <img title="[% $smarty.const.STORY_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  class="type-icon">
                                                        [% /if %]
                                                    </a>
                                                [% else %]
                                                    [% if $ticket.activityid %]
                                                        <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;">
                                                            [% if $ticket.SetIconFromDir %]
                                                                <img title="[% $smarty.const.WF_NAME %]" src="[% $ticket.IconFromDir %]" class="type-icon">
                                                            [% else %]
                                                                <img title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon">
                                                            [% /if %]
                                                        </a>
                                                    [% else %]
                                                        [% if $ticket.type_name  %]
                                                            [% if  $ticket.icon_path && $ticket.icon_path != "" %]
                                                                <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;">
                                                                    [% if $ticket.SetIconFromDir %]
                                                                        <img title="[% $ticket.type_name %]" src="[% $ticket.IconFromDir %]" class="type-icon">
                                                                    [% else %]
                                                                        <img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon">
                                                                    [% /if %]
                                                                    
                                                                </a>
                                                            [% else %]
                                                                <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;">
                                                                    [% if $ticket.SetIconFromDir %]
                                                                        <img title="[% $ticket.type_name %]" src="[% $ticket.IconFromDir %]" class="type-icon">
                                                                    [% else %]
                                                                        <img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon">
                                                                    [% /if %]
                                                                </a>
                                                            [% /if %]
                                                        [% else %]
                                                            <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;">
                                                                [% if $ticket.SetIconFromDir %]
                                                                    <img title="[% $user->gettext('Standard Ticket') %]" src="[% $ticket.IconFromDir %]" class="type-icon">
                                                                [% else %]
                                                                    <img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  class="type-icon">
                                                                [% /if %]
                                                                
                                                            </a>
                                                        [% /if %]
                                                    [% /if %]
                                                [% /if %]

                                                <a href="index.php?module=ticket&event=show&id=[% $ticket.id %]" target="_blank">
                                                    [% $ticket.id %]
                                                </a>

                                                <span onclick="loadTicketIframe([% $ticket.id %]);">
                                                    [% $ticket.ticketdescr %]
                                                </span>
                                                <span class="legend prio[% $ticket.ticketprioid %]">[% $user->gettext($ticket.descr) %]</span>

                                            </span>
                                            <span class="float-end">


                                                <span class="badge badge-error">[% $ticket.projectname %]</span>

                                                [% foreach from= $ticket.tickettagarray item=TTag %]  
                                                    <span class="badge bg-secondary">[% $TTag %]</span>
                                                [% foreachelse %]

                                                [% /foreach %]

                                                [%*
                                                [% if $ticket.tickettag %]
                                                <span class="badge bg-secondary">[% $ticket.tickettag %]</span>
                                                [% else %]
                                                <span class="badge bg-secondary">[% $user->gettext('Ohne Tag') %]</span>
                                                [% /if %]
                                                *%]
                                                <span class="badge badge-inverse" id="aufwand_[% $ticket.id %]" title="[% $user->gettext('Erwarteter Aufwand (Minuten)') %]">[% $ticket.expexpense|default:0 %]</span>

                                                [% foreach $ticket.supporters as $names %]
                                                    <span title="[% $names.name %]" class="badge badge-warning">[% $names.enc %]</span>
                                                [% /foreach %]
                                                [% if $user->hasRight(900) %]

                                                    <span class="btn-group" id="addToSprintBtn_[% $ticket.id %]" style="display:none;" >
                                                        <a href="javascript: addTicketInSprint( [% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('In Sprint hinzufügen') %]"><span class="fa fa-check"></span></a>
                                                        <a href="javascript: removeFromBl([% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('Aus Backlog entfernen') %]"><span class="fa fa-times"></span></a>
                                                    </span>
                                                    <span class="btn-group"id="removeFromSprintBtn_[% $ticket.id %]">
                                                        <a href="javascript: remove([% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('Aus Sprint entfernen') %]"><span class="fa fa-times"></span></a>
                                                    </span>
                                                [% /if %]
                                            </span>
                                        </div>
                                        [% if $ticket.isstory %]
                                            <div class="StoryTickets"  style="display:none;">
                                                <br>
                                                <br>

                                                [% foreach $ticket.storytickets as $sticket %]
                                                    <div class='row' style="margin-top: 15px;" id="">
                                                        <div class='col-sm-12'>
                                                            <span class="pull-left">
                                                                ----------- [% if $sticket.isstory %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.STORY_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  class="type-icon"></a>[% else %][% if $sticket.activityid %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon"></a>[% else %][% if $sticket.type_name  %][% if  $sticket.icon_path && $sticket.icon_path != "" %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $sticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon"></a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon">[% /if %]</a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  class="type-icon"></a>[% /if %][% /if %][% /if %]


                                                                <a href="index.php?module=ticket&event=show&id=[% $sticket.id %]" target="_blank">
                                                                    [% $sticket.id %]
                                                                </a>

                                                                <span onclick="loadTicketIframe([% $sticket.id %]);">
                                                                    [% $sticket.ticketdescr %]
                                                                </span>
                                                                <span class="legend prio[% $sticket.ticketprioid %]">[% $user->gettext($sticket.descr) %]</span>

                                                            </span>
                                                            <span class="pull-left"> &nbsp;
                                                                <span class="badge badge-error">[% $sticket.projectname %]</span>
                                                                [% foreach from= $sticket.tickettagarray item=TTag %]  
                                                                    <span class="badge bg-secondary">[% $TTag %]</span>
                                                                [% foreachelse %]

                                                                [% /foreach %]
                                                                [%*
                                                                [% if $ticket.tickettag %]
                                                                <span class="badge bg-secondary">[% $ticket.tickettag %]</span>
                                                                [% else %]
                                                                <span class="badge bg-secondary">[% $user->gettext('Ohne Tag') %]</span>
                                                                [% /if %]
                                                                *%]
                                                                <span class="badge badge-inverse" id="aufwand_[% $sticket.id %]" title="[% $user->gettext('Erwarteter Aufwand (Minuten)') %]">[% $sticket.expexpense|default:0 %]</span>

                                                                [% foreach $sticket.supporters as $names %]
                                                                    <span title="[% $names.name %]" class="badge badge-warning">[% $names.enc %]</span>
                                                                [% /foreach %]
                                                                [% if $user->hasRight(900) %]

                                                                [% /if %]
                                                            </span>                                          
                                                        </div>
                                                    </div>
                                                [% /foreach %]
                                            </div>
                                        [% /if %]
                                    </div>
                                [% /foreach %]
                            [% else  %]
                                [% if $user->hasRight(900) %] 
                                    <a class='btn btn-outline-primary openInLargeModal' href="index.php?module=backlog&class=sprint&event=create&id=[% $backlog.id %]">[% $user->gettext('Neuen Sprint zufügen') %]</a>
                                [% /if %]
                            [% /if %]  </div>                                              
                    </div>
                </div>
            </div> 
            [% foreach $PrepSprints as $PrepSprint %]
                <div class="card panel-info shadow-sm rounded">
                    <div class="card-header">
                       
                            <div class="row">
                                <div class="col-sm-6">
                                    <h3 class="card-title">

                                        [% $user->gettext('Nächster Sprint') %]:
                                        [% $PrepSprint->Params.name.value %]
                                    </h3>
                                </div>

                                <div class="col-sm-6 text-end">
                                    <a href="index.php?module=backlog&class=sprint&event=edit&id=[% $PrepSprint->ID %]" class="btn btn-outline-primary">[% $user->gettext('Zum Sprint') %]</a>
                                    <a class="collapsed" href="#NewSprintContent_[% $PrepSprint->ID %]" data-toggle="collapse"><span class="fa fa-chevron-down"></span></a>
                                </div>
                            </div>
                      
                    </div>
                    <div id="NewSprintContent_[% $PrepSprint->ID %]" class="NewSprintClass collapse">
                        <div class="card-body [% if NewSprintID %]dropable[% /if %]" data-sprintid="[% $NewSprintID %]">
                            <div class="col-sm-12 grid-striped sortable" id="NewSprintList_[% $PrepSprint->ID %]">
                                [% foreach $PrepSprint->loadTicketsByTags_OnlyTickets() as $ticket %]
                                    <div class='row striped_row' id="row_[% $ticket.id %]">
                                        <div class='col-sm-12'>
                                            <span class="pull-left">
                                        [% if $ticket.isstory %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.STORY_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  class="type-icon"></a>[% else %][% if $ticket.activityid %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon"></a>[% else %][% if $ticket.type_name  %][% if  $ticket.icon_path && $ticket.icon_path != "" %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon"></a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon">[% /if %]</a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  class="type-icon"></a>[% /if %][% /if %][% /if %]


                                        <a href="index.php?module=ticket&event=show&id=[% $ticket.id %]" target="_blank">
                                            [% $ticket.id %]
                                        </a>

                                        <span onclick="loadTicketIframe([% $ticket.id %]);">
                                            [% $ticket.ticketdescr %]
                                        </span>
                                        <span class="legend prio[% $ticket.ticketprioid %]">[% $user->gettext($ticket.descr) %]</span>

                                    </span>
                                    <span class="float-end">
                                        <span class="badge badge-error">[% $ticket.projectname %]</span>
                                        [% foreach from= $ticket.tickettagarray item=TTag %]  
                                            <span class="badge bg-secondary">[% $TTag %]</span>
                                        [% foreachelse %]

                                        [% /foreach %]
                                        [%*
                                        [% if $ticket.tickettag %]
                                        <span class="badge bg-secondary">[% $ticket.tickettag %]</span>
                                        [% else %]
                                        <span class="badge bg-secondary">[% $user->gettext('Ohne Tag') %]</span>
                                        [% /if %]
                                        *%]
                                        <span class="badge badge-inverse" id="aufwand_[% $ticket.id %]" title="[% $user->gettext('Erwarteter Aufwand (Minuten)') %]">[% $ticket.expexpense|default:0 %]</span>

                                        [% foreach $ticket.supporters as $names %]
                                            <span title="[% $names.name %]" class="badge badge-warning">[% $names.enc %]</span>
                                        [% /foreach %]
                                        [% if $user->hasRight(900) %]
                                            <span class="btn-group" id="addToSprintBtn_[% $ticket.id %]" style="display:none;">
                                                <a href="javascript: addTicketInSprint( [% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('In Sprint hinzufügen') %]"><span class="fa fa-check"></span></a>
                                                <a href="javascript: removeFromBl([% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('Aus Backlog entfernen') %]"><span class="fa fa-times"></span></a>
                                            </span>
                                            <span class="btn-group"id="removeFromSprintBtn_[% $ticket.id %]">
                                                <a href="javascript: remove([% $ticket.id %], [% $PrepSprint->ID %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('Aus Sprint entfernen') %]"><span class="fa fa-times"></span></a>
                                            </span>     
                                        [% /if %]
                                    </span>                                          
                                </div>
                                [% if $ticket.isstory %]
                                    <div class="StoryTickets"  style="display:none;">
                                        <br>
                                        <br>

                                        [% foreach $ticket.storytickets as $sticket %]
                                            <div class='row' style="margin-top: 15px;" id="">
                                                <div class='col-sm-12'>
                                                    <span class="pull-left">
                                                        ----------- [% if $sticket.isstory %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.STORY_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  class="type-icon"></a>[% else %][% if $sticket.activityid %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon"></a>[% else %][% if $sticket.type_name  %][% if  $sticket.icon_path && $sticket.icon_path != "" %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $sticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon"></a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon">[% /if %]</a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  class="type-icon"></a>[% /if %][% /if %][% /if %]


                                                        <a href="index.php?module=ticket&event=show&id=[% $sticket.id %]" target="_blank">
                                                            [% $sticket.id %]
                                                        </a>

                                                        <span onclick="loadTicketIframe([% $sticket.id %]);">
                                                            [% $sticket.ticketdescr %]
                                                        </span>
                                                        <span class="legend prio[% $sticket.ticketprioid %]">[% $user->gettext($sticket.descr) %]</span>

                                                    </span>
                                                    <span class="pull-left"> &nbsp;
                                                        <span class="badge badge-error">[% $sticket.projectname %]</span>
                                                        [% foreach from= $sticket.tickettagarray item=TTag %]  
                                                            <span class="badge bg-secondary">[% $TTag %]</span>
                                                        [% foreachelse %]

                                                        [% /foreach %]
                                                        [%*
                                                        [% if $ticket.tickettag %]
                                                        <span class="badge bg-secondary">[% $ticket.tickettag %]</span>
                                                        [% else %]
                                                        <span class="badge bg-secondary">[% $user->gettext('Ohne Tag') %]</span>
                                                        [% /if %]
                                                        *%]
                                                        <span class="badge badge-inverse" id="aufwand_[% $sticket.id %]" title="[% $user->gettext('Erwarteter Aufwand (Minuten)') %]">[% $sticket.expexpense|default:0 %]</span>

                                                        [% foreach $sticket.supporters as $names %]
                                                            <span title="[% $names.name %]" class="badge badge-warning">[% $names.enc %]</span>
                                                        [% /foreach %]
                                                        [% if $user->hasRight(900) %]

                                                        [% /if %]
                                                    </span>                                          
                                                </div>
                                            </div>
                                        [% /foreach %]
                                    </div>
                                [% /if %]
                            </div>

                        [% /foreach %]
                    </div>
                </div>
            </div>
        </div> 
    [% /foreach %]
    <div class="card panel-info shadow-sm rounded">
        <div class="card-header">
            <h3 class="card-title">
                [% $user->gettext('Tickets im Backlog') %] 
            </h3>                    
        </div>
        <div class="card-body">
            <div class="card panel-info shadow-sm rounded">
                <div class="card-body">
                        <label for="TagFilter">[% $user->gettext('Schlagwort') %]</label>
                        <select class="form-control" name="TagFilter"  onchange="$('#blform').submit();">
                            <option value="0" [% if !$SelectedTag %]selected="selected"[% /if %]>[% $user->gettext('--- Alle ---') %]</option>
                            [% foreach $TicketTags as $Value %]
                                <option value="[% $Value.id %]" [% if $SelectedTag == $Value.id %]selected="selected"[% /if %]>[% $Value.tag|default:"Ohne Tag" %]</option>
                            [% /foreach %]
                        </select>
                        <label for="TicketTypeFilter">[% $user->gettext('Tickettyp') %]</label>
                        <select class="form-control" name="TicketTypeFilter"  onchange="$('#blform').submit();">
                            <option value="-1" [% if !$SelectedTicketType %]selected="selected"[% /if %]>[% $user->gettext('--- Alle ---') %]</option>
                            [% foreach $TicketTypes as $Value %]
                                <option value="[% $Value.TypeID %]" [% if $SelectedTicketType == $Value.TypeID %]selected="selected"[% /if %]>[% $Value.TypeName %]</option>
                            [% /foreach %]
                        </select>
                         <label for="StatusID">[% $user->gettext('Status') %]</label>
                        <select data-actions-box='true' onmouseout="$('#blform').submit();" name="StatusID[]" id="StatusID"  multiple class="selectpicker" data-live-search="true" data-selected-text-format="count>0"
                            data-count-selected-text= "[%$user->gettext('Status')%] ({0} [%$user->gettext('gewählt')%])" data-title="[% $user->gettext('Status wählen') %]" title="[% $user->gettext('Status') %]">

                        [% foreach from=$stats item=stat %]
                            <option value="[% $stat.tstatus %]" [% if $Tools->FCS_InArray($stat.tstatus, $statusid) || $statusid == null || $Tools->FCS_Count($statusid) == 0 %]selected="selected" [% /if %]>[% $stat.descr %]</option>
                        [% /foreach %]
                    </select>
                    <button onclick="$('#blform').submit();" class="btn btn-outline-primary">[% $user->gettext('Tickets filtern') %]</button>

                </div>

            </div>
            <div class="col-sm-12 col-12 grid-striped">
                <div id="TicketList" class="sortable">
                    [% foreach from=$TagsWithTickets.tickets item=$ticket key=$id %]
                        <div class='row striped_row' id="row_[% $ticket.id %]" >
                            <div class='col-sm-12'>
                                <span class="pull-left">

                                    [% if $ticket.activityid %]
                                        <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img style="max-height: 10px;" title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon"></a>
                                        [% else %]
                                            [% if $ticket.type_name  %]
                                                [% if  $ticket.icon_path && $ticket.icon_path != "" %]
                                                <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img  title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon"></a>
                                                [% else %]
                                                <a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon" style="max-height: 16px;"></a>
                                                [% /if %]
                                            [% else %]
                                        [% if $ticket.isstory %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img st title="[% $smarty.const.STORY_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  class="type-icon"></a>[% else %][% if $ticket.activityid %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon"></a>[% else %][% if $ticket.type_name  %][% if  $ticket.icon_path && $ticket.icon_path != "" %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon"></a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon">[% /if %]</a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  class="type-icon"></a>[% /if %][% /if %][% /if %]
                                    [% /if %]
                                [% /if %]


                            <a href="index.php?module=ticket&event=show&id=[% $ticket.id %]" target="_blank">
                                [% $ticket.id %]
                            </a>


                            <span onclick="loadTicketIframe([% $ticket.id %]);">
                                [% $ticket.ticketdescr %]
                            </span>
                            <span class="legend prio[% $ticket.ticketprioid %]">[% $user->gettext($ticket.descr) %]</span>

                        </span>
                        <span class="float-end"> 

                            <span class="badge badge-error">[% $ticket.projectname %]</span>

                            [% foreach from= $ticket.tickettagarray item=TTag %]  
                                <span class="badge bg-secondary">[% $TTag %]</span>
                            [% foreachelse %]

                            [% /foreach %]
                            [%*
                            [% if $ticket.tickettag %]
                            <span class="badge bg-secondary">[% $ticket.tickettag %]</span>
                            [% else %]
                            <span class="badge bg-secondary">[% $user->gettext('Ohne Tag') %]</span>
                            [% /if %]
                            *%]
                            <span class="badge badge-inverse" id="aufwand_[% $ticket.id %]" title="[% $user->gettext('Erwarteter Aufwand (Minuten)') %]">[% $ticket.expexpense|default:0 %]</span>

                            [% foreach $ticket.supporters as $names %]
                                <span title="[% $names.name %]" class="badge badge-warning">[% $names.enc %]</span>
                            [% /foreach %]
                            [% if $user->hasRight(900) %]
                                <div class="btn-group" id="addToSprintBtn_[% $ticket.id %]">
                                    <a href="javascript: addTicketInSprint( [% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('In Sprint hinzufügen') %]"><span class="fa fa-check"></span></a>
                                    <a href="javascript: removeFromBl([% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('Aus Backlog entfernen') %]"><span class="fa fa-times"></span></a>
                                </div>
                                <div class="btn-group" style="display:none;" id="removeFromSprintBtn_[% $ticket.id %]">
                                    <a href="javascript: remove([% $ticket.id %]);" class="btn btn-outline-secondary btn-xs" title="[% $user->gettext('Aus Sprint entfernen') %]"><span class="fa fa-times"></span></a>
                                </div>
                            [% /if %]
                        </span>
                    </div>
                    [% if $ticket.isstory %]
                        <div class="StoryTickets" style="display:none;">
                            <br>
                            <br>

                            [% foreach $ticket.storytickets as $sticket %]
                                <div class='row' style="margin-top: 15px;" id="">
                                    <div class='col-sm-12'>
                                        <span class="pull-left">
                                            ----------- [% if $sticket.isstory %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.STORY_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STORY_ICON %]"  class="type-icon"></a>[% else %][% if $sticket.activityid %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $smarty.const.WF_NAME %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.WF_ICON %]"  class="type-icon"></a>[% else %][% if $sticket.type_name  %][% if  $sticket.icon_path && $sticket.icon_path != "" %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $sticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $sticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $ticket.icon_path %]"  class="type-icon"></a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $ticket.type_name %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.NO_ICON %]" class="type-icon">[% /if %]</a>[% else %]<a href= "index.php?module=ticket&amp;event=show&amp;id=[% $ticket.id %]" style="text-decoration:none;color: #333333;"><img title="[% $user->gettext('Standard Ticket') %]" src="index.php?module=upload&class=download&event=ShowImage&name=[% $smarty.const.STANDARD_ICON %]"  class="type-icon"></a>[% /if %][% /if %][% /if %]


                                            <a href="index.php?module=ticket&event=show&id=[% $sticket.id %]" target="_blank">
                                                [% $sticket.id %]
                                            </a>

                                            <span onclick="loadTicketIframe([% $sticket.id %]);">
                                                [% $sticket.ticketdescr %]
                                            </span>
                                            <span class="legend prio[% $sticket.ticketprioid %]">[% $user->gettext($sticket.descr) %]</span>

                                        </span>
                                        <span class="pull-left"> &nbsp;
                                            <span class="badge badge-error">[% $sticket.projectname %]</span>
                                            [% foreach from= $sticket.tickettagarray item=TTag %]  
                                                <span class="badge bg-secondary">[% $TTag %]</span>
                                            [% foreachelse %]

                                            [% /foreach %]
                                            [%*
                                            [% if $ticket.tickettag %]
                                            <span class="badge bg-secondary">[% $ticket.tickettag %]</span>
                                            [% else %]
                                            <span class="badge bg-secondary">[% $user->gettext('Ohne Tag') %]</span>
                                            [% /if %]
                                            *%]
                                            <span class="badge badge-inverse" id="aufwand_[% $sticket.id %]" title="[% $user->gettext('Erwarteter Aufwand (Minuten)') %]">[% $sticket.expexpense|default:0 %]</span>

                                            [% foreach $sticket.supporters as $names %]
                                                <span title="[% $names.name %]" class="badge badge-warning">[% $names.enc %]</span>
                                            [% /foreach %]
                                            [% if $user->hasRight(900) %]

                                            [% /if %]
                                        </span>                                          
                                    </div>
                                </div>
                            [% /foreach %]
                        </div>
                    [% /if %]
                </div>
            [% /foreach%]
        </div>
    </div>

</div>
</div>
</div>
    <div class='col-sm-5 col-12' id="IframeDiv" style="display:none;">
        <iframe style='min-width: 100%; height: 80vh !important;'  frameBorder="0" id='TicketIframe'></iframe>
    </div>

</div>

</div>
</div>
</form>
<script>
    var ticketsorder = [];
    var mainsprintsorder = [];
    [% foreach $PrepSprints as $PrepSprint %]
    var sprintsorder_[% $PrepSprint->ID %] = [];
    [% /foreach %]

    [% if $user->hasRight(900)%]
    $(".sortable").sortable(
            {
                start: function () {

                    $(".sortable").css('min-height', 50);
                    //   $(".NewSprintClass").collapse('show');


                },

                update: function (event, ui) {
                    if (this === ui.item.parent()[0]) {
                        var old_id = $(this).attr('id');
                        var new_id = ui.item.parent().attr('id');
                        var el = ui.item.attr('id');
                        var el_TicketID = el.split('_')[1];
                        if (!(old_id === 'TicketList' && new_id === 'TicketList')) {
                            if (old_id === 'TicketList') {
                                $('#addToSprintBtn_' + el_TicketID).hide();
                                $('#removeFromSprintBtn_' + el_TicketID).show();
                            }
                            if (new_id === 'TicketList') {
                                $('#addToSprintBtn_' + el_TicketID).show();
                                $('#removeFromSprintBtn_' + el_TicketID).hide();
                            }

                        }

                        console.log("NewID:" + new_id);

                        if (new_id.includes('NewSprintList')) {
                            removeAndAddDynamic(el_TicketID, new_id.split('_')[1]);
                        }

                        if (new_id === 'TicketList') {
                            removeAndAddDynamic(el_TicketID, 0);
                        }
                        if (new_id === 'SprintList') {
                            removeAndAddDynamic(el_TicketID, $("#sprintid").val());
                        }

                        var index = 1;
                        $("#TicketList").children().each(function () {
                            var currentElement = $(this);
                            // Show element
                            var ElementID = currentElement.attr('id');
                            var id = ElementID.split('_')[1];
                            ticketsorder.push({'index': index, 'id': id});
                            index++;

                        });



                        if (old_id === 'TicketList' || new_id === 'TicketList') {
                            $.post('index.php?module=backlog&event=changeTicketOrder', {data: JSON.stringify(ticketsorder), backlogid: $("#id").val()}, function (data) {
                                ticketsorder = [];
                            });
                        }

                        if (old_id === 'SprintList' || new_id === 'SprintList') {
                            console.log("Change SprintOrder");

                        }
                        if (new_id.includes('NewSprintList_')) {





                        }
                        $(".sortable").css('min-height', 0);
                        if ($(this).attr('id') === 'TicketList') {

                            // $(".NewSprintClass").collapse('hide');
                        }
                    }

                },
                connectWith: ".sortable"
            });
    [% /if %]
    [% if $user->hasRight(900)%]
    $("#table2  tr").draggable({
        start: function (event, ui) {
            $('.dropable').addClass('hightlightDropZone');
        },
        stop: function (event, ui) {
            $('.dropable').removeClass('hightlightDropZone');
        },
        helper: function () {
            var selected = $('tr.selectedRow');
            if (selected.length === 0) {
                selected = $(this).addClass('selectedRow');
            }
            var container = $('<div/>').attr('id', 'draggingContainer');
            container.append(selected.clone().removeClass("selectedRow"));
            return container;
        }
    });

    /**
     * Comment
     */
    function addTicketToSprint(tid) {
        $.post('index.php?module=backlog&class=sprint&event=addTicket', {tid: tid, sprintid: $("#sprintid").val()}, function (data) {
            if (data.error) {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout
                });
            } else {
                window.location = 'index.php?module=backlog&event=edit&id=' + $("#id").val();
            }
        });
    }

    $("#table1, .dropable").droppable({
        drop: function (event, ui) {
            var dropObj = (ui.draggable.attr("id")).split("_");
            /* DROP from Sprint to Backlog */
            if (dropObj[0] === 'S') {
                console.log("a");
            }
            /* DROP from Backlog to Sprint*/
            if (dropObj[0] === 'B') {
                SprintID = $(this).data('sprintid');
                if (SprintID > 0) {
                    $.post('index.php?module=backlog&class=sprint&event=addTicket', {tid: parseInt(dropObj[1]), sprintid: SprintID}, function (data) {
                        if (data.error) {
                            noty({
                                text: data.messages[0],
                                type: 'error',
                                timeout: notifyTimeout
                            });
                        } else {
                            window.location = 'index.php?module=backlog&event=edit&id=' + $("#id").val();
                        }
                    });
                }
            }
        }
    });
    [% /if %]
    $(document).on("click", "tr", function () {
        $(this).toggleClass("selectedRow");
    });
    $("#GroupIDs").select2({theme: 'bootstrap-5'}).on("select2:select", function (e) {
        console.log($("#GroupIDs").val());
        updateBl();
    }).on("select2:unselect", function (e) {
        console.log($("#GroupIDs").val());
        updateBl();
    });

    /**
     * Comment
     */
    function updateBl() {
        $.post('index.php?module=backlog&event=updateJSON', {name: $("#inputNameField").val(), groups: $("#GroupIDs").val(), id: $('#id').val()}, function (data) {
            var data = JSON.parse(data);
            if (data.error) {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout
                });
            } else {
                $('#blName').html($("#inputNameField").val());
                $("#staticName").show();
                $("#inputName").hide();

            }
        });
    }

    /**
     *
     */
    function orderUp(id) {
        console.log(id);
        $.post('index.php?module=backlog&event=orderup', {ticketid: id, backlogid: $("#id").val()}, function (data) {
            window.location = 'index.php?module=backlog&event=edit&id=' + $("#id").val();
        });
    }



    function removeFromBl(id) {
        bootbox.confirm("[% $user->gettext('Ticket aus Backlog wirklich entfernen?') %]", function (result) {
            if (result) {
                $.post('index.php?module=backlog&event=removeTicket', {id: id}, function (data) {
                    $("#row_" + id).detach();
                });
            }
        });

    }

    /**
     * Comment
     */
    function remove(TicketID, sprintID) {
        sprintID = sprintID || $('#sprintid').val();
        bootbox.confirm("[% $user->gettext('Ticket wirklich aus Sprint entfernen?') %]", function (result) {
            if (result) {
                $.post('index.php?module=backlog&class=sprint&event=removeTicket', {sprintid: sprintID, ticketid: TicketID}, function (data) {
                    var data = JSON.parse(data);
                    if (data.error) {
                        noty({
                            text: data.messages[0],
                            type: 'error',
                            timeout: notifyTimeout
                        });
                    } else {
                        window.location = 'index.php?module=backlog&event=edit&id=' + $("#id").val();
                    }
                    //w
                });
            }
        })
    }

    function removeAndAddDynamic(TicketID, SprintID) {


        $.post('index.php?module=backlog&class=sprint&event=removeTicket', {sprintid: SprintID, ticketid: TicketID}, function (data) {
            if (SprintID > 0) {
                addInSprintDynamic(TicketID, SprintID);
            }

        });


    }


    /**
     * Comment
     */
    function addToSprint() {
        var tickets = [];
        $('.sprintCB').each(function () {
            if ($(this).is(':checked')) {
                tickets.push((parseInt(($(this).attr('id')).substring(3))));
            }
        });
        if (tickets.length === 0) {
            alert('[% $user->gettext('Bitte wählen Sie mindestens ein Ticket zum Zufügen in Sprint.') %]');
        }
        if (parseInt($("#sprintSelect").val()) === 0) {
            alert('[% $user->gettext('Bitte wählen Sie ein Sprint.') %]');
        }
        $.post('index.php?module=backlog&class=sprint&event=addTickets', {ticketids: tickets, sprintid: $("#sprintSelect").val()}, function (data) {
            console.log(data);
        });
    }

    function switchInput(state) {
        if (state) {
            $("#inputName").show();
            $("#staticName").hide();
        } else {
            $.post('index.php?module=backlog&event=updateJSON', {name: $("#inputNameField").val(), id: $('#id').val()}, function (data) {
                var data = JSON.parse(data);
                if (data.error) {
                    noty({
                        text: data.messages[0],
                        type: 'error',
                        timeout: notifyTimeout
                    });
                } else {
                    $('#blName').html($("#inputNameField").val());
                    $("#staticName").show();
                    $("#inputName").hide();

                }
            });
        }
    }

    function changeAufwand(ticketid) {
        $('#staticAufwand_' + ticketid).hide();
        $('#inputAufwand_' + ticketid).show();
    }

    function cancelChangeAufwand(ticketid) {
        $('#staticAufwand_' + ticketid).show();
        $('#inputAufwand_' + ticketid).hide();
    }

    function saveAufwand(ticketid) {
        $.post('index.php?module=backlog&class=sprint&event=changeTExpexpense', {tid: ticketid, expense: $("#expense_" + ticketid).val()}, function (data) {
            var data = JSON.parse(data);
            if (data.error) {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout
                });
            } else {
                if ($("#expense_" + ticketid).val() < 0) {
                    $("#expense_" + ticketid).val(0);
                }
                $("#expenseVal_" + ticketid).html($("#expense_" + ticketid).val());
                $('#staticAufwand_' + ticketid).show();
                $('#inputAufwand_' + ticketid).hide();
            }

        });

    }

    function activate(SprintID) {
        $.post('index.php?module=backlog&class=sprint&event=activeSprint', {id: SprintID}, function (data) {
            var data = JSON.parse(data);
            if (!data.error) {
                location.reload();
            } else {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout      
                });
            }
        });
    }

    function toggleRow(TagHash) {
        $('.Tag_' + TagHash).toggle();
    }

    /**
     * 
     */
    $(document).ready(function () {
            $(".selectpicker").selectpicker({deselectAllText: 'Nichts auswählen', selectAllText: 'Alle auswählen'});

        // var iFrameHeight = $("#BacklogCol").height();
        // $("#TicketIframe").height(iFrameHeight);
    });
    function loadTicketIframe(TicketID) {
        console.log("iFrame von Ticket #" + TicketID + " wird geladen.");
        // var iFrameHeight = $("#BacklogCol").height();
        // $("#TicketIframe").height(iFrameHeight);
        $("#BacklogCol").removeClass('col-sm-12');
        $("#BacklogCol").addClass('col-sm-7');
        $("#IframeDiv").show();
        $("#TicketIframe").attr("src", "index.php?module=ticket&event=show&id=" + TicketID + "&InBacklog=1");

        // $("#row_"+TicketID).css('background-color', 'red');

    }

    /**
     * Comment
     */
    function closeAllIframe() {
        $("#BacklogCol").removeClass('col-sm-6');
        $("#BacklogCol").addClass('col-sm-12');
        $("#TicketIframe").attr("src", "");
        $("#IframeDiv").hide();
    }

    function addInSprintDynamic(TicketID, SprintID) {
        $.post('index.php?module=backlog&class=sprint&event=addTicket', {tid: TicketID, sprintid: SprintID}, function (data) {
            if (data.error) {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout
                });
            } else {
                var ListID = "";
                if ($("#sprintid").val() === SprintID) {
                    ListID = 'SprintList';
                } else {
                    ListID = 'NewSprintList_' + SprintID;
                }
                var MainSprintIndex = 1;

                $("#" + ListID).children().each(function () {
                    var currentElement = $(this);
                    // Show element
                    var ElementID = currentElement.attr('id');
                    var id = ElementID.split('_')[1];
                    mainsprintsorder.push({'index': MainSprintIndex, 'id': id});
                    MainSprintIndex++;

                });

                $.post('index.php?module=backlog&class=sprint&event=changeTicketOrder', {data: JSON.stringify(mainsprintsorder), sprintid: SprintID}, function (data) {
                    console.log(data);

                    mainsprintsorder = [];
                });


                noty({
                    text: data.messages[0],
                    type: 'success',
                    timeout: notifyTimeout
                });

            }
        });
    }

    /**
     * add
     */
    function addTicketInSprint(TicketID) {
        $.post('index.php?module=backlog&class=sprint&event=addTicket', {tid: TicketID, sprintid: $("#sprintid").val()}, function (data) {
            if (data.error) {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout
                });
            } else {
                noty({
                    text: data.messages[0],
                    type: 'success',
                    timeout: notifyTimeout
                });
                $('#addToSprintBtn_' + TicketID).hide();
                $('#removeFromSprintBtn_' + TicketID).show();

                $("#row_" + TicketID).detach().appendTo("#SprintList");

            }
        });
    }

    function addTicketInNewSprint(TicketID) {
        $.post('index.php?module=backlog&class=sprint&event=addTicket', {tid: TicketID, sprintid: $("#newsprintid").val()}, function (data) {
            if (data.error) {
                noty({
                    text: data.messages[0],
                    type: 'error',
                    timeout: notifyTimeout
                });
            } else {
                noty({
                    text: data.messages[0],
                    type: 'success',
                    timeout: notifyTimeout
                });
                $('#addToSprintBtn_' + TicketID).hide();
                $('#removeFromSprintBtn_' + TicketID).show();

                $("#row_" + TicketID).detach().appendTo("#NewSprintList");

            }
        });
    }

    /**
     * Comment
     */
    function remove(TicketID, sprintID) {
        sprintID = sprintID || $('#sprintid').val();
        bootbox.confirm("[% $user->gettext('Ticket wirklich aus Sprint entfernen?') %]", function (result) {
            if (result) {
                $.post('index.php?module=backlog&class=sprint&event=removeTicket', {sprintid: sprintID, ticketid: TicketID}, function (data) {
                    var data = JSON.parse(data);
                    console.log(data);
                    if (data.error) {
                        noty({
                            text: data.messages[0],
                            type: 'error',
                            timeout: notifyTimeout
                        });
                    } else {
                        noty({
                            text: data.messages[0],
                            type: 'success',
                            timeout: notifyTimeout
                        });
                        $('#addToSprintBtn_' + TicketID).show();
                        $('#removeFromSprintBtn_' + TicketID).hide();

                        $("#row_" + TicketID).detach().appendTo("#TicketList");
                    }
                    //w
                });
            }
        })
    }

    /**
     * Comment
     */
    function updateAufwandTicket(ticketid, aufwand) {
        $("#aufwand_" + ticketid).html(aufwand);
    }

    $(document).ready(function () {
        $(".StoryTickets").hide();
    });

    /**
     * toggleStoryTickets
     */
    function toggleStoryTickets() {
        var isCheck = $("#StoryTicketCB").is(':checked');
        console.log(isCheck);
        if (isCheck) {
            $(".StoryTickets").show();
        } else {
            $(".StoryTickets").hide();
        }


    }
    
</script>
