<?php $__env->startSection('content'); ?>
<style type="text/css" media="screen">
	.btn-custom{  
		width: 150px;  
    } 

    .table-btn td{
        padding:10px;
    }
</style>

    <div class="input-prepend input-append">
    </div>
    <h4 class="nametag"><?php echo e(trans($_CONST["LANG_DEST"].".title")); ?></h4>
	<br><br><br>
    <?php echo Form::open(array(  'class'=>'form-horizontal well')); ?>

    <div class="input-group">
        <span class="input-group-addon"><?php echo e(trans($_CONST["LANG_DEST"].".select_class")); ?>：</span>
        <?php echo Form::select('id', $categories, $cid, array('class' => 'form-control') ); ?>

    </div>
    <?php echo Form::close(); ?>

	<hr>

		<div class="row">	
            <div class="col-xs-8 col-sm-8 col-md-8">
                <table class="table-btn">
                    <tr><td>
                    <a  href="<?php echo route($_CONST["CONTROLLER_ROUTE"].'.create', 'category='.$cid); ?>" class="btn btn-primary btn-custom" style="margin-top:10px">
                        <span class="glyphicon glyphicon-file"></span>
                            新增
                    </a>
                    </td></tr>
                </table>
			</div>

			<div class="col-md-4 col-sm-4 col-xs-4 pull-right" style="margin-top:10px">
				<div class="input-group">
					<input type="text" class="form-control" placeholder="Product's name" id="search_input">
					<span class="input-group-btn">
						<button class="btn btn-default" type="button" name="search">Seach</button>
					</span>
				</div>
			</div>

		</div>
		<hr>

    <table class="table table-bordered" id="product-table" style="word-break:break-all">
		<thead>
			<tr><th>發佈</th><th>分類</th><th>商品ID</th><th>品名</th><th>產品描述</th><th>Name</th><th>Description</th><th>價格</th><th style="width:100px">圖片</th><th style="width:180px">功能按鈕</th></tr>
		</thead>
		<tbody>
        <?php foreach($products as $product): ?> 
        <tr data-id=<?php echo $product->id; ?> >
		<td>
                    <?php if($product->publish): ?>
                    <a href="<?php echo action($_CONST["CONTROLLER_ACTION"].'@getDisable', $product->id); ?>" class="btn btn-success" ><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></a>
                    <?php else: ?>
                    <a href="<?php echo action($_CONST["CONTROLLER_ACTION"].'@getEnable', $product->id); ?>" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
                    <?php endif; ?>
		</td>
            <td style="width:129px font-size:12px"><?php echo $categories[$product->category_id]; ?></td>
            <td style="width:129px font-size:12px"><?php echo $product->id; ?></td>
            <td style="width:129px font-size:12px" id="td_pro_title"><?php echo $product->title_tw; ?></td>
            <td style="width:129px font-size:12px"><?php echo $product->description_tw; ?></td>
            <td style="width:129px font-size:12px" id="td_pro_title"><?php echo $product->title_en; ?></td>
            <td style="width:129px font-size:12px"><?php echo $product->description_en; ?></td>
		    <td style="width:100px font-size:12px"><?php echo $product->price; ?></td>
            <td style="width:129px font-size:12px"><?php echo HTML::image($product->img_path,"",['style'=>'width:100px;height:100px']); ?></td>
            <td style="width:100px font-size:12px">
                <?php echo Form::open(array(
                    'route'=>array('admin.product.destroy', $product->id),
                    'method' => 'delete')
                ); ?>

                <a href="<?php echo route('admin.product.edit', $product->id); ?>" class="btn btn-primary">
                    <span class="glyphicon glyphicon-pencil"></span>
                    編輯
                </a>

                <a href="#" onclick="if (confirm('<?php echo trans('Myadmin::layout.whether_to_delete'); ?>'))$(this).closest('form').submit()" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove"></span>
                    刪除
                </a>
                <?php echo Form::close(); ?>

            </td>

        </tr>
        <?php endforeach; ?>
		<input type="hidden" value="" class="id-change"></input>
		</tbody>
    </table>


    <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
            var base_url = "<?php echo route('admin.product.index'); ?>";
			var c_array = [];
			var unique;

            $("#search").click(function(){
                var redirect = base_url+'/'+$("input[name=search]").val();
                window.location.href = redirect;
            });

            $("select[name=id]").change(function(){
                var t = $("select[name=id]").val();
                var base_url = "<?php echo route($_CONST["CONTROLLER_ROUTE"].".index"); ?>";
                if (t==0) {
                    var target = base_url;
                }else {
                    var target = base_url + '/' + t;
                }
                window.location = target;
            });

			$("#search_input").keyup(function(){
				// When value of the input is not blank
				if( $(this).val() != ""){
				// Show only matching TR, hide rest of them
			 		$("#product-table tbody>tr").hide();
					$("#product-table #td_pro_title:contains-ci('"+$(this).val()+"')").parent("tr").show();
		 		}
		 		else{
			 		// When there is no input or clean again, show everything back
			 		$("#product-table tbody>tr").show();
		 		}
			});

        });

		$.extend($.expr[":"],
		{
			"contains-ci": function(elem, i, match, array)
			{
				return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
			}
		});
    </script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('Myadmin::layout.basic', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>