{extends "../frame.tpl"}

{block body_class}class="panel_frame"{/block}

{block title}
    Pokladna
{/block}

{block tabs}
    {windowTab id='flapStock' label="Náhled do skladu"}
{/block}

{block css append}
    <style>
        .ui-widget-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
        .ui-front {
            z-index: 100;
        }
    </style>
{/block}

{block content}
<div class="container-fluid">

    <input type="hidden" class="err-str" value="{$err_str}">

    <div id="dialog_print_iframe" title="Tisk">
        <iframe id="print_iframe" class='on-demand boxFlex' style="height:510px; width:1050px;" src="about:blank"></iframe>
    </div>


        <div class="row bottom-space">
            <div class="col-md-12">
                <h1 class="h4 main-panel-title">Nahlédnutí do skladu</h1>
            </div>
            <div class="col-md-7">
                <input type="text" name="product_stock" id="product_stock" class="form-control input-sm id_product" placeholder="Produkt.." size="2" maxlength="255" onkeypress="checkInputData('int');" />
            </div>
            <div class="col-md-1" id="delete-icon" style="display:none;">
                    <button id="delete-button" title="Odstranit položku"
                    class="btn btn-sm btn-danger deleteItem"><span
                        class="glyphicon glyphicon-remove"></span></button>
            </div>
        </div>

        <div class="panel">
            <div class="panel-heading" style="padding-bottom:4px">
                <div class="row">
                    <div class="col-md-5">
                        <small><strong>Název produktu</strong></small>
                    </div>
                    <div class="col-md-3">
                        <small><strong>EAN</strong></small>
                    </div>
                    <div class="col-md-2">
                        <small><strong>Skladem {* / fyzicky skladem *}</strong></small>
                    </div>
                    <div class="col-md-2 text-center">
                        <small><strong>Tisk štítků</strong></small>
                    </div>
                </div>
            </div>
            <div class="panel" id="stock">
                <div class="panel-heading" id="products" >
                    {foreach $products as $product}
                        <div class="row">
                            <div class="col-md-5 name">
                                <a href="javascript:nw('product', '{$product.id_product}');">
                                    <strong>{$product.title}</strong>
                                </a>

                                {if $module.PRODUCTS__NOTE}
                                    <br>
                                     Pozn: <strong>
                                            {$product.note}
                                    </strong>
                                {/if}
                            </div>
                            <div class="col-md-3 ean">
                                {$product.ean}
                            </div>
                            <div class="col-md-2 pieces">
                                {$product.in_store + $product.piecesOrdered}
                            </div>
                            <div class="col-md-2 text-center">
                                <a href="launch.php?s=printCenter.php&type=order&set=Products&IDs[0][idp]={$product.id_product}&IDs[0][idv]={$product.id_variation}&IDs[0][pcs]=10" class="print-product"><span class="btn glyphicon glyphicon-barcode"> </span></a>
                            </div>
                        </div>
                    {/foreach}
                </div>
            </div>
    </div>

 </div>
{/block}

{block windowButtons}
{/block}

{*{if !empty($display)}*}
    <script type="text/javascript">
        {block onready append}
        $(document).on('click', '.print_invoice', function() {
            $("#dialog_print_iframe").dialog('open');
        });

        $(document).on('click', '.print-product', function() {
            $("#print_iframe")[0].contentWindow.location.href = $(this).attr('href');
            $("#dialog_print_iframe").dialog('open');
            return false;
        });

        $( "#dialog_print_iframe" ).dialog(
                {
                    dialogClass: "no-close",
                    autoOpen: false,
                    width: 1100,
                    height: 600,
                    title: "Tisk faktury",
                    resizable: false,
                    modal: true,
                    draggable: false
                }
        );


        function checkInputDataType(type, event)
        {
            if (!event)
                return;

            if(type == 'int')
            {
                if((event.which < 48 || event.which > 57) && event.which != 13 && event.which != 8 && event.which != 9) { //&& event.which != 13 && (event.which < 96 || event.which > 105)) {
                    event.preventDefault();
                }
            }
        }

        var $product_stock = new $.wpjAutoComplete({
            input: "#product_stock",
            type:'product_id',
            source: './launch.php?s=autocomplete.php&limit=50&visible=0'
        });

        $product_stock.inputHidden.bind( "autocompleteselect", function(event, ui) {
            var id_product = ui.item.value;
            findProducts(id_product, '');
        });

        function findProducts(id_product, ean){
            $('#stock').load('launch.php?s=pos.store.php&acn=edit #products', { id_product:  id_product, ean: ean }, function(response, status) {
                if (status == "success") {
                    showRemoveButton();
                    showErrorFromResponse(response);
                }
            });
        }


        $(document).on('click', '#delete-button', function() {
                $('#stock').empty();
                $('.id_product').val('');
                hiddenRemoveButton();
        });

        $(document).on('click', '.id_product', function() {
            $(this).val("");
            // TODO: dodelat smazani selectu
        });

        function showRemoveButton(){
            $('#delete-icon').css("display","inline");
        }

        function hiddenRemoveButton(){
            $('#delete-icon').css("display","none");

        }



        function showErrorFromResponse(response){
            showInfoPanel($(response).find('.err-str').val());
        }

        function showInfoPanel(str){
            var infoRow =
                    "<div class=\"row static\">" +
                    " <div class=\"alert autoclose alert-success alert-dismissable fade in\">" +
                    " <button type=\"button\" class=\"close\" data-dismiss=\"alert\">" +
                    "<span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>"+
                    "<span class=\"glyphicon glyphicon-ok\"></span>" +
                    "<strong>"+str +"</strong>" +
                    "</div>"+
                    "</div>";

            $(".container-fluid").prepend(infoRow);
            setTimeout(function(){
                $(".alert.autoclose").alert("close")
            }, 2000);
            //
        }

        $(".alert.autoclose").mouseover(function(e){
            $(this).hide()
        });


        {/block}
    </script>
{*{/if}*}
